overlay sim fix

This commit is contained in:
zelig 2017-02-17 00:03:35 +06:30 committed by Lewis Marshall
parent 7c0a205335
commit 01fb8ed943
2 changed files with 9 additions and 14 deletions

View file

@ -328,12 +328,6 @@ func (self *Conn) nodesUp() error {
return nil return nil
} }
// sa := node.Adapter()
// err := sa.Stop()
// if err != nil {
// return err
// }
// Start(id) starts up the node (relevant only for instance with own p2p or remote) // Start(id) starts up the node (relevant only for instance with own p2p or remote)
func (self *Network) Start(id *adapters.NodeId) error { func (self *Network) Start(id *adapters.NodeId) error {
node := self.GetNode(id) node := self.GetNode(id)

View file

@ -29,6 +29,7 @@ type Network struct {
// SimNode is the adapter used by Swarm simulations. // SimNode is the adapter used by Swarm simulations.
type SimNode struct { type SimNode struct {
connect func(s string) error
hive *network.Hive hive *network.Hive
adapters.NodeAdapter adapters.NodeAdapter
} }
@ -41,11 +42,7 @@ func af() <-chan time.Time {
// Start() starts up the hive // Start() starts up the hive
// makes SimNode implement *NodeAdapter // makes SimNode implement *NodeAdapter
func (self *SimNode) Start() error { func (self *SimNode) Start() error {
connect := func(s string) error { return self.hive.Start(self.connect, af)
id := network.HexToBytes(s)
return self.Connect(id)
}
return self.hive.Start(connect, af)
} }
// Stop() shuts down the hive // Stop() shuts down the hive
@ -71,7 +68,11 @@ func (self *Network) NewSimNode(conf *simulations.NodeConfig) adapters.NodeAdapt
// bzz protocol Run function. messaging through SimPipe // bzz protocol Run function. messaging through SimPipe
ct := network.BzzCodeMap(network.HiveMsgs...) // bzz protocol code map ct := network.BzzCodeMap(network.HiveMsgs...) // bzz protocol code map
na.Run = network.Bzz(addr.OverlayAddr(), pp, na, ct, nil).Run na.Run = network.Bzz(addr.OverlayAddr(), pp, na, ct, nil).Run
connect := func(s string) error {
return self.Connect(id, adapters.NewNodeIdFromHex(s))
}
return &SimNode{ return &SimNode{
connect: connect,
hive: pp, hive: pp,
NodeAdapter: na, NodeAdapter: na,
} }
@ -106,7 +107,7 @@ func NewSessionController() (*simulations.ResourceController, chan bool) {
if parent != nil { if parent != nil {
parent.SetResource(conf.Id, c) parent.SetResource(conf.Id, c)
} }
ids := p2ptest.RandomNodeIds(5) ids := p2ptest.RandomNodeIds(50)
for _, id := range ids { for _, id := range ids {
ppnet.NewNode(&simulations.NodeConfig{Id: id}) ppnet.NewNode(&simulations.NodeConfig{Id: id})
ppnet.Start(id) ppnet.Start(id)