libp2p / go-libp2p-pubsub

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

Question: Extending Gossipsub protocol list #408

Closed richard-ramos closed 3 years ago

richard-ramos commented 3 years ago

Is it possible to extend the list of protocols returned in: https://github.com/libp2p/go-libp2p-pubsub/blob/5457a2845b06d859df6d3683867808e46a15c500/gossipsub.go#L401-L403 I'd like to include an additional ID besides GossipSubID_v11, GossipSubID_v10, FloodSubID, yet I find it difficult to extend GossipSubRouter to include my custom ID.

Floodsub supports this feature with NewFoodsubWithProtocols https://github.com/libp2p/go-libp2p-pubsub/blob/5457a2845b06d859df6d3683867808e46a15c500/floodsub.go#L17-L22 Is adding a similar functionality something viable? I could create a PR that adds a NewGossipsubWithProtocols(ctx context.Context, h host.Host, ps []protocol.ID, opts ...Option) (*PubSub, error)

vyzo commented 3 years ago

In principle we could, but there is some impedance mismatch in that the router uses the protocol ID to enable certain features. For example, it checks for the floodsub ID to determine whether to just treat those peers as simple floodsub peers. It also checks for the GSv1.1 ID to check whether to enable PX.

richard-ramos commented 3 years ago

Here's the code for my previous idea: https://github.com/libp2p/go-libp2p-pubsub/compare/master...richard-ramos:master

There is some impedance mismatch in that the router uses the protocol ID to enable certain features.

Perhaps this coud be solved by always return GossipSubID_v11, GossipSubID_v10, FloodSubID, yet still allowing to add custom protocols? Something like this code:

func (gs *GossipSubRouter) Protocols() []protocol.ID {
    ps := []protocol.ID{GossipSubID_v11, GossipSubID_v10, FloodSubID}
    return append(ps, gs.protocols...)
}

If having this logic is not desirable, would you mind sharing some tips on how could I achieve something similar with the current implementation of GossipSub?

vyzo commented 3 years ago

Sure, but how should the router behave towards the custom protocol? Is it gsv1.1 compatible?

Also, its not entirely clear to me why you want a custom protocol -- what do you gain by it?

On Tue, Mar 23, 2021, 20:01 RichΛrd @.***> wrote:

Here's the code for my previous idea: master...richard-ramos:master https://github.com/libp2p/go-libp2p-pubsub/compare/master...richard-ramos:master

There is some impedance mismatch in that the router uses the protocol ID to enable certain features.

Perhaps this coud be solved by always return GossipSubID_v11, GossipSubID_v10, FloodSubID, yet still allowing to add custom protocols? Something like this code:

func (gs *GossipSubRouter) Protocols() []protocol.ID { ps := []protocol.ID{GossipSubID_v11, GossipSubID_v10, FloodSubID} return append(ps, gs.protocols...) }

If having this logic is not desirable, would you mind sharing some tips on how could I achieve something similar with the current implementation of GossipSub?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/libp2p/go-libp2p-pubsub/issues/408#issuecomment-805112922, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAI4SUCHT22FYBGR5AFE6DTFDJOBANCNFSM4ZVULGEA .

richard-ramos commented 3 years ago

I'm attempting to implement this spec: https://specs.vac.dev/specs/waku/v2/waku-relay The TLDR is:

I tried to implement it without forking go-libp2p-pubsub, but found it very difficult to do so, hence why attempted to implement it here using the solution that I described earlier: https://github.com/status-im/go-waku/blob/master/waku/v2/protocol/waku_relay.go#L29-L43

vyzo commented 3 years ago

ok, I see.

The proper solution would be to support a custom protocol list with a feature check function. I would accept a pr implementing this so that you dont have to maintain a fork.

On Tue, Mar 23, 2021, 20:55 RichΛrd @.***> wrote:

I'm attempting to implement this spec: https://specs.vac.dev/specs/waku/v2/waku-relay The TLDR is:

  • It's a thin layer over GossipSub
  • Has the following protocol identifier: /vac/waku/relay/2.0.0-beta2
  • Uses StrictNoSign

I tried to implement it without forking go-libp2p-pubsub, but found it very difficult to do so, hence why attempted to implement it here using the solution that I described earlier: https://github.com/status-im/go-waku/blob/master/waku/v2/protocol/waku_relay.go#L29-L43

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/libp2p/go-libp2p-pubsub/issues/408#issuecomment-805151181, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAI4SQ77JV4BSRP4D423TTTFDPZNANCNFSM4ZVULGEA .

richard-ramos commented 3 years ago

Cool! I will start working on it! Do you have specific requirements on how should this feature check function work?

Thanks!

vyzo commented 3 years ago

well, we should normalize the features we check by protocol ID, should be straightforward.

On Tue, Mar 23, 2021, 21:26 RichΛrd @.***> wrote:

Cool! I will start working on it! Do you have specific requirements on how should this feature check function work?

Thanks!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/libp2p/go-libp2p-pubsub/issues/408#issuecomment-805171685, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAI4SV3PRK4T2CRWHW7JRTTFDTPLANCNFSM4ZVULGEA .

BigLep commented 3 years ago

@richard-ramos : are you planning to open a PR here?

richard-ramos commented 3 years ago

Hello @BigLep, I'm not able to work on a PR for this for the time being!

vyzo commented 3 years ago

@richard-ramos

Implemented support for custom gossipsub protocols in #413.

To use it, just instantiate your gossipsub using the WithGossipSubProtocols option; it takes a list of protocols and a feature test function.

So you shouldn't have to maintain a fork anymore and miss out on all the bug fixes and new features.

richard-ramos commented 3 years ago

Awesome! thank you!