Draft
Conversation
zelig
reviewed
Apr 16, 2026
| defer bc.mu.Unlock() | ||
|
|
||
| for _, sub := range bc.subscribers { | ||
| msg := bc.mode.FormatBroadcast(bc, sub, rawMsg) |
Member
There was a problem hiding this comment.
I dont think this is needed inside the fanout loop. Why would you reserialise for every subscriber?
Member
Author
There was a problem hiding this comment.
the message serialization varies between subscribers e.g. one of them did not get the SOC ID and address for message verification, another subscriber already got it. Then, these metadata will be either attached or not in the message payload.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pubsub
A brokered publish/subscribe protocol over Bee's p2p layer, exposed to end-users via WebSocket.
Overview
One node acts as a broker: it accepts p2p streams, validates incoming messages, and fans them out to all connected receivers. Other nodes connect as either a publisher (publish + receive) or a subscriber (receive only).
Connection flow
The connecting node receives a
SubscriberConnwhichws.gobridges to the WebSocket: inbound WS frames are forwarded to the p2p stream (publishers only); p2p frames from the broker are decoded and forwarded to the WS client (all connections).Mode system
Protocol-specific behaviour is isolated behind a
Modeinterface. TheServiceis mode-agnostic: it delegates header construction, message reading/validation, and broadcast formatting to the active mode. New protocol variants can be added by implementingModeand registering a mode ID innewMode.GSOC Ephemeral mode (mode 1)
Messages are Single Owner Chunks (SOC) signed by the holder of the topic's private key. The topic address is derived from the SOC owner public key and an arbitrary topic ID, so only the key holder(s) can publish and the messages have the same SOC wrapping (except the SOC signatures).
Publisher → Broker (p2p)
The broker verifies the ECDSA signature on every message before broadcasting.
Broker → Subscriber (p2p)
0x01[SOC ID: 32 B][owner: 20 B][sig: 65 B][span: 4 B][payload: N B]0x02[sig: 65 B][span: 4 B][payload: N B]The handshake frame (identity metadata) is sent once per topic on the first broadcast. Subsequent messages are data-only.
WebSocket (both directions)
Both the publisher (inbound) and subscriber (outbound) see the raw SOC payload:
The node handles all p2p framing and signature verification transparently.
Extensibility
Modefor a different message format and register a mode ID.ValidatePublishercan enforce allow-lists, stake checks, or capability tokens.broadcastToSubscriberscan write to a store;handleSubscribercan replay on connect.FormatBroadcastreceives the individualbrokerSubscriber, enabling selective filtering or transformation.Checklist
Description
Open API Spec Version Changes (if applicable)
Motivation and Context (Optional)
Related Issue (Optional)
Screenshots (if appropriate):
AI Disclosure