Need help! IPFS Swarm connect failure between two networks

My code is:

const ipfs2 = await IPFS.create({
repo: ‘./ipfs2’,
config: {
Addresses: {
Swarm: [
‘/ip4/0.0.0.0/tcp/4013’,
‘/ip4/127.0.0.1/tcp/4013/ws’
],
API: ‘/ip4/127.0.0.1/tcp/5012’,
Gateway: ‘/ip4/127.0.0.1/tcp/9191’
}
}
})

ipfs = ipfs2;
let ipfsId = await ipfs2.id()
peerId = ipfsId.id

ipfs2.libp2p.connectionManager.on(‘peer:connect’, connection => {
console.log(peer connect: ${connection.remotePeer.toB58String()})
})

ipfs2.libp2p.connectionManager.on(‘peer:disconnect’, connection => {
console.log(peer disconnect: ${connection.remotePeer.toB58String()})
})

try {
await ipfs2.swarm.connect(IPFS.multiaddr("/ip4/xx.xx.xx.xx/tcp/4013/p2p/QmZy5ceAfDsmXYpExCYaE4MPVvy4BgNJtrAaML3dS2yiJX"))
} catch (error) {
console.log(error)
}

/ip4/xx.xx.xx.xx/tcp/4013/p2p/QmZy5ceAfDsmXYpExCYaE4MPVvy4BgNJtrAaML3dS2yiJX is the address that the other machine is listening on.

Got Error:

AggregateError:
Error: socket hang up
at Array.map ()
at maybeSettle (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/p-some/index.js:31:11)
at /Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/p-some/index.js:69:23
Error: Error occurred during XX handshake: Error occurred while verifying signed payload: Peer ID doesn’t match libp2p public key.
at Noise.performXXHandshake (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/libp2p-noise/dist/src/noise.js:166:19)
Error: The operation was aborted
at AbortSignal.onAbort (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/libp2p-tcp/src/index.js:86:14)
at AbortSignal.dispatchEvent (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/event-target-shim/dist/event-target-shim.js:818:35)
at abortSignal (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/abort-controller/dist/abort-controller.js:52:12)
at AbortController.abort (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/abort-controller/dist/abort-controller.js:91:9)
at AbortSignal.onAbort (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/any-signal/index.js:13:16)
at AbortSignal.dispatchEvent (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/event-target-shim/dist/event-target-shim.js:818:35)
at abortSignal (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/abort-controller/dist/abort-controller.js:52:12)
at AbortController.abort (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/abort-controller/dist/abort-controller.js:91:9)
at AbortSignal.onAbort (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/any-signal/index.js:13:16)
at AbortSignal.dispatchEvent (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/event-target-shim/dist/event-target-shim.js:818:35)
Error: The operation was aborted
at AbortSignal.onAbort (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/libp2p-tcp/src/index.js:86:14)
at AbortSignal.dispatchEvent (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/event-target-shim/dist/event-target-shim.js:818:35)
at abortSignal (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/abort-controller/dist/abort-controller.js:52:12)
at AbortController.abort (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/abort-controller/dist/abort-controller.js:91:9)
at AbortSignal.onAbort (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/any-signal/index.js:13:16)
at AbortSignal.dispatchEvent (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/event-target-shim/dist/event-target-shim.js:818:35)
at abortSignal (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/abort-controller/dist/abort-controller.js:52:12)
at AbortController.abort (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/abort-controller/dist/abort-controller.js:91:9)
at AbortSignal.onAbort (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/any-signal/index.js:13:16)
at AbortSignal.dispatchEvent (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/event-target-shim/dist/event-target-shim.js:818:35)
at maybeSettle (/Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/p-some/index.js:31:11)
at /Users/charlesliu/Desktop/learn_ipfs/orbitDB-demo copy/node_modules/p-some/index.js:69:23
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
code: ‘ERR_TIMEOUT’

Need Help! What am I missing for making it works?

Hello @windseason

The problem with this configuration is trying to listen for connection in the same port for different listeners. Changing the websockets swarm address to use a different port than TCP should fix the issue.

Let me know :slight_smile:

