mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
swarm/network: tweaks and fixes
This commit is contained in:
parent
7341530f6f
commit
020214b7ca
4 changed files with 20 additions and 15 deletions
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
|
@ -140,7 +139,7 @@ type nodeConfigJSON struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
PrivateKey string `json:"private_key"`
|
PrivateKey string `json:"private_key"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Service string `json:"service"`
|
Service string `json:"service"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NodeConfig) MarshalJSON() ([]byte, error) {
|
func (n *NodeConfig) MarshalJSON() ([]byte, error) {
|
||||||
|
|
@ -216,9 +215,11 @@ var serviceFuncs = make(Services)
|
||||||
// start devp2p nodes
|
// start devp2p nodes
|
||||||
func RegisterServices(services Services) {
|
func RegisterServices(services Services) {
|
||||||
for name, f := range services {
|
for name, f := range services {
|
||||||
if _, exists := serviceFuncs[name]; exists {
|
// TODO: FIXME: protocol tester if called more than once, throws an error so for now
|
||||||
panic(fmt.Sprintf("node service already exists: %q", name))
|
// just overwrite
|
||||||
}
|
// if _, exists := serviceFuncs[name]; exists {
|
||||||
|
// panic(fmt.Sprintf("node service already exists: %q", name))
|
||||||
|
// }
|
||||||
serviceFuncs[name] = f
|
serviceFuncs[name] = f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,7 @@ func (self *Kademlia) Register(peers chan OverlayAddr) error {
|
||||||
func (self *Kademlia) SuggestPeer() (a OverlayAddr, o int, want bool) {
|
func (self *Kademlia) SuggestPeer() (a OverlayAddr, o int, want bool) {
|
||||||
minsize := self.MinBinSize
|
minsize := self.MinBinSize
|
||||||
depth := self.Depth()
|
depth := self.Depth()
|
||||||
|
empty := self.FirstEmptyBin()
|
||||||
// if there is a callable neighbour within the current proxBin, connect
|
// if there is a callable neighbour within the current proxBin, connect
|
||||||
// this makes sure nearest neighbour set is fully connected
|
// this makes sure nearest neighbour set is fully connected
|
||||||
log.Debug(fmt.Sprintf("candidate prox peer checking above PO %v", depth))
|
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
|
return a == nil && po >= depth
|
||||||
})
|
})
|
||||||
if a != nil {
|
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
|
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
|
var bpo []int
|
||||||
prev := -1
|
prev := -1
|
||||||
|
|
@ -238,7 +239,10 @@ func (self *Kademlia) SuggestPeer() (a OverlayAddr, o int, want bool) {
|
||||||
log.Trace(fmt.Sprintf("check PO%02d: ", po))
|
log.Trace(fmt.Sprintf("check PO%02d: ", po))
|
||||||
f(func(val pot.PotVal, j int) bool {
|
f(func(val pot.PotVal, j int) bool {
|
||||||
a = self.callable(val)
|
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
|
return false
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -347,7 +347,7 @@ func NewNodeIdFromAddr(addr Addr) *adapters.NodeId {
|
||||||
|
|
||||||
// NewAddrFromNodeId constucts a bzzAddr from an adapters.NodeId
|
// NewAddrFromNodeId constucts a bzzAddr from an adapters.NodeId
|
||||||
// the overlay address is derived as the hash of the 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
|
id := n.NodeID
|
||||||
return &bzzAddr{
|
return &bzzAddr{
|
||||||
OAddr: ToOverlayAddr(n.Bytes()),
|
OAddr: ToOverlayAddr(n.Bytes()),
|
||||||
|
|
|
||||||
|
|
@ -24,20 +24,20 @@ import (
|
||||||
|
|
||||||
type Simulation struct {
|
type Simulation struct {
|
||||||
mtx sync.Mutex
|
mtx sync.Mutex
|
||||||
stores map[discover.NodeID]*adapters.stateStore
|
stores map[discover.NodeID]*adapters.SimStateStore
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSimulation() *Simulation {
|
func NewSimulation() *Simulation {
|
||||||
return &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()
|
s.mtx.Lock()
|
||||||
store, ok := s.stores[id.NodeID]
|
store, ok := s.stores[id.NodeID]
|
||||||
if !ok {
|
if !ok {
|
||||||
store = NewSimStore()
|
store = adapters.NewSimStateStore()
|
||||||
s.stores[id.NodeID] = store
|
s.stores[id.NodeID] = store
|
||||||
}
|
}
|
||||||
s.mtx.Unlock()
|
s.mtx.Unlock()
|
||||||
|
|
@ -62,7 +62,7 @@ func (s *Simulation) NewService(id *adapters.NodeId, snapshot []byte) node.Servi
|
||||||
HiveParams: hp,
|
HiveParams: hp,
|
||||||
}
|
}
|
||||||
|
|
||||||
return network.NewBzz(config, kad, store)
|
return []node.Service{network.NewBzz(config, kad, store)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createMockers() map[string]*simulations.MockerConfig {
|
func createMockers() map[string]*simulations.MockerConfig {
|
||||||
|
|
@ -122,7 +122,7 @@ func setupMocker(net *simulations.Network) []*adapters.NodeId {
|
||||||
defer close(ch)
|
defer close(ch)
|
||||||
ch <- network.NewAddrFromNodeId(peerId)
|
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())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue