Can you explain how federation works on protocol level?
Can you explain how federation works on protocol level?
Let's say we have lemmy instances A, B, C.
alice from A makes a post "Hello, world" to B. What happens? How is it processed on servers A, B, C and how do users from A, B, C receive her post?
Alice can't make a post to B, but I assume you mean a community on B, let's call it foo. When Alice makes a post it first goes through A's local API and creates the local (and canonical) version of Alice's post. Once A has finished processing Alice's post, it will create an ActivityPub representation of Alice's post to send to B.
ActivityPub is basically a bunch of assumptions laid on top of JSON. An ActivityPub 'file' can be divided into broadly 3 types,
Object
,Activity
and actors.[^note1] These types then have subtypes; for example, both Alice and foo are actors but Alice is aPerson
while foo is aGroup
.A second important assumption of ActivityPub is the concept of inboxs and outboxs, but, for Lemmy, only inboxs matter. An inbox is just a URL where Lemmy can send activities and it's something all actors have.
So when instance A is finished processing Alice's post, it will turn it into a
Page
object, wrap that in aCreate
activity and send it foo's inbox.:::spoiler Round about what the JSON would look like
:::
.
Now instance B will then receive this and do the same kind of processing A did when Alice created the post via the API. Once it has finished, it will turn the post back into a
Page
but this time wrap it in anAnnounce
activity. B will then look at all the actors that follow the foo (i.e. are subscribed to it) and send this Announce to all of their inboxs. Assuming a user on instance C follows foo, it will receive thisAnnounce
and process it like A and B before it, creating the local version of Alice's post.Edit: I made a small mistake, I said that foo wrapped the
Page
in anAnnounce
, when it actually wraps theCreate
in anAnnounce
.[^note1]: Technically,
Activity
and actors are themselves objects, but they're treated differently. There's alsoCollection
's which are their own type, but Lemmy doesn't really utilise them.Thank you, very clear.
So B will list all users subscribed to foo, look at their instances, and send the update to them.
I assume that if someone from a new instance (D) subscribes to foo, then D will need to request all the old posts from foo, since they weren't pushed to D?
Lemmy is pretty bad about backfilling content. Communities do have outboxs, but these only list the last 50 posts and you can't get the vote or comments on any of them. See GitHub issues #5283, #3448 and #2004.
ActivityPub works like a magazine subscription. They don't send you back issues for subscribing.
Why does a mastodon user get completely different profiles and history when viewed from different lemmy instances? They look like 2 completely different users when compared except for having the same @address. In fact this makes them immune from moderation if they comment from a different instance than the mod is on.
Mastodon doesn't have
Group
support (fep-1b12), so when they reply to a post, they don't send it to the community's inbox (only to the inbox of thePerson
they're replying to), thus breaking Lemmy's model of federation.Does ActivityPub really send copies of all activities to www.w3.org?
No, the
https://www.w3.org/ns/activitystreams#Public
is just there to indicate that it's ok for receiving instances to display this publicly, nothing actually gets sent to it. See the spec for more details.