diff options
author | Janos Guljas <janos@resenje.org> | 2017-12-14 17:35:49 +0800 |
---|---|---|
committer | Janos Guljas <janos@resenje.org> | 2017-12-14 17:36:12 +0800 |
commit | 47a801455966298d1d1519eebb955024c8f02b84 (patch) | |
tree | 5b8144ba4844092dc0bae599fc3314eaacf1a7b4 /p2p/simulations/network.go | |
parent | 19982f946735948478b6b7e7706f1b615f171d0d (diff) | |
parent | 3654aeaa4f87452ac5bc801a18808189595e2ef8 (diff) | |
download | go-tangerine-47a801455966298d1d1519eebb955024c8f02b84.tar go-tangerine-47a801455966298d1d1519eebb955024c8f02b84.tar.gz go-tangerine-47a801455966298d1d1519eebb955024c8f02b84.tar.bz2 go-tangerine-47a801455966298d1d1519eebb955024c8f02b84.tar.lz go-tangerine-47a801455966298d1d1519eebb955024c8f02b84.tar.xz go-tangerine-47a801455966298d1d1519eebb955024c8f02b84.tar.zst go-tangerine-47a801455966298d1d1519eebb955024c8f02b84.zip |
cmd/swarm: Merge branch 'master' into multiple-ens-endpoints
Fix a conflict in cmd/swarm envVarsOverride function.
Diffstat (limited to 'p2p/simulations/network.go')
-rw-r--r-- | p2p/simulations/network.go | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/p2p/simulations/network.go b/p2p/simulations/network.go index fd8777673..caf428ece 100644 --- a/p2p/simulations/network.go +++ b/p2p/simulations/network.go @@ -403,9 +403,8 @@ func (self *Network) getNodeByName(name string) *Node { func (self *Network) GetNodes() (nodes []*Node) { self.lock.Lock() defer self.lock.Unlock() - for _, node := range self.Nodes { - nodes = append(nodes, node) - } + + nodes = append(nodes, self.Nodes...) return nodes } @@ -477,7 +476,7 @@ func (self *Network) InitConn(oneID, otherID discover.NodeID) (*Conn, error) { if err != nil { return nil, err } - if time.Now().Sub(conn.initiated) < dialBanTimeout { + if time.Since(conn.initiated) < dialBanTimeout { return nil, fmt.Errorf("connection between %v and %v recently attempted", oneID, otherID) } if conn.Up { @@ -502,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 { @@ -665,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 } |