Consistently use the peer stringer to print the peer address.
This provides more information than using the address directly.
This commit is contained in:
parent
2a42cc134f
commit
aff33f1e3c
1 changed files with 17 additions and 18 deletions
35
peer.go
35
peer.go
|
@ -259,8 +259,7 @@ func (p *peer) pushVersionMsg() error {
|
||||||
func (p *peer) handleVersionMsg(msg *btcwire.MsgVersion) {
|
func (p *peer) handleVersionMsg(msg *btcwire.MsgVersion) {
|
||||||
// Detect self connections.
|
// Detect self connections.
|
||||||
if msg.Nonce == p.server.nonce {
|
if msg.Nonce == p.server.nonce {
|
||||||
peerLog.Debugf("Disconnecting peer connected to self %s",
|
peerLog.Debugf("Disconnecting peer connected to self %s", p)
|
||||||
p.addr)
|
|
||||||
p.Disconnect()
|
p.Disconnect()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -268,7 +267,7 @@ func (p *peer) handleVersionMsg(msg *btcwire.MsgVersion) {
|
||||||
// Limit to one version message per peer.
|
// Limit to one version message per peer.
|
||||||
if p.versionKnown {
|
if p.versionKnown {
|
||||||
p.logError("Only one version message per peer is allowed %s.",
|
p.logError("Only one version message per peer is allowed %s.",
|
||||||
p.addr)
|
p)
|
||||||
p.Disconnect()
|
p.Disconnect()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -277,7 +276,7 @@ func (p *peer) handleVersionMsg(msg *btcwire.MsgVersion) {
|
||||||
p.protocolVersion = minUint32(p.protocolVersion, uint32(msg.ProtocolVersion))
|
p.protocolVersion = minUint32(p.protocolVersion, uint32(msg.ProtocolVersion))
|
||||||
p.versionKnown = true
|
p.versionKnown = true
|
||||||
peerLog.Debugf("Negotiated protocol version %d for peer %s",
|
peerLog.Debugf("Negotiated protocol version %d for peer %s",
|
||||||
p.protocolVersion, p.addr)
|
p.protocolVersion, p)
|
||||||
p.lastBlock = msg.LastBlock
|
p.lastBlock = msg.LastBlock
|
||||||
|
|
||||||
// Set the supported services for the peer to what the remote peer
|
// Set the supported services for the peer to what the remote peer
|
||||||
|
@ -304,7 +303,7 @@ func (p *peer) handleVersionMsg(msg *btcwire.MsgVersion) {
|
||||||
err = p.pushVersionMsg()
|
err = p.pushVersionMsg()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.logError("Can't send version message to %s: %v",
|
p.logError("Can't send version message to %s: %v",
|
||||||
p.addr, err)
|
p, err)
|
||||||
p.Disconnect()
|
p.Disconnect()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -828,7 +827,7 @@ func (p *peer) handleGetAddrMsg(msg *btcwire.MsgGetAddr) {
|
||||||
// Push the addresses.
|
// Push the addresses.
|
||||||
err := p.pushAddrMsg(addrCache)
|
err := p.pushAddrMsg(addrCache)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.logError("Can't push address message to %s: %v", p.addr, err)
|
p.logError("Can't push address message to %s: %v", p, err)
|
||||||
p.Disconnect()
|
p.Disconnect()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -886,7 +885,7 @@ func (p *peer) handleAddrMsg(msg *btcwire.MsgAddr) {
|
||||||
// A message that has no addresses is invalid.
|
// A message that has no addresses is invalid.
|
||||||
if len(msg.AddrList) == 0 {
|
if len(msg.AddrList) == 0 {
|
||||||
p.logError("Command [%s] from %s does not contain any addresses",
|
p.logError("Command [%s] from %s does not contain any addresses",
|
||||||
msg.Command(), p.addr)
|
msg.Command(), p)
|
||||||
p.Disconnect()
|
p.Disconnect()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -971,7 +970,7 @@ func (p *peer) readMessage() (btcwire.Message, []byte, error) {
|
||||||
summary = " (" + summary + ")"
|
summary = " (" + summary + ")"
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("Received %v%s from %s",
|
return fmt.Sprintf("Received %v%s from %s",
|
||||||
msg.Command(), summary, p.addr)
|
msg.Command(), summary, p)
|
||||||
}))
|
}))
|
||||||
peerLog.Tracef("%v", newLogClosure(func() string {
|
peerLog.Tracef("%v", newLogClosure(func() string {
|
||||||
return spew.Sdump(msg)
|
return spew.Sdump(msg)
|
||||||
|
@ -1009,7 +1008,7 @@ func (p *peer) writeMessage(msg btcwire.Message) {
|
||||||
summary = " (" + summary + ")"
|
summary = " (" + summary + ")"
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("Sending %v%s to %s", msg.Command(),
|
return fmt.Sprintf("Sending %v%s to %s", msg.Command(),
|
||||||
summary, p.addr)
|
summary, p)
|
||||||
}))
|
}))
|
||||||
peerLog.Tracef("%v", newLogClosure(func() string {
|
peerLog.Tracef("%v", newLogClosure(func() string {
|
||||||
return spew.Sdump(msg)
|
return spew.Sdump(msg)
|
||||||
|
@ -1029,7 +1028,7 @@ func (p *peer) writeMessage(msg btcwire.Message) {
|
||||||
p.server.AddBytesSent(uint64(n))
|
p.server.AddBytesSent(uint64(n))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.Disconnect()
|
p.Disconnect()
|
||||||
p.logError("Can't send message to %s: %v", p.addr, err)
|
p.logError("Can't send message to %s: %v", p, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1087,7 +1086,7 @@ out:
|
||||||
// allowed errors.
|
// allowed errors.
|
||||||
if cfg.RegressionTest && p.isAllowedByRegression(err) {
|
if cfg.RegressionTest && p.isAllowedByRegression(err) {
|
||||||
peerLog.Errorf("Allowed regression test "+
|
peerLog.Errorf("Allowed regression test "+
|
||||||
"error from %s: %v", p.addr, err)
|
"error from %s: %v", p, err)
|
||||||
idleTimer.Reset(idleTimeoutMinutes * time.Minute)
|
idleTimer.Reset(idleTimeoutMinutes * time.Minute)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -1095,7 +1094,7 @@ out:
|
||||||
// Only log the error if we're not forcibly disconnecting.
|
// Only log the error if we're not forcibly disconnecting.
|
||||||
if atomic.LoadInt32(&p.disconnect) == 0 {
|
if atomic.LoadInt32(&p.disconnect) == 0 {
|
||||||
p.logError("Can't read message from %s: %v",
|
p.logError("Can't read message from %s: %v",
|
||||||
p.addr, err)
|
p, err)
|
||||||
}
|
}
|
||||||
break out
|
break out
|
||||||
}
|
}
|
||||||
|
@ -1198,7 +1197,7 @@ out:
|
||||||
p.server.blockManager.DonePeer(p)
|
p.server.blockManager.DonePeer(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
peerLog.Tracef("Peer input handler done for %s", p.addr)
|
peerLog.Tracef("Peer input handler done for %s", p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// queueHandler handles the queueing of outgoing data for the peer. This runs
|
// queueHandler handles the queueing of outgoing data for the peer. This runs
|
||||||
|
@ -1330,7 +1329,7 @@ cleanup:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.queueWg.Done()
|
p.queueWg.Done()
|
||||||
peerLog.Tracef("Peer queue handler done for %s", p.addr)
|
peerLog.Tracef("Peer queue handler done for %s", p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// outHandler handles all outgoing messages for the peer. It must be run as a
|
// outHandler handles all outgoing messages for the peer. It must be run as a
|
||||||
|
@ -1424,7 +1423,7 @@ cleanup:
|
||||||
break cleanup
|
break cleanup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
peerLog.Tracef("Peer output handler done for %s", p.addr)
|
peerLog.Tracef("Peer output handler done for %s", p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueueMessage adds the passed bitcoin message to the peer send queue. It
|
// QueueMessage adds the passed bitcoin message to the peer send queue. It
|
||||||
|
@ -1480,7 +1479,7 @@ func (p *peer) Disconnect() {
|
||||||
if atomic.AddInt32(&p.disconnect, 1) != 1 {
|
if atomic.AddInt32(&p.disconnect, 1) != 1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
peerLog.Tracef("disconnecting %s", p.addr)
|
peerLog.Tracef("disconnecting %s", p)
|
||||||
close(p.quit)
|
close(p.quit)
|
||||||
if atomic.LoadInt32(&p.connected) != 0 {
|
if atomic.LoadInt32(&p.connected) != 0 {
|
||||||
p.conn.Close()
|
p.conn.Close()
|
||||||
|
@ -1495,7 +1494,7 @@ func (p *peer) Start() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
peerLog.Tracef("Starting peer %s", p.addr)
|
peerLog.Tracef("Starting peer %s", p)
|
||||||
|
|
||||||
// Send an initial version message if this is an outbound connection.
|
// Send an initial version message if this is an outbound connection.
|
||||||
if !p.inbound {
|
if !p.inbound {
|
||||||
|
@ -1520,7 +1519,7 @@ func (p *peer) Start() error {
|
||||||
|
|
||||||
// Shutdown gracefully shuts down the peer by disconnecting it.
|
// Shutdown gracefully shuts down the peer by disconnecting it.
|
||||||
func (p *peer) Shutdown() {
|
func (p *peer) Shutdown() {
|
||||||
peerLog.Tracef("Shutdown peer %s", p.addr)
|
peerLog.Tracef("Shutdown peer %s", p)
|
||||||
p.Disconnect()
|
p.Disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue