diff --git a/p2p/enode/localnode.go b/p2p/enode/localnode.go index 4827b6c0aedc..a18204e752ce 100644 --- a/p2p/enode/localnode.go +++ b/p2p/enode/localnode.go @@ -63,7 +63,7 @@ type LocalNode struct { type lnEndpoint struct { track *netutil.IPTracker staticIP, fallbackIP net.IP - fallbackUDP int + fallbackUDP uint16 // port } // NewLocalNode creates a local node. @@ -208,8 +208,8 @@ func (ln *LocalNode) SetFallbackUDP(port int) { ln.mu.Lock() defer ln.mu.Unlock() - ln.endpoint4.fallbackUDP = port - ln.endpoint6.fallbackUDP = port + ln.endpoint4.fallbackUDP = uint16(port) + ln.endpoint6.fallbackUDP = uint16(port) ln.updateEndpoints() } @@ -261,7 +261,7 @@ func (ln *LocalNode) updateEndpoints() { } // get returns the endpoint with highest precedence. -func (e *lnEndpoint) get() (newIP net.IP, newPort int) { +func (e *lnEndpoint) get() (newIP net.IP, newPort uint16) { newPort = e.fallbackUDP if e.fallbackIP != nil { newIP = e.fallbackIP @@ -277,15 +277,18 @@ func (e *lnEndpoint) get() (newIP net.IP, newPort int) { // predictAddr wraps IPTracker.PredictEndpoint, converting from its string-based // endpoint representation to IP and port types. -func predictAddr(t *netutil.IPTracker) (net.IP, int) { +func predictAddr(t *netutil.IPTracker) (net.IP, uint16) { ep := t.PredictEndpoint() if ep == "" { return nil, 0 } ipString, portString, _ := net.SplitHostPort(ep) ip := net.ParseIP(ipString) - port, _ := strconv.Atoi(portString) - return ip, port + port, err := strconv.ParseUint(portString, 10, 16) + if err != nil { + return nil, 0 + } + return ip, uint16(port) } func (ln *LocalNode) invalidate() { diff --git a/p2p/simulations/adapters/types.go b/p2p/simulations/adapters/types.go index 1da464a10d41..aeb8ef77726b 100644 --- a/p2p/simulations/adapters/types.go +++ b/p2p/simulations/adapters/types.go @@ -242,7 +242,7 @@ func assignTCPPort() (uint16, error) { if err != nil { return 0, err } - p, err := strconv.ParseInt(port, 10, 32) + p, err := strconv.ParseUint(port, 10, 16) if err != nil { return 0, err }