Description
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 libp2p/universal-connectivity#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/[email protected]
├── @chainsafe/[email protected]
├── @headlessui/[email protected]
├── @heroicons/[email protected]
├── @libp2p/[email protected]
├── @libp2p/[email protected]
├── @libp2p/[email protected]
├── @libp2p/[email protected]
├── @libp2p/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
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