diff --git a/p2p/protocols/protocol.go b/p2p/protocols/protocol.go index b16720dd39..1ecac2ffe4 100644 --- a/p2p/protocols/protocol.go +++ b/p2p/protocols/protocol.go @@ -423,3 +423,14 @@ func (p *Peer) Handshake(ctx context.Context, hs interface{}, verify func(interf } return rhs, nil } + +// HasCap returns true fi Peer has a capability +// with provided name. +func (p *Peer) HasCap(capName string) (yes bool) { + for _, c := range p.Caps() { + if c.Name == capName { + return true + } + } + return false +} diff --git a/swarm/network/stream/delivery.go b/swarm/network/stream/delivery.go index 489d2a0293..567da4fc88 100644 --- a/swarm/network/stream/delivery.go +++ b/swarm/network/stream/delivery.go @@ -261,7 +261,7 @@ func (d *Delivery) RequestFromPeers(ctx context.Context, req *network.Request) ( } // nodes that do not provide stream protocol // should not be requested, e.g. bootnodes - if !hasStreamCap(sp.Peer.Peer) { + if !p.HasCap("stream") { return true } spID = &id diff --git a/swarm/network/stream/stream.go b/swarm/network/stream/stream.go index d0e12f5b5c..0dafcc3b3a 100644 --- a/swarm/network/stream/stream.go +++ b/swarm/network/stream/stream.go @@ -518,7 +518,7 @@ func (r *Registry) requestPeerSubscriptions(kad *network.Kademlia, subs map[enod kad.EachConn(nil, 255, func(p *network.Peer, po int) bool { // nodes that do not provide stream protocol // should not be subscribed, e.g. bootnodes - if !hasStreamCap(p.Peer.Peer) { + if !p.HasCap("stream") { return true } //if the peer's bin is shallower than the kademlia depth, @@ -929,13 +929,3 @@ func (api *API) SubscribeStream(peerId enode.ID, s Stream, history *Range, prior func (api *API) UnsubscribeStream(peerId enode.ID, s Stream) error { return api.streamer.Unsubscribe(peerId, s) } - -// hasStreamCap check if p2p.Peer the "stream" capability. -func hasStreamCap(p *p2p.Peer) (yes bool) { - for _, c := range p.Caps() { - if c.Name == "stream" { - return true - } - } - return false -}