Skip to content

Commit

Permalink
Connect to random neighbors without sleep if random nbr is not full
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed Jul 11, 2020
1 parent afa3cfc commit 72c33f2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions node/neighbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

const (
maxNumRandomNeighbors = 16
randomNeighborConnectInterval = 5 * config.ConsensusTimeout
randomNeighborConnectInterval = 4 * config.ConsensusTimeout
)

// The neighbor node list
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 72c33f2

Please sign in to comment.