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

Network.LibP2P.Protocol.GossipSub.MessageCache

Description

GossipSub sliding-window message cache operations (docs/11-pubsub.md).

Stores recently seen messages in circular windows for IWANT responses and IHAVE gossip emission. Each heartbeat calls cacheShift to rotate windows; messages older than mcLen windows are evicted.

For gossip emission, only the mcGossip most recent windows are consulted (subset of full cache).

Pure operations — the MessageCache and CacheEntry types are defined in Types.hs to avoid circular imports with Router.hs.

Synopsis

Documentation

newMessageCache :: Int -> Int -> MessageCache Source #

Create an empty message cache with given window count and gossip window count.

cachePut :: MessageId -> PubSubMessage -> MessageCache -> MessageCache Source #

Add a message to the current (newest) window.

cacheGet :: MessageId -> MessageCache -> Maybe PubSubMessage Source #

Look up a message by ID.

cacheGetGossipIds :: Topic -> MessageCache -> [MessageId] Source #

Get message IDs for gossip emission (IHAVE) — only from the gossip windows. Filters by topic.

cacheShift :: MessageCache -> MessageCache Source #

Rotate windows: prepend a new empty window, drop the oldest. Entries in the dropped window are removed from the index.