Closed joeltg closed 1 year ago
(@TimDaub fyi this will affect you if you try to upgrade)
This module still works for me if I declare a pubsub
service that is an instance of gossipsub. It's not terribly obvious though.
I think what's missing is a way for services and other libp2p components to express their dependencies in a way that the user can discover a compile time - I've opened a PR which I think will fix this here: https://github.com/libp2p/js-libp2p/pull/1762 - I'd love some input on it if you've got the time.
The change to this module after that PR is merged would be to change these lines to add & { pubsub: PubSub }
like:
import type { PubSub } from '@libp2p/interface-pubsub'
//... whole file here
export function pubsubPeerDiscovery (init: PubsubPeerDiscoveryInit = {}): (components: PubSubPeerDiscoveryComponents & { pubsub: PubSub }) => PeerDiscovery {
return (components: PubSubPeerDiscoveryComponents) => new PubSubPeerDiscovery(components, init)
}
Yeah, I was trying to develop a service similar to this one that depends on pubsub and I resorted to just casting const { pubsub } = components as Components & { pubsub?: PubSub }
and asserting that it exists at runtime. Works for now!
Maybe I'm forgetting something (crazy how fast context gets garbage collected in my head) but why say PubSubPeerDiscoveryComponents & { pubsub: PubSub }
and not just have pubsub: PubSub
in the PubSubPeerDiscoveryComponents
definition itself?
but why say PubSubPeerDiscoveryComponents & { pubsub: PubSub } and not just have pubsub: PubSub in the PubSubPeerDiscoveryComponents definition itself?
No, you're right - I was thinking of the circuit relay server updates in https://github.com/libp2p/js-libp2p/pull/1762 where the component has an implicit dependency on another component but doesn't actually interact with it in the code.
I have a dirty patch that makes peer discovery work via gossipsub for 0.46.2 here: https://github.com/Hmac512/fix-libp2p-peer-discover-046/blob/9aadfdc80332e2bbde0ce78b91f9183799fba32d/src/gossipNode.ts#L169
Need to clean up the code. It tests forming a mesh with 10 nodes, and it runs successfully.
I left some extra stuff in the patches I added while debugging. Will simplify it later.
The fix is too dirty to be merged into the official packages, but posting here if anyone needs it.
What’s the status on exposing the services in the main js-libp2p?
We should probably update the README
to outline how to configure these services with pubsub peer discovery.
Would be helpful
libp2p v0.45.0 moved pubsub/DHT/fetch/identify/ping etc. into a separate "services" object, and as far as I can tell they are no longer available in the initial
Components
object, making it impossible (???) to make composable services that depend on e.g. pubsub to provide peer discovery. Can anyone confirm if this is true? What's the best approach to something like pubsub-peer-discovery in a post-v0.45.0 world? cc @achingbrain