Skip to content

How to set up Gossipsub to use delegated router to discover peers? #511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Rinse12 opened this issue Jan 10, 2025 · 0 comments
Open

How to set up Gossipsub to use delegated router to discover peers? #511

Rinse12 opened this issue Jan 10, 2025 · 0 comments

Comments

@Rinse12
Copy link

Rinse12 commented Jan 10, 2025

If I set up my own delegated routing client, gossip sub doesn’t use it to query peers of the pubsub topic. Here is my config

export const pubsubTopicToDhtKey = async (pubsubTopic) => {
  // pubsub topic dht key used by kubo is a cid of "floodsub:topic" https://github.com/libp2p/go-libp2p-pubsub/blob/3aa9d671aec0f777a7f668ca2b2ceb37218fb6bb/discovery.go#L328
  const string = `floodsub:${pubsubTopic}`;

  // convert string to same cid as kubo https://github.com/libp2p/go-libp2p/blob/024293c77e17794b0dd9dacec3032b4c5a535f64/p2p/discovery/routing/routing.go#L70
  const bytes = new TextEncoder().encode(string);
  const hash = await sha256.digest(bytes);
  const cidVersion = 1;
  const multicodec = 0x55;
  const cid = CID.create(cidVersion, multicodec, hash);
  return cid.toString(base32);
};

const pubsubTopic = "random-topic";
const topicPeersCidInRouter = await pubsubTopicToDhtKey(pubsubTopic);

const delegatedRoutingClient = createDelegatedRoutingV1HttpApiClient(
  "https://myownrouter.com"
);

// https://myownrouter.com/routing/v1/providers/<topicPeersCidInRouter> exists and is 200

const helia = await createHelia({
  libp2p: {
    peerId: await getPeerId(),
    addresses: {
      listen: [], // Empty for browser environment
    },
    services: {
      identify: identify(),
      pubsub: gossipsub(),
      delegatedRouting0: () => delegatedRoutingClient,
    },
    peerDiscovery: undefined,
  },
  blockstore: new MemoryBlockstore(),
  blockBrokers: [bitswap()],
});


helia.libp2p.services.pubsub.subscribe(pubsubTopic, () => {}); // this never connects to the peers from https://myownrouter.com/routing/v1/providers/<topicPeersCidInRouter>

// libp2p is not querying the router for gossip sub peers
// no dial or connection attempts are being made
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant