mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm/network: Use net.ParseIP to check for loopback address
This commit is contained in:
parent
407f429723
commit
98ad48ae29
1 changed files with 7 additions and 5 deletions
|
|
@ -17,7 +17,6 @@
|
||||||
package network
|
package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -232,10 +231,13 @@ func sanitizeEnodeRemote(paddr net.Addr, baddr *BzzAddr) {
|
||||||
ip, _, err := net.SplitHostPort(paddr.String())
|
ip, _, err := net.SplitHostPort(paddr.String())
|
||||||
if len(hsSubmatch) < 2 {
|
if len(hsSubmatch) < 2 {
|
||||||
log.Warn("sanitize found non ipv4 string", "remotestring", paddr.String(), "handshakeaddr", baddr)
|
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")) {
|
} else if err == nil {
|
||||||
remoteStr := fmt.Sprintf("@%s:%s", ip, string(hsSubmatch[2]))
|
hsip := net.ParseIP(string(hsSubmatch[1]))
|
||||||
log.Debug("rewrote peer uaddr host/port", "addr", baddr)
|
if hsip != nil && hsip.IsLoopback() {
|
||||||
baddr.UAddr = regexpEnodeIP.ReplaceAll(baddr.UAddr, []byte(remoteStr))
|
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 {
|
} else {
|
||||||
log.Trace("passthrough handshake addr rewrite", "submatch", hsSubmatch[1])
|
log.Trace("passthrough handshake addr rewrite", "submatch", hsSubmatch[1])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue