From 72c33f2acade57eec02227bddf058de35a40218b Mon Sep 17 00:00:00 2001 From: Yilun Date: Fri, 10 Jul 2020 13:29:14 -0700 Subject: [PATCH] Connect to random neighbors without sleep if random nbr is not full Signed-off-by: Yilun --- node/neighbor.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/node/neighbor.go b/node/neighbor.go index fc0ee0f5d..064cec32d 100644 --- a/node/neighbor.go +++ b/node/neighbor.go @@ -14,7 +14,7 @@ import ( const ( maxNumRandomNeighbors = 16 - randomNeighborConnectInterval = 5 * config.ConsensusTimeout + randomNeighborConnectInterval = 4 * config.ConsensusTimeout ) // The neighbor node list @@ -95,14 +95,16 @@ func (localNode *LocalNode) startConnectingToRandomNeighbors() { } for { - time.Sleep(util.RandDuration(randomNeighborConnectInterval, 1.0/3.0)) - if len(localNode.randomNeighbors) >= maxNumRandomNeighbors { + time.Sleep(util.RandDuration(randomNeighborConnectInterval, 1.0/3.0)) + nbr := localNode.GetNbrNode(localNode.randomNeighbors[0]) if nbr != nil && !nbr.nnetNode.IsStopped() { c.MaybeStopRemoteNode(nbr.nnetNode) } localNode.randomNeighbors = localNode.randomNeighbors[1:] + } else { + time.Sleep(time.Second) } randID := util.RandomBytes(config.NodeIDBytes)