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
|
||||
|
||||
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])
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue