make logging about peers rather quieter.
Only log errors for most cases if the peer is persisent (and thus requested). Only log by default after version exchange, and after losing a peer that had completed version exchange. Make most other messages debug.
This commit is contained in:
parent
0cf8601169
commit
5c1340be8f
3 changed files with 39 additions and 21 deletions
|
@ -136,6 +136,8 @@ func (b *blockManager) handleNewPeerMsg(peers *list.List, p *peer) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Infof("[BMGR] New valid peer %s", p.addr)
|
||||||
|
|
||||||
// The peer is not a candidate for sync if it's not a full node.
|
// The peer is not a candidate for sync if it's not a full node.
|
||||||
if p.services&btcwire.SFNodeNetwork != btcwire.SFNodeNetwork {
|
if p.services&btcwire.SFNodeNetwork != btcwire.SFNodeNetwork {
|
||||||
return
|
return
|
||||||
|
@ -161,6 +163,8 @@ func (b *blockManager) handleDonePeerMsg(peers *list.List, p *peer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Infof("[BMGR] Lost peer %s", p.addr)
|
||||||
|
|
||||||
// Attempt to find a new peer to sync from if the quitting peer is the
|
// Attempt to find a new peer to sync from if the quitting peer is the
|
||||||
// sync peer.
|
// sync peer.
|
||||||
if b.syncPeer != nil && b.syncPeer == p {
|
if b.syncPeer != nil && b.syncPeer == p {
|
||||||
|
|
43
peer.go
43
peer.go
|
@ -209,7 +209,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 {
|
||||||
log.Errorf("[PEER] Only one version message per peer is allowed %s.",
|
p.logError("[PEER] Only one version message per peer is allowed %s.",
|
||||||
p.conn.RemoteAddr())
|
p.conn.RemoteAddr())
|
||||||
p.Disconnect()
|
p.Disconnect()
|
||||||
return
|
return
|
||||||
|
@ -231,7 +231,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] Can't send version message: %v", err)
|
p.logError("[PEER] Can't send version message: %v", err)
|
||||||
p.Disconnect()
|
p.Disconnect()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -240,7 +240,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] Can't get remote address: %v", err)
|
p.logError("[PEER] Can't get remote address: %v", err)
|
||||||
p.Disconnect()
|
p.Disconnect()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ 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] Can't advertise local "+
|
p.logError("[PEER] Can't advertise local "+
|
||||||
"address: %v", err)
|
"address: %v", err)
|
||||||
p.Disconnect()
|
p.Disconnect()
|
||||||
return
|
return
|
||||||
|
@ -631,7 +631,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] Can't push address message: %v", err)
|
p.logError("[PEER] Can't push address message: %v", err)
|
||||||
p.Disconnect()
|
p.Disconnect()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -684,7 +684,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 {
|
||||||
log.Errorf("[PEER] Command [%s] from %s does not contain any addresses",
|
p.logError("[PEER] Command [%s] from %s does not contain any addresses",
|
||||||
msg.Command(), p.conn.RemoteAddr())
|
msg.Command(), p.conn.RemoteAddr())
|
||||||
p.Disconnect()
|
p.Disconnect()
|
||||||
return
|
return
|
||||||
|
@ -777,7 +777,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] Can't send message: %v", err)
|
p.logError("[PEER] Can't send message: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -827,14 +827,14 @@ 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 {
|
||||||
log.Errorf("[PEER] Can't read message: %v", err)
|
p.logError("[PEER] Can't read message: %v", err)
|
||||||
}
|
}
|
||||||
break out
|
break out
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure version message comes first.
|
// Ensure version message comes first.
|
||||||
if _, ok := rmsg.(*btcwire.MsgVersion); !ok && !p.versionKnown {
|
if _, ok := rmsg.(*btcwire.MsgVersion); !ok && !p.versionKnown {
|
||||||
log.Errorf("[PEER] A version message must precede all others")
|
p.logError("[PEER] A version message must precede all others")
|
||||||
break out
|
break out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -904,7 +904,10 @@ out:
|
||||||
// the peer is done.
|
// the peer is done.
|
||||||
p.Disconnect()
|
p.Disconnect()
|
||||||
p.server.donePeers <- p
|
p.server.donePeers <- p
|
||||||
|
// Only tell blockmanager we are gone if we ever told it we existed.
|
||||||
|
if p.versionKnown {
|
||||||
p.server.blockManager.DonePeer(p)
|
p.server.blockManager.DonePeer(p)
|
||||||
|
}
|
||||||
|
|
||||||
log.Tracef("[PEER] Peer input handler done for %s", p.conn.RemoteAddr())
|
log.Tracef("[PEER] Peer input handler done for %s", p.conn.RemoteAddr())
|
||||||
}
|
}
|
||||||
|
@ -999,7 +1002,7 @@ 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] Can't send outbound version "+
|
p.logError("[PEER] Can't send outbound version "+
|
||||||
"message %v", err)
|
"message %v", err)
|
||||||
p.conn.Close()
|
p.conn.Close()
|
||||||
return err
|
return err
|
||||||
|
@ -1085,14 +1088,14 @@ func newOutboundPeer(s *server, addr string, persistent bool) *peer {
|
||||||
// function returns the peer must have a valid netaddress.
|
// function returns the peer must have a valid netaddress.
|
||||||
ip, portStr, err := net.SplitHostPort(addr)
|
ip, portStr, err := net.SplitHostPort(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Tried to create a new outbound peer with invalid "+
|
p.logError("Tried to create a new outbound peer with invalid "+
|
||||||
"address %s: %v", addr, err)
|
"address %s: %v", addr, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
port, err := strconv.ParseUint(portStr, 10, 16)
|
port, err := strconv.ParseUint(portStr, 10, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Tried to create a new outbound peer with invalid "+
|
p.logError("Tried to create a new outbound peer with invalid "+
|
||||||
"port %s: %v", portStr, err)
|
"port %s: %v", portStr, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1122,7 +1125,7 @@ func newOutboundPeer(s *server, addr string, persistent bool) *peer {
|
||||||
conn, err := dial("tcp", addr)
|
conn, err := dial("tcp", addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.retrycount += 1
|
p.retrycount += 1
|
||||||
log.Errorf("[SRVR] Failed to connect to %s: %v",
|
log.Debugf("[SRVR] Failed to connect to %s: %v",
|
||||||
faddr, err)
|
faddr, err)
|
||||||
if !persistent {
|
if !persistent {
|
||||||
p.server.donePeers <- p
|
p.server.donePeers <- p
|
||||||
|
@ -1130,7 +1133,7 @@ func newOutboundPeer(s *server, addr string, persistent bool) *peer {
|
||||||
}
|
}
|
||||||
scaledInterval := connectionRetryInterval.Nanoseconds() * p.retrycount / 2
|
scaledInterval := connectionRetryInterval.Nanoseconds() * p.retrycount / 2
|
||||||
scaledDuration := time.Duration(scaledInterval)
|
scaledDuration := time.Duration(scaledInterval)
|
||||||
log.Infof("[SRVR] Retrying connection to %s "+
|
log.Debugf("[SRVR] Retrying connection to %s "+
|
||||||
"in %s", faddr, scaledDuration)
|
"in %s", faddr, scaledDuration)
|
||||||
time.Sleep(scaledDuration)
|
time.Sleep(scaledDuration)
|
||||||
continue
|
continue
|
||||||
|
@ -1143,7 +1146,8 @@ func newOutboundPeer(s *server, addr string, persistent bool) *peer {
|
||||||
p.server.addrManager.Attempt(p.na)
|
p.server.addrManager.Attempt(p.na)
|
||||||
|
|
||||||
// Connection was successful so log it and start peer.
|
// Connection was successful so log it and start peer.
|
||||||
log.Infof("[SRVR] Connected to %s", conn.RemoteAddr())
|
log.Debugf("[SRVR] Connected to %s",
|
||||||
|
conn.RemoteAddr())
|
||||||
p.conn = conn
|
p.conn = conn
|
||||||
p.retrycount = 0
|
p.retrycount = 0
|
||||||
p.Start()
|
p.Start()
|
||||||
|
@ -1154,3 +1158,12 @@ func newOutboundPeer(s *server, addr string, persistent bool) *peer {
|
||||||
}()
|
}()
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// logError makes sure that we only log errors loudly on user peers.
|
||||||
|
func (p *peer) logError(fmt string, args...interface{}) {
|
||||||
|
if p.persistent {
|
||||||
|
log.Errorf(fmt, args...)
|
||||||
|
} else {
|
||||||
|
log.Debugf(fmt, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
11
server.go
11
server.go
|
@ -84,7 +84,7 @@ func (s *server) handleAddPeerMsg(peers *list.List, banned map[string]time.Time,
|
||||||
// Disconnect banned peers.
|
// Disconnect banned peers.
|
||||||
host, _, err := net.SplitHostPort(p.addr)
|
host, _, err := net.SplitHostPort(p.addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("[SRVR] %v", err)
|
log.Debugf("[SRVR] can't split hostport %v", err)
|
||||||
p.Shutdown()
|
p.Shutdown()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ func (s *server) handleAddPeerMsg(peers *list.List, banned map[string]time.Time,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the new peer and start it.
|
// Add the new peer and start it.
|
||||||
log.Infof("[SRVR] New peer %s (%s)", p.addr, direction)
|
log.Debugf("[SRVR] New peer %s (%s)", p.addr, direction)
|
||||||
peers.PushBack(p)
|
peers.PushBack(p)
|
||||||
if p.inbound {
|
if p.inbound {
|
||||||
p.Start()
|
p.Start()
|
||||||
|
@ -139,7 +139,7 @@ func (s *server) handleDonePeerMsg(peers *list.List, p *peer) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
peers.Remove(e)
|
peers.Remove(e)
|
||||||
log.Infof("[SRVR] Removed peer %s (%s)", p.addr,
|
log.Debugf("[SRVR] Removed peer %s (%s)", p.addr,
|
||||||
direction)
|
direction)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ func (s *server) handleDonePeerMsg(peers *list.List, p *peer) bool {
|
||||||
func (s *server) handleBanPeerMsg(banned map[string]time.Time, p *peer) {
|
func (s *server) handleBanPeerMsg(banned map[string]time.Time, p *peer) {
|
||||||
host, _, err := net.SplitHostPort(p.addr)
|
host, _, err := net.SplitHostPort(p.addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("[SRVR] %v", err)
|
log.Debugf("[SRVR] can't split ban peer %s %v", p.addr, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
direction := directionString(p.inbound)
|
direction := directionString(p.inbound)
|
||||||
|
@ -214,7 +214,8 @@ func (s *server) listenHandler(listener net.Listener) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Only log the error if we're not forcibly shutting down.
|
// Only log the error if we're not forcibly shutting down.
|
||||||
if atomic.LoadInt32(&s.shutdown) == 0 {
|
if atomic.LoadInt32(&s.shutdown) == 0 {
|
||||||
log.Errorf("[SRVR] %v", err)
|
log.Errorf("[SRVR] can't accept connection: %v",
|
||||||
|
err)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue