From de0a2ee49b2c663a46923e4a7b40b8b93f3a7c2d Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 2 Apr 2018 16:14:24 -0700 Subject: [PATCH] server: don't directly mutate net.TCPAddr for inbound connections to set peer port In this commit, we fix a minor logging bug introduced in a prior commit. Before we would directly modify the *net.TCPAddr that was a part of the brontide connection. This achieved our goal, but would print weird log messages as we mutated the port in the already established connection. In this commit, we fix that by ensuring we create a copy iff it's a net.TCPAddr, then modify that and replace the instance in the lnwire.NetAddress. Fixes #991. --- server.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server.go b/server.go index 05019aa0..c4f5cea1 100644 --- a/server.go +++ b/server.go @@ -1370,7 +1370,14 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq, // address for reconnecting purposes. if tcpAddr, ok := addr.(*net.TCPAddr); ok { targetPort := s.fetchNodeAdvertisedPort(pubKey, tcpAddr) - tcpAddr.Port = targetPort + + // Once we have the correct port, we'll make a new copy of the + // address so we don't modify the underlying pointer directly. + addr = &net.TCPAddr{ + IP: tcpAddr.IP, + Port: targetPort, + Zone: tcpAddr.Zone, + } } peerAddr := &lnwire.NetAddress{