aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/network/simulation
diff options
context:
space:
mode:
authorlash <nolash@users.noreply.github.com>2019-01-10 19:33:51 +0800
committerViktor TrĂ³n <viktor.tron@gmail.com>2019-01-10 19:33:51 +0800
commit7240f4d800d3ffb97cf23a27d13746428d761cec (patch)
tree7a632be60e304e1aed98a826dc526df48c3a1c0e /swarm/network/simulation
parent7ca40306af9da68a0d31439117246de8247f99d6 (diff)
downloaddexon-7240f4d800d3ffb97cf23a27d13746428d761cec.tar.gz
dexon-7240f4d800d3ffb97cf23a27d13746428d761cec.tar.zst
dexon-7240f4d800d3ffb97cf23a27d13746428d761cec.zip
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
Diffstat (limited to 'swarm/network/simulation')
-rw-r--r--swarm/network/simulation/example_test.go13
-rw-r--r--swarm/network/simulation/kademlia.go4
-rw-r--r--swarm/network/simulation/kademlia_test.go3
-rw-r--r--swarm/network/simulation/simulation.go21
4 files changed, 23 insertions, 18 deletions
diff --git a/swarm/network/simulation/example_test.go b/swarm/network/simulation/example_test.go
index e9a360dfd..9d1492979 100644
--- a/swarm/network/simulation/example_test.go
+++ b/swarm/network/simulation/example_test.go
@@ -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.
diff --git a/swarm/network/simulation/kademlia.go b/swarm/network/simulation/kademlia.go
index ebec468f1..6d8d0e0a2 100644
--- a/swarm/network/simulation/kademlia.go
+++ b/swarm/network/simulation/kademlia.go
@@ -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)
diff --git a/swarm/network/simulation/kademlia_test.go b/swarm/network/simulation/kademlia_test.go
index f02b0e541..36b244d3d 100644
--- a/swarm/network/simulation/kademlia_test.go
+++ b/swarm/network/simulation/kademlia_test.go
@@ -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)
diff --git a/swarm/network/simulation/simulation.go b/swarm/network/simulation/simulation.go
index 106eeb71e..13c5b1c57 100644
--- a/swarm/network/simulation/simulation.go
+++ b/swarm/network/simulation/simulation.go
@@ -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))