Which feeds are replicated, and what does that mean?
By default, your client will replicate the feeds you follow, and all the feeds that they follow. That is, whenever your client can get its hands on their updates, it will store them, ready to be displayed to you and forwarded to anyone who asks.
To do so, your client will contact any peer it thinks might have such updates, if it can reach it. If the clients are on the same WiFi as you, that's easy. If you are on different networks and cannot establish a direct connection, then someone has to "bounce" the information. This task is solved by two different mechanisms at the moment: pubs and rooms.
What is a pub?
A pub is "just another ssb peer" once you speak to it, but it is different in some ways before that:
First, it announces itself as being a pub. Here is the message that my pub made.
{
"type": "pub",
"address": {
"key": "@93JiSXW2dUogOnNJADVGKkNAjZJ1whw7nU0r/VIL1zE=.ed25519",
"host": "muchmuch.coffee",
"port": 8008
}
}
As you can see, this is mostly just an invitation to talk. Anyone on the internet can connect to it it with the information in that message and exchange updates. The info needed is of course the address and port, but also the ID of the feed, because the "secret handshake" protocol that is used to exchange updates requires the "caller" to know the ID of the "callee". Of course, if you see this message on the pub's feed, you already know its ID, so that's quite redundant here.
The second way that pubs differ from other peers is that they usually distribute invites in some way. Some pubs do so with a web interface where you can copy the invite or scan it as a QR code. Others even put the invite in their own profile description here on ssb. Yet others are "private" pubs (like I happen to run one) where invites are handed around by hand, just to facilitate the replication of feeds I'm interested in.
What does "accepting an invite" actually do?
When I use an invite to join a pub, your local client will request the pub to follow me. This is called "accepting an invite."
Once my client sees that the pub is following me, it will publish two messages, in this order:
{
"type": "pub",
"address": {
"host": "muchmuch.coffee",
"port": 8008,
"key": "@93JiSXW2dUogOnNJADVGKkNAjZJ1whw7nU0r/VIL1zE=.ed25519"
}
}
{
"type": "contact",
"contact": "@93JiSXW2dUogOnNJADVGKkNAjZJ1whw7nU0r/VIL1zE=.ed25519",
"following": true,
"autofollow": true
}
Whether the second message is a good idea is the topic of some debate, but for now at least patchwork does it like this. It simply follows the pub, meaning that now everyone who used an invite on this pub will be in my "two hops" distance. This means that my client will immediately start downloading all the feeds of all the people "on" this pub. Depending on how many feeds those are, that can keep my machine busy for quite a while, and pollute my drive with a lot of unneeded or even undesirable data from perfect strangers. Hence the controversy.
But the first message is actually more important here: it announces to anyone who can see my feed already: "Hey, if you need updates from me but cannot reach me directly, here's a place to get them that should be reachable most of the time." And here again, you see the address and port, and the feed ID of the pub. This time around this is actually super important, because as I said before, the feed ID is needed to establish a secure connection to the pub.
Now, let's say you follow my feed. You probably have some reason to do so. Let's assume for now that you came across one of my posts in a thread or such. In this case, the moment you follow me, you already have a full copy of my feed up until now, including that first message announcing that "pub X follows me." Your client can now connect to my pub anytime it wants and ask for updates.
However, if your reason to follow my feed is that someone on the web told you to install patchwork and paste my ID into the search bar, you may well end up in the situation I described before: an empty page of a feed that you follow, but your client has no way to retrieve the data of my feed. This is because without my feed being stored locally, there is no indication as to which publicly-reachable peers could give you an update. To resolve this situation of an empty page, there are currently three possibilities:
First, your client can contact a pub that replicates my feed for some other reason than my feed. The replication should work even if your client has no idea that this pub replicates me, and just contacts the pub to get updates on some other feed where it does know that this pub will have updates. In that case you'd get all updates for my feed from the pub and that's it, from then on your client knows that it can get my updates on that pub (and potentially other pubs that are also announced in my feed).
Second, you could be on the same WiFi as someone who has my feed. In that case, connecting to them is easy, and again you'd download my feed, then be aware of all pubs that replicate me.
Third, you could be in the same room as someone who has my feed.
What is a room?
A room, like a pub, is usually publicly reachable on the internet.
To "get into" a room you will use a similar invite mechanism as for pubs.
However, the room will not follow your feed, and so your client will also not announce the room with a message. Your client and the room server simply both make an internal note that yes, you successfully entered the room and are authorized to do so again at your convenience.
The room now simply works as a relay. It "simulates" being on the same WiFi as other peers in the same room. So they become "possible connections" in your left sidebar in patchwork, and you can click to connect to them. If you do, the gossip exchanged between you and those peers will pass through the room server, allowing you to connect even if you're both behind NAT or such. From there the replication happens as before: once you connect, your client asks if the other side has any updates on the feeds you follow. "Oh yeah, there's this feed @MRiJ+CvDnD9Z...
that I'm following, but I'm at sequence number 0." "No problem" the other side says, "I'm at sequence number 5466, here , take the whole load."
And from that point on your client will also know all the pubs to connect to.
Crucially, while all this gossiping passes through the room server, the server itself can actually not read any of it. It simply shuffles encrypted bytes back and forth between your client and the other side.
Also, in addition to getting the list of all pubs, your client will now know that that other client replicates me, and is reachable in that room. So it can go back to that room anytime and if the other side is online too, then they can exchange updates again.