Skip to content

Commit

Permalink
p2p: don't automatically prefix proto with /p2p
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
  • Loading branch information
magik6k committed Jun 3, 2018
1 parent 90beabb commit 65dd899
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
11 changes: 6 additions & 5 deletions core/commands/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ Examples:
return
}

//TODO: Do we really want/need implicit prefix?
proto := "/p2p/" + req.Arguments()[0]
proto := req.Arguments()[0]
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)
return
}

if strings.HasPrefix(listen, "/ipfs") {
if listen != "/ipfs" {
res.SetError(errors.New("only '/ipfs' is allowed as libp2p listen address"), cmdkit.ErrNormal)
Expand Down Expand Up @@ -246,9 +250,6 @@ var p2pCloseCmd = &cmds.Command{

match := func(listener p2p.Listener) bool {
out := true
if p || !strings.HasPrefix(proto, "/p2p/") {
proto = "/p2p/" + proto
}

if p {
out = out && (proto == listener.Protocol())
Expand Down
32 changes: 19 additions & 13 deletions test/sharness/t0180-p2p.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test_expect_success "enable filestore config setting" '
'

test_expect_success 'start p2p listener' '
ipfsi 0 p2p forward p2p-test /ipfs /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log
ipfsi 0 p2p forward /p2p/p2p-test /ipfs /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log
'

# Server to client communications
Expand Down Expand Up @@ -69,7 +69,7 @@ test_server_to_client() {
spawn_sending_server

test_expect_success 'S->C Setup client side' '
ipfsi 1 p2p forward p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/${PEERID_0} 2>&1 > dialer-stdouterr.log
ipfsi 1 p2p forward /p2p/p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/${PEERID_0} 2>&1 > dialer-stdouterr.log
'

test_server_to_client
Expand All @@ -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-test
ipfsi 1 p2p close -p /p2p/p2p-test
'

check_test_ports
Expand All @@ -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-test /ip4/127.0.0.1/tcp/10102 /ipfs/${PEERID_0} 2>&1 > dialer-stdouterr.log
ipfsi 1 p2p forward /p2p/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' '
Expand All @@ -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-test
ipfsi 1 p2p close -p /p2p/p2p-test
'

check_test_ports
Expand All @@ -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-test /ipfs /ip4/127.0.0.1/tcp/10101
test_must_fail ipfsi 0 p2p forward /p2p/p2p-test /ipfs /ip4/127.0.0.1/tcp/10101
'

test_expect_success "'ipfs p2p stream ls' output is empty" '
Expand All @@ -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-test /ip4/127.0.0.1/tcp/10102 /ipfs/$PEERID_0 2>&1 > dialer-stdouterr.log &&
ipfsi 1 p2p forward /p2p/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 &&
Expand All @@ -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-test &&
ipfsi 0 p2p close -p /p2p/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-test &&
ipfsi 1 p2p close -p /p2p/p2p-test &&
ipfsi 1 p2p ls > actual &&
test_must_be_empty actual
'
Expand All @@ -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-test2 /ipfs /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log &&
ipfsi 1 p2p forward p2p-test2 /ip4/127.0.0.1/tcp/10102 /ipfs/$PEERID_0 2>&1 > dialer-stdouterr.log &&
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 &&
ma-pipe-unidir --pidFile=client.pid recv /ip4/127.0.0.1/tcp/10102 &
test_wait_for_file 30 100ms listener.pid &&
Expand Down Expand Up @@ -225,12 +225,18 @@ 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 1234 /ipfs /ip4/127.0.0.1/tcp/10101 &&
ipfsi 0 p2p close -p 1234 &&
ipfsi 0 p2p forward /p2p/1234 /ipfs /ip4/127.0.0.1/tcp/10101 &&
ipfsi 0 p2p close -p /p2p/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_cmp expected actual
'

check_test_ports

test_expect_success 'stop iptb' '
Expand Down

0 comments on commit 65dd899

Please sign in to comment.