Merge pull request #1008 from wpaulino/peer-connection-logic

server: fix inbound/outbound peer connection logic
This commit is contained in:
Olaoluwa Osuntokun 2018-06-06 18:07:18 -07:00 committed by GitHub
commit 849ee5e0dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

@ -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,

@ -1513,7 +1513,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) {
@ -1525,7 +1526,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 "+
@ -1648,7 +1649,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
@ -1675,7 +1676,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)
}
}
}
@ -1745,7 +1746,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.
@ -1776,7 +1777,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)
}
}
}