prevent abuse from peers

This commit is contained in:
Anton Kalyaev
2017-01-12 17:56:40 +04:00
committed by Anton Kaliaev
parent 47df1fb7d4
commit 873d34157d
2 changed files with 65 additions and 9 deletions

View File

@ -102,6 +102,21 @@ func TestPEXReactorReceive(t *testing.T) {
r.Receive(PexChannel, peer, msg)
}
func TestPEXReactorAbuseFromPeer(t *testing.T) {
book := NewAddrBook(createTempFileName("addrbook"), true)
r := NewPEXReactor(book)
r.SetMaxMsgCountByPeer(5)
peer := createRandomPeer(false)
msg := wire.BinaryBytes(struct{ PexMessage }{&pexRequestMessage{}})
for i := 0; i < 10; i++ {
r.Receive(PexChannel, peer, msg)
}
assert.True(t, r.ReachedMaxMsgCountForPeer(peer.ListenAddr))
}
func createRandomPeer(outbound bool) *Peer {
addr := Fmt("%v.%v.%v.%v:46656", rand.Int()%256, rand.Int()%256, rand.Int()%256, rand.Int()%256)
return &Peer{