Thanks for replying, @vasco-santos
I’ve changed the code, see below:
const ipfs2 = await IPFS.create({
repo: ‘./ipfs_database/ipfs2’,
config: {
Addresses: {
Swarm: [
‘/ip4/0.0.0.0/tcp/4013’,
‘/ip4/127.0.0.1/tcp/4014/ws’
],
API: ‘/ip4/127.0.0.1/tcp/5012’,
Gateway: ‘/ip4/127.0.0.1/tcp/9191’
}
}
})

But Still got same error:

Forgot to mention two of my test machines are behind NAT. So, Is there any other ipfs configuration I need ?

One of my machine’s ipfs node started and it printed:

Swarm listening on /ip4/127.0.0.1/tcp/4013/p2p/QmUAxg31UkJ26VFN438o24NWsayKah3gxvYz81J6krfThW
Swarm listening on /ip4/192.168.70.180/tcp/4013/p2p/QmUAxg31UkJ26VFN438o24NWsayKah3gxvYz81J6krfThW
Swarm listening on /ip4/127.0.0.1/tcp/4014/ws/p2p/QmUAxg31UkJ26VFN438o24NWsayKah3gxvYz81J6krfThW

so I copied one of the multiaddr above to the other machine, and tried to use swarm connect to it:

try {
await ipfs2.swarm.connect(IPFS.multiaddr("/ip4/192.168.70.180/tcp/4013/p2p/QmUAxg31UkJ26VFN438o24NWsayKah3gxvYz81J6krfThW"))
} catch (error) {
console.log(error)
}

The multiaddr is using local address, I guess this is the issue? If this is the case, How can I get right address to connect with ?

I learned examples today, I found I need to have the node enable relay, so I change the config to :
const ipfs2 = await IPFS.create({
repo: ‘./ipfs_database/ipfs2’,
config: {
Addresses: {
Swarm: [
‘/ip4/0.0.0.0/tcp/4002’,
‘/ip4/127.0.0.1/tcp/4003/ws’
]
},
relay: {
enabled: true, // enable relay dialer/listener (STOP)
hop: {
enabled: true // make this node a relay (HOP)
}
}
}
})

However, I didn’t find any swarm listening address starts with “/p2p-circuit/p2p/” , what I got is :
Swarm listening on /ip4/127.0.0.1/tcp/4002/p2p/QmfUPWYfLW3TKHHgqM4fd27RB4vZog86KJtaN8khScURPY
Swarm listening on /ip4/10.228.33.154/tcp/4002/p2p/QmfUPWYfLW3TKHHgqM4fd27RB4vZog86KJtaN8khScURPY
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/p2p/QmfUPWYfLW3TKHHgqM4fd27RB4vZog86KJtaN8khScURPY

It looks like the relay is not enabled?

Yes that is the issue. A local address cannot be reached from the public network.

We are working on some ways of dealing with the NAT traversal, but for now you will need to leverage a relay. The design for this should have the following flow:

  • All your nodes should listen on a given relay address publicly reachable
  • Each one of your node will have a swarm address through that relay

The communication works good here because when you listen on a relay, the peer will initiate the connection itself to a publicly reachable machine. The problem with NAT is that you cannot be dialled.

With this in mind, what you want to do is running a relay node publicly available. You can use this ready to go: GitHub - libp2p/js-libp2p-relay-server: An out of the box libp2p relay server implementing v1 of circuit relay protocol

After this, all your nodes should have a swarm address with the address of the relay server + /p2p-circuit/.

Let me know if you could get this running

1 Like

Thanks! I am very grateful! I will try it.

By looking at the libp2p repos, I found there is one more useful repo, a webrtc implementation GitHub - libp2p/js-libp2p-webrtc-star: libp2p WebRTC transport that includes a discovery mechanism provided by the signalling-star.

Actually, my goal is to have two nodes to talk with each other through internet, so, I wonder if this js-libp2p-webrtc-star could also do the trick?

You can also use libp2p-webrtc-star yes. There are two things you need to consider: discovery and connectivity.

Regarding peer discovery, you will need to guarantee that peers can discover each other. If in your use case you will have well known peers that will have a given multiaddr over time and you can just say it to other peers (manually configured), you basically use a bootstrap discovery, where you give addresses in advance to bootstrap your network. However, if you expect several peers to appear and disappear over time (for instance a chat app), you will need to use a more “dynamic” discovery service.

In the connectivity side of things, once you discovered peers (this basically means you have a set of multiaddrs for a given peer), you can try to dial them and establish a connection. Some scenarios like nodes behind NATs or browser nodes will not be able to receive direct connections as they will not have direct reachable addresses currently.

