lexnv / subp2p-explorer

Submit extrinsics and explore substrate p2p network
Other
16 stars 2 forks source link

Reusable/util Swarm #6

Open rvalle opened 7 months ago

rvalle commented 7 months ago

Projects depending on subp2p explorer will need to build a swarm too.

It would be beneficial to move the swarm building code to utility including the typical sets of behaviors used, while still allowing for a custom set of behaviors.

This would also facilitate managing the later #3 migration.

rvalle commented 6 months ago

@lexnv I am looking into it. This seems not obvious, by the way behaviors are created and initialized after/become swarm is created.

I currently need the behavior PeerId+Discovery and you use also the PeerId+Discovery+Notification, are you planning on putting together other sets?

Perhaps we could provide utility swarm creation for the typical ones.

lexnv commented 6 months ago

One way to approach this would be to make the default-behavior exposed by the subp2p explorer have an optional notifications::behavior::Notifications. This way users can enable it or disable it depending on their workflow.

In the meanwhile, I think you could use the following approach:

https://github.com/lexnv/subp2p-explorer/blob/da19e6d15c9680b51b5278229f8b24b779f02726/cli/src/utils.rs#L107-L128

And define your own custom Behavior protocol, similar to:

https://github.com/lexnv/subp2p-explorer/blob/da19e6d15c9680b51b5278229f8b24b779f02726/subp2p-explorer/src/lib.rs#L15-L22

rvalle commented 6 months ago

Having an optional notifications, or a behavior with optional sub-behaviors sounds ideal. I will investigate.

Yes, perhaps we can start by the default behaviour.