Skip to content

Commit

Permalink
server: Use server peer in log statements.
Browse files Browse the repository at this point in the history
This change a few cases that log the peer to use the server peer instead
of the underlying peer from the peer package.  This doesn't change the
output in any way, but it is more consistent with the vast majority of
other instances.  It also preferable since it ensures consistent logging
output if a custom stringer is ever implemented on server peers.
  • Loading branch information
davecgh committed Oct 28, 2023
1 parent 517091c commit b60de60
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ func (sp *serverPeer) pushAddrMsg(addresses []*addrmgr.NetAddress) {
}
known, err := sp.PushAddrMsg(addrs)
if err != nil {
peerLog.Errorf("Can't push address message to %s: %v", sp.Peer, err)
peerLog.Errorf("Can't push address message to %s: %v", sp, err)
sp.Disconnect()
return
}
Expand Down Expand Up @@ -739,7 +739,7 @@ func (sp *serverPeer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion) {
// Reject peers that have a protocol version that is too old.
if msg.ProtocolVersion < int32(wire.SendHeadersVersion) {
srvrLog.Debugf("Rejecting peer %s with protocol version %d prior to "+
"the required version %d", sp.Peer, msg.ProtocolVersion,
"the required version %d", sp, msg.ProtocolVersion,
wire.SendHeadersVersion)
sp.Disconnect()
return
Expand All @@ -750,8 +750,7 @@ func (sp *serverPeer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion) {
if !isInbound && !hasServices(msg.Services, wantServices) {
missingServices := wantServices & ^msg.Services
srvrLog.Debugf("Rejecting peer %s with services %v due to not "+
"providing desired services %v", sp.Peer, msg.Services,
missingServices)
"providing desired services %v", sp, msg.Services, missingServices)
sp.Disconnect()
return
}
Expand Down Expand Up @@ -874,7 +873,7 @@ func (sp *serverPeer) pushMiningStateMsg(height uint32, blockHashes []chainhash.
// mined on and pushes a miningstate wire message back to the requesting peer.
func (sp *serverPeer) OnGetMiningState(_ *peer.Peer, msg *wire.MsgGetMiningState) {
if sp.getMiningStateSent {
peerLog.Tracef("Ignoring getminingstate from %v - already sent", sp.Peer)
peerLog.Tracef("Ignoring getminingstate from %v - already sent", sp)
return
}
sp.getMiningStateSent = true
Expand Down Expand Up @@ -961,7 +960,7 @@ func (sp *serverPeer) OnMiningState(_ *peer.Peer, msg *wire.MsgMiningState) {
// It sends the available requested info to the remote peer.
func (sp *serverPeer) OnGetInitState(_ *peer.Peer, msg *wire.MsgGetInitState) {
if sp.initStateSent {
peerLog.Tracef("Ignoring getinitstate from %v - already sent", sp.Peer)
peerLog.Tracef("Ignoring getinitstate from %v - already sent", sp)
return
}
sp.initStateSent = true
Expand Down Expand Up @@ -1264,8 +1263,7 @@ func (sp *serverPeer) OnGetHeaders(_ *peer.Peer, msg *wire.MsgGetHeaders) {
workSum, err := chain.ChainWork(&tipHash)
if err == nil && workSum.Lt(&sp.server.minKnownWork) {
srvrLog.Debugf("Sending empty headers to peer %s in response to "+
"getheaders due to local best known tip having too little work",
sp.Peer)
"getheaders due to local best known tip having too little work", sp)
sp.QueueMessage(&wire.MsgHeaders{}, nil)
return
}
Expand Down Expand Up @@ -1373,7 +1371,7 @@ func (sp *serverPeer) OnGetAddr(_ *peer.Peer, msg *wire.MsgGetAddr) {
// Only respond with addresses once per connection. This helps reduce
// traffic and further reduces fingerprinting attacks.
if sp.addrsSent {
peerLog.Tracef("Ignoring getaddr from %v - already sent", sp.Peer)
peerLog.Tracef("Ignoring getaddr from %v - already sent", sp)
return
}
sp.addrsSent = true
Expand Down

0 comments on commit b60de60

Please sign in to comment.