libp2p / go-libp2p-pubsub

The PubSub implementation for go-libp2p
https://github.com/libp2p/specs/tree/master/pubsub
Other
327 stars 186 forks source link

Question about pubsub message relaying #292

Closed lukasz-zimnoch closed 4 years ago

lukasz-zimnoch commented 4 years ago

Looking at handleIncomingRPC method defined in pubsub.go we can see a part which forwards received messages if our pubsub instance has an existing subscription to the given message topic:

(...)

for _, pmsg := range rpc.GetPublish() {
    if !p.subscribedToMsg(pmsg) {
        log.Warning("received message we didn't subscribe to. Dropping.")
        continue
    }

    msg := &Message{pmsg, rpc.from, nil}
    p.pushMsg(msg)
}

p.rt.HandleRPC(rpc)

If our pubsub doesn't have this subscription, we are just ignoring the current message. Also, HandleRPC is a no-op in floodsub implementation so we don't do anything with the rpc later.

The question: is there a particular reason why pubsub ignores messages they are not subscribed to, instead of just passing them to other peers and gain on the delivery rate?

vyzo commented 4 years ago

There is no reason to pass messages if we are not subscribing, that's a DoS waiting to happen. We are considering adding a relay-only option to pubsub that would enable relaying without subscription.

pdyraga commented 4 years ago

We are considering adding a relay-only option to pubsub that would enable relaying without subscription.

Is there any PR or issue for that one where we could learn more and potentially contribute?

Unless I misunderstood, I think this is what @lukasz-zimnoch is asking about. If there is a peer that is not subscribed to the given topic and this peer is the only point currently connecting two other peers subscribed to that topic, we could have a relay-only somewhere in pubsub allowing to pass-thru messages.

vyzo commented 4 years ago

Yes, issue #28 has been open for a while.

lukasz-zimnoch commented 4 years ago

@vyzo I see there was already a contribution https://github.com/libp2p/go-libp2p-pubsub/pull/229 but has been closed. We are interested in contributing here but we need to know more. Why #229 didn't pass and what is a must for a complete solution here? Could you provide those details?

pdyraga commented 4 years ago

@lukasz-zimnoch @vyzo What if we close this issue as it kinda duplicates #28 and we'll continue the discussion there?

vyzo commented 4 years ago

I wanted to avoid distractions while the gossipsub v1.1 work was in progress; we can certainly reopen that pr.

vyzo commented 4 years ago

Actually there were a couple of things wrong with that pr, if you are interested in opening a new one it should use a reference counter and avoid the use of a relay object -- just the topic handle will do.

edit: the issue is that it conflates subscriptions with relaying and only allows it to happen once.

vyzo commented 4 years ago

I think we can indeed close this issue and continue discussion in #28.