mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
p2p: add "looking for peers" log message
This commit is contained in:
parent
323d2f5631
commit
28d1085aff
2 changed files with 28 additions and 2 deletions
26
p2p/dial.go
26
p2p/dial.go
|
|
@ -39,6 +39,10 @@ const (
|
||||||
// private networks.
|
// private networks.
|
||||||
dialHistoryExpiration = inboundThrottleTime + 5*time.Second
|
dialHistoryExpiration = inboundThrottleTime + 5*time.Second
|
||||||
|
|
||||||
|
// Config for the "Looking for peers" message.
|
||||||
|
dialStatsLogInterval = 10 * time.Second // printed at most this often
|
||||||
|
dialStatsPeerLimit = 3 // but not if more than this many dialed peers
|
||||||
|
|
||||||
// Endpoint resolution is throttled with bounded backoff.
|
// Endpoint resolution is throttled with bounded backoff.
|
||||||
initialResolveDelay = 60 * time.Second
|
initialResolveDelay = 60 * time.Second
|
||||||
maxResolveDelay = time.Hour
|
maxResolveDelay = time.Hour
|
||||||
|
|
@ -113,6 +117,10 @@ type dialScheduler struct {
|
||||||
history expHeap
|
history expHeap
|
||||||
historyTimer mclock.Timer
|
historyTimer mclock.Timer
|
||||||
historyTimerTime mclock.AbsTime
|
historyTimerTime mclock.AbsTime
|
||||||
|
|
||||||
|
// for logStats
|
||||||
|
lastStatsLog mclock.AbsTime
|
||||||
|
doneSinceLastLog int
|
||||||
}
|
}
|
||||||
|
|
||||||
type dialSetupFunc func(net.Conn, connFlag, *enode.Node) error
|
type dialSetupFunc func(net.Conn, connFlag, *enode.Node) error
|
||||||
|
|
@ -162,6 +170,7 @@ func newDialScheduler(config dialConfig, it enode.Iterator, setupFunc dialSetupF
|
||||||
addPeerCh: make(chan *conn),
|
addPeerCh: make(chan *conn),
|
||||||
remPeerCh: make(chan *conn),
|
remPeerCh: make(chan *conn),
|
||||||
}
|
}
|
||||||
|
d.lastStatsLog = d.clock.Now()
|
||||||
d.ctx, d.cancel = context.WithCancel(context.Background())
|
d.ctx, d.cancel = context.WithCancel(context.Background())
|
||||||
d.wg.Add(2)
|
d.wg.Add(2)
|
||||||
go d.readNodes(it)
|
go d.readNodes(it)
|
||||||
|
|
@ -225,6 +234,7 @@ loop:
|
||||||
nodesCh = nil
|
nodesCh = nil
|
||||||
}
|
}
|
||||||
d.rearmHistoryTimer(historyExp)
|
d.rearmHistoryTimer(historyExp)
|
||||||
|
d.logStats()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case node := <-nodesCh:
|
case node := <-nodesCh:
|
||||||
|
|
@ -238,6 +248,7 @@ loop:
|
||||||
id := task.dest.ID()
|
id := task.dest.ID()
|
||||||
delete(d.dialing, id)
|
delete(d.dialing, id)
|
||||||
d.updateStaticPool(id)
|
d.updateStaticPool(id)
|
||||||
|
d.doneSinceLastLog++
|
||||||
|
|
||||||
case c := <-d.addPeerCh:
|
case c := <-d.addPeerCh:
|
||||||
if c.is(dynDialedConn) || c.is(staticDialedConn) {
|
if c.is(dynDialedConn) || c.is(staticDialedConn) {
|
||||||
|
|
@ -312,6 +323,21 @@ func (d *dialScheduler) readNodes(it enode.Iterator) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// logStats prints dialer statistics to the log. The message is suppressed when enough
|
||||||
|
// peers are connected because users should only see it while their client is starting up
|
||||||
|
// or comes back online.
|
||||||
|
func (d *dialScheduler) logStats() {
|
||||||
|
now := d.clock.Now()
|
||||||
|
if d.lastStatsLog.Add(dialStatsLogInterval) > now {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if d.dialPeers < dialStatsPeerLimit && d.dialPeers < d.maxDialPeers {
|
||||||
|
d.log.Info("Looking for peers", "peercount", len(d.peers), "tried", d.doneSinceLastLog, "static", len(d.static))
|
||||||
|
}
|
||||||
|
d.doneSinceLastLog = 0
|
||||||
|
d.lastStatsLog = now
|
||||||
|
}
|
||||||
|
|
||||||
// rearmHistoryTimer configures d.historyTimer to fire when the
|
// rearmHistoryTimer configures d.historyTimer to fire when the
|
||||||
// next item in d.history expires.
|
// next item in d.history expires.
|
||||||
func (d *dialScheduler) rearmHistoryTimer(ch chan struct{}) {
|
func (d *dialScheduler) rearmHistoryTimer(ch chan struct{}) {
|
||||||
|
|
|
||||||
|
|
@ -726,7 +726,7 @@ running:
|
||||||
// The handshakes are done and it passed all checks.
|
// The handshakes are done and it passed all checks.
|
||||||
p := srv.launchPeer(c)
|
p := srv.launchPeer(c)
|
||||||
peers[c.node.ID()] = p
|
peers[c.node.ID()] = p
|
||||||
p.log.Debug("Adding p2p peer", "addr", p.RemoteAddr(), "peers", len(peers), "name", truncateName(c.name))
|
srv.log.Debug("Adding p2p peer", "peercount", len(peers), "id", p.ID(), "conn", c.flags, "addr", p.RemoteAddr(), "name", truncateName(c.name))
|
||||||
srv.dialsched.peerAdded(c)
|
srv.dialsched.peerAdded(c)
|
||||||
if conn, ok := c.fd.(*meteredConn); ok {
|
if conn, ok := c.fd.(*meteredConn); ok {
|
||||||
conn.handshakeDone(p)
|
conn.handshakeDone(p)
|
||||||
|
|
@ -741,7 +741,7 @@ running:
|
||||||
// A peer disconnected.
|
// A peer disconnected.
|
||||||
d := common.PrettyDuration(mclock.Now() - pd.created)
|
d := common.PrettyDuration(mclock.Now() - pd.created)
|
||||||
delete(peers, pd.ID())
|
delete(peers, pd.ID())
|
||||||
pd.log.Debug("Removing p2p peer", "addr", pd.RemoteAddr(), "peers", len(peers), "duration", d, "req", pd.requested, "err", pd.err)
|
srv.log.Debug("Removing p2p peer", "peercount", len(peers), "id", pd.ID(), "duration", d, "req", pd.requested, "err", pd.err)
|
||||||
srv.dialsched.peerRemoved(pd.rw)
|
srv.dialsched.peerRemoved(pd.rw)
|
||||||
if pd.Inbound() {
|
if pd.Inbound() {
|
||||||
inboundCount--
|
inboundCount--
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue