This commit is contained in:
nolash 2017-05-17 17:50:33 +02:00 committed by Lewis Marshall
parent 3a4aee8087
commit aaeb8497a0
3 changed files with 6 additions and 14 deletions

View file

@ -225,8 +225,7 @@ func (self *SimNode) Start(snapshot []byte) error {
services := []node.ServiceConstructor{} services := []node.ServiceConstructor{}
// we need to control the order of the services // so we can control the order of the services if we need
// for example, bzz needs to start before pss
for _, name := range self.config.Services { for _, name := range self.config.Services {
service := self.serviceFuncs[name](self.Id, snapshot) service := self.serviceFuncs[name](self.Id, snapshot)
services = append(services, func(ctx *node.ServiceContext) (node.Service, error) { services = append(services, func(ctx *node.ServiceContext) (node.Service, error) {

View file

@ -205,10 +205,11 @@ func RandomNodeConfig() *NodeConfig {
} }
// Services is a collection of services which can be run in a simulation // Services is a collection of services which can be run in a simulation
// it is mapped to strings representing TYPES of nodes
type Services map[string]ServiceFunc type Services map[string]ServiceFunc
// ServiceFunc returns a node.Service which can be used to boot devp2p nodes // ServiceFunc returns a node.Service which can be used to boot devp2p nodes
type ServiceFunc func(id *NodeId, snapshot []byte) node.Service type ServiceFunc func(id *NodeId, snapshot []byte) []node.Service
// serviceFuncs is a map of registered services which are used to boot devp2p // serviceFuncs is a map of registered services which are used to boot devp2p
// nodes // nodes

View file

@ -177,6 +177,7 @@ func TestPssSimpleLinear(t *testing.T) {
nodeconfig := adapters.RandomNodeConfig() nodeconfig := adapters.RandomNodeConfig()
addr := network.NewAddrFromNodeId(nodeconfig.Id) addr := network.NewAddrFromNodeId(nodeconfig.Id)
ps := newTestPss(addr.OAddr) ps := newTestPss(addr.OAddr)
ps.Register(pssPingTopic, pssPingHandler)
pt := p2ptest.NewProtocolTester(t, nodeconfig.Id, 2, newServices(), ps.Protocols()[0].Run) pt := p2ptest.NewProtocolTester(t, nodeconfig.Id, 2, newServices(), ps.Protocols()[0].Run)
msg := newPssPingMsg(ps, pssPingProtocol, pssPingTopic, []byte{1,2,3}) msg := newPssPingMsg(ps, pssPingProtocol, pssPingTopic, []byte{1,2,3})
@ -347,11 +348,7 @@ func triggerChecks(trigger chan *adapters.NodeId, net *simulations.Network, id *
func newServices() adapters.Services { func newServices() adapters.Services {
bzzs := make(map[*adapters.NodeId]*network.Bzz) return func(id *adapters.NodeId, snapshot []byte) []node.Service {
adaptersservices := make(map[string]adapters.ServiceFunc)
adaptersservices["bzz"] = func(id *adapters.NodeId, snapshot []byte) node.Service {
// setup hive // setup hive
addr := network.NewAddrFromNodeId(id) addr := network.NewAddrFromNodeId(id)
@ -371,12 +368,8 @@ func newServices() adapters.Services {
config.HiveParams.KeepAliveInterval = time.Second config.HiveParams.KeepAliveInterval = time.Second
bzzs[id] = network.NewBzz(config) network.NewBzz(config)
return bzzs[id]
}
adaptersservices["pss"] = func(id *adapters.NodeId, snapshot []byte) node.Service {
// pss setup // pss setup
cachedir, err := ioutil.TempDir("", "pss-cache") cachedir, err := ioutil.TempDir("", "pss-cache")
if err != nil { if err != nil {
@ -395,7 +388,6 @@ func newServices() adapters.Services {
return NewPss(bzzs[id].Kademlia, dpa, pssp) return NewPss(bzzs[id].Kademlia, dpa, pssp)
} }
return adaptersservices
} }
/* /*