libp2p-hs-0.1.0.0: Haskell implementation of the libp2p networking stack
Safe HaskellNone
LanguageGHC2021

Network.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

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 -> IO () Source #

Handle an inbound GossipSub stream.

Reads framed RPCs in a loop and dispatches each to the Router's handleRPC. On error or EOF, cleans up the peer's cached stream and removes the peer.

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 protocol ID.