limits: sync streams, listings per author, inbound connections per IP
A peer may hold 4 sync streams and open 1500 a minute; banned peers get none and cannot redial. A node keeps at most 100 unexpired listings per author (--max-per-author); updates, renewals and deletions of held ones still work. At most 16 inbound connections per public IP or IPv6 /64 (--max-conns-per-ip); local and private addresses are exempt. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
@@ -127,6 +127,64 @@ func TestOurOwnMessagesAreNeverLimited(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPeerMayOnlyHoldAFewSyncStreamsAtOnce(t *testing.T) {
|
||||
f := newGuardFixture(t)
|
||||
var ends []func()
|
||||
for i := 0; i < maxSyncStreams; i++ {
|
||||
end, ok := f.g.beginSync("greedy")
|
||||
if !ok {
|
||||
t.Fatalf("stream %d refused within the limit", i)
|
||||
}
|
||||
ends = append(ends, end)
|
||||
}
|
||||
if _, ok := f.g.beginSync("greedy"); ok {
|
||||
t.Fatal("a stream over the limit was accepted")
|
||||
}
|
||||
if _, ok := f.g.beginSync("other"); !ok {
|
||||
t.Fatal("one peer's streams must not use up another's")
|
||||
}
|
||||
ends[0]()
|
||||
end, ok := f.g.beginSync("greedy")
|
||||
if !ok {
|
||||
t.Fatal("a finished stream must free its place")
|
||||
}
|
||||
end()
|
||||
for _, e := range ends[1:] {
|
||||
e()
|
||||
}
|
||||
if len(f.g.streams) != 1 { // only "other" is still open
|
||||
t.Fatalf("%d peers still have streams recorded", len(f.g.streams))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncRequestsAreRatedAndBannedPeersAreRefused(t *testing.T) {
|
||||
f := newGuardFixture(t)
|
||||
for i := 0; i < maxSyncPerWindow; i++ {
|
||||
end, ok := f.g.beginSync("busy")
|
||||
if !ok {
|
||||
t.Fatalf("request %d within the rate refused", i)
|
||||
}
|
||||
end()
|
||||
}
|
||||
if _, ok := f.g.beginSync("busy"); ok {
|
||||
t.Fatal("a request over the rate was accepted")
|
||||
}
|
||||
f.now = f.now.Add(guardWindow)
|
||||
if end, ok := f.g.beginSync("busy"); !ok {
|
||||
t.Fatal("the next minute must start fresh")
|
||||
} else {
|
||||
end()
|
||||
}
|
||||
|
||||
f.verdict = pubsub.ValidationReject
|
||||
for i := 0; i < maxBadPerWindow; i++ {
|
||||
f.send("mallory")
|
||||
}
|
||||
if _, ok := f.g.beginSync("mallory"); ok {
|
||||
t.Fatal("a banned peer got a sync stream")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFinishedWindowsAreForgotten(t *testing.T) {
|
||||
f := newGuardFixture(t)
|
||||
for i := 0; i < 5000; i++ {
|
||||
|
||||
Reference in New Issue
Block a user