Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
swarm/network: Rename Got to Connect
Browse files Browse the repository at this point in the history
  • Loading branch information
nolash committed Dec 18, 2018
1 parent 1b6f698 commit 7b6829a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
46 changes: 23 additions & 23 deletions swarm/network/kademlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,18 +738,18 @@ func (k *Kademlia) connectedNeighbours(peers [][]byte) (got bool, n int, missing
// iterate through nearest neighbors in the peerpot map
// if we can't find the neighbor in the map we created above
// then we don't know all our neighbors
var gots int
var connects int
var culprits [][]byte
for _, p := range peers {
pk := common.Bytes2Hex(p)
if pm[pk] {
gots++
connects++
} else {
log.Trace(fmt.Sprintf("%08x: ExpNN: %s not found", k.base, pk))
culprits = append(culprits, p)
}
}
return gots == len(peers), gots, culprits
return connects == len(peers), connects, culprits
}

// connectedPotential checks whether the peer is connected to a health minimum of peers it knows about in bins that are shallower than depth
Expand Down Expand Up @@ -785,15 +785,15 @@ func (k *Kademlia) connectedPotential() []uint8 {
// Health state of the Kademlia
// used for testing only
type Health struct {
KnowNN bool // whether node knows all its nearest neighbours
CountKnowNN int // amount of nearest neighbors connected to
CulpritsKnowNN [][]byte // which known NNs are missing
GotNN bool // whether node is connected to all its nearest neighbours
CountGotNN int // amount of nearest neighbors connected to
CulpritsGotNN [][]byte // which known NNs are missing
Potent bool // have we connected to a healthy minimum of known peers shallower than depth
Saturated bool // whether we have all the peers we'd like to have
Hive string
KnowNN bool // whether node knows all its nearest neighbours
CountKnowNN int // amount of nearest neighbors connected to
CulpritsKnowNN [][]byte // which known NNs are missing
ConnectNN bool // whether node is connected to all its nearest neighbours
CountConnectNN int // amount of nearest neighbors connected to
CulpritsConnectNN [][]byte // which known NNs are missing
Potent bool // have we connected to a healthy minimum of known peers shallower than depth
Saturated bool // whether we have all the peers we'd like to have
Hive string
}

// Healthy reports the health state of the kademlia connectivity
Expand All @@ -802,21 +802,21 @@ type Health struct {
func (k *Kademlia) Healthy(pp *PeerPot) *Health {
k.lock.RLock()
defer k.lock.RUnlock()
gotnn, countgotnn, culpritsgotnn := k.connectedNeighbours(pp.NNSet)
connectnn, countconnectnn, culpritsconnectnn := k.connectedNeighbours(pp.NNSet)
knownn, countknownn, culpritsknownn := k.knowNeighbours(pp.NNSet)
depth := depthForPot(k.conns, k.MinProxBinSize, k.base)
impotentBins := k.connectedPotential()
saturated := k.saturation() < depth
log.Trace(fmt.Sprintf("%08x: healthy: knowNNs: %v, gotNNs: %v, saturated: %v\n", k.base, knownn, gotnn, saturated))
log.Trace(fmt.Sprintf("%08x: healthy: knowNNs: %v, connectNNs: %v, saturated: %v\n", k.base, knownn, connectnn, saturated))
return &Health{
KnowNN: knownn,
CountKnowNN: countknownn,
CulpritsKnowNN: culpritsknownn,
GotNN: gotnn,
CountGotNN: countgotnn,
CulpritsGotNN: culpritsgotnn,
Saturated: saturated,
Potent: len(impotentBins) == 0,
Hive: k.string(),
KnowNN: knownn,
CountKnowNN: countknownn,
CulpritsKnowNN: culpritsknownn,
ConnectNN: connectnn,
CountConnectNN: countconnectnn,
CulpritsConnectNN: culpritsconnectnn,
Saturated: saturated,
Potent: len(impotentBins) == 0,
Hive: k.string(),
}
}
6 changes: 3 additions & 3 deletions swarm/network/kademlia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func getHealth(k *Kademlia) *Health {
// - we are connected to all known neighbors
func assertHealthSimple(t *testing.T, k *Kademlia, expectHealthy bool) error {
healthParams := getHealth(k)
health := healthParams.KnowNN && healthParams.GotNN && healthParams.CountKnowNN > 0
health := healthParams.KnowNN && healthParams.ConnectNN && healthParams.CountKnowNN > 0
if expectHealthy != health {
return fmt.Errorf("expected kademlia health %v, is %v\n%v", expectHealthy, health, k.String())
}
Expand All @@ -287,7 +287,7 @@ func assertHealthSimple(t *testing.T, k *Kademlia, expectHealthy bool) error {
// - IF we know of peers in bins shallower than depth, connected to at least HealthBinSize of them
func assertHealthPotential(t *testing.T, k *Kademlia, expectHealthyAndPotent bool) error {
healthParams := getHealth(k)
health := healthParams.KnowNN && healthParams.GotNN && healthParams.CountKnowNN > 0 && healthParams.Potent
health := healthParams.KnowNN && healthParams.ConnectNN && healthParams.CountKnowNN > 0 && healthParams.Potent
if expectHealthyAndPotent != health {
return fmt.Errorf("expected kademlia health %v, is %v\n%v", expectHealthyAndPotent, health, k.String())
}
Expand Down Expand Up @@ -693,7 +693,7 @@ func testKademliaCase(t *testing.T, pivotAddr string, addrs ...string) {
}

h := k.Healthy(pp)
if !(h.GotNN && h.KnowNN && h.CountKnowNN > 0) {
if !(h.ConnectNN && h.KnowNN && h.CountKnowNN > 0) {
t.Fatalf("not healthy: %#v\n%v", h, k.String())
}
}
Expand Down
8 changes: 4 additions & 4 deletions swarm/network/simulation/kademlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ func (s *Simulation) WaitTillHealthy(ctx context.Context) (ill map[enode.ID]*net
h := k.Healthy(pp)
//print info
log.Debug(k.String())
log.Debug("kademlia", "gotNN", h.GotNN, "knowNN", h.KnowNN)
log.Debug("kademlia", "health", h.GotNN && h.KnowNN, "addr", hex.EncodeToString(k.BaseAddr()), "node", id)
log.Debug("kademlia", "ill condition", !h.GotNN, "addr", hex.EncodeToString(k.BaseAddr()), "node", id)
if !h.GotNN {
log.Debug("kademlia", "connectNN", h.ConnectNN, "knowNN", h.KnowNN)
log.Debug("kademlia", "health", h.ConnectNN && h.KnowNN, "addr", hex.EncodeToString(k.BaseAddr()), "node", id)
log.Debug("kademlia", "ill condition", !h.ConnectNN, "addr", hex.EncodeToString(k.BaseAddr()), "node", id)
if !h.ConnectNN {
ill[id] = k
}
}
Expand Down
12 changes: 6 additions & 6 deletions swarm/network/simulations/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul
if err := client.Call(&healthy, "hive_healthy", ppmap); err != nil {
return false, fmt.Errorf("error getting node health: %s", err)
}
log.Info(fmt.Sprintf("node %4s healthy: got nearest neighbours: %v, know nearest neighbours: %v,\n\n%v", id, healthy.GotNN, healthy.KnowNN, healthy.Hive))
return healthy.KnowNN && healthy.GotNN, nil
log.Info(fmt.Sprintf("node %4s healthy: connected nearest neighbours: %v, know nearest neighbours: %v,\n\n%v", id, healthy.ConnectNN, healthy.KnowNN, healthy.Hive))
return healthy.KnowNN && healthy.ConnectNN, nil
}

// 64 nodes ~ 1min
Expand Down Expand Up @@ -409,7 +409,7 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
return fmt.Errorf("error getting node health: %s", err)
}

log.Info(fmt.Sprintf("NODE: %s, IS HEALTHY: %t", addr, healthy.GotNN && healthy.KnowNN && healthy.CountKnowNN > 0))
log.Info(fmt.Sprintf("NODE: %s, IS HEALTHY: %t", addr, healthy.ConnectNN && healthy.KnowNN && healthy.CountKnowNN > 0))
var nodeStr string
if err := client.Call(&nodeStr, "hive_string"); err != nil {
return fmt.Errorf("error getting node string %s", err)
Expand All @@ -418,7 +418,7 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
for _, a := range addrs {
log.Info(common.Bytes2Hex(a))
}
if !healthy.GotNN || healthy.CountKnowNN == 0 {
if !healthy.ConnectNN || healthy.CountKnowNN == 0 {
isHealthy = false
break
}
Expand Down Expand Up @@ -497,9 +497,9 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
if err := client.Call(&healthy, "hive_healthy", ppmap); err != nil {
return false, fmt.Errorf("error getting node health: %s", err)
}
log.Info(fmt.Sprintf("node %4s healthy: got nearest neighbours: %v, know nearest neighbours: %v", id, healthy.GotNN, healthy.KnowNN))
log.Info(fmt.Sprintf("node %4s healthy: got nearest neighbours: %v, know nearest neighbours: %v", id, healthy.ConnectNN, healthy.KnowNN))

return healthy.KnowNN && healthy.GotNN, nil
return healthy.KnowNN && healthy.ConnectNN, nil
}

// 64 nodes ~ 1min
Expand Down

0 comments on commit 7b6829a

Please sign in to comment.