aboutsummaryrefslogtreecommitdiffstats
path: root/swarm
diff options
context:
space:
mode:
authorElad <theman@elad.im>2019-01-16 21:33:02 +0800
committerRafael Matias <rafael@skyle.net>2019-02-19 19:54:56 +0800
commita3f31f51f38040e0aef76f4da95ae462fb649f81 (patch)
tree83463e8403270e1803d23609ac5a4ff2ccf61d6f /swarm
parente63995b3f36837b97330a7ccaf56277099904d26 (diff)
downloaddexon-a3f31f51f38040e0aef76f4da95ae462fb649f81.tar
dexon-a3f31f51f38040e0aef76f4da95ae462fb649f81.tar.gz
dexon-a3f31f51f38040e0aef76f4da95ae462fb649f81.tar.bz2
dexon-a3f31f51f38040e0aef76f4da95ae462fb649f81.tar.lz
dexon-a3f31f51f38040e0aef76f4da95ae462fb649f81.tar.xz
dexon-a3f31f51f38040e0aef76f4da95ae462fb649f81.tar.zst
dexon-a3f31f51f38040e0aef76f4da95ae462fb649f81.zip
cmd/swarm/swarm-snapshot: swarm snapshot generator (#18453)
* cmd/swarm/swarm-snapshot: add binary to create network snapshots * cmd/swarm/swarm-snapshot: refactor and extend tests * p2p/simulations: remove unused triggerChecks func and fix linter * internal/cmdtest: raise the timeout for killing TestCmd * cmd/swarm/swarm-snapshot: add more comments and other minor adjustments * cmd/swarm/swarm-snapshot: remove redundant check in createSnapshot * cmd/swarm/swarm-snapshot: change comment wording * p2p/simulations: revert Simulation.Run from master https://github.com/ethersphere/go-ethereum/pull/1077/files#r247078904 * cmd/swarm/swarm-snapshot: address pr comments * swarm/network/simulations/discovery: removed snapshot write to file * cmd/swarm/swarm-snapshot, swarm/network/simulations: removed redundant connection event check, fixed lint error (cherry picked from commit 34f11e752f61b81c13cdde0649a3c7b14f801c69)
Diffstat (limited to 'swarm')
-rw-r--r--swarm/network/kademlia.go2
-rw-r--r--swarm/network/simulations/discovery/discovery_test.go85
2 files changed, 11 insertions, 76 deletions
diff --git a/swarm/network/kademlia.go b/swarm/network/kademlia.go
index 7d52f26f7..da99287f1 100644
--- a/swarm/network/kademlia.go
+++ b/swarm/network/kademlia.go
@@ -640,6 +640,8 @@ func (k *Kademlia) saturation() int {
})
// TODO evaluate whether this check cannot just as well be done within the eachbin
depth := depthForPot(k.conns, k.NeighbourhoodSize, k.base)
+
+ // if in the iterator above we iterated deeper than the neighbourhood depth - return depth
if depth < prev {
return depth
}
diff --git a/swarm/network/simulations/discovery/discovery_test.go b/swarm/network/simulations/discovery/discovery_test.go
index e5121c477..7d0378987 100644
--- a/swarm/network/simulations/discovery/discovery_test.go
+++ b/swarm/network/simulations/discovery/discovery_test.go
@@ -18,16 +18,12 @@ package discovery
import (
"context"
- "encoding/json"
- "errors"
"flag"
"fmt"
"io/ioutil"
- "math/rand"
"os"
"path"
"strings"
- "sync"
"testing"
"time"
@@ -86,12 +82,10 @@ func getDbStore(nodeID string) (*state.DBStore, error) {
}
var (
- nodeCount = flag.Int("nodes", 10, "number of nodes to create (default 10)")
- initCount = flag.Int("conns", 1, "number of originally connected peers (default 1)")
- snapshotFile = flag.String("snapshot", "", "path to create snapshot file in")
- loglevel = flag.Int("loglevel", 3, "verbosity of logs")
- rawlog = flag.Bool("rawlog", false, "remove terminal formatting from logs")
- serviceOverride = flag.String("services", "", "remove or add services to the node snapshot; prefix with \"+\" to add, \"-\" to remove; example: +pss,-discovery")
+ nodeCount = flag.Int("nodes", 10, "number of nodes to create (default 10)")
+ initCount = flag.Int("conns", 1, "number of originally connected peers (default 1)")
+ loglevel = flag.Int("loglevel", 3, "verbosity of logs")
+ rawlog = flag.Bool("rawlog", false, "remove terminal formatting from logs")
)
func init() {
@@ -247,25 +241,14 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul
action := func(ctx context.Context) error {
return nil
}
- wg := sync.WaitGroup{}
for i := range ids {
// collect the overlay addresses, to
addrs = append(addrs, ids[i].Bytes())
- for j := 0; j < conns; j++ {
- var k int
- if j == 0 {
- k = (i + 1) % len(ids)
- } else {
- k = rand.Intn(len(ids))
- }
- wg.Add(1)
- go func(i, k int) {
- defer wg.Done()
- net.Connect(ids[i], ids[k])
- }(i, k)
- }
}
- wg.Wait()
+ err := net.ConnectNodesChain(nil)
+ if err != nil {
+ return nil, err
+ }
log.Debug(fmt.Sprintf("nodes: %v", len(addrs)))
// construct the peer pot, so that kademlia health can be checked
ppmap := network.NewPeerPotMap(network.NewKadParams().NeighbourhoodSize, addrs)
@@ -309,40 +292,6 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul
if result.Error != nil {
return result, nil
}
-
- if *snapshotFile != "" {
- var err error
- var snap *simulations.Snapshot
- if len(*serviceOverride) > 0 {
- var addServices []string
- var removeServices []string
- for _, osvc := range strings.Split(*serviceOverride, ",") {
- if strings.Index(osvc, "+") == 0 {
- addServices = append(addServices, osvc[1:])
- } else if strings.Index(osvc, "-") == 0 {
- removeServices = append(removeServices, osvc[1:])
- } else {
- panic("stick to the rules, you know what they are")
- }
- }
- snap, err = net.SnapshotWithServices(addServices, removeServices)
- } else {
- snap, err = net.Snapshot()
- }
-
- if err != nil {
- return nil, errors.New("no shapshot dude")
- }
- jsonsnapshot, err := json.Marshal(snap)
- if err != nil {
- return nil, fmt.Errorf("corrupt json snapshot: %v", err)
- }
- log.Info("writing snapshot", "file", *snapshotFile)
- err = ioutil.WriteFile(*snapshotFile, jsonsnapshot, 0755)
- if err != nil {
- return nil, err
- }
- }
return result, nil
}
@@ -457,23 +406,7 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
return nil
}
- //connects in a chain
- wg := sync.WaitGroup{}
- //connects in a ring
- for i := range ids {
- for j := 1; j <= conns; j++ {
- k := (i + j) % len(ids)
- if k == i {
- k = (k + 1) % len(ids)
- }
- wg.Add(1)
- go func(i, k int) {
- defer wg.Done()
- net.Connect(ids[i], ids[k])
- }(i, k)
- }
- }
- wg.Wait()
+ net.ConnectNodesChain(nil)
log.Debug(fmt.Sprintf("nodes: %v", len(addrs)))
// construct the peer pot, so that kademlia health can be checked
check := func(ctx context.Context, id enode.ID) (bool, error) {