Skip to content

Commit

Permalink
Merge pull request #205 from libp2p/fix/mcache-docs
Browse files Browse the repository at this point in the history
godocs: clarify config params of MessageCache.
  • Loading branch information
vyzo authored Oct 6, 2019
2 parents 55553ac + e897918 commit d72666d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions mcache.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
package pubsub

import (
"fmt"

pb "github.com/libp2p/go-libp2p-pubsub/pb"
)

// NewMessageCache creates a sliding window cache that remembers messages for as
// long as `history` slots.
//
// When queried for messages to advertise, the cache only returns messages in
// the last `gossip` slots.
//
// The `gossip` parameter must be smaller or equal to `history`, or this
// function will panic.
//
// The slack between `gossip` and `history` accounts for the reaction time
// between when a message is advertised via IHAVE gossip, and the peer pulls it
// via an IWANT command.
func NewMessageCache(gossip, history int) *MessageCache {
if gossip > history {
err := fmt.Errorf("invalid parameters for message cache; gossip slots (%d) cannot be larger than history slots (%d)",
gossip, history)
panic(err)
}
return &MessageCache{
msgs: make(map[string]*pb.Message),
history: make([][]CacheEntry, history),
Expand Down

0 comments on commit d72666d

Please sign in to comment.