p2p: change the required prefix to /x/
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Jun 18, 2018 at 01:31 UTC
c19102816f6328c247a691f43a65e197d17334a9
3 files changed
+34
-32
core/commands/p2p.go
+8
-6
@@ -19,6 +19,8 @@ import (
19
"gx/ipfs/QmdE4gMduCKCGAcczM2F5ioYDfdeKuPix138wrES1YSr7f/go-ipfs-cmdkit"
20
)
21
22
+const P2PProtoPrefix = "/x/"
23
+
24
// P2PListenerInfoOutput is output type of ls command
25
type P2PListenerInfoOutput struct {
26
Protocol string
@@ -71,16 +73,16 @@ var p2pForwardCmd = &cmds.Command{
73
Forward connections made to <listen-address> to <target-address>.
74
75
<protocol> specifies the libp2p protocol name to use for libp2p
74
-connections and/or handlers.
76
+connections and/or handlers. It must be prefixed with '` + P2PProtoPrefix + `'.
77
78
To create a libp2p service listener, specify '/ipfs' as <listen-address>
79
80
Examples:
79
- ipfs p2p forward myproto /ipfs /ip4/127.0.0.1/tcp/1234
81
+ ipfs p2p forward ` + P2PProtoPrefix + `myproto /ipfs /ip4/127.0.0.1/tcp/1234
82
- Forward connections to 'myproto' libp2p service to 127.0.0.1:1234
83
82
- ipfs p2p forward myproto /ip4/127.0.0.1/tcp/4567 /ipfs/QmPeer
83
- - Forward connections to 127.0.0.1:4567 to 'myproto' service on /ipfs/QmPeer
84
+ ipfs p2p forward ` + P2PProtoPrefix + `myproto /ip4/127.0.0.1/tcp/4567 /ipfs/QmPeer
85
+ - Forward connections to 127.0.0.1:4567 to '` + P2PProtoPrefix + `myproto' service on /ipfs/QmPeer
86
87
`,
88
},
@@ -100,8 +102,8 @@ Examples:
102
listen := req.Arguments()[1]
103
target := req.Arguments()[2]
104
103
- if !strings.HasPrefix(proto, "/p2p/") {
104
- res.SetError(errors.New("protocol name must be within '/p2p/' namespace"), cmdkit.ErrNormal)
105
+ if !strings.HasPrefix(proto, P2PProtoPrefix) {
106
+ res.SetError(errors.New("protocol name must be within '" + P2PProtoPrefix + "' namespace"), cmdkit.ErrNormal)
107
return
108
}
109
docs/experimental-features.md
+7
-7
@@ -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 `/p2p/kickass/1.0`.
280
+going to use `/x/kickass/1.0`.
281
282
***Setup:***
283
@@ -292,10 +292,10 @@ port `$APP_PORT`.
292
Then, configure the p2p listener by running:
293
294
```sh
295
-> ipfs p2p forward /p2p/kickass/1.0 /ipfs /ip4/127.0.0.1/tcp/$APP_PORT
295
+> ipfs p2p forward /x/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
298
+This will configure IPFS to forward all incoming `/x/kickass/1.0` streams to
299
`127.0.0.1:$APP_PORT` (opening a new connection to `127.0.0.1:$APP_PORT` per
300
incoming stream.
301
@@ -303,10 +303,10 @@ incoming stream.
303
304
First, configure the client p2p dialer, so that it forwards all inbound
305
connections on `127.0.0.1:SOME_PORT` to the server node listening
306
-on `/p2p/kickass/1.0`.
306
+on `/x/kickass/1.0`.
307
308
```sh
309
-> ipfs p2p forward /p2p/kickass/1.0 /ip4/127.0.0.1/tcp/$SOME_PORT /ipfs/$SERVER_ID
309
+> ipfs p2p forward /x/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 /p2p/ssh /ipfs /ip4/127.0.0.1/tcp/22
344
+ipfs p2p forward /x/ssh /ipfs /ip4/127.0.0.1/tcp/22
345
```
346
347
***Then, on "client" node:***
348
349
```sh
350
-ipfs p2p forward /p2p/ssh /ip4/127.0.0.1/tcp/2222 /ipfs/$SERVER_ID
350
+ipfs p2p forward /x/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
-19
@@ -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/p2p-test /ipfs /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log
41
+ ipfsi 0 p2p forward /x/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/p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/${PEERID_0} 2>&1 > dialer-stdouterr.log
72
+ ipfsi 1 p2p forward /x/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/p2p-test
90
+ ipfsi 1 p2p close -p /x/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/p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/${PEERID_0} 2>&1 > dialer-stdouterr.log
105
+ ipfsi 1 p2p forward /x/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/p2p-test
122
+ ipfsi 1 p2p close -p /x/p2p-test
123
'
124
125
check_test_ports
@@ -127,7 +127,7 @@ check_test_ports
127
# Listing streams
128
129
test_expect_success "'ipfs p2p ls' succeeds" '
130
- echo "/p2p/p2p-test /ipfs /ip4/127.0.0.1/tcp/10101" > expected &&
130
+ echo "/x/p2p-test /ipfs /ip4/127.0.0.1/tcp/10101" > expected &&
131
ipfsi 0 p2p ls > actual
132
'
133
@@ -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/p2p-test /ipfs /ip4/127.0.0.1/tcp/10101
139
+ test_must_fail ipfsi 0 p2p forward /x/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/p2p-test /ip4/127.0.0.1/tcp/10102 /ipfs/$PEERID_0 2>&1 > dialer-stdouterr.log &&
150
+ ipfsi 1 p2p forward /x/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 &&
@@ -156,7 +156,7 @@ test_expect_success "Setup: Idle stream" '
156
'
157
158
test_expect_success "'ipfs p2p stream ls' succeeds" '
159
- echo "3 /p2p/p2p-test /ipfs/$PEERID_1 /ip4/127.0.0.1/tcp/10101" > expected
159
+ echo "3 /x/p2p-test /ipfs/$PEERID_1 /ip4/127.0.0.1/tcp/10101" > expected
160
ipfsi 0 p2p stream ls > actual
161
'
162
@@ -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/p2p-test &&
175
+ ipfsi 0 p2p close -p /x/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/p2p-test &&
181
+ ipfsi 1 p2p close -p /x/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/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 &&
191
+ ipfsi 0 p2p forward /x/p2p-test2 /ipfs /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log &&
192
+ ipfsi 1 p2p forward /x/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 &&
@@ -198,7 +198,7 @@ test_expect_success "Setup: Idle stream(2)" '
198
'
199
200
test_expect_success "'ipfs p2p stream ls' succeeds(2)" '
201
- echo "4 /p2p/p2p-test2 /ipfs/$PEERID_1 /ip4/127.0.0.1/tcp/10101" > expected
201
+ echo "4 /x/p2p-test2 /ipfs/$PEERID_1 /ip4/127.0.0.1/tcp/10101" > expected
202
ipfsi 0 p2p stream ls > actual
203
test_cmp expected actual
204
'
@@ -225,15 +225,15 @@ 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 /p2p/1234 /ipfs /ip4/127.0.0.1/tcp/10101 &&
229
- ipfsi 0 p2p close -p /p2p/1234 &&
228
+ ipfsi 0 p2p forward /x/1234 /ipfs /ip4/127.0.0.1/tcp/10101 &&
229
+ ipfsi 0 p2p close -p /x/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
234
+test_expect_success "non /x/ scoped protocols are not allowed" '
235
+ test_must_fail ipfsi 0 p2p forward /its/not/a/x/path /ipfs /ip4/127.0.0.1/tcp/10101 2> actual &&
236
+ echo "Error: protocol name must be within '"'"'/x/'"'"' namespace" > expected
237
test_cmp expected actual
238
'
239