diff --git a/swarm/network/discovery.go b/swarm/network/discovery.go index 2181f784b6..3019594809 100644 --- a/swarm/network/discovery.go +++ b/swarm/network/discovery.go @@ -26,7 +26,7 @@ import ( // discovery bzz extension for requesting and relaying node address records -// Peer wraps BzzPeer and embeds an Overlay connectivity driver +// Peer wraps BzzPeer and embeds Kademlia overlay connectivity driver type Peer struct { *BzzPeer kad *Kademlia @@ -146,7 +146,7 @@ func (d *Peer) handlePeersMsg(msg *peersMsg) error { return d.kad.Register(msg.Peers...) } -// subPeers msg is communicating the depth/sharpness/focus of the overlay table of a peer +// subPeers msg is communicating the depth of the overlay table of a peer type subPeersMsg struct { Depth uint8 } @@ -177,7 +177,7 @@ func (d *Peer) handleSubPeersMsg(msg *subPeersMsg) error { return nil } -// seen takes an Overlay peer and checks if it was sent to a peer already +// seen takes an peer address and checks if it was sent to a peer already // if not, marks the peer as sent func (d *Peer) seen(p *BzzAddr) bool { d.mtx.Lock() diff --git a/swarm/network/kademlia.go b/swarm/network/kademlia.go index 344533f0a9..55a0c6f13d 100644 --- a/swarm/network/kademlia.go +++ b/swarm/network/kademlia.go @@ -132,7 +132,7 @@ func (e *entry) Hex() string { return fmt.Sprintf("%x", e.Address()) } -// Register enters each OverlayAddr as kademlia peer record into the +// Register enters each address as kademlia peer record into the // database of known peer addresses func (k *Kademlia) Register(peers ...*BzzAddr) error { k.lock.Lock() @@ -290,6 +290,8 @@ func (k *Kademlia) On(p *Peer) (uint8, bool) { // Not receiving from the returned channel will block On function // when the neighbourhood depth is changed. func (k *Kademlia) NeighbourhoodDepthC() <-chan int { + k.lock.Lock() + defer k.lock.Unlock() if k.nDepthC == nil { k.nDepthC = make(chan int) } diff --git a/swarm/network/protocol.go b/swarm/network/protocol.go index 732eed47c5..ef0956d5f8 100644 --- a/swarm/network/protocol.go +++ b/swarm/network/protocol.go @@ -62,33 +62,6 @@ var DiscoverySpec = &protocols.Spec{ }, } -// -// // Addr interface that peerPool needs -// type Addr interface { -// OverlayPeer -// Over() []byte -// Under() []byte -// String() string -// Update(OverlayAddr) OverlayAddr -// } -// -// // Peer interface represents an live peer connection -// type Peer interface { -// Addr // the address of a peer -// Conn // the live connection (protocols.Peer) -// LastActive() time.Time // last time active -// } -// -// // Conn interface represents an live peer connection -// type Conn interface { -// ID() discover.NodeID // the key that uniquely identifies the Node for the peerPool -// Handshake(context.Context, interface{}, func(interface{}) error) (interface{}, error) // can send messages -// Send(context.Context, interface{}) error // can send messages -// Drop(error) // disconnect this peer -// Run(func(context.Context, interface{}) error) error // the run function to run a protocol -// Off() OverlayAddr -// } - // BzzConfig captures the config params used by the hive type BzzConfig struct { OverlayAddr []byte // base address of the overlay network @@ -275,7 +248,7 @@ type BzzPeer struct { LightNode bool } -func NewBzzTestPeer(p *protocols.Peer, addr *BzzAddr) *BzzPeer { +func NewBzzPeer(p *protocols.Peer, addr *BzzAddr) *BzzPeer { return &BzzPeer{ Peer: p, localAddr: addr, @@ -283,11 +256,6 @@ func NewBzzTestPeer(p *protocols.Peer, addr *BzzAddr) *BzzPeer { } } -// // Off returns the overlay peer record for offline persistence -// func (p *BzzPeer) Off() OverlayAddr { -// return p.BzzAddr -// } - // LastActive returns the time the peer was last active func (p *BzzPeer) LastActive() time.Time { return p.lastActive diff --git a/swarm/network/stream/stream.go b/swarm/network/stream/stream.go index 21620c501d..deffdfc3f9 100644 --- a/swarm/network/stream/stream.go +++ b/swarm/network/stream/stream.go @@ -458,7 +458,7 @@ func (r *Registry) updateSyncing() { func (r *Registry) runProtocol(p *p2p.Peer, rw p2p.MsgReadWriter) error { peer := protocols.NewPeer(p, rw, Spec) - bp := network.NewBzzTestPeer(peer, r.addr) + bp := network.NewBzzPeer(peer, r.addr) np := network.NewPeer(bp, r.delivery.kad) r.delivery.kad.On(np) defer r.delivery.kad.Off(np) diff --git a/swarm/pss/pss.go b/swarm/pss/pss.go index 14285f7f1a..b55c97fddf 100644 --- a/swarm/pss/pss.go +++ b/swarm/pss/pss.go @@ -110,7 +110,7 @@ func (params *PssParams) WithPrivateKey(privatekey *ecdsa.PrivateKey) *PssParams // // Implements node.Service type Pss struct { - *network.Kademlia // we can get the Kademliaaddress from this + *network.Kademlia // we can get the Kademlia address from this privateKey *ecdsa.PrivateKey // pss can have it's own independent key w *whisper.Whisper // key and encryption backend auxAPIs []rpc.API // builtins (handshake, test) can add APIs