Webrtc-star uses a star server that acts as a discovery point and as an intermediary to exchange SDP offers and establish a Webrtc connections. The STUN and/or TURN servers used by this protocol will allow nodes behind a NAT to establish a connection. So, webrtc-star provides you both discoverability and connectivity out of the box by using a star server. The drawbacks of this solution are the usage of one or more centralized servers and the usage of WebRCT (not directly a disadvantage, but a limitation as for example go-ipfs nodes do not support WebRTC at the moment and you will not be able to connect with them if you need to in your use case).

Using a relay server enables you to establish connectivity between not previously able to connect peers, by accepting connections on behalf of nodes who previously established connections with them and bound them as a relay. One big advantage of this is that a relay server can use any transport supported by libp2p, including TCP and Websockets. The relay protocol itself does not come with any discovery capabilities. However, we recently created GitHub - libp2p/js-libp2p-pubsub-peer-discovery: A js-libp2p module that uses pubsub for mdns like peer discovery which enables peers using a given relay to discover other peers using this discovery protocol. The ready to go relay that I previously mentioned already supports this discovery protocol. One of the highlights of using a relay server is that you can have a fleet of relay servers in the network (which are basically a libp2p node with relay enabled), instead of single deployed star servers.

You have examples for using webrtc-star within the browser in https://github.com/libp2p/js-libp2p/tree/master/examples/libp2p-in-the-browser but you can easily replicate the same in Node, or Node + Browser. Moreover, you should check other examples in libp2p repo to consolidate the discovery part.

1 Like

why am I getting these messages??
super annoying…

GAVIN WASHBURN
Founder | Business Development

Mobile: (602) 206-2100
Email: mail@middlemaan.com
Web: middlemaan.com

Wow! Thanks for your comprehensive explanation about the differences between them. I almost have finished setting up the js-libp2p-relay-server, but I am not sure if I setup my ipfs nodes correctly. Where should I put the public address of the relay server for ipfs configuration when I create a ipfs node? Do you have any example? My guess is maybe I need to use swarm connect to have ipfs nodes connect with relay server first and then the two ipfs nodes could talk with each other. I am going to test this way today.

@windseason happy to help!

You can do swarm connect first and then they will be able to talk through the relay. This example seems to do that: js-ipfs/examples/circuit-relaying at master · ipfs/js-ipfs · GitHub. However, I recommend you simply add the public address of the relay in the swarm addresses in the configuration like:

Swarm: [
‘/ip4/0.0.0.0/tcp/4002’,
‘/ip4/127.0.0.1/tcp/4003/ws’,
'/ip4/84.2.3.1/tcp/4000/ws/p2p-circuit
]
}

Taking into account that 84.2.3.1 would be your address. This will make libp2p automatically dial the address for your and it will be logged with the “Swarm listening on” when you start your daemon.

Another thing that libp2p@0.30 introduced is the AutoRelay, which if enabled will automatically bind to relay nodes that it discovers over time up to a configurable limit. This is not yet supported in js-ipfs as libp2p needs to be updated, but it will become even smoother as you can just rely on peer discovery to find relays and then listen on them. If you are interested in this, I can point you to: js-libp2p/examples/auto-relay at master · libp2p/js-libp2p · GitHub

I have setup my relay server! Cheers! :grinning:

When I do what you taught me, I got below error:

Error: Transport (Circuit) could not listen on any available address
at TransportManager.listen (/Users/charlesliu/thesis/DemoCode/client-demo/node_modules/ipfs-core/node_modules/libp2p/src/transport-manager.js:179:23)
at processTicksAndRejections (internal/process/task_queues.js:89:5)
at async Libp2p._onStarting (/Users/charlesliu/thesis/DemoCode/client-demo/node_modules/ipfs-core/node_modules/libp2p/src/index.js:465:5)
at async Libp2p.start (/Users/charlesliu/thesis/DemoCode/client-demo/node_modules/ipfs-core/node_modules/libp2p/src/index.js:230:7)
at async start (/Users/charlesliu/thesis/DemoCode/client-demo/node_modules/ipfs-core/src/components/network.js:45:5)
at async Function.start (/Users/charlesliu/thesis/DemoCode/client-demo/node_modules/ipfs-core/src/utils/service.js:55:26)
at async IPFS.start (/Users/charlesliu/thesis/DemoCode/client-demo/node_modules/ipfs-core/src/components/start.js:20:33)
at async Object.create (/Users/charlesliu/thesis/DemoCode/client-demo/node_modules/ipfs-core/src/components/index.js:230:7)
at async App. (/Users/charlesliu/thesis/DemoCode/client-demo/main.js:50:18) {
code: ‘ERR_NO_VALID_ADDRESSES’
}

