From 1db9d2ca957a24f71fe54cac998b66fce9387dae Mon Sep 17 00:00:00 2001
From: "alex.sharov" <AskAlexSharov@gmail.com>
Date: Sun, 4 Jul 2021 10:55:15 +0700
Subject: [PATCH] better handshake

---
 p2p/dial.go   | 11 +++++++----
 p2p/server.go |  6 +++++-
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/p2p/dial.go b/p2p/dial.go
index ce1a6e4ebd..79358082b9 100644
--- a/p2p/dial.go
+++ b/p2p/dial.go
@@ -42,7 +42,7 @@ const (
 	dialHistoryExpiration = inboundThrottleTime + 5*time.Second
 
 	// Config for the "Looking for peers" message.
-	dialStatsLogInterval = 60 * time.Second // printed at most this often
+	dialStatsLogInterval = 10 * time.Second // printed at most this often
 	dialStatsPeerLimit   = 20               // but not if more than this many dialed peers
 
 	// Endpoint resolution is throttled with bounded backoff.
@@ -247,7 +247,7 @@ loop:
 			nodesCh = nil
 		}
 		d.rearmHistoryTimer(historyExp)
-		d.logStats()
+		//d.logStats()
 
 		select {
 		case <-d.ctx.Done():
@@ -341,13 +341,16 @@ 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() {
+func (d *dialScheduler) logStats(activePeerCount, maxActivePeers int) {
 	now := d.clock.Now()
 	if d.lastStatsLog.Add(dialStatsLogInterval) > now {
 		return
 	}
 	if d.dialPeers < dialStatsPeerLimit && d.dialPeers < d.maxDialPeers {
-		d.log.Info("[p2p] Looking for peers", "protocol", d.subProtocolVersion, "peers", fmt.Sprintf("%d/%d", len(d.peers), d.maxDialPeers), "tried", d.doneSinceLastLog, "static", len(d.static))
+		active := fmt.Sprintf("%d/%d", activePeerCount, maxActivePeers)
+		connected := fmt.Sprintf("%d/%d", len(d.peers), d.maxDialPeers)
+		fmt.Printf("aa: %d,%d\n", d.maxActiveDials, d.dialPeers)
+		d.log.Info("[p2p] Peers", "protocol", d.subProtocolVersion, "activePeers", active, "connected", connected, "static", len(d.static), "tried", d.doneSinceLastLog)
 	}
 	d.doneSinceLastLog = 0
 	d.lastStatsLog = now
diff --git a/p2p/server.go b/p2p/server.go
index 3883f763e6..63ff712e2d 100644
--- a/p2p/server.go
+++ b/p2p/server.go
@@ -741,6 +741,8 @@ func (srv *Server) run() {
 	for _, n := range srv.TrustedNodes {
 		trusted[n.ID()] = true
 	}
+	logEvery := time.NewTicker(10 * time.Second)
+	defer logEvery.Stop()
 
 running:
 	for {
@@ -748,7 +750,9 @@ running:
 		case <-srv.quit:
 			// The server was stopped. Run the cleanup logic.
 			break running
-
+		case <-logEvery.C:
+			fmt.Printf("inbound: %d/%d\n", inboundCount, srv.maxInboundConns())
+			srv.dialsched.logStats(len(peers), srv.MaxPeers)
 		case n := <-srv.addtrusted:
 			// This channel is used by AddTrustedPeer to add a node
 			// to the trusted node set.
-- 
GitLab