From 4976fcc91a43b5c7047c51a03985887b694f0fbb Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Thu, 24 Jan 2019 12:02:18 +0100 Subject: swarm: bootnode-mode, new bootnodes and no p2p package discovery (#18498) (cherry picked from commit bbd120354a8d226b446591eeda9f9462cb9b690a) --- swarm/network/stream/delivery.go | 9 ++++++++- swarm/network/stream/delivery_test.go | 2 +- swarm/network/stream/stream.go | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) (limited to 'swarm/network/stream') diff --git a/swarm/network/stream/delivery.go b/swarm/network/stream/delivery.go index e1a13fe8d..c9a8dc57a 100644 --- a/swarm/network/stream/delivery.go +++ b/swarm/network/stream/delivery.go @@ -255,8 +255,15 @@ func (d *Delivery) RequestFromPeers(ctx context.Context, req *network.Request) ( return true } sp = d.getPeer(id) + // sp is nil, when we encounter a peer that is not registered for delivery, i.e. doesn't support the `stream` protocol if sp == nil { - //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 !p.HasCap("stream") { + // TODO: if we have no errors, delete this if + log.Error("Delivery.RequestFromPeers: peer doesn't have stream cap. we should have returned at sp == nil") return true } spID = &id diff --git a/swarm/network/stream/delivery_test.go b/swarm/network/stream/delivery_test.go index 70d3829b3..13e13c0f5 100644 --- a/swarm/network/stream/delivery_test.go +++ b/swarm/network/stream/delivery_test.go @@ -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, diff --git a/swarm/network/stream/stream.go b/swarm/network/stream/stream.go index fb571c856..e06048053 100644 --- a/swarm/network/stream/stream.go +++ b/swarm/network/stream/stream.go @@ -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 !p.HasCap("stream") { + return true + } //if the peer's bin is shallower than the kademlia depth, //only the peer's bin should be subscribed if po < kadDepth { -- cgit