Skip to content

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

@Rinse12

Description

@Rinse12

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions