Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
swarm/network: check stream and pss caps in Hive.Run
Browse files Browse the repository at this point in the history
  • Loading branch information
janos committed Jan 21, 2019
1 parent 6072822 commit 3029a82
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions swarm/network/hive.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,31 @@ func (h *Hive) Run(p *BzzPeer) error {
defer h.untrackPeer(p)

dp := NewPeer(p, h.Kademlia)
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)

hasCap := func(capName string) (yes bool) {
for _, c := range p.Caps() {
if c.Name == capName {
return true
}
}
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)
}
NotifyPeer(p.BzzAddr, h.Kademlia)
defer h.Off(dp)
}
defer h.Off(dp)
return dp.Run(dp.HandleMsg)
}

Expand Down

0 comments on commit 3029a82

Please sign in to comment.