Skip to content

Commit

Permalink
Refactor Gossipsub Parameters To Make Them More Configurable (libp2p#421
Browse files Browse the repository at this point in the history
)

Co-authored-by: nisdas <[email protected]>
  • Loading branch information
Stebalien and nisdas authored May 3, 2021
1 parent cbb7bfc commit 0094708
Show file tree
Hide file tree
Showing 4 changed files with 271 additions and 177 deletions.
5 changes: 4 additions & 1 deletion gossip_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type gossipTracer struct {

msgID MsgIdFunction

followUpTime time.Duration

// promises for messages by message ID; for each message tracked, we track the promise
// expiration time for each peer.
promises map[string]map[peer.ID]time.Time
Expand All @@ -39,6 +41,7 @@ func (gt *gossipTracer) Start(gs *GossipSubRouter) {
}

gt.msgID = gs.p.msgID
gt.followUpTime = gs.params.IWantFollowupTime
}

// track a promise to deliver a message from a list of msgIDs we are requesting
Expand All @@ -61,7 +64,7 @@ func (gt *gossipTracer) AddPromise(p peer.ID, msgIDs []string) {

_, ok = promises[p]
if !ok {
promises[p] = time.Now().Add(GossipSubIWantFollowupTime)
promises[p] = time.Now().Add(gt.followUpTime)
peerPromises, ok := gt.peerPromises[p]
if !ok {
peerPromises = make(map[string]struct{})
Expand Down
7 changes: 1 addition & 6 deletions gossip_tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ import (

func TestBrokenPromises(t *testing.T) {
// tests that unfullfilled promises are tracked correctly
originalGossipSubIWantFollowupTime := GossipSubIWantFollowupTime
GossipSubIWantFollowupTime = 100 * time.Millisecond
defer func() {
GossipSubIWantFollowupTime = originalGossipSubIWantFollowupTime
}()

gt := newGossipTracer()
gt.followUpTime = 100 * time.Millisecond

peerA := peer.ID("A")
peerB := peer.ID("B")
Expand Down
Loading

0 comments on commit 0094708

Please sign in to comment.