diff --git a/p2p/simulations/adapters/types.go b/p2p/simulations/adapters/types.go index c418cb7e32..9d2249651b 100644 --- a/p2p/simulations/adapters/types.go +++ b/p2p/simulations/adapters/types.go @@ -20,7 +20,6 @@ import ( "crypto/ecdsa" "encoding/hex" "encoding/json" - "fmt" "net" "os" @@ -140,7 +139,7 @@ type nodeConfigJSON struct { Id string `json:"id"` PrivateKey string `json:"private_key"` Name string `json:"name"` - Service string `json:"service"` + Service string `json:"service"` } func (n *NodeConfig) MarshalJSON() ([]byte, error) { @@ -216,9 +215,11 @@ var serviceFuncs = make(Services) // start devp2p nodes func RegisterServices(services Services) { for name, f := range services { - if _, exists := serviceFuncs[name]; exists { - panic(fmt.Sprintf("node service already exists: %q", name)) - } + // TODO: FIXME: protocol tester if called more than once, throws an error so for now + // just overwrite + // if _, exists := serviceFuncs[name]; exists { + // panic(fmt.Sprintf("node service already exists: %q", name)) + // } serviceFuncs[name] = f } diff --git a/swarm/network/kademlia.go b/swarm/network/kademlia.go index 6be4feebf9..9aebe2d6eb 100644 --- a/swarm/network/kademlia.go +++ b/swarm/network/kademlia.go @@ -190,6 +190,7 @@ func (self *Kademlia) Register(peers chan OverlayAddr) error { func (self *Kademlia) SuggestPeer() (a OverlayAddr, o int, want bool) { minsize := self.MinBinSize depth := self.Depth() + empty := self.FirstEmptyBin() // if there is a callable neighbour within the current proxBin, connect // this makes sure nearest neighbour set is fully connected log.Debug(fmt.Sprintf("candidate prox peer checking above PO %v", depth)) @@ -203,10 +204,10 @@ func (self *Kademlia) SuggestPeer() (a OverlayAddr, o int, want bool) { return a == nil && po >= depth }) if a != nil { - log.Trace(fmt.Sprintf("candidate prox peer found: %v (%v)", a, ppo)) + log.Debug(fmt.Sprintf("candidate prox peer found: %v (%v)", a, ppo)) return a, 0, false } - log.Trace(fmt.Sprintf("no candidate prox peers to connect to (Depth: %v, minProxSize: %v) %#v", depth, self.MinProxBinSize, a)) + log.Debug(fmt.Sprintf("no candidate prox peers to connect to (Depth: %v, minProxSize: %v) %#v", depth, self.MinProxBinSize, a)) var bpo []int prev := -1 @@ -238,7 +239,10 @@ func (self *Kademlia) SuggestPeer() (a OverlayAddr, o int, want bool) { log.Trace(fmt.Sprintf("check PO%02d: ", po)) f(func(val pot.PotVal, j int) bool { a = self.callable(val) - return a == nil && po < depth + if po == empty { + log.Debug(fmt.Sprintf("candidate prox peer found: %v (%v)", a, ppo)) + } + return a == nil && po <= depth }) return false }) diff --git a/swarm/network/protocol.go b/swarm/network/protocol.go index 7753a69b1c..22ed971bf8 100644 --- a/swarm/network/protocol.go +++ b/swarm/network/protocol.go @@ -347,7 +347,7 @@ func NewNodeIdFromAddr(addr Addr) *adapters.NodeId { // NewAddrFromNodeId constucts a bzzAddr from an adapters.NodeId // the overlay address is derived as the hash of the nodeId -func NewAddrFromNodeId(n *adapters.NodeId) Addr { +func NewAddrFromNodeId(n *adapters.NodeId) *bzzAddr { id := n.NodeID return &bzzAddr{ OAddr: ToOverlayAddr(n.Bytes()), diff --git a/swarm/network/simulations/overlay.go b/swarm/network/simulations/overlay.go index 9c7ce159e6..c1ada22405 100644 --- a/swarm/network/simulations/overlay.go +++ b/swarm/network/simulations/overlay.go @@ -24,20 +24,20 @@ import ( type Simulation struct { mtx sync.Mutex - stores map[discover.NodeID]*adapters.stateStore + stores map[discover.NodeID]*adapters.SimStateStore } func NewSimulation() *Simulation { return &Simulation{ - stores: make(map[discover.NodeID]*adapters.stateStore), + stores: make(map[discover.NodeID]*adapters.SimStateStore), } } -func (s *Simulation) NewService(id *adapters.NodeId, snapshot []byte) node.Service { +func (s *Simulation) NewService(id *adapters.NodeId, snapshot []byte) []node.Service { s.mtx.Lock() store, ok := s.stores[id.NodeID] if !ok { - store = NewSimStore() + store = adapters.NewSimStateStore() s.stores[id.NodeID] = store } s.mtx.Unlock() @@ -62,7 +62,7 @@ func (s *Simulation) NewService(id *adapters.NodeId, snapshot []byte) node.Servi HiveParams: hp, } - return network.NewBzz(config, kad, store) + return []node.Service{network.NewBzz(config, kad, store)} } func createMockers() map[string]*simulations.MockerConfig { @@ -122,7 +122,7 @@ func setupMocker(net *simulations.Network) []*adapters.NodeId { defer close(ch) ch <- network.NewAddrFromNodeId(peerId) }() - if err := net.GetNode(id).Node.(*adapters.SimNode).Service().(*network.Bzz).Hive.Register(ch); err != nil { + if err := net.GetNode(id).Node.(*adapters.SimNode).Service(&network.Bzz{}).(*network.Bzz).Hive.Register(ch); err != nil { panic(err.Error()) } }