p2p: don't automatically prefix proto with /p2p
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Jun 2, 2018 at 19:41 UTC
df6decd31cddf8ca7e94f389f77e2c6469a923f4
3 files changed
+30
-23
core/commands/p2p.go
+6
-5
@@ -96,11 +96,15 @@ Examples:
96
return
97
}
98
99
- //TODO: Do we really want/need implicit prefix?
100
- proto := "/p2p/" + req.Arguments()[0]
99
+ proto := req.Arguments()[0]
100
listen := req.Arguments()[1]
101
target := req.Arguments()[2]
102
103
+ if !strings.HasPrefix(proto, "/p2p/") {
104
+ res.SetError(errors.New("protocol name must be within '/p2p/' namespace"), cmdkit.ErrNormal)
105
+ return
106
+ }
107
+
108
if strings.HasPrefix(listen, "/ipfs") {
109
if listen != "/ipfs" {
110
res.SetError(errors.New("only '/ipfs' is allowed as libp2p listen address"), cmdkit.ErrNormal)
@@ -246,9 +250,6 @@ var p2pCloseCmd = &cmds.Command{
250
251
match := func(listener p2p.Listener) bool {
252
out := true
249
- if p || !strings.HasPrefix(proto, "/p2p/") {
250
- proto = "/p2p/" + proto
251
- }
253
254
if p {
255
out = out && (proto == listener.Protocol())
docs/experimental-features.md
+5
-5
@@ -277,7 +277,7 @@ The `p2p` command needs to be enabled in config:
277
278
First, pick a protocol name for your application. Think of the protocol name as
279
a port number, just significantly more user-friendly. In this example, we're
280
-going to use `/kickass/1.0`.
280
+going to use `/p2p/kickass/1.0`.
281
282
***Setup:***
283
@@ -292,7 +292,7 @@ port `$APP_PORT`.
292
Then, configure the p2p listener by running:
293
294
```sh
295
-> ipfs p2p forward /kickass/1.0 /ipfs /ip4/127.0.0.1/tcp/$APP_PORT
295
+> ipfs p2p forward /p2p/kickass/1.0 /ipfs /ip4/127.0.0.1/tcp/$APP_PORT
296
```
297
298
This will configure IPFS to forward all incoming `/p2p/kickass/1.0` streams to
@@ -306,7 +306,7 @@ connections on `127.0.0.1:SOME_PORT` to the server node listening
306
on `/p2p/kickass/1.0`.
307
308
```sh
309
-> ipfs p2p forward /kickass/1.0 /ip4/127.0.0.1/tcp/$SOME_PORT /ipfs/$SERVER_ID
309
+> ipfs p2p forward /p2p/kickass/1.0 /ip4/127.0.0.1/tcp/$SOME_PORT /ipfs/$SERVER_ID
310
```
311
312
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 "<id>\n"`_
341
***First, on the "server" node:***
342
343
```sh
344
-ipfs p2p forward ssh /ipfs /ip4/127.0.0.1/tcp/22
344
+ipfs p2p forward /p2p/ssh /ipfs /ip4/127.0.0.1/tcp/22
345
```
346
347
***Then, on "client" node:***
348
349
```sh
350
-ipfs p2p forward ssh /ip4/127.0.0.1/tcp/2222 /ipfs/$SERVER_ID
350
+ipfs p2p forward /p2p/ssh /ip4/127.0.0.1/tcp/2222 /ipfs/$SERVER_ID
351
```
352
353
You should now be able to connect to your ssh server through a libp2p connection
test/sharness/t0180-p2p.sh
+19
-13
@@ -38,7 +38,7 @@ test_expect_success "enable filestore config setting" '
38
'
39
40
test_expect_success 'start p2p listener' '
41
- ipfsi 0 p2p forward p2p-test /ipfs /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log
41
+ ipfsi 0 p2p forward /p2p/p2p-test /ipfs /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log
42
'
43
44
# Server to client communications
@@ -69,7 +69,7 @@ test_server_to_client() {
69
spawn_sending_server
70
71
test_expect_success 'S->C Setup client side' '
72
- ipfsi 1 p2p forward p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/${PEERID_0} 2>&1 > dialer-stdouterr.log
72
+ ipfsi 1 p2p forward /p2p/p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/${PEERID_0} 2>&1 > dialer-stdouterr.log
73
'
74
75
test_server_to_client
@@ -87,7 +87,7 @@ spawn_sending_server
87
test_server_to_client
88
89
test_expect_success 'S->C Close local listener' '
90
- ipfsi 1 p2p close -p p2p-test
90
+ ipfsi 1 p2p close -p /p2p/p2p-test
91
'
92
93
check_test_ports
@@ -102,7 +102,7 @@ test_expect_success 'C->S Spawn receiving server' '
102
'
103
104
test_expect_success 'C->S Setup client side' '
105
- ipfsi 1 p2p forward p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/${PEERID_0} 2>&1 > dialer-stdouterr.log
105
+ ipfsi 1 p2p forward /p2p/p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/${PEERID_0} 2>&1 > dialer-stdouterr.log
106
'
107
108
test_expect_success 'C->S Connect and receive data' '
@@ -119,7 +119,7 @@ test_expect_success 'C->S Output looks good' '
119
'
120
121
test_expect_success 'C->S Close local listener' '
122
- ipfsi 1 p2p close -p p2p-test
122
+ ipfsi 1 p2p close -p /p2p/p2p-test
123
'
124
125
check_test_ports
@@ -136,7 +136,7 @@ test_expect_success "'ipfs p2p ls' output looks good" '
136
'
137
138
test_expect_success "Cannot re-register app handler" '
139
- test_must_fail ipfsi 0 p2p forward p2p-test /ipfs /ip4/127.0.0.1/tcp/10101
139
+ test_must_fail ipfsi 0 p2p forward /p2p/p2p-test /ipfs /ip4/127.0.0.1/tcp/10101
140
'
141
142
test_expect_success "'ipfs p2p stream ls' output is empty" '
@@ -147,7 +147,7 @@ test_expect_success "'ipfs p2p stream ls' output is empty" '
147
test_expect_success "Setup: Idle stream" '
148
ma-pipe-unidir --listen --pidFile=listener.pid recv /ip4/127.0.0.1/tcp/10101 &
149
150
- ipfsi 1 p2p forward p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/$PEERID_0 2>&1 > dialer-stdouterr.log &&
150
+ ipfsi 1 p2p forward /p2p/p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/$PEERID_0 2>&1 > dialer-stdouterr.log &&
151
ma-pipe-unidir --pidFile=client.pid recv /ip4/127.0.0.1/tcp/10102 &
152
153
test_wait_for_file 30 100ms listener.pid &&
@@ -172,13 +172,13 @@ test_expect_success "'ipfs p2p stream close' closes stream" '
172
'
173
174
test_expect_success "'ipfs p2p close' closes remote handler" '
175
- ipfsi 0 p2p close -p p2p-test &&
175
+ ipfsi 0 p2p close -p /p2p/p2p-test &&
176
ipfsi 0 p2p ls > actual &&
177
test_must_be_empty actual
178
'
179
180
test_expect_success "'ipfs p2p close' closes local handler" '
181
- ipfsi 1 p2p close -p p2p-test &&
181
+ ipfsi 1 p2p close -p /p2p/p2p-test &&
182
ipfsi 1 p2p ls > actual &&
183
test_must_be_empty actual
184
'
@@ -188,8 +188,8 @@ check_test_ports
188
test_expect_success "Setup: Idle stream(2)" '
189
ma-pipe-unidir --listen --pidFile=listener.pid recv /ip4/127.0.0.1/tcp/10101 &
190
191
- ipfsi 0 p2p forward p2p-test2 /ipfs /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log &&
192
- ipfsi 1 p2p forward p2p-test2 /ip4/127.0.0.1/tcp/10102 /ipfs/$PEERID_0 2>&1 > dialer-stdouterr.log &&
191
+ ipfsi 0 p2p forward /p2p/p2p-test2 /ipfs /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log &&
192
+ ipfsi 1 p2p forward /p2p/p2p-test2 /ip4/127.0.0.1/tcp/10102 /ipfs/$PEERID_0 2>&1 > dialer-stdouterr.log &&
193
ma-pipe-unidir --pidFile=client.pid recv /ip4/127.0.0.1/tcp/10102 &
194
195
test_wait_for_file 30 100ms listener.pid &&
@@ -225,12 +225,18 @@ test_expect_success "'ipfs p2p stream close -a' closes streams" '
225
check_test_ports
226
227
test_expect_success "'ipfs p2p close' closes app numeric handlers" '
228
- ipfsi 0 p2p forward 1234 /ipfs /ip4/127.0.0.1/tcp/10101 &&
229
- ipfsi 0 p2p close -p 1234 &&
228
+ ipfsi 0 p2p forward /p2p/1234 /ipfs /ip4/127.0.0.1/tcp/10101 &&
229
+ ipfsi 0 p2p close -p /p2p/1234 &&
230
ipfsi 0 p2p ls > actual &&
231
test_must_be_empty actual
232
'
233
234
+test_expect_success "non /p2p/ scoped protocols are not allowed" '
235
+ test_must_fail ipfsi 0 p2p forward /its/not/a/p2p/path /ipfs /ip4/127.0.0.1/tcp/10101 2> actual &&
236
+ echo "Error: protocol name must be within '"'"'/p2p/'"'"' namespace" > expected
237
+ test_cmp expected actual
238
+'
239
+
240
check_test_ports
241
242
test_expect_success 'stop iptb' '