From 1682880dbf8aa44e70d1e6f5e0ece74ea317691a Mon Sep 17 00:00:00 2001 From: lash Date: Sun, 17 Feb 2019 08:59:29 +0100 Subject: [PATCH] swarm/network: Remove redundance pointer return from sanitize --- swarm/network/protocol.go | 7 ++++--- swarm/network/protocol_test.go | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/swarm/network/protocol.go b/swarm/network/protocol.go index bdca16f134..25a919777e 100644 --- a/swarm/network/protocol.go +++ b/swarm/network/protocol.go @@ -216,7 +216,8 @@ func (b *Bzz) performHandshake(p *protocols.Peer, handshake *HandshakeMsg) error handshake.err = 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 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 // applicable on the interface the connection came in on // 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) ip, _, err := net.SplitHostPort(paddr.String()) 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) baddr.UAddr = regexpEnodeIP.ReplaceAll(baddr.UAddr, []byte(remoteStr)) } - return baddr + return } // runBzz is the p2p protocol run function for the bzz base protocol diff --git a/swarm/network/protocol_test.go b/swarm/network/protocol_test.go index eec997f7e1..97cb4b97ba 100644 --- a/swarm/network/protocol_test.go +++ b/swarm/network/protocol_test.go @@ -272,8 +272,8 @@ func TestSanitizeEnodeRemote(t *testing.T) { baddr := RandomAddr() oldUAddr := []byte(nodLocal.String()) baddr.UAddr = oldUAddr - newUAddr := sanitizeEnodeRemote(&remoteAddr, baddr).UAddr - if !bytes.Equal(newUAddr, []byte(nodRemote.String())) { - t.Fatalf("insane address. expected %v, got %v", nodRemote.String(), string(newUAddr)) + sanitizeEnodeRemote(&remoteAddr, baddr) + if !bytes.Equal(baddr.UAddr, []byte(nodRemote.String())) { + t.Fatalf("insane address. expected %v, got %v", nodRemote.String(), string(baddr.UAddr)) } }