diff --git a/swarm/network/protocol.go b/swarm/network/protocol.go index 95d43cfe85..4161907d74 100644 --- a/swarm/network/protocol.go +++ b/swarm/network/protocol.go @@ -17,7 +17,6 @@ package network import ( - "bytes" "context" "errors" "fmt" @@ -232,10 +231,13 @@ func sanitizeEnodeRemote(paddr net.Addr, baddr *BzzAddr) { ip, _, err := net.SplitHostPort(paddr.String()) if len(hsSubmatch) < 2 { log.Warn("sanitize found non ipv4 string", "remotestring", paddr.String(), "handshakeaddr", baddr) - } else if err == nil && bytes.Equal(hsSubmatch[1], []byte("127.0.0.1")) { - remoteStr := fmt.Sprintf("@%s:%s", ip, string(hsSubmatch[2])) - log.Debug("rewrote peer uaddr host/port", "addr", baddr) - baddr.UAddr = regexpEnodeIP.ReplaceAll(baddr.UAddr, []byte(remoteStr)) + } else if err == nil { + hsip := net.ParseIP(string(hsSubmatch[1])) + if hsip != nil && hsip.IsLoopback() { + remoteStr := fmt.Sprintf("@%s:%s", ip, string(hsSubmatch[2])) + log.Debug("rewrote peer uaddr host/port", "addr", baddr) + baddr.UAddr = regexpEnodeIP.ReplaceAll(baddr.UAddr, []byte(remoteStr)) + } } else { log.Trace("passthrough handshake addr rewrite", "submatch", hsSubmatch[1]) }