p2p: a per-peer guard drops floods and bans peers that send invalid gossip

Per relaying peer and minute: over 1200 messages are dropped unread (no penalty); 20 invalid ones (bad signature, too little work, garbage) ban the peer for an hour, closing the connection and blacklisting it in gossip. Ignored messages (clock trouble, unknown listing) never count. In the simulator the attacker is cut off from every node it reached and honest listings still arrive 50 of 50; the message-flood scenario now uses a second attacker.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
2026-11-19 00:21:59 +01:00
co-authored by Claude Sonnet 5.5
parent bcae85b06f
commit daa80a6d56
6 changed files with 305 additions and 12 deletions
+6 -2
View File
@@ -153,7 +153,7 @@ func (s *sim) hostile(regions []string, rep *reportTable) {
lt := "/allmende/1/listings/" + region
mt := "/allmende/1/messages/" + region
atk := s.newAttacker(targets, lt, mt)
defer atk.close()
defer func() { atk.close() }() // atk is replaced before the flood
// 1. listings that must never be stored
ident := &simNode{}
@@ -221,7 +221,7 @@ func (s *sim) hostile(regions []string, rep *reportTable) {
poll(pairs, 100*time.Millisecond)
}
rep.latency("attack 1b", "honest listings published while the attacker is connected", await(pairs, s.timeout))
rep.row("attack 1c", fmt.Sprintf("the attacker is still connected to %d of %d nodes it dialed (there is no peer scoring: nobody cuts it off)",
rep.row("attack 1c", fmt.Sprintf("the attacker is still connected to %d of %d nodes it dialed (a node bans a peer after 20 invalid messages in a minute and cuts it off)",
len(atk.h.Network().Peers()), len(targets)))
// 2. a message flood at one listing, with real (cheap) proof-of-work
@@ -249,6 +249,10 @@ func (s *sim) hostile(regions []string, rep *reportTable) {
}
return c
}
// The first attacker has been banned by now; the flood comes from a new
// peer, whose messages are all valid (the point is the queue, not a ban).
atk.close()
atk = s.newAttacker(targets, lt, mt)
const flood = 400
for i := 0; i < flood; i++ {
tk, err := message.NewThreadKey()