-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Creating a Gossipsub
struct is somewhat awkward in the current design.
We have a bunch of new_with_X
functions, see for example here: https://github.com/sigp/rust-libp2p/blob/master/protocols/gossipsub/src/behaviour.rs#L342
Apart from being somewhat non-ergonomic, we have recently introduced some metrics into the protocol. One metric requires building a histogram of the score distribution: https://github.com/sigp/rust-libp2p/blob/master/protocols/gossipsub/src/metrics.rs#L227
The metrics need to build constructed when the Gossipsub
struct is instantiated but this particular metrics requires bounds for the score. In the current design the scoring system can be activated at some future time rather than during the creation of the Gossipsub
struct so we cannot properly initialise this metric.
One way we could resolve this is to use a builder
pattern to create the Gossipsub
struct and force the user to choose scoring on creation. An example of the builder pattern is with the config: https://github.com/sigp/rust-libp2p/blob/master/protocols/gossipsub/src/config.rs#L389
There are a few traits we need to deal with for the Gossipsub
struct, which makes this slightly more complicated than the example. However I'm hoping a builder pattern will be a nicer way of handling the variable configurations for creating a Gossipsub
struct.
I had started work on this at some time ages ago and have found an old file lying around which starts this modification. I've put it in this branch: https://github.com/sigp/rust-libp2p/tree/gossipsub-builder
Feel free to use anything in there (I think its just a single file at the moment) or to write from scratch :).