My ipfs node configuration:
84.70.116.xxx is my server’s public ip address

 const node = await IPFS.create({
      repo: './ipfs_databases/app1',
      config: {
        Addresses: {
          Swarm: [
            '/ip4/0.0.0.0/tcp/4002',
            '/ip4/127.0.0.1/tcp/4003/ws',
            '/ip4/84.70.116.xxx/tcp/443/wss/p2p-circuit'
          ]
        },
        relay: {
          enabled: true, // enable relay dialer/listener (STOP)
          hop: {
            enabled: true // make this node a relay (HOP),
          }
        }
      }
    })

My configuration for starting server

libp2p-relay-server --peerId /path/to/peer-id.json 
--listenMultiaddrs '/ip4/0.0.0.0/tcp/15002/ws' '/ip4/0.0.0.0/tcp/8001' 
--announceMultiaddrs '/dns4/my.test.com/tcp/8000' '/dns4/my.test.com/tcp/443/wss'
--disablePubsubDiscovery

I found the format of peer-id generated by below command is different than ipfs node’s, it doesn’t start with Qm, is this the issue?

peer-id --type=ed25519 > id.json

the peer-id I generated is:

{
  "id": "12D3KooWGKakawDMbo7iU3wdPQsB3C9cXgfghTQvD6GRyVTLZUkG",
  "privKey": "CAESQGt96OS/wpY/r66yK6aBWf0wK9cIZ3cJoOb2jNE7pk01YKIxdYuYvfNCGYSBCStfhCBwSez8/9nLp0JdP2Lt+Qk=",
  "pubKey": "CAESIGCiMXWLmL3zQhmEgQkrX4QgcEns/P/Zy6dCXT9i7fkJ"
}

12D3KooWGKakawDMbo7iU3wdPQsB3C9cXgfghTQvD6GRyVTLZUkG doesn’t seem right.

Ok, I recommend that you start by running both in a local environment and get this to work before going into a production environment. So, I would do:

  1. everything working locally
  2. dial manually the server in production to guarantee it is reachable
  3. use it directly as a swarm address afterwards

I believe you will not be able to connect to the peer, if you do swarm connect, instead of adding it as the swarm. This is probably because you will need to setup SSL in the server and map this to the correct IPFS/libp2p ports. We have some docs in https://github.com/libp2p/js-libp2p-webrtc-star/blob/master/DEPLOYMENT.md regarding a possible way of setting up SSL using nginx as a proxy. You can also google for how to do this.

Ok, so you should not have those announceMultiaddrs unless you configure DNS. You should do it, specially because browser nodes will only be able to dial a relay server if it has SSL+DNS multiaddr, but I would start Node first and without it, and then iterate.

Ok, so this is not a problem at all. A PeerId can currently be created using 3 different types of keys: [‘RSA’, ‘Ed25519’, ‘secp256k1’] as you can see in GitHub - libp2p/js-peer-id: peer-id implementation in JavaScript. Deprecated; use https://github.com/libp2p/js-libp2p-peer-id instead.

RSA keys will generate the Qm based addresses, while ed25519 will generate IDs like yours. RSA keys are still the default, but we are moving into ed25519 keys by default as we can include them inline with the peer id when exchanging messages, while the same is not feasible with RSA. So, I suggest you just use ed25519

Let me know how this goes

Thanks @vasco-santos

Finally, I can use swarm successfully to connect relay node and work just like the example https://github.com/ipfs/js-ipfs/tree/master/examples/circuit-relaying does.

However, specifying the replay address in Swarm like below still fails:

Swarm: [
‘/ip4/0.0.0.0/tcp/4002’,
‘/ip4/127.0.0.1/tcp/4003/ws’,
'/ip4/84.70.116.xxx/tcp/443/wss/p2p-circuit'
]
}

the error message is

(node:59880) UnhandledPromiseRejectionWarning: Error: Transport (Circuit) could not listen on any available address
at TransportManager.listen (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/libp2p/src/transport-manager.js:179:23)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Libp2p._onStarting (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/libp2p/src/index.js:465:5)
at async Libp2p.start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/libp2p/src/index.js:230:7)
at async start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs/src/core/components/start.js:78:5)
at async Object.create (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs/src/core/index.js:108:57)
at async main (/Users/charlesliu/thesis/DemoCode/swarm-test/peer1.js:4:17)
(Use node --trace-warnings ... to show where the warning was created)
(node:59880) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see Command-line API | Node.js v21.2.0 Documentation). (rejection id: 2)
(node:59880) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

@vasco-santos

One more question.

Depend on relay servers to establish connections between nodes that behind NATs is great, but it seems some kind of centralized solution(correct me if I understand incorrectly).

So, I guess I can only depend on pubsub to send messages between nodes which cannot connect directly if I just want a decentralized solution? Or use webrtc solution?

Did you try running this in a local environment first? I feel the error is related to network configuration on your deployed machine. But not sure yet. Let me know, and you can also run your node using the debugger mode to obtain the logs by:

DEBUG=libp2p* node your-project.js

Yes, but depending on how you setup you can get into a more decentralized network. The nice thing about using the relays is that you can spin up several relays and rely on all of them. If there is a problem with one of them, your network will not be affected and everything will just keep working.

Pubsub allows you to exchange messages between nodes, even if they are not connected. This will happen if they are connected with same peers, or at least indirectly connected.

Webrtc solution is the centralized solution, as you currently need to use a signalling server instead of any libp2p node supporting a relay.

I installed the relay server locally in my mac book pro and start it:

libp2p-relay-server --peerId ./id.json --listenMultiaddrs '/ip4/127.0.0.1/tcp/15002/ws' '/ip4/127.0.0.1/tcp/8001'
Relay server listening on:
<Multiaddr 047f000001063a9add03 - /ip4/127.0.0.1/tcp/15002/ws>
<Multiaddr 047f000001061f41 - /ip4/127.0.0.1/tcp/8001>
metrics server listening on 8003

then, ipfs node config:

 const node = await IPFS.create({
    repo: './ipfs_database/ipfs2',
    config: {
      Addresses: {
        Swarm: [
          '/ip4/127.0.0.1/tcp/15002/ws/p2p-circuit'
        ]
      },
      // If you want to connect to the public bootstrap nodes, remove the next line
      Bootstrap: []
    }
  })

