swarm/network: Rename minproxbinsize, add as member of simulation (#18408)
* swarm/network: Rename minproxbinsize, add as member of simulation * swarm/network: Deactivate WaitTillHealthy, unreliable pending suggestpeer
This commit is contained in:
parent
7ca40306af
commit
7240f4d800
@ -54,13 +54,13 @@ var Pof = pot.DefaultPof(256)
|
||||
// KadParams holds the config params for Kademlia
|
||||
type KadParams struct {
|
||||
// adjustable parameters
|
||||
MaxProxDisplay int // number of rows the table shows
|
||||
MinProxBinSize int // nearest neighbour core minimum cardinality
|
||||
MinBinSize int // minimum number of peers in a row
|
||||
MaxBinSize int // maximum number of peers in a row before pruning
|
||||
RetryInterval int64 // initial interval before a peer is first redialed
|
||||
RetryExponent int // exponent to multiply retry intervals with
|
||||
MaxRetries int // maximum number of redial attempts
|
||||
MaxProxDisplay int // number of rows the table shows
|
||||
NeighbourhoodSize int // nearest neighbour core minimum cardinality
|
||||
MinBinSize int // minimum number of peers in a row
|
||||
MaxBinSize int // maximum number of peers in a row before pruning
|
||||
RetryInterval int64 // initial interval before a peer is first redialed
|
||||
RetryExponent int // exponent to multiply retry intervals with
|
||||
MaxRetries int // maximum number of redial attempts
|
||||
// function to sanction or prevent suggesting a peer
|
||||
Reachable func(*BzzAddr) bool `json:"-"`
|
||||
}
|
||||
@ -68,13 +68,13 @@ type KadParams struct {
|
||||
// NewKadParams returns a params struct with default values
|
||||
func NewKadParams() *KadParams {
|
||||
return &KadParams{
|
||||
MaxProxDisplay: 16,
|
||||
MinProxBinSize: 2,
|
||||
MinBinSize: 2,
|
||||
MaxBinSize: 4,
|
||||
RetryInterval: 4200000000, // 4.2 sec
|
||||
MaxRetries: 42,
|
||||
RetryExponent: 2,
|
||||
MaxProxDisplay: 16,
|
||||
NeighbourhoodSize: 2,
|
||||
MinBinSize: 2,
|
||||
MaxBinSize: 4,
|
||||
RetryInterval: 4200000000, // 4.2 sec
|
||||
MaxRetries: 42,
|
||||
RetryExponent: 2,
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ func (k *Kademlia) SuggestPeer() (a *BzzAddr, o int, want bool) {
|
||||
k.lock.Lock()
|
||||
defer k.lock.Unlock()
|
||||
minsize := k.MinBinSize
|
||||
depth := depthForPot(k.conns, k.MinProxBinSize, k.base)
|
||||
depth := depthForPot(k.conns, k.NeighbourhoodSize, k.base)
|
||||
// if there is a callable neighbour within the current proxBin, connect
|
||||
// this makes sure nearest neighbour set is fully connected
|
||||
var ppo int
|
||||
@ -306,7 +306,7 @@ func (k *Kademlia) sendNeighbourhoodDepthChange() {
|
||||
// It provides signaling of neighbourhood depth change.
|
||||
// This part of the code is sending new neighbourhood depth to nDepthC if that condition is met.
|
||||
if k.nDepthC != nil {
|
||||
nDepth := depthForPot(k.conns, k.MinProxBinSize, k.base)
|
||||
nDepth := depthForPot(k.conns, k.NeighbourhoodSize, k.base)
|
||||
if nDepth != k.nDepth {
|
||||
k.nDepth = nDepth
|
||||
k.nDepthC <- nDepth
|
||||
@ -366,7 +366,7 @@ func (k *Kademlia) EachBin(base []byte, pof pot.Pof, o int, eachBinFunc func(con
|
||||
|
||||
var startPo int
|
||||
var endPo int
|
||||
kadDepth := depthForPot(k.conns, k.MinProxBinSize, k.base)
|
||||
kadDepth := depthForPot(k.conns, k.NeighbourhoodSize, k.base)
|
||||
|
||||
k.conns.EachBin(base, Pof, o, func(po, size int, f func(func(val pot.Val, i int) bool) bool) bool {
|
||||
if startPo > 0 && endPo != k.MaxProxDisplay {
|
||||
@ -432,15 +432,15 @@ func (k *Kademlia) eachAddr(base []byte, o int, f func(*BzzAddr, int) bool) {
|
||||
func (k *Kademlia) NeighbourhoodDepth() (depth int) {
|
||||
k.lock.RLock()
|
||||
defer k.lock.RUnlock()
|
||||
return depthForPot(k.conns, k.MinProxBinSize, k.base)
|
||||
return depthForPot(k.conns, k.NeighbourhoodSize, k.base)
|
||||
}
|
||||
|
||||
// depthForPot returns the proximity order that defines the distance of
|
||||
// the nearest neighbour set with cardinality >= MinProxBinSize
|
||||
// if there is altogether less than MinProxBinSize peers it returns 0
|
||||
// the nearest neighbour set with cardinality >= NeighbourhoodSize
|
||||
// if there is altogether less than NeighbourhoodSize peers it returns 0
|
||||
// caller must hold the lock
|
||||
func depthForPot(p *pot.Pot, minProxBinSize int, pivotAddr []byte) (depth int) {
|
||||
if p.Size() <= minProxBinSize {
|
||||
func depthForPot(p *pot.Pot, neighbourhoodSize int, pivotAddr []byte) (depth int) {
|
||||
if p.Size() <= neighbourhoodSize {
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -448,7 +448,7 @@ func depthForPot(p *pot.Pot, minProxBinSize int, pivotAddr []byte) (depth int) {
|
||||
var size int
|
||||
|
||||
// determining the depth is a two-step process
|
||||
// first we find the proximity bin of the shallowest of the MinProxBinSize peers
|
||||
// first we find the proximity bin of the shallowest of the NeighbourhoodSize peers
|
||||
// the numeric value of depth cannot be higher than this
|
||||
var maxDepth int
|
||||
|
||||
@ -461,7 +461,7 @@ func depthForPot(p *pot.Pot, minProxBinSize int, pivotAddr []byte) (depth int) {
|
||||
|
||||
// this means we have all nn-peers.
|
||||
// depth is by default set to the bin of the farthest nn-peer
|
||||
if size == minProxBinSize {
|
||||
if size == neighbourhoodSize {
|
||||
maxDepth = i
|
||||
return false
|
||||
}
|
||||
@ -538,12 +538,12 @@ func (k *Kademlia) string() string {
|
||||
|
||||
rows = append(rows, "=========================================================================")
|
||||
rows = append(rows, fmt.Sprintf("%v KΛÐΞMLIΛ hive: queen's address: %x", time.Now().UTC().Format(time.UnixDate), k.BaseAddr()[:3]))
|
||||
rows = append(rows, fmt.Sprintf("population: %d (%d), MinProxBinSize: %d, MinBinSize: %d, MaxBinSize: %d", k.conns.Size(), k.addrs.Size(), k.MinProxBinSize, k.MinBinSize, k.MaxBinSize))
|
||||
rows = append(rows, fmt.Sprintf("population: %d (%d), NeighbourhoodSize: %d, MinBinSize: %d, MaxBinSize: %d", k.conns.Size(), k.addrs.Size(), k.NeighbourhoodSize, k.MinBinSize, k.MaxBinSize))
|
||||
|
||||
liverows := make([]string, k.MaxProxDisplay)
|
||||
peersrows := make([]string, k.MaxProxDisplay)
|
||||
|
||||
depth := depthForPot(k.conns, k.MinProxBinSize, k.base)
|
||||
depth := depthForPot(k.conns, k.NeighbourhoodSize, k.base)
|
||||
rest := k.conns.Size()
|
||||
k.conns.EachBin(k.base, Pof, 0, func(po, size int, f func(func(val pot.Val, i int) bool) bool) bool {
|
||||
var rowlen int
|
||||
@ -611,10 +611,10 @@ type PeerPot struct {
|
||||
|
||||
// NewPeerPotMap creates a map of pot record of *BzzAddr with keys
|
||||
// as hexadecimal representations of the address.
|
||||
// the MinProxBinSize of the passed kademlia is used
|
||||
// the NeighbourhoodSize of the passed kademlia is used
|
||||
// used for testing only
|
||||
// TODO move to separate testing tools file
|
||||
func NewPeerPotMap(minProxBinSize int, addrs [][]byte) map[string]*PeerPot {
|
||||
func NewPeerPotMap(neighbourhoodSize int, addrs [][]byte) map[string]*PeerPot {
|
||||
|
||||
// create a table of all nodes for health check
|
||||
np := pot.NewPot(nil, 0)
|
||||
@ -628,7 +628,7 @@ func NewPeerPotMap(minProxBinSize int, addrs [][]byte) map[string]*PeerPot {
|
||||
for i, a := range addrs {
|
||||
|
||||
// actual kademlia depth
|
||||
depth := depthForPot(np, minProxBinSize, a)
|
||||
depth := depthForPot(np, neighbourhoodSize, a)
|
||||
|
||||
// all nn-peers
|
||||
var nns [][]byte
|
||||
@ -670,7 +670,7 @@ func (k *Kademlia) saturation() int {
|
||||
return prev == po && size >= k.MinBinSize
|
||||
})
|
||||
// TODO evaluate whether this check cannot just as well be done within the eachbin
|
||||
depth := depthForPot(k.conns, k.MinProxBinSize, k.base)
|
||||
depth := depthForPot(k.conns, k.NeighbourhoodSize, k.base)
|
||||
if depth < prev {
|
||||
return depth
|
||||
}
|
||||
@ -683,7 +683,7 @@ func (k *Kademlia) saturation() int {
|
||||
// TODO move to separate testing tools file
|
||||
func (k *Kademlia) knowNeighbours(addrs [][]byte) (got bool, n int, missing [][]byte) {
|
||||
pm := make(map[string]bool)
|
||||
depth := depthForPot(k.conns, k.MinProxBinSize, k.base)
|
||||
depth := depthForPot(k.conns, k.NeighbourhoodSize, k.base)
|
||||
// create a map with all peers at depth and deeper known in the kademlia
|
||||
k.eachAddr(nil, 255, func(p *BzzAddr, po int) bool {
|
||||
// in order deepest to shallowest compared to the kademlia base address
|
||||
@ -719,7 +719,11 @@ func (k *Kademlia) knowNeighbours(addrs [][]byte) (got bool, n int, missing [][]
|
||||
// It is used in Healthy function for testing only
|
||||
func (k *Kademlia) connectedNeighbours(peers [][]byte) (got bool, n int, missing [][]byte) {
|
||||
pm := make(map[string]bool)
|
||||
depth := depthForPot(k.conns, k.MinProxBinSize, k.base)
|
||||
|
||||
// create a map with all peers at depth and deeper that are connected in the kademlia
|
||||
// in order deepest to shallowest compared to the kademlia base address
|
||||
// all bins (except self) are included (0 <= bin <= 255)
|
||||
depth := depthForPot(k.conns, k.NeighbourhoodSize, k.base)
|
||||
k.eachConn(nil, 255, func(p *Peer, po int) bool {
|
||||
if po < depth {
|
||||
return false
|
||||
@ -772,7 +776,7 @@ func (k *Kademlia) Healthy(pp *PeerPot) *Health {
|
||||
defer k.lock.RUnlock()
|
||||
gotnn, countgotnn, culpritsgotnn := k.connectedNeighbours(pp.NNSet)
|
||||
knownn, countknownn, culpritsknownn := k.knowNeighbours(pp.NNSet)
|
||||
depth := depthForPot(k.conns, k.MinProxBinSize, k.base)
|
||||
depth := depthForPot(k.conns, k.NeighbourhoodSize, k.base)
|
||||
saturated := k.saturation() < depth
|
||||
log.Trace(fmt.Sprintf("%08x: healthy: knowNNs: %v, gotNNs: %v, saturated: %v\n", k.base, knownn, gotnn, saturated))
|
||||
return &Health{
|
||||
|
@ -45,7 +45,7 @@ func newTestKademliaParams() *KadParams {
|
||||
params := NewKadParams()
|
||||
// TODO why is this 1?
|
||||
params.MinBinSize = 1
|
||||
params.MinProxBinSize = 2
|
||||
params.NeighbourhoodSize = 2
|
||||
return params
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ func Register(k *Kademlia, regs ...string) {
|
||||
// empty bins above the farthest "nearest neighbor-peer" then
|
||||
// the depth should be set at the farthest of those empty bins
|
||||
//
|
||||
// TODO: Make test adapt to change in MinProxBinSize
|
||||
// TODO: Make test adapt to change in NeighbourhoodSize
|
||||
func TestNeighbourhoodDepth(t *testing.T) {
|
||||
baseAddressBytes := RandomAddr().OAddr
|
||||
kad := NewKademlia(baseAddressBytes, NewKadParams())
|
||||
@ -237,7 +237,7 @@ func assertHealth(t *testing.T, k *Kademlia, expectHealthy bool, expectSaturatio
|
||||
return true
|
||||
})
|
||||
|
||||
pp := NewPeerPotMap(k.MinProxBinSize, addrs)
|
||||
pp := NewPeerPotMap(k.NeighbourhoodSize, addrs)
|
||||
healthParams := k.Healthy(pp[kid])
|
||||
|
||||
// definition of health, all conditions but be true:
|
||||
@ -605,7 +605,7 @@ func TestKademliaHiveString(t *testing.T) {
|
||||
Register(k, "10000000", "10000001")
|
||||
k.MaxProxDisplay = 8
|
||||
h := k.String()
|
||||
expH := "\n=========================================================================\nMon Feb 27 12:10:28 UTC 2017 KΛÐΞMLIΛ hive: queen's address: 000000\npopulation: 2 (4), MinProxBinSize: 2, MinBinSize: 1, MaxBinSize: 4\n============ DEPTH: 0 ==========================================\n000 0 | 2 8100 (0) 8000 (0)\n001 1 4000 | 1 4000 (0)\n002 1 2000 | 1 2000 (0)\n003 0 | 0\n004 0 | 0\n005 0 | 0\n006 0 | 0\n007 0 | 0\n========================================================================="
|
||||
expH := "\n=========================================================================\nMon Feb 27 12:10:28 UTC 2017 KΛÐΞMLIΛ hive: queen's address: 000000\npopulation: 2 (4), NeighbourhoodSize: 2, MinBinSize: 1, MaxBinSize: 4\n============ DEPTH: 0 ==========================================\n000 0 | 2 8100 (0) 8000 (0)\n001 1 4000 | 1 4000 (0)\n002 1 2000 | 1 2000 (0)\n003 0 | 0\n004 0 | 0\n005 0 | 0\n006 0 | 0\n007 0 | 0\n========================================================================="
|
||||
if expH[104:] != h[104:] {
|
||||
t.Fatalf("incorrect hive output. expected %v, got %v", expH, h)
|
||||
}
|
||||
@ -636,7 +636,7 @@ func testKademliaCase(t *testing.T, pivotAddr string, addrs ...string) {
|
||||
}
|
||||
}
|
||||
|
||||
ppmap := NewPeerPotMap(k.MinProxBinSize, byteAddrs)
|
||||
ppmap := NewPeerPotMap(k.NeighbourhoodSize, byteAddrs)
|
||||
|
||||
pp := ppmap[pivotAddr]
|
||||
|
||||
@ -662,7 +662,7 @@ in higher level tests for streaming. They were generated randomly.
|
||||
|
||||
=========================================================================
|
||||
Mon Apr 9 12:18:24 UTC 2018 KΛÐΞMLIΛ hive: queen's address: 7efef1
|
||||
population: 9 (49), MinProxBinSize: 2, MinBinSize: 2, MaxBinSize: 4
|
||||
population: 9 (49), NeighbourhoodSize: 2, MinBinSize: 2, MaxBinSize: 4
|
||||
000 2 d7e5 ec56 | 18 ec56 (0) d7e5 (0) d9e0 (0) c735 (0)
|
||||
001 2 18f1 3176 | 14 18f1 (0) 10bb (0) 10d1 (0) 0421 (0)
|
||||
002 2 52aa 47cd | 11 52aa (0) 51d9 (0) 5161 (0) 5130 (0)
|
||||
@ -745,7 +745,7 @@ in higher level tests for streaming. They were generated randomly.
|
||||
|
||||
=========================================================================
|
||||
Mon Apr 9 18:43:48 UTC 2018 KΛÐΞMLIΛ hive: queen's address: bc7f3b
|
||||
population: 9 (49), MinProxBinSize: 2, MinBinSize: 2, MaxBinSize: 4
|
||||
population: 9 (49), NeighbourhoodSize: 2, MinBinSize: 2, MaxBinSize: 4
|
||||
000 2 0f49 67ff | 28 0f49 (0) 0211 (0) 07b2 (0) 0703 (0)
|
||||
001 2 e84b f3a4 | 13 f3a4 (0) e84b (0) e58b (0) e60b (0)
|
||||
002 1 8dba | 1 8dba (0)
|
||||
@ -779,7 +779,7 @@ in higher level tests for streaming. They were generated randomly.
|
||||
|
||||
=========================================================================
|
||||
Mon Apr 9 19:04:35 UTC 2018 KΛÐΞMLIΛ hive: queen's address: b4822e
|
||||
population: 8 (49), MinProxBinSize: 2, MinBinSize: 2, MaxBinSize: 4
|
||||
population: 8 (49), NeighbourhoodSize: 2, MinBinSize: 2, MaxBinSize: 4
|
||||
000 2 786c 774b | 29 774b (0) 786c (0) 7a79 (0) 7d2f (0)
|
||||
001 2 d9de cf19 | 10 cf19 (0) d9de (0) d2ff (0) d2a2 (0)
|
||||
002 2 8ca1 8d74 | 5 8d74 (0) 8ca1 (0) 9793 (0) 9f51 (0)
|
||||
@ -813,7 +813,7 @@ in higher level tests for streaming. They were generated randomly.
|
||||
|
||||
=========================================================================
|
||||
Mon Apr 9 19:16:25 UTC 2018 KΛÐΞMLIΛ hive: queen's address: 9a90fe
|
||||
population: 8 (49), MinProxBinSize: 2, MinBinSize: 2, MaxBinSize: 4
|
||||
population: 8 (49), NeighbourhoodSize: 2, MinBinSize: 2, MaxBinSize: 4
|
||||
000 2 72ef 4e6c | 24 0b1e (0) 0d66 (0) 17f5 (0) 17e8 (0)
|
||||
001 2 fc2b fa47 | 13 fa47 (0) fc2b (0) fffd (0) ecef (0)
|
||||
002 2 b847 afa8 | 6 afa8 (0) ad77 (0) bb7c (0) b847 (0)
|
||||
@ -848,7 +848,7 @@ in higher level tests for streaming. They were generated randomly.
|
||||
|
||||
=========================================================================
|
||||
Mon Apr 9 19:25:18 UTC 2018 KΛÐΞMLIΛ hive: queen's address: 5dd5c7
|
||||
population: 13 (49), MinProxBinSize: 2, MinBinSize: 2, MaxBinSize: 4
|
||||
population: 13 (49), NeighbourhoodSize: 2, MinBinSize: 2, MaxBinSize: 4
|
||||
000 2 e528 fad0 | 22 fad0 (0) e528 (0) e3bb (0) ed13 (0)
|
||||
001 3 3f30 18e0 1dd3 | 7 3f30 (0) 23db (0) 10b6 (0) 18e0 (0)
|
||||
002 4 7c54 7804 61e4 60f9 | 10 61e4 (0) 60f9 (0) 636c (0) 7186 (0)
|
||||
|
@ -188,7 +188,7 @@ func newServices() adapters.Services {
|
||||
return k
|
||||
}
|
||||
params := NewKadParams()
|
||||
params.MinProxBinSize = 2
|
||||
params.NeighbourhoodSize = 2
|
||||
params.MaxBinSize = 3
|
||||
params.MinBinSize = 1
|
||||
params.MaxRetries = 1000
|
||||
|
@ -18,8 +18,14 @@ package simulation_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
||||
"github.com/ethereum/go-ethereum/swarm/network"
|
||||
"github.com/ethereum/go-ethereum/swarm/network/simulation"
|
||||
)
|
||||
|
||||
@ -28,10 +34,6 @@ import (
|
||||
// all nodes have the their Kademlias healthy.
|
||||
func ExampleSimulation_WaitTillHealthy() {
|
||||
|
||||
log.Error("temporarily disabled as simulations.WaitTillHealthy cannot be trusted")
|
||||
|
||||
/* Commented out to avoid go vet errors/warnings
|
||||
|
||||
sim := simulation.New(map[string]simulation.ServiceFunc{
|
||||
"bzz": func(ctx *adapters.ServiceContext, b *sync.Map) (node.Service, func(), error) {
|
||||
addr := network.NewAddr(ctx.Config.Node())
|
||||
@ -59,7 +61,7 @@ func ExampleSimulation_WaitTillHealthy() {
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
ill, err := sim.WaitTillHealthy(ctx, 2)
|
||||
ill, err := sim.WaitTillHealthy(ctx)
|
||||
if err != nil {
|
||||
// inspect the latest detected not healthy kademlias
|
||||
for id, kad := range ill {
|
||||
@ -71,7 +73,6 @@ func ExampleSimulation_WaitTillHealthy() {
|
||||
|
||||
// continue with the test
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
// Watch all peer events in the simulation network, buy receiving from a channel.
|
||||
|
@ -34,7 +34,7 @@ var BucketKeyKademlia BucketKey = "kademlia"
|
||||
// WaitTillHealthy is blocking until the health of all kademlias is true.
|
||||
// If error is not nil, a map of kademlia that was found not healthy is returned.
|
||||
// TODO: Check correctness since change in kademlia depth calculation logic
|
||||
func (s *Simulation) WaitTillHealthy(ctx context.Context, kadMinProxSize int) (ill map[enode.ID]*network.Kademlia, err error) {
|
||||
func (s *Simulation) WaitTillHealthy(ctx context.Context) (ill map[enode.ID]*network.Kademlia, err error) {
|
||||
// Prepare PeerPot map for checking Kademlia health
|
||||
var ppmap map[string]*network.PeerPot
|
||||
kademlias := s.kademlias()
|
||||
@ -43,7 +43,7 @@ func (s *Simulation) WaitTillHealthy(ctx context.Context, kadMinProxSize int) (i
|
||||
for _, k := range kademlias {
|
||||
addrs = append(addrs, k.BaseAddr())
|
||||
}
|
||||
ppmap = network.NewPeerPotMap(kadMinProxSize, addrs)
|
||||
ppmap = network.NewPeerPotMap(s.neighbourhoodSize, addrs)
|
||||
|
||||
// Wait for healthy Kademlia on every node before checking files
|
||||
ticker := time.NewTicker(200 * time.Millisecond)
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
)
|
||||
|
||||
func TestWaitTillHealthy(t *testing.T) {
|
||||
t.Skip("WaitTillHealthy depends on discovery, which relies on a reliable SuggestPeer, which is not reliable")
|
||||
|
||||
sim := New(map[string]ServiceFunc{
|
||||
"bzz": func(ctx *adapters.ServiceContext, b *sync.Map) (node.Service, func(), error) {
|
||||
@ -54,7 +55,7 @@ func TestWaitTillHealthy(t *testing.T) {
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
|
||||
defer cancel()
|
||||
ill, err := sim.WaitTillHealthy(ctx, 2)
|
||||
ill, err := sim.WaitTillHealthy(ctx)
|
||||
if err != nil {
|
||||
for id, kad := range ill {
|
||||
t.Log("Node", id)
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
"github.com/ethereum/go-ethereum/p2p/simulations"
|
||||
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
||||
"github.com/ethereum/go-ethereum/swarm/network"
|
||||
)
|
||||
|
||||
// Common errors that are returned by functions in this package.
|
||||
@ -42,13 +43,14 @@ type Simulation struct {
|
||||
// of p2p/simulations.Network.
|
||||
Net *simulations.Network
|
||||
|
||||
serviceNames []string
|
||||
cleanupFuncs []func()
|
||||
buckets map[enode.ID]*sync.Map
|
||||
pivotNodeID *enode.ID
|
||||
shutdownWG sync.WaitGroup
|
||||
done chan struct{}
|
||||
mu sync.RWMutex
|
||||
serviceNames []string
|
||||
cleanupFuncs []func()
|
||||
buckets map[enode.ID]*sync.Map
|
||||
pivotNodeID *enode.ID
|
||||
shutdownWG sync.WaitGroup
|
||||
done chan struct{}
|
||||
mu sync.RWMutex
|
||||
neighbourhoodSize int
|
||||
|
||||
httpSrv *http.Server //attach a HTTP server via SimulationOptions
|
||||
handler *simulations.Server //HTTP handler for the server
|
||||
@ -72,8 +74,9 @@ type ServiceFunc func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Se
|
||||
// which is used to start node.Service returned by ServiceFunc.
|
||||
func New(services map[string]ServiceFunc) (s *Simulation) {
|
||||
s = &Simulation{
|
||||
buckets: make(map[enode.ID]*sync.Map),
|
||||
done: make(chan struct{}),
|
||||
buckets: make(map[enode.ID]*sync.Map),
|
||||
done: make(chan struct{}),
|
||||
neighbourhoodSize: network.NewKadParams().NeighbourhoodSize,
|
||||
}
|
||||
|
||||
adapterServices := make(map[string]adapters.ServiceFunc, len(services))
|
||||
|
@ -46,7 +46,7 @@ import (
|
||||
// serviceName is used with the exec adapter so the exec'd binary knows which
|
||||
// service to execute
|
||||
const serviceName = "discovery"
|
||||
const testMinProxBinSize = 2
|
||||
const testNeighbourhoodSize = 2
|
||||
const discoveryPersistenceDatadir = "discovery_persistence_test_store"
|
||||
|
||||
var discoveryPersistencePath = path.Join(os.TempDir(), discoveryPersistenceDatadir)
|
||||
@ -268,7 +268,7 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul
|
||||
wg.Wait()
|
||||
log.Debug(fmt.Sprintf("nodes: %v", len(addrs)))
|
||||
// construct the peer pot, so that kademlia health can be checked
|
||||
ppmap := network.NewPeerPotMap(network.NewKadParams().MinProxBinSize, addrs)
|
||||
ppmap := network.NewPeerPotMap(network.NewKadParams().NeighbourhoodSize, addrs)
|
||||
check := func(ctx context.Context, id enode.ID) (bool, error) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@ -404,7 +404,7 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
|
||||
}
|
||||
healthy := &network.Health{}
|
||||
addr := id.String()
|
||||
ppmap := network.NewPeerPotMap(network.NewKadParams().MinProxBinSize, addrs)
|
||||
ppmap := network.NewPeerPotMap(network.NewKadParams().NeighbourhoodSize, addrs)
|
||||
if err := client.Call(&healthy, "hive_healthy", ppmap); err != nil {
|
||||
return fmt.Errorf("error getting node health: %s", err)
|
||||
}
|
||||
@ -492,7 +492,7 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
|
||||
return false, fmt.Errorf("error getting node client: %s", err)
|
||||
}
|
||||
healthy := &network.Health{}
|
||||
ppmap := network.NewPeerPotMap(network.NewKadParams().MinProxBinSize, addrs)
|
||||
ppmap := network.NewPeerPotMap(network.NewKadParams().NeighbourhoodSize, addrs)
|
||||
|
||||
if err := client.Call(&healthy, "hive_healthy", ppmap); err != nil {
|
||||
return false, fmt.Errorf("error getting node health: %s", err)
|
||||
@ -566,7 +566,7 @@ func newService(ctx *adapters.ServiceContext) (node.Service, error) {
|
||||
addr := network.NewAddr(ctx.Config.Node())
|
||||
|
||||
kp := network.NewKadParams()
|
||||
kp.MinProxBinSize = testMinProxBinSize
|
||||
kp.NeighbourhoodSize = testNeighbourhoodSize
|
||||
|
||||
if ctx.Config.Reachable != nil {
|
||||
kp.Reachable = func(o *network.BzzAddr) bool {
|
||||
|
@ -86,7 +86,7 @@ func (s *Simulation) NewService(ctx *adapters.ServiceContext) (node.Service, err
|
||||
addr := network.NewAddr(node)
|
||||
|
||||
kp := network.NewKadParams()
|
||||
kp.MinProxBinSize = 2
|
||||
kp.NeighbourhoodSize = 2
|
||||
kp.MaxBinSize = 4
|
||||
kp.MinBinSize = 1
|
||||
kp.MaxRetries = 1000
|
||||
|
@ -544,7 +544,7 @@ func testDeliveryFromNodes(t *testing.T, nodes, chunkCount int, skipCheck bool)
|
||||
|
||||
log.Debug("Waiting for kademlia")
|
||||
// TODO this does not seem to be correct usage of the function, as the simulation may have no kademlias
|
||||
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -704,7 +704,7 @@ func benchmarkDeliveryFromNodes(b *testing.B, nodes, chunkCount int, skipCheck b
|
||||
}
|
||||
netStore := item.(*storage.NetStore)
|
||||
|
||||
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ func testIntervals(t *testing.T, live bool, history *Range, skipCheck bool) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
|
||||
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,7 @@ func runFileRetrievalTest(nodeCount int) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -287,7 +287,7 @@ func runRetrievalTest(chunkCount int, nodeCount int) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ func testSyncingViaGlobalSync(t *testing.T, chunkCount int, nodeCount int) {
|
||||
ctx, cancelSimRun := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||
defer cancelSimRun()
|
||||
|
||||
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -391,7 +391,7 @@ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int)
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -471,7 +471,7 @@ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int)
|
||||
conf.hashes = append(conf.hashes, hashes...)
|
||||
mapKeysToNodes(conf)
|
||||
|
||||
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -563,7 +563,7 @@ func mapKeysToNodes(conf *synctestConfig) {
|
||||
np, _, _ = pot.Add(np, a, pof)
|
||||
}
|
||||
|
||||
ppmap := network.NewPeerPotMap(network.NewKadParams().MinProxBinSize, conf.addrs)
|
||||
ppmap := network.NewPeerPotMap(network.NewKadParams().NeighbourhoodSize, conf.addrs)
|
||||
|
||||
//for each address, run EachNeighbour on the chunk hashes pot to identify closest nodes
|
||||
log.Trace(fmt.Sprintf("Generated hash chunk(s): %v", conf.hashes))
|
||||
|
@ -189,7 +189,7 @@ func testSyncBetweenNodes(t *testing.T, nodes, chunkCount int, skipCheck bool, p
|
||||
}
|
||||
}
|
||||
// here we distribute chunks of a random file into stores 1...nodes
|
||||
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ func setupSim(serviceMap map[string]simulation.ServiceFunc) (int, int, *simulati
|
||||
func watchSim(sim *simulation.Simulation) (context.Context, context.CancelFunc) {
|
||||
ctx, cancelSimRun := context.WithTimeout(context.Background(), 1*time.Minute)
|
||||
|
||||
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
@ -353,7 +353,7 @@ func testSwarmNetwork(t *testing.T, o *testSwarmNetworkOptions, steps ...testSwa
|
||||
}
|
||||
|
||||
if *waitKademlia {
|
||||
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
|
||||
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ func newServices() adapters.Services {
|
||||
return k
|
||||
}
|
||||
params := network.NewKadParams()
|
||||
params.MinProxBinSize = 2
|
||||
params.NeighbourhoodSize = 2
|
||||
params.MaxBinSize = 3
|
||||
params.MinBinSize = 1
|
||||
params.MaxRetries = 1000
|
||||
|
@ -209,7 +209,7 @@ func newServices(allowRaw bool) adapters.Services {
|
||||
return k
|
||||
}
|
||||
params := network.NewKadParams()
|
||||
params.MinProxBinSize = 2
|
||||
params.NeighbourhoodSize = 2
|
||||
params.MaxBinSize = 3
|
||||
params.MinBinSize = 1
|
||||
params.MaxRetries = 1000
|
||||
|
@ -1965,7 +1965,7 @@ func newServices(allowRaw bool) adapters.Services {
|
||||
return k
|
||||
}
|
||||
params := network.NewKadParams()
|
||||
params.MinProxBinSize = 2
|
||||
params.NeighbourhoodSize = 2
|
||||
params.MaxBinSize = 3
|
||||
params.MinBinSize = 1
|
||||
params.MaxRetries = 1000
|
||||
@ -2045,7 +2045,7 @@ func newTestPss(privkey *ecdsa.PrivateKey, kad *network.Kademlia, ppextra *PssPa
|
||||
// set up routing if kademlia is not passed to us
|
||||
if kad == nil {
|
||||
kp := network.NewKadParams()
|
||||
kp.MinProxBinSize = 3
|
||||
kp.NeighbourhoodSize = 3
|
||||
kad = network.NewKademlia(nid[:], kp)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user