mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-05 22:33:10 +00:00
update IHAVE spam test to test for behavioural tests because of broken promises
This commit is contained in:
parent
5f682c8ca5
commit
883f8b8c92
@ -140,7 +140,20 @@ func TestGossipsubAttackSpamIHAVE(t *testing.T) {
|
|||||||
attacker := hosts[1]
|
attacker := hosts[1]
|
||||||
|
|
||||||
// Set up gossipsub on the legit host
|
// Set up gossipsub on the legit host
|
||||||
ps, err := NewGossipSub(ctx, legit)
|
ps, err := NewGossipSub(ctx, legit,
|
||||||
|
WithPeerScore(
|
||||||
|
&PeerScoreParams{
|
||||||
|
AppSpecificScore: func(peer.ID) float64 { return 0 },
|
||||||
|
BehaviourPenaltyWeight: -1,
|
||||||
|
BehaviourPenaltyDecay: ScoreParameterDecay(time.Minute),
|
||||||
|
DecayInterval: DefaultDecayInterval,
|
||||||
|
DecayToZero: DefaultDecayToZero,
|
||||||
|
},
|
||||||
|
&PeerScoreThresholds{
|
||||||
|
GossipThreshold: -100,
|
||||||
|
PublishThreshold: -500,
|
||||||
|
GraylistThreshold: -1000,
|
||||||
|
}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -200,6 +213,12 @@ func TestGossipsubAttackSpamIHAVE(t *testing.T) {
|
|||||||
}
|
}
|
||||||
firstBatchCount := iwc
|
firstBatchCount := iwc
|
||||||
|
|
||||||
|
// the score should still be 0 because we haven't broken any promises yet
|
||||||
|
score := ps.rt.(*GossipSubRouter).score.Score(attacker.ID())
|
||||||
|
if score != 0 {
|
||||||
|
t.Fatalf("Expected 0 score, but got %f", score)
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for a hearbeat
|
// Wait for a hearbeat
|
||||||
time.Sleep(GossipSubHeartbeatInterval)
|
time.Sleep(GossipSubHeartbeatInterval)
|
||||||
|
|
||||||
@ -222,6 +241,12 @@ func TestGossipsubAttackSpamIHAVE(t *testing.T) {
|
|||||||
if iwc-firstBatchCount > GossipSubMaxIHaveLength {
|
if iwc-firstBatchCount > GossipSubMaxIHaveLength {
|
||||||
t.Fatalf("Expecting max %d IWANTs per heartbeat but received %d", GossipSubMaxIHaveLength, iwc-firstBatchCount)
|
t.Fatalf("Expecting max %d IWANTs per heartbeat but received %d", GossipSubMaxIHaveLength, iwc-firstBatchCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The score should now be negative because of broken promises
|
||||||
|
score = ps.rt.(*GossipSubRouter).score.Score(attacker.ID())
|
||||||
|
if score >= 0 {
|
||||||
|
t.Fatalf("Expected negative score, but got %f", score)
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user