mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-21 14:03:09 +00:00
Add Backoff For Pruned Peers
This commit is contained in:
parent
be065ce051
commit
3d93f5f991
@ -1091,6 +1091,10 @@ func (gs *GossipSubRouter) Leave(topic string) {
|
||||
log.Debugf("LEAVE: Remove mesh link to %s in %s", p, topic)
|
||||
gs.tracer.Prune(p, topic)
|
||||
gs.sendPrune(p, topic)
|
||||
// Add a backoff to this peer to prevent us from eagerly
|
||||
// re-grafting this peer into our mesh if we rejoin this
|
||||
// topic before the backoff period.
|
||||
gs.addBackoff(p, topic)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1815,6 +1815,52 @@ func TestGossipsubOpportunisticGrafting(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
func TestGossipSubLeaveTopic(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
h := getNetHosts(t, ctx, 2)
|
||||
psubs := []*PubSub{
|
||||
getGossipsub(ctx, h[0]),
|
||||
getGossipsub(ctx, h[1]),
|
||||
}
|
||||
|
||||
connect(t, h[0], h[1])
|
||||
|
||||
// Join all peers
|
||||
var subs []*Subscription
|
||||
for _, ps := range psubs {
|
||||
sub, err := ps.Subscribe("test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
subs = append(subs, sub)
|
||||
}
|
||||
|
||||
time.Sleep(time.Second)
|
||||
|
||||
psubs[0].rt.Leave("test")
|
||||
time.Sleep(time.Second)
|
||||
peerMap := psubs[0].rt.(*GossipSubRouter).backoff["test"]
|
||||
if len(peerMap) != 1 {
|
||||
t.Fatalf("No peer is populated in the backoff map for peer 0")
|
||||
}
|
||||
_, ok := peerMap[h[1].ID()]
|
||||
if !ok {
|
||||
t.Errorf("Expected peer does not exist in the backoff map")
|
||||
}
|
||||
|
||||
// Ensure that remote peer 1 also applies the backoff appropriately
|
||||
// for peer 0.
|
||||
peerMap2 := psubs[1].rt.(*GossipSubRouter).backoff["test"]
|
||||
if len(peerMap2) != 1 {
|
||||
t.Fatalf("No peer is populated in the backoff map for peer 1")
|
||||
}
|
||||
_, ok = peerMap2[h[0].ID()]
|
||||
if !ok {
|
||||
t.Errorf("Expected peer does not exist in the backoff map")
|
||||
}
|
||||
}
|
||||
|
||||
type sybilSquatter struct {
|
||||
h host.Host
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user