Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-pubsub
Commits
d72666d4
Unverified
Commit
d72666d4
authored
Oct 06, 2019
by
vyzo
Committed by
GitHub
Oct 06, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #205 from libp2p/fix/mcache-docs
godocs: clarify config params of MessageCache.
parents
55553ac0
e897918f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
0 deletions
+19
-0
mcache.go
mcache.go
+19
-0
No files found.
mcache.go
View file @
d72666d4
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
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment