From 09253eacc3d60ddb32e7e380fa5b9001a027962c Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Tue, 3 Apr 2018 01:16:04 -0400 Subject: [PATCH 1/2] server: use correct inbound value for peerConnected calls In this commit, we address the meaning of the inbound parameter to peerConnected. An inbound connection is defined as a connection initiated by the peer, rather than ourselves. We also update the inbound value for the peerConnected calls within OutboundPeerConnected and InboundPeerConnected to reflect the definition above. --- server.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/server.go b/server.go index fd7f8e96..02c376a8 100644 --- a/server.go +++ b/server.go @@ -1537,7 +1537,8 @@ func (s *server) shouldRequestGraphSync() bool { // peerConnected is a function that handles initialization a newly connected // peer by adding it to the server's global list of all active peers, and -// starting all the goroutines the peer needs to function properly. +// starting all the goroutines the peer needs to function properly. The inbound +// boolean should be true if the peer initiated the connection to us. func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq, inbound bool) { @@ -1549,7 +1550,7 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq, // peer's address for reconnection purposes. // // TODO: leave the address field empty if there aren't any? - if !inbound { + if inbound { advertisedAddr, err := s.fetchNodeAdvertisedAddr(pubKey) if err != nil { srvrLog.Errorf("Unable to retrieve advertised address "+ @@ -1672,7 +1673,7 @@ func (s *server) InboundPeerConnected(conn net.Conn) { case ErrPeerNotConnected: // We were unable to locate an existing connection with the // target peer, proceed to connect. - s.peerConnected(conn, nil, false) + s.peerConnected(conn, nil, true) case nil: // We already have a connection with the incoming peer. If the @@ -1699,7 +1700,7 @@ func (s *server) InboundPeerConnected(conn net.Conn) { s.removePeer(connectedPeer) s.ignorePeerTermination[connectedPeer] = struct{}{} s.scheduledPeerConnection[pubStr] = func() { - s.peerConnected(conn, nil, false) + s.peerConnected(conn, nil, true) } } } @@ -1769,7 +1770,7 @@ func (s *server) OutboundPeerConnected(connReq *connmgr.ConnReq, conn net.Conn) case ErrPeerNotConnected: // We were unable to locate an existing connection with the // target peer, proceed to connect. - s.peerConnected(conn, connReq, true) + s.peerConnected(conn, connReq, false) case nil: // We already have a connection open with the target peer. @@ -1800,7 +1801,7 @@ func (s *server) OutboundPeerConnected(connReq *connmgr.ConnReq, conn net.Conn) s.removePeer(connectedPeer) s.ignorePeerTermination[connectedPeer] = struct{}{} s.scheduledPeerConnection[pubStr] = func() { - s.peerConnected(conn, connReq, true) + s.peerConnected(conn, connReq, false) } } } From 077b1fffcc1ea260b3d415c98f3f13b8c633dc6f Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Tue, 3 Apr 2018 01:16:10 -0400 Subject: [PATCH 2/2] Revert "rpcserver: flip inbound bool for display, fix internally later" This reverts commit 5126e431355ea074404064b91c57732e96d0a1e6 since the underlying issue has now been fixed. --- rpcserver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpcserver.go b/rpcserver.go index cfdd4502..41e346f6 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1292,7 +1292,7 @@ func (r *rpcServer) ListPeers(ctx context.Context, peer := &lnrpc.Peer{ PubKey: hex.EncodeToString(nodePub), Address: serverPeer.conn.RemoteAddr().String(), - Inbound: !serverPeer.inbound, // Flip for display + Inbound: serverPeer.inbound, BytesRecv: atomic.LoadUint64(&serverPeer.bytesReceived), BytesSent: atomic.LoadUint64(&serverPeer.bytesSent), SatSent: satSent,