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
identifyprotocol.- 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)
@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.
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.