Go-ipfs p2p experimental feature

Hi there! Can’t understand basic usage of this feature:

Open a listener on one node (node A) ipfs p2p listener open > p2p-test /ip4/127.0.0.1/tcp/10101

Ok. It’s easy.

Where /ip4/127.0.0.1/tcp/10101 put address of application > you want to pass p2p connections to

What application? Side app? What does it mean “pass p2p connections to”? Where? Usual host:port format?

On the other node, connect to the listener on node A ipfs > p2p stream dial $NODE_A_PEERID p2p-test /ip4/127.0.0.1/tcp/10102

Why different port? How connect if node B dial makes similar listener as listener on node A?

Node B is now listening for a connection on TCP at > 127.0.0.1:10102, connect your application there to complete the connection

What app? How connect? How this scheme is working and looking?

Maybe somebody has a code example? Thank you all.

Practical example: I have two servers running, server #1 is running requestbin but it’s not accessible directly from server #2, only accessible if I go via server #1.

We can use libp2p streams to tunnel our traffic from server #2 via server #1, therefore getting access to our requestbin instance.

Since our requestbin application is running on localhost:8000, we want to tunnel traffic on server #1 to /ip4/127.0.0.1/tcp/8000, so we’ll setup our daemon on server #1 like this:

// random ipfs repository path
$ export IPFS_PATH=$(mktemp -d)
$ ipfs init
$ ipfs daemon &
$ ipfs config --json Experimental.Libp2pStreamMounting true
$ ipfs p2p listener open p2p-test /ip4/127.0.0.1/tcp/8000
# ^ is basically saying: open a listener with the protocol `p2p-test` that will send tcp traffic to localhost:8000

Now on server #2 (or different terminal window, remember to change default ports if on same machine):

$ export IPFS_PATH=$(mktemp -d)
$ ipfs init
$ ipfs daemon&
$ ipfs config --json Experimental.Libp2pStreamMounting true
$ ipfs p2p stream dial QmejtFLt4N97SvqYxUYEvW3zGciBRwwXuUHTBB4t9Cbw1J p2p-test /ip4/127.0.0.1/tcp/9000
# ^ is basically saying: dial to $NODE_ID with `p2p-test` protocol and send all traffic from localhost:9000 to that protocol + node

Now we can use localhost:9000 on server #2 to actually end up at localhost:8000 on server #1!

2 Likes

Sorry, still not clear. The reason why i’ve asked so many questions is to make answering proccess more simple.

Ok, let me answer your questions directly.

Where /ip4/127.0.0.1/tcp/10101 put address of application > you want to pass p2p connections to

What application? Side app? What does it mean “pass p2p connections to”? Where? Usual host:port format?

Whatever application you want. You’re tunneling connections from your daemon to port X, X can be whatever you want. “pass p2p connections” means tunneling a connection from Y to Z. You can find more information about what tunnelling is here: Tunneling protocol - Wikipedia It’s using the multiaddr format rather than the host:port format

On the other node, connect to the listener on node A ipfs > p2p stream dial $NODE_A_PEERID p2p-test /ip4/127.0.0.1/tcp/10102

Why different port? How connect if node B dial makes similar listener as listener on node A?

It’s the port where you would be able to connect to whatever the protocol (p2p-test in this case) is bound to. I’m not sure I understand the second question, could you elaborate what you mean here?

Node B is now listening for a connection on TCP at > 127.0.0.1:10102, connect your application there to complete the connection

What app? How connect? How this scheme is working and looking?

The application/service/port you’re streaming towards. You can connect with whatever can use TCP, as it’s just a TCP port that gets opened, where everything you send ends up at whatever the listener is pointing to from the previous steps.


In general, libp2p stream mounting usage is the same as with ssh tunnels. Check out this guide for how ssh tunnels works: Quick-Tip: SSH Tunneling Made Easy

Basically, libp2p stream mounting is the same as ssh tunnels, but it works over libp2p rather than ssh.

4 Likes