Offshore Rock

The Relay Lighthouse

ja· en· ko
If you're new hereA relay-server mechanism that delivers letters to many islands in one batch.

You connect small islands to one another all at once. Instead of writing letter by letter to each one, subscribe to a lighthouse and the sea's news arrives in a batch. For a sparsely populated island, whether a relay exists changes the whole experience of federation—and this is the kit for building that lighthouse yourself.

Offshore there are two styles, Mastodon and LitePub, and their subscription handshakes differ slightly. So this lighthouse wears both faces at once.

Highlights

  • Both subscribing and unsubscribing are the Follow handshake (follow.ts)—the lighthouse, too, is an actor.
  • Both styles come with tests (mastodon.test.ts / litepub.test.ts).
  • About 2,900 lines. A lighthouse kit for any island that wants to build its own relay server.

A passage from the sutra

export function createRelay(
  type: RelayType,
  options: RelayOptions,
): Relay {
  switch (type) {
    case "mastodon":
      return new MastodonRelay(options, relayBuilder);
    case "litepub":
      return new LitePubRelay(options, relayBuilder);
  }
}
packages/relay/src/factory.ts L26-L36— The fork between the two styles

Floor plan

packages/relay/src/factory.ts
createRelay()—the fork between styles
packages/relay/src/mastodon.ts
The Mastodon-style relay
packages/relay/src/litepub.ts
The LitePub-style relay
packages/relay/src/follow.ts
The Follow handshake (subscribe/unsubscribe)

Neighboring rooms

Outside links