Topic-based publish/subscribe — a GossipSub implementation over PeerNetwork. More...
#include "node/peer_network.h"#include "peer/peer.h"#include "core/bytes.h"#include "peer/peer_id.h"#include <atomic>#include <chrono>#include <condition_variable>#include <cstdint>#include <deque>#include <functional>#include <mutex>#include <random>#include <string>#include <thread>#include <unordered_map>#include <unordered_set>#include <utility>#include <vector>Go to the source code of this file.
Classes | |
| class | librats::PubSub |
| struct | librats::PubSub::Config |
| GossipSub tuning. More... | |
Namespaces | |
| namespace | librats |
Enumerations | |
| enum class | librats::ValidationResult { librats::Accept , librats::Reject , librats::Ignore } |
| Outcome of validating an inbound published message before it is delivered or forwarded. More... | |
Topic-based publish/subscribe — a GossipSub implementation over PeerNetwork.
This is the real GossipSub, not plain floodsub. Each subscribed topic maintains a bounded mesh of full-message peers (formed and torn down with GRAFT/PRUNE), published messages are eagerly pushed along the mesh, and a lazy-pull gossip layer (IHAVE/IWANT, driven by the heartbeat) lets a peer recover a message it missed. Publishing to a topic we are not subscribed to uses a short-lived fanout set instead of a mesh. A node-id+sequence dedup key stops a message looping around the mesh, and a message cache keeps recent payloads so IWANT can be answered with real content.
It depends on nothing but PeerNetwork — no Node, no reactor internals, no friend. A background heartbeat thread (started by start(), joined by stop()) runs mesh maintenance and gossip emission once per interval.
Wire format (MessageType::Gossip payload), all integers big-endian. The first byte is the op; a 40-byte message id is origin(32 id-bytes) || seqno(u64 BE): PUBLISH [0][origin:32][seqno:u64][topic_len:u16][topic][data] SUBSCRIBE [1][topic_len:u16][topic] UNSUBSCRIBE [2][topic_len:u16][topic] GRAFT [3][topic_len:u16][topic] // "add me to your mesh for topic" PRUNE [4][topic_len:u16][topic] // "drop me from your mesh for topic" IHAVE [5][topic_len:u16][topic][count:u16][id:40]* // "I hold these message ids" IWANT [6][count:u16][id:40]* // "send me these message ids"
Definition in file pubsub.h.