aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/network/simulation/node.go
diff options
context:
space:
mode:
authorholisticode <holistic.computing@gmail.com>2018-07-31 04:55:25 +0800
committerBalint Gabor <balint.g@gmail.com>2018-07-31 04:55:25 +0800
commitd6efa691872efb723ea3177a92da9e9b31c34eba (patch)
tree9c7e85c9cab9a2cf1240db47a8de44162f69353e /swarm/network/simulation/node.go
parent3ea8ac6a9ab9e56164707119e9142f06fae4c316 (diff)
downloadgo-tangerine-d6efa691872efb723ea3177a92da9e9b31c34eba.tar
go-tangerine-d6efa691872efb723ea3177a92da9e9b31c34eba.tar.gz
go-tangerine-d6efa691872efb723ea3177a92da9e9b31c34eba.tar.bz2
go-tangerine-d6efa691872efb723ea3177a92da9e9b31c34eba.tar.lz
go-tangerine-d6efa691872efb723ea3177a92da9e9b31c34eba.tar.xz
go-tangerine-d6efa691872efb723ea3177a92da9e9b31c34eba.tar.zst
go-tangerine-d6efa691872efb723ea3177a92da9e9b31c34eba.zip
Merge netsim mig to master (#17241)
* swarm: merged stream-tests migration to develop * swarm/network: expose simulation RandomUpNode to use in stream tests * swarm/network: wait for subs in PeerEvents and fix stream.runSyncTest * swarm: enforce waitkademlia for snapshot tests * swarm: fixed syncer tests and snapshot_sync_test * swarm: linting of simulation package * swarm: address review comments * swarm/network/stream: fix delivery_test bugs and refactor * swarm/network/stream: addressed PR comments @janos * swarm/network/stream: enforce waitKademlia, improve TestIntervals * swarm/network/stream: TestIntervals not waiting for chunk to be stored
Diffstat (limited to 'swarm/network/simulation/node.go')
-rw-r--r--swarm/network/simulation/node.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/swarm/network/simulation/node.go b/swarm/network/simulation/node.go
index bc433cfd8..784588fa6 100644
--- a/swarm/network/simulation/node.go
+++ b/swarm/network/simulation/node.go
@@ -195,7 +195,7 @@ func (s *Simulation) AddNodesAndConnectStar(count int, opts ...AddNodeOption) (i
return ids, nil
}
-//Upload a snapshot
+//UploadSnapshot uploads a snapshot to the simulation
//This method tries to open the json file provided, applies the config to all nodes
//and then loads the snapshot into the Simulation network
func (s *Simulation) UploadSnapshot(snapshotFile string, opts ...AddNodeOption) error {
@@ -203,7 +203,12 @@ func (s *Simulation) UploadSnapshot(snapshotFile string, opts ...AddNodeOption)
if err != nil {
return err
}
- defer f.Close()
+ defer func() {
+ err := f.Close()
+ if err != nil {
+ log.Error("Error closing snapshot file", "err", err)
+ }
+ }()
jsonbyte, err := ioutil.ReadAll(f)
if err != nil {
return err
@@ -294,7 +299,7 @@ func (s *Simulation) StopNode(id discover.NodeID) (err error) {
// StopRandomNode stops a random node.
func (s *Simulation) StopRandomNode() (id discover.NodeID, err error) {
- n := s.randomUpNode()
+ n := s.RandomUpNode()
if n == nil {
return id, ErrNodeNotFound
}
@@ -324,18 +329,18 @@ func init() {
rand.Seed(time.Now().UnixNano())
}
-// randomUpNode returns a random SimNode that is up.
+// RandomUpNode returns a random SimNode that is up.
// Arguments are NodeIDs for nodes that should not be returned.
-func (s *Simulation) randomUpNode(exclude ...discover.NodeID) *adapters.SimNode {
+func (s *Simulation) RandomUpNode(exclude ...discover.NodeID) *adapters.SimNode {
return s.randomNode(s.UpNodeIDs(), exclude...)
}
-// randomUpNode returns a random SimNode that is not up.
+// randomDownNode returns a random SimNode that is not up.
func (s *Simulation) randomDownNode(exclude ...discover.NodeID) *adapters.SimNode {
return s.randomNode(s.DownNodeIDs(), exclude...)
}
-// randomUpNode returns a random SimNode from the slice of NodeIDs.
+// randomNode returns a random SimNode from the slice of NodeIDs.
func (s *Simulation) randomNode(ids []discover.NodeID, exclude ...discover.NodeID) *adapters.SimNode {
for _, e := range exclude {
var i int