mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm/network: Remove redundance pointer return from sanitize
This commit is contained in:
parent
a18a3e0ba7
commit
1682880dbf
2 changed files with 7 additions and 6 deletions
|
|
@ -216,7 +216,8 @@ func (b *Bzz) performHandshake(p *protocols.Peer, handshake *HandshakeMsg) error
|
||||||
handshake.err = err
|
handshake.err = err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
handshake.peerAddr = sanitizeEnodeRemote(p.RemoteAddr(), rsh.(*HandshakeMsg).Addr)
|
handshake.peerAddr = rsh.(*HandshakeMsg).Addr
|
||||||
|
sanitizeEnodeRemote(p.RemoteAddr(), handshake.peerAddr)
|
||||||
handshake.LightNode = rsh.(*HandshakeMsg).LightNode
|
handshake.LightNode = rsh.(*HandshakeMsg).LightNode
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -225,7 +226,7 @@ func (b *Bzz) performHandshake(p *protocols.Peer, handshake *HandshakeMsg) error
|
||||||
// this method ensures that the addr of the peer will be the one
|
// this method ensures that the addr of the peer will be the one
|
||||||
// applicable on the interface the connection came in on
|
// applicable on the interface the connection came in on
|
||||||
// it modifies the passed bzzaddr in place, and returns the same pointer
|
// it modifies the passed bzzaddr in place, and returns the same pointer
|
||||||
func sanitizeEnodeRemote(paddr net.Addr, baddr *BzzAddr) *BzzAddr {
|
func sanitizeEnodeRemote(paddr net.Addr, baddr *BzzAddr) {
|
||||||
hsSubmatch := regexpEnodeIP.FindSubmatch(baddr.UAddr)
|
hsSubmatch := regexpEnodeIP.FindSubmatch(baddr.UAddr)
|
||||||
ip, _, err := net.SplitHostPort(paddr.String())
|
ip, _, err := net.SplitHostPort(paddr.String())
|
||||||
if err == nil && string(hsSubmatch[1]) != ip {
|
if err == nil && string(hsSubmatch[1]) != ip {
|
||||||
|
|
@ -233,7 +234,7 @@ func sanitizeEnodeRemote(paddr net.Addr, baddr *BzzAddr) *BzzAddr {
|
||||||
log.Debug("rewrote peer uaddr host/port", "addr", baddr)
|
log.Debug("rewrote peer uaddr host/port", "addr", baddr)
|
||||||
baddr.UAddr = regexpEnodeIP.ReplaceAll(baddr.UAddr, []byte(remoteStr))
|
baddr.UAddr = regexpEnodeIP.ReplaceAll(baddr.UAddr, []byte(remoteStr))
|
||||||
}
|
}
|
||||||
return baddr
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// runBzz is the p2p protocol run function for the bzz base protocol
|
// runBzz is the p2p protocol run function for the bzz base protocol
|
||||||
|
|
|
||||||
|
|
@ -272,8 +272,8 @@ func TestSanitizeEnodeRemote(t *testing.T) {
|
||||||
baddr := RandomAddr()
|
baddr := RandomAddr()
|
||||||
oldUAddr := []byte(nodLocal.String())
|
oldUAddr := []byte(nodLocal.String())
|
||||||
baddr.UAddr = oldUAddr
|
baddr.UAddr = oldUAddr
|
||||||
newUAddr := sanitizeEnodeRemote(&remoteAddr, baddr).UAddr
|
sanitizeEnodeRemote(&remoteAddr, baddr)
|
||||||
if !bytes.Equal(newUAddr, []byte(nodRemote.String())) {
|
if !bytes.Equal(baddr.UAddr, []byte(nodRemote.String())) {
|
||||||
t.Fatalf("insane address. expected %v, got %v", nodRemote.String(), string(newUAddr))
|
t.Fatalf("insane address. expected %v, got %v", nodRemote.String(), string(baddr.UAddr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue