aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/simulations/network.go
diff options
context:
space:
mode:
authorlash <nolash@users.noreply.github.com>2018-11-12 21:57:17 +0800
committerViktor TrĂ³n <viktor.tron@gmail.com>2018-11-12 21:57:17 +0800
commit201a0bf18181da8d783f6e7adf3ceaccd159eb73 (patch)
tree2c2f85937827ddc4ca8a9b2d9382d908d6843842 /p2p/simulations/network.go
parenta0876f7433f63276a3d8d4e099b261fd16aada40 (diff)
downloadgo-tangerine-201a0bf18181da8d783f6e7adf3ceaccd159eb73.tar
go-tangerine-201a0bf18181da8d783f6e7adf3ceaccd159eb73.tar.gz
go-tangerine-201a0bf18181da8d783f6e7adf3ceaccd159eb73.tar.bz2
go-tangerine-201a0bf18181da8d783f6e7adf3ceaccd159eb73.tar.lz
go-tangerine-201a0bf18181da8d783f6e7adf3ceaccd159eb73.tar.xz
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 'p2p/simulations/network.go')
-rw-r--r--p2p/simulations/network.go44
1 files changed, 41 insertions, 3 deletions
diff --git a/p2p/simulations/network.go b/p2p/simulations/network.go
index 200015ff3..92ccfde81 100644
--- a/p2p/simulations/network.go
+++ b/p2p/simulations/network.go
@@ -644,11 +644,18 @@ type NodeSnapshot struct {
// Snapshot creates a network snapshot
func (net *Network) Snapshot() (*Snapshot, error) {
+ return net.snapshot(nil, nil)
+}
+
+func (net *Network) SnapshotWithServices(addServices []string, removeServices []string) (*Snapshot, error) {
+ return net.snapshot(addServices, removeServices)
+}
+
+func (net *Network) snapshot(addServices []string, removeServices []string) (*Snapshot, error) {
net.lock.Lock()
defer net.lock.Unlock()
snap := &Snapshot{
Nodes: make([]NodeSnapshot, len(net.Nodes)),
- Conns: make([]Conn, len(net.Conns)),
}
for i, node := range net.Nodes {
snap.Nodes[i] = NodeSnapshot{Node: *node}
@@ -660,9 +667,40 @@ func (net *Network) Snapshot() (*Snapshot, error) {
return nil, err
}
snap.Nodes[i].Snapshots = snapshots
+ for _, addSvc := range addServices {
+ haveSvc := false
+ for _, svc := range snap.Nodes[i].Node.Config.Services {
+ if svc == addSvc {
+ haveSvc = true
+ break
+ }
+ }
+ if !haveSvc {
+ snap.Nodes[i].Node.Config.Services = append(snap.Nodes[i].Node.Config.Services, addSvc)
+ }
+ }
+ if len(removeServices) > 0 {
+ var cleanedServices []string
+ for _, svc := range snap.Nodes[i].Node.Config.Services {
+ haveSvc := false
+ for _, rmSvc := range removeServices {
+ if rmSvc == svc {
+ haveSvc = true
+ break
+ }
+ }
+ if !haveSvc {
+ cleanedServices = append(cleanedServices, svc)
+ }
+
+ }
+ snap.Nodes[i].Node.Config.Services = cleanedServices
+ }
}
- for i, conn := range net.Conns {
- snap.Conns[i] = *conn
+ for _, conn := range net.Conns {
+ if conn.Up {
+ snap.Conns = append(snap.Conns, *conn)
+ }
}
return snap, nil
}