mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
swarm/network: check stream and pss caps in Hive.Run
This commit is contained in:
parent
6072822d5f
commit
3029a8289c
1 changed files with 23 additions and 11 deletions
|
|
@ -155,19 +155,31 @@ func (h *Hive) Run(p *BzzPeer) error {
|
||||||
defer h.untrackPeer(p)
|
defer h.untrackPeer(p)
|
||||||
|
|
||||||
dp := NewPeer(p, h.Kademlia)
|
dp := NewPeer(p, h.Kademlia)
|
||||||
depth, changed := h.On(dp)
|
|
||||||
// if we want discovery, advertise change of depth
|
hasCap := func(capName string) (yes bool) {
|
||||||
if h.Discovery {
|
for _, c := range p.Caps() {
|
||||||
if changed {
|
if c.Name == capName {
|
||||||
// if depth changed, send to all peers
|
return true
|
||||||
NotifyDepth(depth, h.Kademlia)
|
}
|
||||||
} else {
|
|
||||||
// otherwise just send depth to new peer
|
|
||||||
dp.NotifyDepth(depth)
|
|
||||||
}
|
}
|
||||||
NotifyPeer(p.BzzAddr, h.Kademlia)
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if hasCap("stream") && hasCap("pss") {
|
||||||
|
depth, changed := h.On(dp)
|
||||||
|
// if we want discovery, advertise change of depth
|
||||||
|
if h.Discovery {
|
||||||
|
if changed {
|
||||||
|
// if depth changed, send to all peers
|
||||||
|
NotifyDepth(depth, h.Kademlia)
|
||||||
|
} else {
|
||||||
|
// otherwise just send depth to new peer
|
||||||
|
dp.NotifyDepth(depth)
|
||||||
|
}
|
||||||
|
NotifyPeer(p.BzzAddr, h.Kademlia)
|
||||||
|
}
|
||||||
|
defer h.Off(dp)
|
||||||
}
|
}
|
||||||
defer h.Off(dp)
|
|
||||||
return dp.Run(dp.HandleMsg)
|
return dp.Run(dp.HandleMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue