Skip to content

Instantly share code, notes, and snippets.

@sahib

sahib/1_question Secret

Last active February 19, 2019 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sahib/7bb3709a75bc9f39fd0d6bcdfe565827 to your computer and use it in GitHub Desktop.
Save sahib/7bb3709a75bc9f39fd0d6bcdfe565827 to your computer and use it in GitHub Desktop.
IPFS stream mounting
Is it possible to setup a p2p listener, that can accept several connections at once?
If so, how? The example below shows what I tried.
$ IPFS_PATH=/tmp/a
$ ipfs init
$ ipfs config --json Experimental.Libp2pStreamMounting true
$ ipfs id -f '<id>\n'
QmUYz9dbqnYPyHCLUi7ghtiwFbdU93MQKFH4qg8iXHWcPV
$ ipfs daemon &
$ ipfs p2p listen /x/hello/1.0 /ip4/127.0.0.1/tcp/9100
$ nc -v -l -p 9100 # This works just fine.
Hello World!
# Now just serve endlessly:
$ while true; do nc -v -l -p 9100; done
# Side note:
# Registering another listener won't work with the same protocol either:
$ ipfs p2p listen /x/brig/1.0 /ip4/127.0.0.1/tcp/9200
Error: listener already registered
$ IPFS_PATH=/tmp/b
$ ipfs init
$ ipfs config --json Experimental.Libp2pStreamMounting true
# Set a different port:
$ ipfs config --json Addresses.Swarm '["/ip4/127.0.0.1/tcp/4002", "/ip6/::/tcp/4002"]'
$ ipfs config Addresses.API '/ip4/127.0.0.1/tcp/5002'
$ ipfs config Addresses.Gateway '/ip4/127.0.0.1/tcp/8081'
$ ipfs daemon &
$ ipfs p2p forward /x/hello/1.0 /ip4/127.0.0.1/tcp/9101 /ipfs/QmUYz9dbqnYPyHCLUi7ghtiwFbdU93MQKFH4qg8iXHWcPV
$ echo "Hello World from 9101!" | nc -v 127.0.0.1 9101
# Opening a new forwarding. I expected to be a able to connect more than one stream to the listener.
# But the second nc just exits immediately without actually connecting:
$ ipfs p2p forward /x/hello/1.0 /ip4/127.0.0.1/tcp/9102 /ipfs/QmUYz9dbqnYPyHCLUi7ghtiwFbdU93MQKFH4qg8iXHWcPV
$ nc -v 127.0.0.1 9101
<waits for input>
$ nc -v 127.0.0.1 9102
localhost.localdomain [127.0.0.1] 9102 (bacula-fd) open
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment