How do you connect to a specific peer?

I have my IPFS server set up and running and it is connected to other peers. I have the IP and the IPFS ‘id’.

In my browser app I use js-ipfs and want to connect directly to my server. How can I do that?

1 Like

I tried ipfs.swarm.connect('/ip4/149.28.../tcp/4001/ipfs/Qm...') but get error:

connect Error: Circuit not enabled!

(It works when I do it at the command line of another peer.)

In short, js-ipfs running in browser context has a limited number of transports and raw TCP socket exposed by go-ipfs node is not reachable by any of them.

If you control the go-ipfs node you want to connect to, then you could make it listen on additional websocket (/ws) port, for example:

"Swarm": [
      "/ip4/0.0.0.0/tcp/4001",
      "/ip4/0.0.0.0/tcp/4004/ws",
      "/ip6/::/tcp/4001"
    ]

That way js-ipfs running in browser will be able to dial your server over websocket transport.

ps. FYI there is an ongoing work to provide automatic relay feature for nodes with limited transport options, such as ones in web browsers. For now we have semi-manual solution (eg. there is no relay discovery, you need to hardcode it in config etc). More details and current status: Tutorial - Understanding Circuit Relay

1 Like

Thank you!

In the end I was able to connect though wss via a Nginx proxy.

2 Likes