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

Network.LibP2P.Protocol.GossipSub.Message

Description

GossipSub RPC message encoding/decoding (protobuf).

Wire format from docs/11-pubsub.md: Message framing: [uvarint length][protobuf RPC] RPC fields: subscriptions(1), publish(2), control(3) SubOpts: subscribe(1), topicid(2) Message: from(1), data(2), seqno(3), topic(4), signature(5), key(6) ControlMessage: ihave(1), iwant(2), graft(3), prune(4) ControlIHave: topicID(1), messageIDs(2) ControlIWant: messageIDs(1) ControlGraft: topicID(1) ControlPrune: topicID(1), peers(2), backoff(3) PeerInfo: peerID(1), signedPeerRecord(2)

Uses proto3-wire, same pattern as DHTMessage.hs and RelayMessage.hs.

Synopsis

Protobuf encode/decode (no framing)

encodeRPC :: RPC -> ByteString Source #

Encode an RPC message to protobuf (no framing).

decodeRPC :: ByteString -> Either ParseError RPC Source #

Decode an RPC from raw bytes.

Sub-message encode/decode (exported for testing)

encodePubSubMessage :: PubSubMessage -> MessageBuilder Source #

Encode a PubSubMessage sub-message.

decodePubSubMessage :: ByteString -> Either ParseError PubSubMessage Source #

Decode a PubSubMessage from raw bytes.

encodeControlMessage :: ControlMessage -> MessageBuilder Source #

Encode a ControlMessage sub-message.

decodeControlMessage :: ByteString -> Either ParseError ControlMessage Source #

Decode a ControlMessage from raw bytes.

Wire framing (uvarint length prefix)

encodeFramed :: RPC -> ByteString Source #

Encode an RPC with uvarint length prefix.

decodeFramed :: Int -> ByteString -> Either String RPC Source #

Decode an RPC from uvarint-length-prefixed bytes.

Serialization helpers

encodePubSubMessageBS :: PubSubMessage -> ByteString Source #

Encode a PubSubMessage to ByteString (used for signature computation).

Stream I/O helpers

writeRPCMessage :: StreamIO -> RPC -> IO () Source #

Write a framed RPC to a stream.

readRPCMessage :: StreamIO -> Int -> IO (Either String RPC) Source #

Read a framed RPC from a stream.