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.
This commit is contained in:
Olaoluwa Osuntokun 2018-04-02 16:14:24 -07:00
parent 5984cbd4ff
commit de0a2ee49b
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -1370,7 +1370,14 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
// address for reconnecting purposes. // address for reconnecting purposes.
if tcpAddr, ok := addr.(*net.TCPAddr); ok { if tcpAddr, ok := addr.(*net.TCPAddr); ok {
targetPort := s.fetchNodeAdvertisedPort(pubKey, tcpAddr) 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{ peerAddr := &lnwire.NetAddress{