mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm/network: add Hive.Peer method to safely retrieve a bzz peer
This commit is contained in:
parent
bc652aebd9
commit
2b2314e6af
2 changed files with 10 additions and 3 deletions
|
|
@ -160,9 +160,7 @@ func testInitialPeersMsg(t *testing.T, peerPO, peerDepth int) {
|
||||||
// block until control peer is found among hive peers
|
// block until control peer is found among hive peers
|
||||||
found := false
|
found := false
|
||||||
for attempts := 0; attempts < 20; attempts++ {
|
for attempts := 0; attempts < 20; attempts++ {
|
||||||
hive.lock.Lock()
|
found = hive.Peer(peerID) != nil
|
||||||
_, found = hive.peers[peerID]
|
|
||||||
hive.lock.Unlock()
|
|
||||||
if found {
|
if found {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -209,6 +209,15 @@ func (h *Hive) PeerInfo(id enode.ID) interface{} {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Peer returns a bzz peer from the Hive. If there is no peer
|
||||||
|
// with the provided enode id, a nil value is returned.
|
||||||
|
func (h *Hive) Peer(id enode.ID) *BzzPeer {
|
||||||
|
h.lock.Lock()
|
||||||
|
defer h.lock.Unlock()
|
||||||
|
|
||||||
|
return h.peers[id]
|
||||||
|
}
|
||||||
|
|
||||||
// loadPeers, savePeer implement persistence callback/
|
// loadPeers, savePeer implement persistence callback/
|
||||||
func (h *Hive) loadPeers() error {
|
func (h *Hive) loadPeers() error {
|
||||||
var as []*BzzAddr
|
var as []*BzzAddr
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue