diff options
author | holisticode <holistic.computing@gmail.com> | 2017-12-13 02:10:41 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-12-13 02:10:41 +0800 |
commit | fd777bb2104f15cb7c2f7eede7069ad436e29b57 (patch) | |
tree | 040b0474fa84b4f5e092bd1364fd88a6d0ac586b /p2p/simulations/network.go | |
parent | 3da1bf8ca18f54d9bd2c8c110854dc071ee3898b (diff) | |
download | dexon-fd777bb2104f15cb7c2f7eede7069ad436e29b57.tar dexon-fd777bb2104f15cb7c2f7eede7069ad436e29b57.tar.gz dexon-fd777bb2104f15cb7c2f7eede7069ad436e29b57.tar.bz2 dexon-fd777bb2104f15cb7c2f7eede7069ad436e29b57.tar.lz dexon-fd777bb2104f15cb7c2f7eede7069ad436e29b57.tar.xz dexon-fd777bb2104f15cb7c2f7eede7069ad436e29b57.tar.zst dexon-fd777bb2104f15cb7c2f7eede7069ad436e29b57.zip |
p2p/simulations: add mocker functionality (#15207)
This commit adds mocker functionality to p2p/simulations. A
mocker allows to starting/stopping of nodes via the HTTP API.
Diffstat (limited to 'p2p/simulations/network.go')
-rw-r--r-- | p2p/simulations/network.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/p2p/simulations/network.go b/p2p/simulations/network.go index f3dda2e44..caf428ece 100644 --- a/p2p/simulations/network.go +++ b/p2p/simulations/network.go @@ -501,6 +501,20 @@ func (self *Network) Shutdown() { close(self.quitc) } +//Reset resets all network properties: +//emtpies the nodes and the connection list +func (self *Network) Reset() { + self.lock.Lock() + defer self.lock.Unlock() + + //re-initialize the maps + self.connMap = make(map[string]int) + self.nodeMap = make(map[discover.NodeID]int) + + self.Nodes = nil + self.Conns = nil +} + // Node is a wrapper around adapters.Node which is used to track the status // of a node in the network type Node struct { @@ -664,6 +678,12 @@ func (self *Network) Load(snap *Snapshot) error { } } for _, conn := range snap.Conns { + + if !self.GetNode(conn.One).Up || !self.GetNode(conn.Other).Up { + //in this case, at least one of the nodes of a connection is not up, + //so it would result in the snapshot `Load` to fail + continue + } if err := self.Connect(conn.One, conn.Other); err != nil { return err } |