How to use circuit relay

We have frequent troubles resolving IPFS links. Most people of our engineering team are behind NATs, sometimes even double NATs. Currently we “solve” this by creating SSH tunnels to a server outside the NAT running ipfs. This works, but is not really decentralised.

[User 1] <-- NAT–> [Node] <-- NAT --> [User 2]

So User 1 adds something, and User 2 is unable to resolve it. Once it is pinned on the central node, resolution works.

So I was checking how to properly solve this problem, and to my surprise I noticed that the circuit relay feature is already implemented https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#circuit-relay .

So how would I use it? From the description above I have to enable it using Swarm.DisableRelay = true. But then what? Are there some instructions on how to use this feature? I am sure we could figure it out given the info above, but it would be nice to have step by step instructions.

Edit: added some ascii art for clarification

That disables it. It’s enabled by default.

I think the basic instructions in your link are pretty straightforward, but in your specific scenario you’d use [Node] as your relay (QmRelay in your linked documentation).

  1. [User 1] connects to relay using ipfs swarm connect /transport/address/ipfs/QmRelay (probably already what is happening now)
  2. [User 2] connects to relay using ipfs swarm connect /transport/address/ipfs/QmRelay (probably already what is happening now)
  3. [User 1] can then connect to [User 2] using the relay [Node]: ipfs swarm connect /ipfs/QmRelay/p2p-circuit/ipfs/QmB

After this, [User 1] and [User 2] should be able to resolve things like normal without them needing to be pinned on the relay node.

When you start up the daemon, the p2p-circuit address for each node should be listed as one of the listening addresses.

Check out https://github.com/ipfs/js-ipfs/blob/master/examples/circuit-relaying/README.md, that gives a walk through the process of setting up a circuit-relay.

1 Like

Yes, sorry about my confusion.

Thanks a lot for the link. I somehow missed this when I first looked.

So now I followed the instructions from @leerspace and was able to use the circuit relay. Two nodes A and B that are connected to a common node C via a NAT and a double NAT can see each others objects.

I tested that by adding random stuff on one node and seeing if I can get it on another node. Basically on A head -c 10 /dev/urandom | ipfs add and on B see if you can resolve it. Works pretty well despite all the NATs.

Now, is it possible to configure a node so that it will always try the circuit relay whenever it tries to resolve something?

1 Like

I might be misreading this, but I think that this might be a limitation of the current relay implementation. Based on the future work section of libp2p relay spec, it seems like automatic relay node discovery isn’t implemented yet.

The two users can connect, but if there is no any other nodes with static IP, the resolving is only done by relay node. And after the resolving, if the user[1] want to get data from user[2], the data must tranlate via the relay node.
So NAT would be a tremendous problem of private network in Asia.