| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
LibP2P.Protocol.GossipSub.Types
Description
GossipSub core types and parameters (specspubsubgossipsub).
Protocol ID: meshsub1.1.0
GossipSub constructs two overlapping overlay networks per topic: a full-message mesh (eager push, degree D=6) and a metadata-only gossip layer (lazy push via IHAVE/IWANT). This module defines all wire types, configuration parameters, per-peer state, and the router state record.
Synopsis
- gossipSubProtocolId :: Text
- gossipSubProtocolIdV10 :: Text
- floodSubProtocolId :: Text
- maxRPCSize :: Int
- type Topic = Text
- type MessageId = ByteString
- data PubSubMessage = PubSubMessage {
- msgFrom :: !(Maybe ByteString)
- msgData :: !ByteString
- msgSeqNo :: !(Maybe ByteString)
- msgTopic :: !Topic
- msgSignature :: !(Maybe ByteString)
- msgKey :: !(Maybe ByteString)
- data SubOpts = SubOpts {
- subSubscribe :: !Bool
- subTopicId :: !Topic
- data ControlMessage = ControlMessage {}
- data IHave = IHave {
- ihaveTopic :: !Topic
- ihaveMessageIds :: ![MessageId]
- data IWant = IWant {
- iwantMessageIds :: ![MessageId]
- data Graft = Graft {
- graftTopic :: !Topic
- data Prune = Prune {
- pruneTopic :: !Topic
- prunePeers :: ![PeerExchangeInfo]
- pruneBackoff :: !(Maybe Word64)
- data PeerExchangeInfo = PeerExchangeInfo {
- pxPeerId :: !ByteString
- pxSignedPeerRecord :: !(Maybe ByteString)
- data RPC = RPC {
- rpcSubscriptions :: ![SubOpts]
- rpcPublish :: ![PubSubMessage]
- rpcControl :: !(Maybe ControlMessage)
- data SignaturePolicy
- data GossipSubError = SigningFailed String
- data ValidationResult
- type TopicValidator = PeerId -> PubSubMessage -> IO ValidationResult
- data GossipSubParams = GossipSubParams {
- paramD :: !Int
- paramDlo :: !Int
- paramDhi :: !Int
- paramDlazy :: !Int
- paramDscore :: !Int
- paramDout :: !Int
- paramHeartbeatInterval :: !NominalDiffTime
- paramFanoutTTL :: !NominalDiffTime
- paramSeenTTL :: !NominalDiffTime
- paramPruneBackoff :: !NominalDiffTime
- paramUnsubBackoff :: !NominalDiffTime
- paramGossipFactor :: !Double
- paramFloodPublish :: !Bool
- paramMessageIdFn :: !(PubSubMessage -> MessageId)
- paramSignaturePolicy :: !SignaturePolicy
- paramMcacheLen :: !Int
- paramMcacheGossip :: !Int
- paramPrunePeers :: !Int
- paramIWantFollowupTime :: !NominalDiffTime
- paramMaxIHaveLength :: !Int
- paramMaxIHaveMessages :: !Int
- paramDirectPeers :: !(Set PeerId)
- defaultGossipSubParams :: GossipSubParams
- data PeerProtocol
- data PeerState = PeerState {
- psProtocol :: !PeerProtocol
- psTopics :: !(Set Topic)
- psIsOutbound :: !Bool
- psConnectedAt :: !UTCTime
- psTopicState :: !(Map Topic TopicPeerState)
- psBehaviorPenalty :: !Double
- psIPAddress :: !(Maybe ByteString)
- psCachedScore :: !Double
- data TopicScoreParams = TopicScoreParams {
- tspTopicWeight :: !Double
- tspTimeInMeshWeight :: !Double
- tspTimeInMeshQuantum :: !NominalDiffTime
- tspTimeInMeshCap :: !Double
- tspFirstMessageDeliveriesWeight :: !Double
- tspFirstMessageDeliveriesDecay :: !Double
- tspFirstMessageDeliveriesCap :: !Double
- tspMeshMessageDeliveriesWeight :: !Double
- tspMeshMessageDeliveriesDecay :: !Double
- tspMeshMessageDeliveriesThreshold :: !Double
- tspMeshMessageDeliveriesCap :: !Double
- tspMeshMessageDeliveriesActivation :: !NominalDiffTime
- tspMeshMessageDeliveryWindow :: !NominalDiffTime
- tspMeshFailurePenaltyWeight :: !Double
- tspMeshFailurePenaltyDecay :: !Double
- tspInvalidMessageDeliveriesWeight :: !Double
- tspInvalidMessageDeliveriesDecay :: !Double
- defaultTopicScoreParams :: TopicScoreParams
- data PeerScoreParams = PeerScoreParams {
- pspTopicParams :: !(Map Topic TopicScoreParams)
- pspAppSpecificWeight :: !Double
- pspAppSpecificScore :: !(PeerId -> Double)
- pspIPColocationFactorWeight :: !Double
- pspIPColocationFactorThreshold :: !Int
- pspBehaviorPenaltyWeight :: !Double
- pspBehaviorPenaltyDecay :: !Double
- pspDecayInterval :: !NominalDiffTime
- pspDecayToZero :: !Double
- pspRetainScore :: !NominalDiffTime
- pspTopicScoreCap :: !Double
- defaultPeerScoreParams :: PeerScoreParams
- data TopicPeerState = TopicPeerState {}
- defaultTopicPeerState :: TopicPeerState
- data ScoreThresholds = ScoreThresholds {}
- defaultScoreThresholds :: ScoreThresholds
- data CacheEntry = CacheEntry {
- ceMessageId :: !MessageId
- ceMessage :: !PubSubMessage
- ceTopic :: !Topic
- data MessageCache = MessageCache {}
- data GossipSubRouter = GossipSubRouter {
- gsParams :: !GossipSubParams
- gsLocalPeerId :: !PeerId
- gsSubscriptions :: !(TVar (Set Topic))
- gsMesh :: !(TVar (Map Topic (Set PeerId)))
- gsFanout :: !(TVar (Map Topic (Set PeerId)))
- gsFanoutPub :: !(TVar (Map Topic UTCTime))
- gsPeers :: !(TVar (Map PeerId PeerState))
- gsSeen :: !(TVar (Map MessageId UTCTime))
- gsBackoff :: !(TVar (Map (PeerId, Topic) UTCTime))
- gsScoreParams :: !PeerScoreParams
- gsThresholds :: !ScoreThresholds
- gsIPPeerCount :: !(TVar (Map ByteString (Set PeerId)))
- gsIWantPromises :: !(TVar (Map (PeerId, MessageId) UTCTime))
- gsIHaveCounts :: !(TVar (Map PeerId Int))
- gsIAskedCounts :: !(TVar (Map PeerId Int))
- gsIWantServed :: !(TVar (Map PeerId Int))
- gsMessageCache :: !(TVar MessageCache)
- gsHeartbeatCount :: !(TVar Int)
- gsSendRPC :: !(PeerId -> RPC -> IO ())
- gsGetTime :: !(IO UTCTime)
- gsOnMessage :: !(TVar (Topic -> PubSubMessage -> IO ()))
- gsValidators :: !(TVar (Map Topic TopicValidator))
- gsOnPeerExchange :: !(TVar (Topic -> [PeerExchangeInfo] -> IO ()))
- gsSignedPeerRecords :: !(TVar (Map PeerId ByteString))
- emptyRPC :: RPC
- emptyControlMessage :: ControlMessage
- defaultMessageId :: PubSubMessage -> MessageId
Protocol constants
gossipSubProtocolId :: Text Source #
GossipSub v1.1 protocol identifier.
gossipSubProtocolIdV10 :: Text Source #
GossipSub v1.0 protocol identifier. Advertised alongside v1.1 for backwards compatibility (gossipsub-v1.1.md: the v1.1 extensions are fully backwards compatible with v1.0 of the protocol).
floodSubProtocolId :: Text Source #
FloodSub protocol identifier. Advertised alongside the meshsub protocols (gossipsub-v1.0.md "Compatibility with FloodSub"): floodsub peers receive all messages for topics they subscribe to and are never sent gossipsub control messages.
maxRPCSize :: Int Source #
Maximum RPC message size: 1 MiB.
Topic and message identity
type MessageId = ByteString Source #
Unique message identifier (typically from || seqno).
Wire types
data PubSubMessage Source #
A published message.
Constructors
| PubSubMessage | |
Fields
| |
Instances
| Show PubSubMessage Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods showsPrec :: Int -> PubSubMessage -> ShowS # show :: PubSubMessage -> String # showList :: [PubSubMessage] -> ShowS # | |
| Eq PubSubMessage Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods (==) :: PubSubMessage -> PubSubMessage -> Bool # (/=) :: PubSubMessage -> PubSubMessage -> Bool # | |
Subscription change announcement.
Constructors
| SubOpts | |
Fields
| |
data ControlMessage Source #
GossipSub control message (IHAVE, IWANT, GRAFT, PRUNE).
Constructors
| ControlMessage | |
Instances
| Show ControlMessage Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods showsPrec :: Int -> ControlMessage -> ShowS # show :: ControlMessage -> String # showList :: [ControlMessage] -> ShowS # | |
| Eq ControlMessage Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods (==) :: ControlMessage -> ControlMessage -> Bool # (/=) :: ControlMessage -> ControlMessage -> Bool # | |
IHAVE: announce message IDs for a topic.
Constructors
| IHave | |
Fields
| |
Instances
IWANT: request full messages by ID.
Constructors
| IWant | |
Fields
| |
Instances
GRAFT: request mesh membership.
Constructors
| Graft | |
Fields
| |
Instances
PRUNE: remove from mesh with optional peer exchange and backoff.
Constructors
| Prune | |
Fields
| |
Instances
data PeerExchangeInfo Source #
Peer exchange info in PRUNE messages (v1.1).
Constructors
| PeerExchangeInfo | |
Fields
| |
Instances
| Show PeerExchangeInfo Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods showsPrec :: Int -> PeerExchangeInfo -> ShowS # show :: PeerExchangeInfo -> String # showList :: [PeerExchangeInfo] -> ShowS # | |
| Eq PeerExchangeInfo Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods (==) :: PeerExchangeInfo -> PeerExchangeInfo -> Bool # (/=) :: PeerExchangeInfo -> PeerExchangeInfo -> Bool # | |
RPC wrapper containing subscriptions, published messages, and control.
Constructors
| RPC | |
Fields
| |
Signature policy
data SignaturePolicy Source #
Signature policy for message signing/validation.
Constructors
| StrictSign | All messages must be signed |
| StrictNoSign | No signatures allowed |
Instances
| Show SignaturePolicy Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods showsPrec :: Int -> SignaturePolicy -> ShowS # show :: SignaturePolicy -> String # showList :: [SignaturePolicy] -> ShowS # | |
| Eq SignaturePolicy Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods (==) :: SignaturePolicy -> SignaturePolicy -> Bool # (/=) :: SignaturePolicy -> SignaturePolicy -> Bool # | |
Errors
data GossipSubError Source #
Fatal GossipSub errors surfaced to the caller.
Constructors
| SigningFailed String | StrictSign publish could not sign the message. Emitting it unsigned would produce a message every compliant receiver must reject, so the publish fails instead. |
Instances
| Exception GossipSubError Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods toException :: GossipSubError -> SomeException # fromException :: SomeException -> Maybe GossipSubError # displayException :: GossipSubError -> String # backtraceDesired :: GossipSubError -> Bool # | |
| Show GossipSubError Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods showsPrec :: Int -> GossipSubError -> ShowS # show :: GossipSubError -> String # showList :: [GossipSubError] -> ShowS # | |
| Eq GossipSubError Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods (==) :: GossipSubError -> GossipSubError -> Bool # (/=) :: GossipSubError -> GossipSubError -> Bool # | |
Topic validation
data ValidationResult Source #
Outcome of an application topic validator (gossipsub-v1.1.md "Extended Validators"). The trichotomy exists because rejection is a scoring event while ignoring is not: a message that is provably invalid (Reject) counts against the propagation source's P4 counter, whereas a message that merely cannot be validated right now (Ignore) is dropped without penalising the peer that relayed it.
Constructors
| ValidationAccept | Deliver and propagate the message |
| ValidationReject | Drop without propagation; penalise the source (P4) |
| ValidationIgnore | Drop without propagation; no penalty |
Instances
| Show ValidationResult Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods showsPrec :: Int -> ValidationResult -> ShowS # show :: ValidationResult -> String # showList :: [ValidationResult] -> ShowS # | |
| Eq ValidationResult Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods (==) :: ValidationResult -> ValidationResult -> Bool # (/=) :: ValidationResult -> ValidationResult -> Bool # | |
type TopicValidator = PeerId -> PubSubMessage -> IO ValidationResult Source #
Application validator for a topic. Receives the propagation source and the message and decides whether it is delivered and forwarded (specspubsubREADME.md "Topic validation"; gossipsub-v1.1.md extended validators).
Configuration
data GossipSubParams Source #
GossipSub router parameters.
Constructors
| GossipSubParams | |
Fields
| |
defaultGossipSubParams :: GossipSubParams Source #
Default GossipSub parameters per spec.
Peer tracking
data PeerProtocol Source #
Peer's negotiated protocol capability. Peers on meshsub1.0.0 must not receive v1.1 control extensions (PX records or the backoff field in PRUNE). Peers on floodsub1.0.0 have no mesh: they are flooded every message for topics they subscribe to and never receive control messages (gossipsub-v1.0.md "Compatibility with FloodSub").
Constructors
| GossipSubPeer | GossipSub v1.1 (meshsub1.1.0) |
| GossipSubV10Peer | GossipSub v1.0 (meshsub1.0.0) |
| FloodSubPeer | FloodSub only (floodsub1.0.0) |
Instances
| Show PeerProtocol Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods showsPrec :: Int -> PeerProtocol -> ShowS # show :: PeerProtocol -> String # showList :: [PeerProtocol] -> ShowS # | |
| Eq PeerProtocol Source # | |
Defined in LibP2P.Protocol.GossipSub.Types | |
Per-peer state tracked by the router.
Constructors
| PeerState | |
Fields
| |
Scoring types
data TopicScoreParams Source #
Per-topic scoring parameters.
Constructors
Instances
| Show TopicScoreParams Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods showsPrec :: Int -> TopicScoreParams -> ShowS # show :: TopicScoreParams -> String # showList :: [TopicScoreParams] -> ShowS # | |
| Eq TopicScoreParams Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods (==) :: TopicScoreParams -> TopicScoreParams -> Bool # (/=) :: TopicScoreParams -> TopicScoreParams -> Bool # | |
defaultTopicScoreParams :: TopicScoreParams Source #
Default topic scoring parameters (conservative values).
data PeerScoreParams Source #
Global peer scoring parameters.
Constructors
| PeerScoreParams | |
Fields
| |
defaultPeerScoreParams :: PeerScoreParams Source #
Default global scoring parameters.
data TopicPeerState Source #
Per-topic per-peer state for scoring counters.
Constructors
| TopicPeerState | |
Fields
| |
Instances
| Show TopicPeerState Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods showsPrec :: Int -> TopicPeerState -> ShowS # show :: TopicPeerState -> String # showList :: [TopicPeerState] -> ShowS # | |
| Eq TopicPeerState Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods (==) :: TopicPeerState -> TopicPeerState -> Bool # (/=) :: TopicPeerState -> TopicPeerState -> Bool # | |
defaultTopicPeerState :: TopicPeerState Source #
Default empty topic peer state.
data ScoreThresholds Source #
Score thresholds controlling router behavior.
Constructors
| ScoreThresholds | |
Fields
| |
Instances
| Show ScoreThresholds Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods showsPrec :: Int -> ScoreThresholds -> ShowS # show :: ScoreThresholds -> String # showList :: [ScoreThresholds] -> ShowS # | |
| Eq ScoreThresholds Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods (==) :: ScoreThresholds -> ScoreThresholds -> Bool # (/=) :: ScoreThresholds -> ScoreThresholds -> Bool # | |
defaultScoreThresholds :: ScoreThresholds Source #
Default score thresholds.
Message cache types
data CacheEntry Source #
A cached message entry.
Constructors
| CacheEntry | |
Fields
| |
Instances
| Show CacheEntry Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods showsPrec :: Int -> CacheEntry -> ShowS # show :: CacheEntry -> String # showList :: [CacheEntry] -> ShowS # | |
| Eq CacheEntry Source # | |
Defined in LibP2P.Protocol.GossipSub.Types | |
data MessageCache Source #
Sliding-window message cache.
Constructors
| MessageCache | |
Instances
| Show MessageCache Source # | |
Defined in LibP2P.Protocol.GossipSub.Types Methods showsPrec :: Int -> MessageCache -> ShowS # show :: MessageCache -> String # showList :: [MessageCache] -> ShowS # | |
| Eq MessageCache Source # | |
Defined in LibP2P.Protocol.GossipSub.Types | |
Router state
data GossipSubRouter Source #
GossipSub router state with STM-managed concurrent state.
Constructors
| GossipSubRouter | |
Fields
| |
Defaults
emptyControlMessage :: ControlMessage Source #
Empty control message with no IHAVEIWANTGRAFT/PRUNE.
defaultMessageId :: PubSubMessage -> MessageId Source #
Default message ID: concatenation of from and seqno fields. Anonymous
messages (StrictNoSign) carry neither field, and a shared empty id would
collapse seen-cache dedup, the mcache and IHAVE/IWANT tracking, so those
fall back to a content-addressed id of SHA-256(topic <> data) (#217).