From 42e4cf8648b8ea9e548637849e67e9e4b4344899 Mon Sep 17 00:00:00 2001 From: Delweng Date: Thu, 26 Feb 2026 12:35:04 +0800 Subject: [PATCH] cmd/devp2p: store lastLocal as well Signed-off-by: Delweng --- cmd/devp2p/internal/v5test/framework.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/devp2p/internal/v5test/framework.go b/cmd/devp2p/internal/v5test/framework.go index 57f33d8561..24ba75e3e2 100644 --- a/cmd/devp2p/internal/v5test/framework.go +++ b/cmd/devp2p/internal/v5test/framework.go @@ -66,6 +66,7 @@ type conn struct { codec *v5wire.Codec idCounter uint32 lastFrom string + lastLocal net.IP } type logger interface { @@ -201,6 +202,13 @@ func (tc *conn) findnode(c net.PacketConn, dists []uint) ([]*enode.Node, error) // write sends a packet on the given connection. func (tc *conn) write(c net.PacketConn, p v5wire.Packet, challenge *v5wire.Whoareyou) v5wire.Nonce { + lip := laddr(c).IP + if tc.lastLocal != nil && !tc.lastLocal.Equal(lip) && challenge == nil { + // New local endpoint: drop old sessions to avoid reusing them across IPs. + tc.codec = v5wire.NewCodec(tc.localNode, tc.localKey, mclock.System{}, nil) + } + tc.lastLocal = slices.Clone(lip) + addr := tc.remoteAddr.String() if challenge != nil && tc.lastFrom != "" { addr = tc.lastFrom