diff options
author | lash <nolash@users.noreply.github.com> | 2018-11-12 21:57:17 +0800 |
---|---|---|
committer | Viktor TrĂ³n <viktor.tron@gmail.com> | 2018-11-12 21:57:17 +0800 |
commit | 201a0bf18181da8d783f6e7adf3ceaccd159eb73 (patch) | |
tree | 2c2f85937827ddc4ca8a9b2d9382d908d6843842 /swarm/network/simulations | |
parent | a0876f7433f63276a3d8d4e099b261fd16aada40 (diff) | |
download | go-tangerine-201a0bf18181da8d783f6e7adf3ceaccd159eb73.tar.gz go-tangerine-201a0bf18181da8d783f6e7adf3ceaccd159eb73.tar.zst go-tangerine-201a0bf18181da8d783f6e7adf3ceaccd159eb73.zip |
p2p/simulations, swarm/network: Custom services in snapshot (#17991)
* p2p/simulations: Add custom services to simnodes + remove sim down conn objs
* p2p/simulation, swarm/network: Add selective services to discovery sim
* p2p/simulations, swarm/network: Remove useless comments
* p2p/simulations, swarm/network: Clean up mess from rebase
* p2p/simulation: Add sleep to prevent connect flakiness in http test
* p2p/simulations: added concurrent goroutines to prevent sleeps on simulation connect/disconnect
* p2p/simulations, swarm/network/simulations: address pr comments
* reinstated dummy service
* fixed http snapshot test
Diffstat (limited to 'swarm/network/simulations')
-rw-r--r-- | swarm/network/simulations/discovery/discovery_test.go | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/swarm/network/simulations/discovery/discovery_test.go b/swarm/network/simulations/discovery/discovery_test.go index 3c3affe58..cd5456b73 100644 --- a/swarm/network/simulations/discovery/discovery_test.go +++ b/swarm/network/simulations/discovery/discovery_test.go @@ -85,11 +85,12 @@ 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", "", "create snapshot") - loglevel = flag.Int("loglevel", 3, "verbosity of logs") - rawlog = flag.Bool("rawlog", false, "remove terminal formatting from logs") + 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") ) func init() { @@ -306,7 +307,25 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul } if *snapshotFile != "" { - snap, err := net.Snapshot() + 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") } |