Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions p2p/enode/localnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion p2p/simulations/adapters/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down