From 7358535725de3ee33164264ae9d2036fe87b8df1 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Tue, 26 Mar 2019 16:41:13 -0700 Subject: [PATCH] peer+server: log pubkey@addr --- peer.go | 2 +- server.go | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/peer.go b/peer.go index 70b40922..4cdeed57 100644 --- a/peer.go +++ b/peer.go @@ -638,7 +638,7 @@ func (p *peer) Disconnect(reason error) { // String returns the string representation of this peer. func (p *peer) String() string { - return p.conn.RemoteAddr().String() + return fmt.Sprintf("%x@%s", p.pubKeyBytes, p.conn.RemoteAddr()) } // readNextMessage reads, and returns the next message on the wire along with diff --git a/server.go b/server.go index 0a4d2ec7..441c43cd 100644 --- a/server.go +++ b/server.go @@ -2161,9 +2161,9 @@ func (s *server) InboundPeerConnected(conn net.Conn) { // the new connection s.t there's only a single connection between us. localPub := s.identityPriv.PubKey() if !connectedPeer.inbound && !shouldDropLocalConnection(localPub, nodePub) { - srvrLog.Warnf("Received inbound connection from peer %x, "+ + srvrLog.Warnf("Received inbound connection from peer %v, "+ "but already have outbound connection, dropping conn", - nodePub.SerializeCompressed()) + connectedPeer) conn.Close() return } @@ -2236,7 +2236,8 @@ func (s *server) OutboundPeerConnected(connReq *connmgr.ConnReq, conn net.Conn) return } - srvrLog.Infof("Established connection to: %v", conn.RemoteAddr()) + srvrLog.Infof("Established connection to: %x@%v", pubStr, + conn.RemoteAddr()) if connReq != nil { // A successful connection was returned by the connmgr. @@ -2268,9 +2269,9 @@ func (s *server) OutboundPeerConnected(connReq *connmgr.ConnReq, conn net.Conn) // the new connection s.t there's only a single connection between us. localPub := s.identityPriv.PubKey() if connectedPeer.inbound && shouldDropLocalConnection(localPub, nodePub) { - srvrLog.Warnf("Established outbound connection to peer %x, "+ + srvrLog.Warnf("Established outbound connection to peer %v, "+ "but already have inbound connection, dropping conn", - nodePub.SerializeCompressed()) + connectedPeer) if connReq != nil { s.connMgr.Remove(connReq.ID()) } @@ -2355,8 +2356,8 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq, addr := conn.RemoteAddr() pubKey := brontideConn.RemotePub() - srvrLog.Infof("Finalizing connection to %x, inbound=%v", - pubKey.SerializeCompressed(), inbound) + srvrLog.Infof("Finalizing connection to %x@%s, inbound=%v", + pubKey.SerializeCompressed(), addr, inbound) peerAddr := &lnwire.NetAddress{ IdentityKey: pubKey, @@ -2473,7 +2474,7 @@ func (s *server) peerInitializer(p *peer) { defer s.mu.Unlock() // Check if there are listeners waiting for this peer to come online. - srvrLog.Debugf("Notifying that peer %x is online", p.PubKey()) + srvrLog.Debugf("Notifying that peer %v is online", p) for _, peerChan := range s.peerConnectedListeners[pubStr] { select { case peerChan <- p: @@ -2527,8 +2528,7 @@ func (s *server) peerTerminationWatcher(p *peer, ready chan struct{}) { // TODO(roasbeef): instead add a PurgeInterfaceLinks function? links, err := p.server.htlcSwitch.GetLinksByInterface(p.pubKeyBytes) if err != nil && err != htlcswitch.ErrNoLinksFound { - srvrLog.Errorf("Unable to get channel links for %x: %v", - p.PubKey(), err) + srvrLog.Errorf("Unable to get channel links for %v: %v", p, err) } for _, link := range links { @@ -2540,7 +2540,7 @@ func (s *server) peerTerminationWatcher(p *peer, ready chan struct{}) { // If there were any notification requests for when this peer // disconnected, we can trigger them now. - srvrLog.Debugf("Notifying that peer %x is offline", p.PubKey()) + srvrLog.Debugf("Notifying that peer %x is offline", p) pubStr := string(pubKey.SerializeCompressed()) for _, offlineChan := range s.peerDisconnectedListeners[pubStr] { close(offlineChan) @@ -2736,13 +2736,14 @@ func (s *server) ConnectToPeer(addr *lnwire.NetAddress, perm bool) error { // connection. if reqs, ok := s.persistentConnReqs[targetPub]; ok { srvrLog.Warnf("Already have %d persistent connection "+ - "requests for %v, connecting anyway.", len(reqs), addr) + "requests for %x@%v, connecting anyway.", len(reqs), + targetPub, addr) } // If there's not already a pending or active connection to this node, // then instruct the connection manager to attempt to establish a // persistent connection to the peer. - srvrLog.Debugf("Connecting to %v", addr) + srvrLog.Debugf("Connecting to %x@%v", targetPub, addr) if perm { connReq := &connmgr.ConnReq{ Addr: addr,