cmd/devp2p/v5test: isolate unsolicited NODES probes

This commit is contained in:
Csaba Kiraly 2026-04-21 11:53:06 +00:00
parent 13d5001c60
commit 50013f189b

View file

@ -324,12 +324,13 @@ func (s *Suite) TestUnsolicitedNodes(t *utesting.T) {
t.Log(`This test sends an unsolicited NODES response advertising a fake node. t.Log(`This test sends an unsolicited NODES response advertising a fake node.
The remote node should neither contact the injected node nor return it from later FINDNODE queries.`) The remote node should neither contact the injected node nor return it from later FINDNODE queries.`)
conn, l1 := s.listen1(t) injectConn, injectL := s.listen1(t)
defer conn.close() defer injectConn.close()
// Establish session so the unsolicited packet is well-formed and authenticated. // Establish a session for the injection path so the unsolicited packet is
ping := &v5wire.Ping{ReqID: conn.nextReqID()} // well-formed and authenticated.
if resp := conn.reqresp(l1, ping); resp.Kind() != v5wire.PongMsg { ping := &v5wire.Ping{ReqID: injectConn.nextReqID()}
if resp := injectConn.reqresp(injectL, ping); resp.Kind() != v5wire.PongMsg {
t.Fatal("expected PONG, got", resp) t.Fatal("expected PONG, got", resp)
} }
@ -338,12 +339,12 @@ The remote node should neither contact the injected node nor return it from late
fakeConn.setEndpoint(fakeL) fakeConn.setEndpoint(fakeL)
unsolicited := &v5wire.Nodes{ unsolicited := &v5wire.Nodes{
ReqID: conn.nextReqID(), ReqID: injectConn.nextReqID(),
RespCount: 1, RespCount: 1,
Nodes: []*enr.Record{fakeConn.localNode.Node().Record()}, Nodes: []*enr.Record{fakeConn.localNode.Node().Record()},
} }
t.Log("sending unsolicited NODES response with injected node") t.Log("sending unsolicited NODES response with injected node")
conn.write(l1, unsolicited, nil) injectConn.write(injectL, unsolicited, nil)
checkNoContact := func(phase string) { checkNoContact := func(phase string) {
buf := make([]byte, 1280) buf := make([]byte, 1280)
@ -363,10 +364,13 @@ The remote node should neither contact the injected node nor return it from late
} }
checkNoContact("after unsolicited NODES") checkNoContact("after unsolicited NODES")
probeConn, probeL := s.listen1(t)
defer probeConn.close()
dist := uint(enode.LogDist(fakeConn.localNode.ID(), s.Dest.ID())) dist := uint(enode.LogDist(fakeConn.localNode.ID(), s.Dest.ID()))
const maxAttempts = 3 const maxAttempts = 3
for attempt := 1; attempt <= maxAttempts; attempt++ { for attempt := 1; attempt <= maxAttempts; attempt++ {
results, err := conn.findnode(l1, []uint{dist}) results, err := probeConn.findnode(probeL, []uint{dist})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }