js-libp2p: In-browser Peer routing with DHT client not working

Background

As a user, I want to be able to write browser-based applications that use PeerIDs, e.g. 12D3KooWRBy97UB99e3J6hiPesre1MZeuNQvfan4gBziswrRJsNK to connect to server peers (kubo) over WebTransport.

For js-libp2p to connect to a peer, it needs to resolve a string PeerID to a list of multi-addresses and establish a connection over a protocol supported by the browser, e.g. WebTransport /ip4/77.191.236.66/udp/27432/quic-v1/webtransport/certhash/uEiCHJ1wdNQ6PuWY_q1fZ1xYBk02c8P8vzYKLUB37swCD3g/certhash/uEiCdUXNMurDDZbHMsIBD-wEwuXN1xqT3LuAaS1XyLtEjVQ/p2p/12D3KooWRBy97UB99e3J6hiPesre1MZeuNQvfan4gBziswrRJsNK

This issue is blocking https://github.com/libp2p/universal-connectivity/issues/1

Problem encountered

The problem is that when a js-libp2p node is instantiated with DHT client mode in the browser, and a call is made tolibp2p.dht.findPeer('12D3KooWBdmLJjhpgJ9KZgLM3f894ff9xyBfPvPjFNn7MKJpyrC2'), the response is missing the WebTransport multi addresses.

Specifically, I get:

/ip4/127.0.0.1/tcp/4001
/ip4/127.0.0.1/udp/4001/quic
/ip4/192.168.50.102/tcp/4001
/ip4/192.168.50.102/udp/4001/quic
/ip4/46.21.210.45/tcp/41752
/ip4/46.21.210.45/udp/41752/quic
/ip6/::1/tcp/4001

But why? πŸ™ƒ

  • I suspect it might have to do with how peer records from the DHT are parsed.
  • Another suspicion is that not all multiaddrs aren’t even stored on the DHT. Instead, they come from the identify protocol.
    • Is there a discrepancy between the DHT and the protocols coming from identify?
    • I can get the correct multiaddr with the kubo:
ipfs routing findpeer 12D3KooWBdmLJjhpgJ9KZgLM3f894ff9xyBfPvPjFNn7MKJpyrC2
/ip4/127.0.0.1/udp/4001/quic-v1
/ip4/46.21.210.45/udp/41752/quic-v1
/ip4/46.21.210.45/udp/41752/quic
/ip4/192.168.50.102/udp/4001/quic
/ip4/127.0.0.1/udp/4001/quic
/ip4/192.168.50.102/tcp/4001
/ip4/127.0.0.1/tcp/4001
/ip4/192.168.50.102/udp/4001/quic-v1
/ip4/127.0.0.1/udp/4001/quic-v1/webtransport/certhash/uEiC2VicD86O_HCbSJBdBTowH40qsRNOLoZsHRKUHMtVJVg/certhash/uEiCP5EPex6pTJYAvokykyQ2CKdcABpYsKmvEtMrt4_gLkw
/ip4/46.21.210.45/udp/41752/quic-v1/webtransport/certhash/uEiC2VicD86O_HCbSJBdBTowH40qsRNOLoZsHRKUHMtVJVg/certhash/uEiCP5EPex6pTJYAvokykyQ2CKdcABpYsKmvEtMrt4_gLkw
/ip6/::1/tcp/4001
/ip4/46.21.210.45/tcp/41752
/ip4/192.168.50.102/udp/4001/quic-v1/webtransport/certhash/uEiC2VicD86O_HCbSJBdBTowH40qsRNOLoZsHRKUHMtVJVg/certhash/uEiCP5EPex6pTJYAvokykyQ2CKdcABpYsKmvEtMrt4_gLkw

Reproduction: https://js-libp2p-transports-example-nextjs.vercel.app/

Source: https://github.com/2color/js-libp2p-transports-example/

Package Versions

  β”œβ”€β”€ @chainsafe/libp2p-noise@11.0.1
  β”œβ”€β”€ @chainsafe/libp2p-yamux@3.0.7
  β”œβ”€β”€ @headlessui/react@1.7.13
  β”œβ”€β”€ @heroicons/react@2.0.16
  β”œβ”€β”€ @libp2p/bootstrap@6.0.0
  β”œβ”€β”€ @libp2p/kad-dht@7.0.0
  β”œβ”€β”€ @libp2p/peer-id@2.0.2
  β”œβ”€β”€ @libp2p/websockets@5.0.4
  β”œβ”€β”€ @libp2p/webtransport@1.0.7
  β”œβ”€β”€ @types/node@18.14.6
  β”œβ”€β”€ @types/react-dom@18.0.11
  β”œβ”€β”€ @types/react@18.0.28
  β”œβ”€β”€ autoprefixer@10.4.13
  β”œβ”€β”€ blockstore-core@3.0.0
  β”œβ”€β”€ datastore-core@8.0.4
  β”œβ”€β”€ datastore-level@9.0.4
  β”œβ”€β”€ eslint-config-next@13.2.3
  β”œβ”€β”€ eslint@8.35.0
  β”œβ”€β”€ libp2p@0.42.2
  β”œβ”€β”€ next@13.2.3
  β”œβ”€β”€ postcss@8.4.21
  β”œβ”€β”€ private-ip@3.0.0
  β”œβ”€β”€ react-dom@18.2.0
  β”œβ”€β”€ react@18.2.0
  β”œβ”€β”€ tailwindcss@3.2.7
  └── typescript@4.9.5

Platform

  • Chrome Version 110.0.5481.177 (Official Build) (arm64)

  • Subsystem: DHT

Severity:

High - The main functionality of the application does not work, API breakage, repo format breakage, etc.

Steps to reproduce the error:

See full reproduction: https://github.com/2color/js-libp2p-transports-example/tree/main/packages/nextjs

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (15 by maintainers)

Most upvoted comments

@maschad : the discussion is in a public channel #ipfs-chatter on Filecoin slack (which is bridged to IPFS Discord/Matrix).

@2color I think this can be closed, right? There’s no change to js-libp2p necessary here, the remote peer needs to be running kubo 0.18.x to tell you its quic-v1 addresses.

have you also explored whether identify and the peerstore are storing multiaddrs ?

I haven’t yet. Would love any tips on how to best debug/explore this with js-libp2p

js-libp2p has a .peerStore property that lets you see what your node knows about a remote peer.

See the example in the jsdoc linked to for how to get that information.