Still got same error:

  libp2p:transports creating listener for Circuit on /ip4/127.0.0.1/tcp/15002/ws/p2p-circuit +2ms
  libp2p:error Error: Transport (Circuit) could not listen on any available address
  libp2p:error     at TransportManager.listen (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/node_modules/libp2p/src/transport-manager.js:179:23)
  libp2p:error     at async Libp2p._onStarting (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/node_modules/libp2p/src/index.js:465:5)
  libp2p:error     at async Libp2p.start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/node_modules/libp2p/src/index.js:230:7)
  libp2p:error     at async start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/src/components/network.js:45:5)
  libp2p:error     at async Function.start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/src/utils/service.js:55:26)
  libp2p:error     at async IPFS.start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/src/components/start.js:20:33)
  libp2p:error     at async Object.create (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/src/components/index.js:230:7)
  libp2p:error     at async main (/Users/charlesliu/thesis/DemoCode/swarm-test/peer1.js:48:16) +0ms
  libp2p:error An error occurred starting libp2p Error: Transport (Circuit) could not listen on any available address
    at TransportManager.listen (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/node_modules/libp2p/src/transport-manager.js:179:23)
    at async Libp2p._onStarting (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/node_modules/libp2p/src/index.js:465:5)
    at async Libp2p.start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/node_modules/libp2p/src/index.js:230:7)
    at async start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/src/components/network.js:45:5)
    at async Function.start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/src/utils/service.js:55:26)
    at async IPFS.start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/src/components/start.js:20:33)
    at async Object.create (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/src/components/index.js:230:7)
    at async main (/Users/charlesliu/thesis/DemoCode/swarm-test/peer1.js:48:16) {
  code: 'ERR_NO_VALID_ADDRESSES'

My node package info:

demo@1.0.0 /Users/charlesliu/thesis/DemoCode/swarm-test
└── ipfs@0.52.3

Ah, you need to add the /p2p/{ID} to the multiaddr, as it must know the peer identity. It should be:

Swarm: [
          '/ip4/127.0.0.1/tcp/15002/ws/p2p-circuit/p2p/{INSERT_YOUR_ID}'
        ]

Still doesn’t work… :frowning:

Is the peer identify the id generated by peer-id? I copied it and paste to the swarm address:

libp2pRelayServer cat id.json
{
  "id": "QmZpR5RL1j2vKij9HgETmKvzGg1xxnbpjVW68xgPcxbB8Z",
....
}
➜  libp2pRelayServer libp2p-relay-server --peerId ./id.json --listenMultiaddrs '/ip4/127.0.0.1/tcp/15002/ws' '/ip4/127.0.0.1/tcp/8001'
Relay server listening on:
<Multiaddr 047f000001063a9add03 - /ip4/127.0.0.1/tcp/15002/ws>
<Multiaddr 047f000001061f41 - /ip4/127.0.0.1/tcp/8001>
metrics server listening on 8003
Swarm: [
'/ip4/127.0.0.1/tcp/15002/ws/p2p-circuit/p2p/QmZpR5RL1j2vKij9HgETmKvzGg1xxnbpjVW68xgPcxbB8Z'
]

got error:

 libp2p:error Error: no valid addresses were provided for transports [TCP,WebSockets,Circuit]
  libp2p:error     at TransportManager.listen (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/libp2p/src/transport-manager.js:188:23)
  libp2p:error     at Libp2p._onStarting (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/libp2p/src/index.js:465:33)
  libp2p:error     at Libp2p.start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/libp2p/src/index.js:230:18)
  libp2p:error     at start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/src/components/network.js:45:18)
  libp2p:error     at async Function.start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/src/utils/service.js:55:26)
  libp2p:error     at async IPFS.start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/src/components/start.js:20:33)
  libp2p:error     at async Object.create (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/src/components/index.js:230:7)
  libp2p:error     at async main (/Users/charlesliu/thesis/DemoCode/swarm-test/peer1.js:48:16) +0ms
  libp2p:error An error occurred starting libp2p Error: no valid addresses were provided for transports [TCP,WebSockets,Circuit]
    at TransportManager.listen (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/libp2p/src/transport-manager.js:188:23)
    at Libp2p._onStarting (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/libp2p/src/index.js:465:33)
    at Libp2p.start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/libp2p/src/index.js:230:18)
    at start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/src/components/network.js:45:18)
    at async Function.start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/src/utils/service.js:55:26)
    at async IPFS.start (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/src/components/start.js:20:33)
    at async Object.create (/Users/charlesliu/thesis/DemoCode/swarm-test/node_modules/ipfs-core/src/components/index.js:230:7)
    at async main (/Users/charlesliu/thesis/DemoCode/swarm-test/peer1.js:48:16) {
  code: 'ERR_NO_VALID_ADDRESSES'

however, I can swarm connect to it

 await node.swarm.connect(IPFS.multiaddr("/ip4/127.0.0.1/tcp/15002/ws/p2p/QmZpR5RL1j2vKij9HgETmKvzGg1xxnbpjVW68xgPcxbB8Z"))

I am running in Node envrionment

Sorry, I provided you the wrong format. It should be:

Swarm: [
'/ip4/127.0.0.1/tcp/15002/ws/p2p/QmZpR5RL1j2vKij9HgETmKvzGg1xxnbpjVW68xgPcxbB8Z/p2p-circuit'
]

Let me know if that solved the issue

Yeah! Thanks you. It finally works!

 addresses: [
    <Multiaddr 047f000001063a9add03a503221220aa8d678d533fa528290df26541f8b01a2e0742ceb570b4d9a7a497b47789edbea202a503221220fe92236810c6fe9c075e3d5999e9c5315dd1ea360b5ad9a95370a6be0d42bb03 - /ip4/127.0.0.1/tcp/15002/ws/p2p/QmZpR5RL1j2vKij9HgETmKvzGg1xxnbpjVW68xgPcxbB8Z/p2p-circuit/p2p/QmfUPWYfLW3TKHHgqM4fd27RB4vZog86KJtaN8khScURPY>
  ],