@@ -4093,6 +4093,11 @@ func (s *server) InboundPeerConnected(conn net.Conn) {
4093
4093
s .peerConnected (conn , nil , true )
4094
4094
4095
4095
case nil :
4096
+ ctx := btclog .WithCtx (
4097
+ context .TODO (),
4098
+ lnutils .LogPubKey ("peer" , connectedPeer .IdentityKey ()),
4099
+ )
4100
+
4096
4101
// We already have a connection with the incoming peer. If the
4097
4102
// connection we've already established should be kept and is
4098
4103
// not of the same type of the new connection (inbound), then
@@ -4102,24 +4107,24 @@ func (s *server) InboundPeerConnected(conn net.Conn) {
4102
4107
if ! connectedPeer .Inbound () &&
4103
4108
! shouldDropLocalConnection (localPub , nodePub ) {
4104
4109
4105
- srvrLog .Warnf ("Received inbound connection from " +
4106
- "peer %v, but already have outbound " +
4107
- "connection, dropping conn" , connectedPeer )
4110
+ srvrLog .WarnS (ctx , "Received inbound connection from " +
4111
+ "peer, but already have outbound " +
4112
+ "connection, dropping conn" ,
4113
+ fmt .Errorf ("already have outbound conn" ))
4108
4114
conn .Close ()
4109
4115
return
4110
4116
}
4111
4117
4112
4118
// Otherwise, if we should drop the connection, then we'll
4113
4119
// disconnect our already connected peer.
4114
- srvrLog .Debugf ("Disconnecting stale connection to %v" ,
4115
- connectedPeer )
4120
+ srvrLog .DebugS (ctx , "Disconnecting stale connection" )
4116
4121
4117
4122
s .cancelConnReqs (pubStr , nil )
4118
4123
4119
4124
// Remove the current peer from the server's internal state and
4120
4125
// signal that the peer termination watcher does not need to
4121
4126
// execute for this peer.
4122
- s .removePeerUnsafe (connectedPeer )
4127
+ s .removePeerUnsafe (ctx , connectedPeer )
4123
4128
s .ignorePeerTermination [connectedPeer ] = struct {}{}
4124
4129
s .scheduledPeerConnection [pubStr ] = func () {
4125
4130
s .peerConnected (conn , nil , true )
@@ -4208,6 +4213,11 @@ func (s *server) OutboundPeerConnected(connReq *connmgr.ConnReq, conn net.Conn)
4208
4213
s .peerConnected (conn , connReq , false )
4209
4214
4210
4215
case nil :
4216
+ ctx := btclog .WithCtx (
4217
+ context .TODO (),
4218
+ lnutils .LogPubKey ("peer" , connectedPeer .IdentityKey ()),
4219
+ )
4220
+
4211
4221
// We already have a connection with the incoming peer. If the
4212
4222
// connection we've already established should be kept and is
4213
4223
// not of the same type of the new connection (outbound), then
@@ -4217,9 +4227,10 @@ func (s *server) OutboundPeerConnected(connReq *connmgr.ConnReq, conn net.Conn)
4217
4227
if connectedPeer .Inbound () &&
4218
4228
shouldDropLocalConnection (localPub , nodePub ) {
4219
4229
4220
- srvrLog .Warnf ("Established outbound connection to " +
4221
- "peer %v, but already have inbound " +
4222
- "connection, dropping conn" , connectedPeer )
4230
+ srvrLog .WarnS (ctx , "Established outbound connection " +
4231
+ "to peer, but already have inbound " +
4232
+ "connection, dropping conn" ,
4233
+ fmt .Errorf ("already have inbound conn" ))
4223
4234
if connReq != nil {
4224
4235
s .connMgr .Remove (connReq .ID ())
4225
4236
}
@@ -4230,13 +4241,12 @@ func (s *server) OutboundPeerConnected(connReq *connmgr.ConnReq, conn net.Conn)
4230
4241
// Otherwise, _their_ connection should be dropped. So we'll
4231
4242
// disconnect the peer and send the now obsolete peer to the
4232
4243
// server for garbage collection.
4233
- srvrLog .Debugf ("Disconnecting stale connection to %v" ,
4234
- connectedPeer )
4244
+ srvrLog .DebugS (ctx , "Disconnecting stale connection" )
4235
4245
4236
4246
// Remove the current peer from the server's internal state and
4237
4247
// signal that the peer termination watcher does not need to
4238
4248
// execute for this peer.
4239
- s .removePeerUnsafe (connectedPeer )
4249
+ s .removePeerUnsafe (ctx , connectedPeer )
4240
4250
s .ignorePeerTermination [connectedPeer ] = struct {}{}
4241
4251
s .scheduledPeerConnection [pubStr ] = func () {
4242
4252
s .peerConnected (conn , connReq , false )
@@ -4684,16 +4694,18 @@ func (s *server) peerInitializer(p *peer.Brontide) {
4684
4694
func (s * server ) peerTerminationWatcher (p * peer.Brontide , ready chan struct {}) {
4685
4695
defer s .wg .Done ()
4686
4696
4687
- ctx := context .TODO ()
4697
+ ctx := btclog .WithCtx (
4698
+ context .TODO (), lnutils .LogPubKey ("peer" , p .IdentityKey ()),
4699
+ )
4688
4700
4689
4701
p .WaitForDisconnect (ready )
4690
4702
4691
- srvrLog .Debugf ( "Peer %v has been disconnected" , p )
4703
+ srvrLog .DebugS ( ctx , "Peer has been disconnected" )
4692
4704
4693
4705
// If the server is exiting then we can bail out early ourselves as all
4694
4706
// the other sub-systems will already be shutting down.
4695
4707
if s .Stopped () {
4696
- srvrLog .Debugf ( "Server quitting, exit early for peer %v" , p )
4708
+ srvrLog .DebugS ( ctx , "Server quitting, exit early for peer" )
4697
4709
return
4698
4710
}
4699
4711
@@ -4728,7 +4740,7 @@ func (s *server) peerTerminationWatcher(p *peer.Brontide, ready chan struct{}) {
4728
4740
4729
4741
// If there were any notification requests for when this peer
4730
4742
// disconnected, we can trigger them now.
4731
- srvrLog .Debugf ( "Notifying that peer %v is offline" , p )
4743
+ srvrLog .DebugS ( ctx , "Notifying that peer is offline" )
4732
4744
pubStr := string (pubKey .SerializeCompressed ())
4733
4745
for _ , offlineChan := range s .peerDisconnectedListeners [pubStr ] {
4734
4746
close (offlineChan )
@@ -4758,7 +4770,7 @@ func (s *server) peerTerminationWatcher(p *peer.Brontide, ready chan struct{}) {
4758
4770
4759
4771
// First, cleanup any remaining state the server has regarding the peer
4760
4772
// in question.
4761
- s .removePeerUnsafe (p )
4773
+ s .removePeerUnsafe (ctx , p )
4762
4774
4763
4775
// Next, check to see if this is a persistent peer or not.
4764
4776
if _ , ok := s .persistentPeers [pubStr ]; ! ok {
@@ -4797,18 +4809,16 @@ func (s *server) peerTerminationWatcher(p *peer.Brontide, ready chan struct{}) {
4797
4809
// the address used by our onion service to dial
4798
4810
// to lnd), so we don't have enough information
4799
4811
// to attempt a reconnect.
4800
- srvrLog .Debugf ("Ignoring reconnection attempt " +
4801
- "to inbound peer %v without " +
4802
- "advertised address" , p )
4812
+ srvrLog .DebugS (ctx , "Ignoring reconnection attempt " +
4813
+ "to inbound peer without advertised address" )
4803
4814
return
4804
4815
4805
4816
// We came across an error retrieving an advertised
4806
4817
// address, log it, and fall back to the existing peer
4807
4818
// address.
4808
4819
default :
4809
- srvrLog .Errorf ("Unable to retrieve advertised " +
4810
- "address for node %x: %v" , p .PubKey (),
4811
- err )
4820
+ srvrLog .ErrorS (ctx , "Unable to retrieve advertised " +
4821
+ "address for peer" , err )
4812
4822
}
4813
4823
4814
4824
// Make an easy lookup map so that we can check if an address
@@ -4850,9 +4860,9 @@ func (s *server) peerTerminationWatcher(p *peer.Brontide, ready chan struct{}) {
4850
4860
// call can stall for arbitrarily long if we shutdown while an
4851
4861
// outbound connection attempt is being made.
4852
4862
go func () {
4853
- srvrLog .Debugf ( "Scheduling connection re-establishment to " +
4854
- "persistent peer %x in %s " ,
4855
- p . IdentityKey (). SerializeCompressed () , backoff )
4863
+ srvrLog .DebugS ( ctx , "Scheduling connection " +
4864
+ "re-establishment to persistent peer " ,
4865
+ "reconnecting_in" , backoff )
4856
4866
4857
4867
select {
4858
4868
case <- time .After (backoff ):
@@ -4862,9 +4872,8 @@ func (s *server) peerTerminationWatcher(p *peer.Brontide, ready chan struct{}) {
4862
4872
return
4863
4873
}
4864
4874
4865
- srvrLog .Debugf ("Attempting to re-establish persistent " +
4866
- "connection to peer %x" ,
4867
- p .IdentityKey ().SerializeCompressed ())
4875
+ srvrLog .DebugS (ctx , "Attempting to re-establish persistent " +
4876
+ "connection" )
4868
4877
4869
4878
s .connectToPersistentPeer (pubStr )
4870
4879
}()
@@ -4971,15 +4980,11 @@ func (s *server) connectToPersistentPeer(pubKeyStr string) {
4971
4980
// active peers.
4972
4981
//
4973
4982
// NOTE: Server mutex must be held when calling this function.
4974
- func (s * server ) removePeerUnsafe (p * peer.Brontide ) {
4983
+ func (s * server ) removePeerUnsafe (ctx context. Context , p * peer.Brontide ) {
4975
4984
if p == nil {
4976
4985
return
4977
4986
}
4978
4987
4979
- ctx := btclog .WithCtx (
4980
- context .TODO (), lnutils .LogPubKey ("peer" , p .IdentityKey ()),
4981
- )
4982
-
4983
4988
srvrLog .DebugS (ctx , "Removing peer" )
4984
4989
4985
4990
// Exit early if we have already been instructed to shutdown, the peers
0 commit comments