mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 11:20:45 +00:00
cmd/devp2p: store lastLocal as well
Signed-off-by: Delweng <delweng@gmail.com>
This commit is contained in:
parent
0f2eb27996
commit
4a4cbe3404
1 changed files with 8 additions and 0 deletions
|
|
@ -66,6 +66,7 @@ type conn struct {
|
||||||
codec *v5wire.Codec
|
codec *v5wire.Codec
|
||||||
idCounter uint32
|
idCounter uint32
|
||||||
lastFrom string
|
lastFrom string
|
||||||
|
lastLocal net.IP
|
||||||
}
|
}
|
||||||
|
|
||||||
type logger interface {
|
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.
|
// write sends a packet on the given connection.
|
||||||
func (tc *conn) write(c net.PacketConn, p v5wire.Packet, challenge *v5wire.Whoareyou) v5wire.Nonce {
|
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()
|
addr := tc.remoteAddr.String()
|
||||||
if challenge != nil && tc.lastFrom != "" {
|
if challenge != nil && tc.lastFrom != "" {
|
||||||
addr = tc.lastFrom
|
addr = tc.lastFrom
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue