Make error logging in peer.go unique.

Helps tracking down errors.
This commit is contained in:
Owain G. Ainsworth 2013-09-17 23:39:22 +01:00
parent 73f08e72a2
commit 989e7a9c48

19
peer.go
View file

@ -230,7 +230,7 @@ func (p *peer) handleVersionMsg(msg *btcwire.MsgVersion) {
// Send version. // Send version.
err := p.pushVersionMsg() err := p.pushVersionMsg()
if err != nil { if err != nil {
log.Errorf("[PEER] %v", err) log.Errorf("[PEER] Can't send version message: %v", err)
p.Disconnect() p.Disconnect()
return return
} }
@ -239,7 +239,7 @@ func (p *peer) handleVersionMsg(msg *btcwire.MsgVersion) {
// Set up a NetAddress for the peer to be used with AddrManager. // Set up a NetAddress for the peer to be used with AddrManager.
na, err := newNetAddress(p.conn.RemoteAddr(), p.services) na, err := newNetAddress(p.conn.RemoteAddr(), p.services)
if err != nil { if err != nil {
log.Errorf("[PEER] %v", err) log.Errorf("[PEER] Can't get remote address: %v", err)
p.Disconnect() p.Disconnect()
return return
} }
@ -256,7 +256,8 @@ func (p *peer) handleVersionMsg(msg *btcwire.MsgVersion) {
// Advertise the local address. // Advertise the local address.
na, err := newNetAddress(p.conn.LocalAddr(), p.services) na, err := newNetAddress(p.conn.LocalAddr(), p.services)
if err != nil { if err != nil {
log.Errorf("[PEER] %v", err) log.Errorf("[PEER] Can't advertise local "+
"address: %v", err)
p.Disconnect() p.Disconnect()
return return
} }
@ -631,7 +632,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 {
log.Errorf("[PEER] %v", err) log.Errorf("[PEER] Can't push address message: %v", err)
p.Disconnect() p.Disconnect()
return return
} }
@ -775,7 +776,7 @@ func (p *peer) writeMessage(msg btcwire.Message) {
err := btcwire.WriteMessage(p.conn, msg, p.protocolVersion, p.btcnet) err := btcwire.WriteMessage(p.conn, msg, p.protocolVersion, p.btcnet)
if err != nil { if err != nil {
p.Disconnect() p.Disconnect()
log.Errorf("[PEER] %v", err) log.Errorf("[PEER] Can't send message: %v", err)
return return
} }
} }
@ -818,13 +819,14 @@ out:
// regression test mode and the error is one of the // regression test mode and the error is one of the
// allowed errors. // allowed errors.
if cfg.RegressionTest && p.isAllowedByRegression(err) { if cfg.RegressionTest && p.isAllowedByRegression(err) {
log.Errorf("[PEER] %v", err) log.Errorf("[PEER] Allowed regression test"+
"error: %v", err)
continue continue
} }
// Only log the error if we're not forcibly disconnecting. // Only log the error if we're not forcibly disconnecting.
if !p.disconnect { if !p.disconnect {
log.Errorf("[PEER] %v", err) log.Errorf("[PEER] Can't read message: %v", err)
} }
break out break out
} }
@ -998,7 +1000,8 @@ func (p *peer) Start() error {
if !p.inbound { if !p.inbound {
err := p.pushVersionMsg() err := p.pushVersionMsg()
if err != nil { if err != nil {
log.Errorf("[PEER] %v", err) log.Errorf("[PEER] Can't send outbound version "+
"message %v", err)
p.conn.Close() p.conn.Close()
return err return err
} }