diff --git a/core/commands/p2p.go b/core/commands/p2p.go index 95c6cc02d..daa904e43 100644 --- a/core/commands/p2p.go +++ b/core/commands/p2p.go @@ -19,6 +19,8 @@ import ( "gx/ipfs/QmdE4gMduCKCGAcczM2F5ioYDfdeKuPix138wrES1YSr7f/go-ipfs-cmdkit" ) +const P2PProtoPrefix = "/x/" + // P2PListenerInfoOutput is output type of ls command type P2PListenerInfoOutput struct { Protocol string @@ -71,16 +73,16 @@ var p2pForwardCmd = &cmds.Command{ Forward connections made to to . specifies the libp2p protocol name to use for libp2p -connections and/or handlers. +connections and/or handlers. It must be prefixed with '` + P2PProtoPrefix + `'. To create a libp2p service listener, specify '/ipfs' as Examples: - ipfs p2p forward myproto /ipfs /ip4/127.0.0.1/tcp/1234 + ipfs p2p forward ` + P2PProtoPrefix + `myproto /ipfs /ip4/127.0.0.1/tcp/1234 - Forward connections to 'myproto' libp2p service to 127.0.0.1:1234 - ipfs p2p forward myproto /ip4/127.0.0.1/tcp/4567 /ipfs/QmPeer - - Forward connections to 127.0.0.1:4567 to 'myproto' service on /ipfs/QmPeer + ipfs p2p forward ` + P2PProtoPrefix + `myproto /ip4/127.0.0.1/tcp/4567 /ipfs/QmPeer + - Forward connections to 127.0.0.1:4567 to '` + P2PProtoPrefix + `myproto' service on /ipfs/QmPeer `, }, @@ -100,8 +102,8 @@ Examples: listen := req.Arguments()[1] target := req.Arguments()[2] - if !strings.HasPrefix(proto, "/p2p/") { - res.SetError(errors.New("protocol name must be within '/p2p/' namespace"), cmdkit.ErrNormal) + if !strings.HasPrefix(proto, P2PProtoPrefix) { + res.SetError(errors.New("protocol name must be within '" + P2PProtoPrefix + "' namespace"), cmdkit.ErrNormal) return } diff --git a/docs/experimental-features.md b/docs/experimental-features.md index 400e6fe7b..d714e6242 100644 --- a/docs/experimental-features.md +++ b/docs/experimental-features.md @@ -277,7 +277,7 @@ The `p2p` command needs to be enabled in config: First, pick a protocol name for your application. Think of the protocol name as a port number, just significantly more user-friendly. In this example, we're -going to use `/p2p/kickass/1.0`. +going to use `/x/kickass/1.0`. ***Setup:*** @@ -292,10 +292,10 @@ port `$APP_PORT`. Then, configure the p2p listener by running: ```sh -> ipfs p2p forward /p2p/kickass/1.0 /ipfs /ip4/127.0.0.1/tcp/$APP_PORT +> ipfs p2p forward /x/kickass/1.0 /ipfs /ip4/127.0.0.1/tcp/$APP_PORT ``` -This will configure IPFS to forward all incoming `/p2p/kickass/1.0` streams to +This will configure IPFS to forward all incoming `/x/kickass/1.0` streams to `127.0.0.1:$APP_PORT` (opening a new connection to `127.0.0.1:$APP_PORT` per incoming stream. @@ -303,10 +303,10 @@ incoming stream. First, configure the client p2p dialer, so that it forwards all inbound connections on `127.0.0.1:SOME_PORT` to the server node listening -on `/p2p/kickass/1.0`. +on `/x/kickass/1.0`. ```sh -> ipfs p2p forward /p2p/kickass/1.0 /ip4/127.0.0.1/tcp/$SOME_PORT /ipfs/$SERVER_ID +> ipfs p2p forward /x/kickass/1.0 /ip4/127.0.0.1/tcp/$SOME_PORT /ipfs/$SERVER_ID ``` Next, have your application open a connection to `127.0.0.1:$SOME_PORT`. This @@ -341,13 +341,13 @@ _you can get `$SERVER_ID` by running `ipfs id -f "\n"`_ ***First, on the "server" node:*** ```sh -ipfs p2p forward /p2p/ssh /ipfs /ip4/127.0.0.1/tcp/22 +ipfs p2p forward /x/ssh /ipfs /ip4/127.0.0.1/tcp/22 ``` ***Then, on "client" node:*** ```sh -ipfs p2p forward /p2p/ssh /ip4/127.0.0.1/tcp/2222 /ipfs/$SERVER_ID +ipfs p2p forward /x/ssh /ip4/127.0.0.1/tcp/2222 /ipfs/$SERVER_ID ``` You should now be able to connect to your ssh server through a libp2p connection diff --git a/test/sharness/t0180-p2p.sh b/test/sharness/t0180-p2p.sh index 940ce1092..ce6399918 100755 --- a/test/sharness/t0180-p2p.sh +++ b/test/sharness/t0180-p2p.sh @@ -38,7 +38,7 @@ test_expect_success "enable filestore config setting" ' ' test_expect_success 'start p2p listener' ' - ipfsi 0 p2p forward /p2p/p2p-test /ipfs /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log + ipfsi 0 p2p forward /x/p2p-test /ipfs /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log ' # Server to client communications @@ -69,7 +69,7 @@ test_server_to_client() { spawn_sending_server test_expect_success 'S->C Setup client side' ' - ipfsi 1 p2p forward /p2p/p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/${PEERID_0} 2>&1 > dialer-stdouterr.log + ipfsi 1 p2p forward /x/p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/${PEERID_0} 2>&1 > dialer-stdouterr.log ' test_server_to_client @@ -87,7 +87,7 @@ spawn_sending_server test_server_to_client test_expect_success 'S->C Close local listener' ' - ipfsi 1 p2p close -p /p2p/p2p-test + ipfsi 1 p2p close -p /x/p2p-test ' check_test_ports @@ -102,7 +102,7 @@ test_expect_success 'C->S Spawn receiving server' ' ' test_expect_success 'C->S Setup client side' ' - ipfsi 1 p2p forward /p2p/p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/${PEERID_0} 2>&1 > dialer-stdouterr.log + ipfsi 1 p2p forward /x/p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/${PEERID_0} 2>&1 > dialer-stdouterr.log ' test_expect_success 'C->S Connect and receive data' ' @@ -119,7 +119,7 @@ test_expect_success 'C->S Output looks good' ' ' test_expect_success 'C->S Close local listener' ' - ipfsi 1 p2p close -p /p2p/p2p-test + ipfsi 1 p2p close -p /x/p2p-test ' check_test_ports @@ -127,7 +127,7 @@ check_test_ports # Listing streams test_expect_success "'ipfs p2p ls' succeeds" ' - echo "/p2p/p2p-test /ipfs /ip4/127.0.0.1/tcp/10101" > expected && + echo "/x/p2p-test /ipfs /ip4/127.0.0.1/tcp/10101" > expected && ipfsi 0 p2p ls > actual ' @@ -136,7 +136,7 @@ test_expect_success "'ipfs p2p ls' output looks good" ' ' test_expect_success "Cannot re-register app handler" ' - test_must_fail ipfsi 0 p2p forward /p2p/p2p-test /ipfs /ip4/127.0.0.1/tcp/10101 + test_must_fail ipfsi 0 p2p forward /x/p2p-test /ipfs /ip4/127.0.0.1/tcp/10101 ' test_expect_success "'ipfs p2p stream ls' output is empty" ' @@ -147,7 +147,7 @@ test_expect_success "'ipfs p2p stream ls' output is empty" ' test_expect_success "Setup: Idle stream" ' ma-pipe-unidir --listen --pidFile=listener.pid recv /ip4/127.0.0.1/tcp/10101 & - ipfsi 1 p2p forward /p2p/p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/$PEERID_0 2>&1 > dialer-stdouterr.log && + ipfsi 1 p2p forward /x/p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/$PEERID_0 2>&1 > dialer-stdouterr.log && ma-pipe-unidir --pidFile=client.pid recv /ip4/127.0.0.1/tcp/10102 & test_wait_for_file 30 100ms listener.pid && @@ -156,7 +156,7 @@ test_expect_success "Setup: Idle stream" ' ' test_expect_success "'ipfs p2p stream ls' succeeds" ' - echo "3 /p2p/p2p-test /ipfs/$PEERID_1 /ip4/127.0.0.1/tcp/10101" > expected + echo "3 /x/p2p-test /ipfs/$PEERID_1 /ip4/127.0.0.1/tcp/10101" > expected ipfsi 0 p2p stream ls > actual ' @@ -172,13 +172,13 @@ test_expect_success "'ipfs p2p stream close' closes stream" ' ' test_expect_success "'ipfs p2p close' closes remote handler" ' - ipfsi 0 p2p close -p /p2p/p2p-test && + ipfsi 0 p2p close -p /x/p2p-test && ipfsi 0 p2p ls > actual && test_must_be_empty actual ' test_expect_success "'ipfs p2p close' closes local handler" ' - ipfsi 1 p2p close -p /p2p/p2p-test && + ipfsi 1 p2p close -p /x/p2p-test && ipfsi 1 p2p ls > actual && test_must_be_empty actual ' @@ -188,8 +188,8 @@ check_test_ports test_expect_success "Setup: Idle stream(2)" ' ma-pipe-unidir --listen --pidFile=listener.pid recv /ip4/127.0.0.1/tcp/10101 & - ipfsi 0 p2p forward /p2p/p2p-test2 /ipfs /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log && - ipfsi 1 p2p forward /p2p/p2p-test2 /ip4/127.0.0.1/tcp/10102 /ipfs/$PEERID_0 2>&1 > dialer-stdouterr.log && + ipfsi 0 p2p forward /x/p2p-test2 /ipfs /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log && + ipfsi 1 p2p forward /x/p2p-test2 /ip4/127.0.0.1/tcp/10102 /ipfs/$PEERID_0 2>&1 > dialer-stdouterr.log && ma-pipe-unidir --pidFile=client.pid recv /ip4/127.0.0.1/tcp/10102 & test_wait_for_file 30 100ms listener.pid && @@ -198,7 +198,7 @@ test_expect_success "Setup: Idle stream(2)" ' ' test_expect_success "'ipfs p2p stream ls' succeeds(2)" ' - echo "4 /p2p/p2p-test2 /ipfs/$PEERID_1 /ip4/127.0.0.1/tcp/10101" > expected + echo "4 /x/p2p-test2 /ipfs/$PEERID_1 /ip4/127.0.0.1/tcp/10101" > expected ipfsi 0 p2p stream ls > actual test_cmp expected actual ' @@ -225,15 +225,15 @@ test_expect_success "'ipfs p2p stream close -a' closes streams" ' check_test_ports test_expect_success "'ipfs p2p close' closes app numeric handlers" ' - ipfsi 0 p2p forward /p2p/1234 /ipfs /ip4/127.0.0.1/tcp/10101 && - ipfsi 0 p2p close -p /p2p/1234 && + ipfsi 0 p2p forward /x/1234 /ipfs /ip4/127.0.0.1/tcp/10101 && + ipfsi 0 p2p close -p /x/1234 && ipfsi 0 p2p ls > actual && test_must_be_empty actual ' -test_expect_success "non /p2p/ scoped protocols are not allowed" ' - test_must_fail ipfsi 0 p2p forward /its/not/a/p2p/path /ipfs /ip4/127.0.0.1/tcp/10101 2> actual && - echo "Error: protocol name must be within '"'"'/p2p/'"'"' namespace" > expected +test_expect_success "non /x/ scoped protocols are not allowed" ' + test_must_fail ipfsi 0 p2p forward /its/not/a/x/path /ipfs /ip4/127.0.0.1/tcp/10101 2> actual && + echo "Error: protocol name must be within '"'"'/x/'"'"' namespace" > expected test_cmp expected actual '