mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
swarm/network: minor changes re review; add missing lock to NeighbourhoodDepthC
This commit is contained in:
parent
b7286a9909
commit
99cd4a66de
5 changed files with 9 additions and 39 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue