From b7c7d95f4f3d22230d3874851c8a59e794febe69 Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Thu, 14 Feb 2019 10:27:47 -0500 Subject: [PATCH] swarm/network: early depth check --- swarm/network/kademlia.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/swarm/network/kademlia.go b/swarm/network/kademlia.go index c3b8995085..d705a2e43a 100644 --- a/swarm/network/kademlia.go +++ b/swarm/network/kademlia.go @@ -710,6 +710,11 @@ func (k *Kademlia) saturation() int { func (k *Kademlia) isSaturated(peersPerBin []int, depth int) bool { // depth could be calculated from k but as this is called from `GetHealthInfo()`, // the depth has already been calculated so we can require it as a parameter + + // early check for depth + if depth != len(peersPerBin) { + return false + } unsaturatedBins := make([]int, 0) k.conns.EachBin(k.base, Pof, 0, func(po, size int, f func(func(val pot.Val) bool) bool) bool { @@ -726,10 +731,6 @@ func (k *Kademlia) isSaturated(peersPerBin []int, depth int) bool { }) log.Trace("list of unsaturated bins", "unsaturatedBins", unsaturatedBins) - // early check for depth - if depth != len(peersPerBin) { - return false - } return len(unsaturatedBins) == 0 }