mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
p2p/protocols, swarm/network/stream: add protocols.Peer.HasCap
This commit is contained in:
parent
6dd6fa17d8
commit
425acb3016
3 changed files with 13 additions and 12 deletions
|
|
@ -423,3 +423,14 @@ func (p *Peer) Handshake(ctx context.Context, hs interface{}, verify func(interf
|
||||||
}
|
}
|
||||||
return rhs, nil
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -261,7 +261,7 @@ func (d *Delivery) RequestFromPeers(ctx context.Context, req *network.Request) (
|
||||||
}
|
}
|
||||||
// nodes that do not provide stream protocol
|
// nodes that do not provide stream protocol
|
||||||
// should not be requested, e.g. bootnodes
|
// should not be requested, e.g. bootnodes
|
||||||
if !hasStreamCap(sp.Peer.Peer) {
|
if !p.HasCap("stream") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
spID = &id
|
spID = &id
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
kad.EachConn(nil, 255, func(p *network.Peer, po int) bool {
|
||||||
// nodes that do not provide stream protocol
|
// nodes that do not provide stream protocol
|
||||||
// should not be subscribed, e.g. bootnodes
|
// should not be subscribed, e.g. bootnodes
|
||||||
if !hasStreamCap(p.Peer.Peer) {
|
if !p.HasCap("stream") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
//if the peer's bin is shallower than the kademlia depth,
|
//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 {
|
func (api *API) UnsubscribeStream(peerId enode.ID, s Stream) error {
|
||||||
return api.streamer.Unsubscribe(peerId, s)
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue