| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
LibP2P.Protocol.GossipSub.Handler
Description
GossipSub Switch integration handler (Phase 10b).
Bridges the GossipSub Router with the Switch by: 1. Registering a StreamHandler for inbound meshsub1.1.0 streams 2. Providing a sendRPC callback that opens/reuses outbound streams 3. Managing lifecycle (heartbeat start/stop)
GossipSub maintains persistent bidirectional RPC streams, unlike Identify/Ping which are one-shot. Each peer has at most one cached outbound stream.
Synopsis
- data GossipSubNode = GossipSubNode {
- gsnRouter :: !GossipSubRouter
- gsnSwitch :: !Switch
- gsnHeartbeat :: !(TVar (Maybe (Async ())))
- gsnStreams :: !(TVar (Map PeerId StreamIO))
- newGossipSubNode :: Switch -> GossipSubParams -> IO GossipSubNode
- handleGossipSubStream :: GossipSubNode -> StreamIO -> PeerId -> PeerProtocol -> Maybe ByteString -> IO ()
- sendCurrentSubscriptions :: GossipSubNode -> StreamIO -> IO ()
- startGossipSub :: GossipSubNode -> IO ()
- stopGossipSub :: GossipSubNode -> IO ()
- gossipJoin :: GossipSubNode -> Topic -> IO ()
- gossipLeave :: GossipSubNode -> Topic -> IO ()
- gossipPublish :: GossipSubNode -> Topic -> ByteString -> IO ()
- gossipSubProtocolId :: ProtocolId
- gossipSubProtocolIdV10 :: ProtocolId
- floodSubProtocolId :: ProtocolId
Types
data GossipSubNode Source #
A GossipSub node: Router + Switch integration.
Constructors
| GossipSubNode | |
Fields
| |
Construction
newGossipSubNode :: Switch -> GossipSubParams -> IO GossipSubNode Source #
Create a new GossipSub node with a Router wired to the Switch.
The Router's gsSendRPC callback opens/reuses outbound streams to peers via the Switch's connection pool.
Stream handling
handleGossipSubStream :: GossipSubNode -> StreamIO -> PeerId -> PeerProtocol -> Maybe ByteString -> IO () Source #
Handle an inbound GossipSub stream.
Reads framed RPCs in a loop and dispatches each to the Router's handleRPC. The peer's negotiated protocol version gates v1.1 control extensions. On error or EOF, cleans up the peer's cached stream and removes the peer.
sendCurrentSubscriptions :: GossipSubNode -> StreamIO -> IO () Source #
Send current topic subscriptions to a newly connected peer. This ensures peers joining after we've already subscribed still learn about our subscriptions (standard GossipSub behavior). Writes directly to the stream to avoid any routing issues.
Lifecycle
startGossipSub :: GossipSubNode -> IO () Source #
Start the GossipSub node: register stream handler, notifier, and start heartbeat.
stopGossipSub :: GossipSubNode -> IO () Source #
Stop the GossipSub node: cancel heartbeat and unregister handler.
Convenience API
gossipJoin :: GossipSubNode -> Topic -> IO () Source #
Subscribe to a topic.
gossipLeave :: GossipSubNode -> Topic -> IO () Source #
Unsubscribe from a topic.
gossipPublish :: GossipSubNode -> Topic -> ByteString -> IO () Source #
Publish a message to a topic (signed with the Switch's identity key).
Constants
gossipSubProtocolId :: ProtocolId Source #
GossipSub v1.1 protocol ID (preferred).
gossipSubProtocolIdV10 :: ProtocolId Source #
GossipSub v1.0 protocol ID, advertised alongside v1.1 so that v1.0-only peers still get a pubsub stream (#157).
floodSubProtocolId :: ProtocolId Source #
FloodSub protocol ID, advertised alongside the meshsub protocols so that floodsub-only peers still get a pubsub stream (#157, gossipsub-v1.0.md "Compatibility with FloodSub").