@@ -196,7 +196,15 @@ type server struct {
196196 // to handle dynamic IP changes.
197197 lastDetectedIP net.IP
198198
199- mu sync.RWMutex
199+ mu sync.RWMutex
200+
201+ // peersByPub is a map of the active peers.
202+ //
203+ // NOTE: The key used here is the raw bytes of the peer's public key to
204+ // string conversion, which means it cannot be printed using `%s` as it
205+ // will just print the binary.
206+ //
207+ // TODO(yy): Use the hex string instead.
200208 peersByPub map [string ]* peer.Brontide
201209
202210 inboundPeers map [string ]* peer.Brontide
@@ -4215,9 +4223,14 @@ func (s *server) addPeer(p *peer.Brontide) {
42154223 return
42164224 }
42174225
4226+ pubBytes := p .IdentityKey ().SerializeCompressed ()
4227+
42184228 // Ignore new peers if we're shutting down.
42194229 if s .Stopped () {
4230+ srvrLog .Infof ("Server stopped, skipped adding peer=%x" ,
4231+ pubBytes )
42204232 p .Disconnect (ErrServerShuttingDown )
4233+
42214234 return
42224235 }
42234236
@@ -4226,8 +4239,9 @@ func (s *server) addPeer(p *peer.Brontide) {
42264239 // TODO(roasbeef): pipe all requests through to the
42274240 // queryHandler/peerManager
42284241
4229- pubSer := p .IdentityKey ().SerializeCompressed ()
4230- pubStr := string (pubSer )
4242+ // NOTE: This pubStr is a raw bytes to string conversion and will NOT
4243+ // be human-readable.
4244+ pubStr := string (pubBytes )
42314245
42324246 s .peersByPub [pubStr ] = p
42334247
@@ -4240,7 +4254,7 @@ func (s *server) addPeer(p *peer.Brontide) {
42404254 // Inform the peer notifier of a peer online event so that it can be reported
42414255 // to clients listening for peer events.
42424256 var pubKey [33 ]byte
4243- copy (pubKey [:], pubSer )
4257+ copy (pubKey [:], pubBytes )
42444258
42454259 s .peerNotifier .NotifyPeerOnline (pubKey )
42464260}
@@ -4257,8 +4271,12 @@ func (s *server) addPeer(p *peer.Brontide) {
42574271func (s * server ) peerInitializer (p * peer.Brontide ) {
42584272 defer s .wg .Done ()
42594273
4274+ pubBytes := p .IdentityKey ().SerializeCompressed ()
4275+
42604276 // Avoid initializing peers while the server is exiting.
42614277 if s .Stopped () {
4278+ srvrLog .Infof ("Server stopped, skipped initializing peer=%x" ,
4279+ pubBytes )
42624280 return
42634281 }
42644282
@@ -4276,8 +4294,6 @@ func (s *server) peerInitializer(p *peer.Brontide) {
42764294 s .wg .Add (1 )
42774295 go s .peerTerminationWatcher (p , ready )
42784296
4279- pubBytes := p .IdentityKey ().SerializeCompressed ()
4280-
42814297 // Start the peer! If an error occurs, we Disconnect the peer, which
42824298 // will unblock the peerTerminationWatcher.
42834299 if err := p .Start (); err != nil {
0 commit comments