mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
swarm/network/stream: check for peer stream cap in delivery and sync
This commit is contained in:
parent
160308b0df
commit
647effca22
3 changed files with 21 additions and 1 deletions
|
|
@ -259,6 +259,11 @@ func (d *Delivery) RequestFromPeers(ctx context.Context, req *network.Request) (
|
|||
//log.Warn("Delivery.RequestFromPeers: peer not found", "id", id)
|
||||
return true
|
||||
}
|
||||
// nodes that do not provide stream protocol
|
||||
// should not be requested, e.g. bootnodes
|
||||
if !hasStreamCap(sp.Peer.Peer) {
|
||||
return true
|
||||
}
|
||||
spID = &id
|
||||
return false
|
||||
})
|
||||
|
|
|
|||
|
|
@ -285,7 +285,7 @@ func TestRequestFromPeers(t *testing.T) {
|
|||
addr := network.RandomAddr()
|
||||
to := network.NewKademlia(addr.OAddr, network.NewKadParams())
|
||||
delivery := NewDelivery(to, nil)
|
||||
protocolsPeer := protocols.NewPeer(p2p.NewPeer(dummyPeerID, "dummy", nil), nil, nil)
|
||||
protocolsPeer := protocols.NewPeer(p2p.NewPeer(dummyPeerID, "dummy", []p2p.Cap{{Name: "stream"}}), nil, nil)
|
||||
peer := network.NewPeer(&network.BzzPeer{
|
||||
BzzAddr: network.RandomAddr(),
|
||||
LightNode: false,
|
||||
|
|
|
|||
|
|
@ -516,6 +516,11 @@ func (r *Registry) requestPeerSubscriptions(kad *network.Kademlia, subs map[enod
|
|||
// nil as base takes the node's base; we need to pass 255 as `EachConn` runs
|
||||
// from deepest bins backwards
|
||||
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) {
|
||||
return true
|
||||
}
|
||||
//if the peer's bin is shallower than the kademlia depth,
|
||||
//only the peer's bin should be subscribed
|
||||
if po < kadDepth {
|
||||
|
|
@ -924,3 +929,13 @@ 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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue