libp2p / js-libp2p

The JavaScript Implementation of libp2p networking stack.
https://libp2p.io
Other
2.27k stars 436 forks source link

Cannot connect to DNS multiaddr format #2528

Closed tuphan-dn closed 2 months ago

tuphan-dn commented 2 months ago

I can connect to my bootstrap node if I add /ip4/37.16.3.238/tcp/8080/p2p/12D3KooWKYkngptku6WmyYJgMKL6uHbxAuqhZ98u7Q67TFL2yF1p into the bootstrap list. However, if I replace it to /dns/mpc-node-ts.fly.dev/tcp/8080/p2p/12D3KooWKYkngptku6WmyYJgMKL6uHbxAuqhZ98u7Q67TFL2yF1p, it's impossible to connect the bootstrap node.

Severity:

High

Description:

I built a libp2p js bootstrap and deployed it to fly.io (with dedicated ipv4 of course). The thing is that I can connect to the bootstrap server with ipv4 multiladdr format but the dns multiaddr one.

Steps to reproduce the error:

I have tried to turn on debug mode and got errors like this. Hope it helpful

[DEV] 2024-05-06T14:07:36.435Z libp2p:kad-dht:query-self routing table was empty, waiting for some peers before running query
[DEV] 2024-05-06T14:07:36.435Z libp2p:connection-manager:auto-dial not enough connections 0/50 - will dial peers to increase the number of connections
[DEV] 2024-05-06T14:07:36.436Z libp2p:connection-manager:auto-dial selected 1/1 peers to dial
[DEV] 2024-05-06T14:07:36.440Z libp2p:connection-manager:auto-dial connecting to a peerStore stored peer 12D3KooWKYkngptku6WmyYJgMKL6uHbxAuqhZ98u7Q67TFL2yF1p
[DEV] 2024-05-06T14:07:36.441Z libp2p:connection-manager dial 12D3KooWKYkngptku6WmyYJgMKL6uHbxAuqhZ98u7Q67TFL2yF1p
[DEV] 2024-05-06T14:07:36.441Z libp2p:connection-manager:dial-queue creating dial target for 12D3KooWKYkngptku6WmyYJgMKL6uHbxAuqhZ98u7Q67TFL2yF1p []
[DEV] 2024-05-06T14:07:36.444Z libp2p:connection-manager:dial-queue loading multiaddrs for 12D3KooWKYkngptku6WmyYJgMKL6uHbxAuqhZ98u7Q67TFL2yF1p
[DEV] 2024-05-06T14:07:36.444Z libp2p:connection-manager:dial-queue loaded multiaddrs for 12D3KooWKYkngptku6WmyYJgMKL6uHbxAuqhZ98u7Q67TFL2yF1p [
[DEV]   '/dns/mpc-node-ts.fly.dev/tcp/8080/p2p/12D3KooWKYkngptku6WmyYJgMKL6uHbxAuqhZ98u7Q67TFL2yF1p'
[DEV] ]
[DEV] 2024-05-06T14:07:36.445Z libp2p:tcp dialing /dns/mpc-node-ts.fly.dev/tcp/8080/p2p/12D3KooWKYkngptku6WmyYJgMKL6uHbxAuqhZ98u7Q67TFL2yF1p
[DEV] 2024-05-06T14:07:36.493Z libp2p:tcp connection opened /dns/mpc-node-ts.fly.dev/tcp/8080/p2p/12D3KooWKYkngptku6WmyYJgMKL6uHbxAuqhZ98u7Q67TFL2yF1p
[DEV] 2024-05-06T14:07:36.494Z libp2p:tcp new outbound connection /dns/mpc-node-ts.fly.dev/tcp/8080/p2p/12D3KooWKYkngptku6WmyYJgMKL6uHbxAuqhZ98u7Q67TFL2yF1p
[DEV] 2024-05-06T14:07:36.494Z libp2p:tcp:socket starting the outbound connection upgrade
[DEV] 2024-05-06T14:07:36.494Z libp2p:tcp:socket selecting outbound crypto protocol [ '/noise' ]
[DEV] 2024-05-06T14:07:36.538Z libp2p:tcp:socket mpc-node-ts.fly.dev:8080 socket end
[DEV] 2024-05-06T14:07:36.538Z libp2p:tcp:socket:error encrypting outbound connection to Error: unexpected end of input failed
[DEV] 2024-05-06T14:07:36.538Z libp2p:tcp:socket:error failed to upgrade outbound connection CodeError: unexpected end of input
[DEV]     at DefaultUpgrader._encryptOutbound (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/libp2p@1.5.0/node_modules/libp2p/src/upgrader.ts:682:13)
[DEV]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[DEV]     at DefaultUpgrader.upgradeOutbound (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/libp2p@1.5.0/node_modules/libp2p/src/upgrader.ts:292:13)
[DEV]     at TCP.dial (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/@libp2p+tcp@9.0.24/node_modules/@libp2p/tcp/src/index.ts:181:18)
[DEV]     at DefaultTransportManager.dial (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/libp2p@1.5.0/node_modules/libp2p/src/transport-manager.ts:116:14)
[DEV]     at Job.queue.add.peerId.peerId (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/libp2p@1.5.0/node_modules/libp2p/src/connection-manager/dial-queue.ts:236:26)
[DEV]     at raceSignal (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/race-signal@1.0.2/node_modules/race-signal/src/index.ts:46:12)
[DEV]     at Job.run (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/@libp2p+utils@5.4.0/node_modules/@libp2p/utils/src/queue/job.ts:79:22) {
[DEV]   code: 'ERR_ENCRYPTION_FAILED',
[DEV]   props: {}
[DEV] }
[DEV] 2024-05-06T14:07:36.540Z libp2p:tcp:socket The mpc-node-ts.fly.dev:8080 socket is destroyed
[DEV] 2024-05-06T14:07:36.540Z libp2p:connection-manager:dial-queue:error dial failed to /dns/mpc-node-ts.fly.dev/tcp/8080/p2p/12D3KooWKYkngptku6WmyYJgMKL6uHbxAuqhZ98u7Q67TFL2yF1p CodeError: unexpected end of input
[DEV]     at DefaultUpgrader._encryptOutbound (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/libp2p@1.5.0/node_modules/libp2p/src/upgrader.ts:682:13)
[DEV]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[DEV]     at DefaultUpgrader.upgradeOutbound (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/libp2p@1.5.0/node_modules/libp2p/src/upgrader.ts:292:13)
[DEV]     at TCP.dial (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/@libp2p+tcp@9.0.24/node_modules/@libp2p/tcp/src/index.ts:181:18)
[DEV]     at DefaultTransportManager.dial (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/libp2p@1.5.0/node_modules/libp2p/src/transport-manager.ts:116:14)
[DEV]     at Job.queue.add.peerId.peerId (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/libp2p@1.5.0/node_modules/libp2p/src/connection-manager/dial-queue.ts:236:26)
[DEV]     at raceSignal (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/race-signal@1.0.2/node_modules/race-signal/src/index.ts:46:12)
[DEV]     at Job.run (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/@libp2p+utils@5.4.0/node_modules/@libp2p/utils/src/queue/job.ts:79:22) {
[DEV]   code: 'ERR_ENCRYPTION_FAILED',
[DEV]   props: {}
[DEV] }
[DEV] 2024-05-06T14:07:36.541Z libp2p:connection-manager:dial-queue:error error in dial queue CodeError: unexpected end of input
[DEV]     at DefaultUpgrader._encryptOutbound (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/libp2p@1.5.0/node_modules/libp2p/src/upgrader.ts:682:13)
[DEV]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[DEV]     at DefaultUpgrader.upgradeOutbound (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/libp2p@1.5.0/node_modules/libp2p/src/upgrader.ts:292:13)
[DEV]     at TCP.dial (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/@libp2p+tcp@9.0.24/node_modules/@libp2p/tcp/src/index.ts:181:18)
[DEV]     at DefaultTransportManager.dial (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/libp2p@1.5.0/node_modules/libp2p/src/transport-manager.ts:116:14)
[DEV]     at Job.queue.add.peerId.peerId (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/libp2p@1.5.0/node_modules/libp2p/src/connection-manager/dial-queue.ts:236:26)
[DEV]     at raceSignal (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/race-signal@1.0.2/node_modules/race-signal/src/index.ts:46:12)
[DEV]     at Job.run (/Users/tuphan/Desktop/mpc-node-ts/node_modules/.pnpm/@libp2p+utils@5.4.0/node_modules/@libp2p/utils/src/queue/job.ts:79:22) {
[DEV]   code: 'ERR_ENCRYPTION_FAILED',
[DEV]   props: {}
[DEV] }
tuphan-dn commented 2 months ago

Here is how I create the libp2p

const swarm = await createLibp2p({
  start: false,
  peerId: peer,
  addresses: {
    listen: [`/ip4/0.0.0.0/tcp/${config.PORT}`],
  },
  transports: [tcp()],
  streamMuxers: [yamux()],
  connectionEncryption: [noise()],
  peerDiscovery: bootstrap({
    list: config.BOOTSTRAP_NODES,
  }),
  services: {
    identify: identify(),
    identifyPush: identifyPush(),
    kad: kadDHT({
      clientMode: false,
    }),
    pubsub: gossipsub(),
    autoNat: autoNAT(),
  },
})
await swarm.services.kad.setMode('server')
await swarm.start()
tuphan-dn commented 2 months ago

I realize that node:dns resolved my domain as ipv6 so I need to change /dns/... to /dns6/..., then it worked perfectly.

SgtPooki commented 2 months ago

thanks so much for reporting and coming back with the fix for your scenario. super helpful for future folks.