-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
t0180-p2p.sh
executable file
·381 lines (286 loc) · 10.6 KB
/
t0180-p2p.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#!/usr/bin/env bash
test_description="Test experimental p2p commands"
. lib/test-lib.sh
# start iptb + wait for peering
test_expect_success 'init iptb' '
iptb testbed create -type localipfs --count 3 --init
'
test_expect_success 'generate test data' '
echo "ABCDEF" > test0.bin &&
echo "012345" > test1.bin
'
startup_cluster 3
test_expect_success 'peer ids' '
PEERID_0=$(iptb attr get 0 id) &&
PEERID_1=$(iptb attr get 1 id)
'
check_test_ports() {
test_expect_success "test ports are closed" '
(! (netstat -aln | grep "LISTEN" | grep -E "[.:]10101 ")) &&
(! (netstat -aln | grep "LISTEN" | grep -E "[.:]10102 ")) &&
(! (netstat -aln | grep "LISTEN" | grep -E "[.:]10103 ")) &&
(! (netstat -aln | grep "LISTEN" | grep -E "[.:]10104 "))
'
}
check_test_ports
test_expect_success 'fail without config option being enabled' '
test_must_fail ipfsi 0 p2p stream ls
'
test_expect_success "enable filestore config setting" '
ipfsi 0 config --json Experimental.Libp2pStreamMounting true
ipfsi 1 config --json Experimental.Libp2pStreamMounting true
ipfsi 2 config --json Experimental.Libp2pStreamMounting true
'
test_expect_success 'start p2p listener' '
ipfsi 0 p2p listen /x/p2p-test /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log
'
test_expect_success 'cannot re-register p2p listener' '
test_must_fail ipfsi 0 p2p listen /x/p2p-test /ip4/127.0.0.1/tcp/10103 2>&1 > listener-stdouterr.log
'
# Server to client communications
spawn_sending_server() {
test_expect_success 'S->C Spawn sending server' '
ma-pipe-unidir --listen --pidFile=listener.pid send /ip4/127.0.0.1/tcp/10101 < test0.bin &
test_wait_for_file 30 100ms listener.pid &&
kill -0 $(cat listener.pid)
'
}
test_server_to_client() {
test_expect_success 'S->C Connect and receive data' '
ma-pipe-unidir recv /ip4/127.0.0.1/tcp/10102 > client.out
'
test_expect_success 'S->C Ensure server finished' '
test ! -f listener.pid
'
test_expect_success 'S->C Output looks good' '
test_cmp client.out test0.bin
'
}
spawn_sending_server
test_expect_success 'S->C(/p2p/peerID) Setup client side' '
ipfsi 1 p2p forward /x/p2p-test /ip4/127.0.0.1/tcp/10102 /p2p/${PEERID_0} 2>&1 > dialer-stdouterr.log
'
test_expect_success 'S->C Setup(dnsaddr/addr/p2p/peerID) client side' '
ipfsi 1 p2p forward /x/p2p-test /ip4/127.0.0.1/tcp/10103 /dnsaddr/bootstrap.libp2p.io/p2p/${PEERID_0} 2>&1 > dialer-stdouterr.log
'
test_expect_success 'S->C Setup(dnsaddr/addr) client side' '
ipfsi 1 p2p forward /x/p2p-test /ip4/127.0.0.1/tcp/10104 /dnsaddr/example-dnsaddr.multiformats.io 2>&1 > dialer-stdouterr.log
'
test_expect_success 'S->C Output is empty' '
test_must_be_empty dialer-stdouterr.log
'
test_expect_success "'ipfs p2p ls | grep' succeeds" '
ipfsi 1 p2p ls | grep "/x/p2p-test /ip4/127.0.0.1/tcp/10104"
'
test_server_to_client
test_expect_success 'S->C Connect with dead server' '
ma-pipe-unidir recv /ip4/127.0.0.1/tcp/10102 > client.out
'
test_expect_success 'S->C Output is empty' '
test_must_be_empty client.out
'
spawn_sending_server
test_server_to_client
test_expect_success 'S->C Close local listener' '
ipfsi 1 p2p close -p /x/p2p-test
'
check_test_ports
# Client to server communications
test_expect_success 'C->S Spawn receiving server' '
ma-pipe-unidir --listen --pidFile=listener.pid recv /ip4/127.0.0.1/tcp/10101 > server.out &
test_wait_for_file 30 100ms listener.pid &&
kill -0 $(cat listener.pid)
'
test_expect_success 'C->S Setup client side' '
ipfsi 1 p2p forward /x/p2p-test /ip4/127.0.0.1/tcp/10102 /p2p/${PEERID_0} 2>&1 > dialer-stdouterr.log
'
test_expect_success 'C->S Connect and receive data' '
ma-pipe-unidir send /ip4/127.0.0.1/tcp/10102 < test1.bin
'
test_expect_success 'C->S Ensure server finished' '
go-sleep 250ms &&
test ! -f listener.pid
'
test_expect_success 'C->S Output looks good' '
test_cmp server.out test1.bin
'
test_expect_success 'C->S Close local listener' '
ipfsi 1 p2p close -p /x/p2p-test
'
check_test_ports
# Checking port
test_expect_success "cannot accept 0 port in 'ipfs p2p listen'" '
test_must_fail ipfsi 2 p2p listen /x/p2p-test/0 /ip4/127.0.0.1/tcp/0
'
test_expect_success "'ipfs p2p forward' accept 0 port" '
ipfsi 2 p2p forward /x/p2p-test/0 /ip4/127.0.0.1/tcp/0 /p2p/$PEERID_0
'
test_expect_success "'ipfs p2p ls' output looks good" '
echo "true" > forward_0_expected &&
ipfsi 2 p2p ls | awk '\''{print $2}'\'' | sed "s/.*\///" | awk -F: '\''{if($1>0)print"true"}'\'' > forward_0_actual &&
ipfsi 2 p2p close -p /x/p2p-test/0 &&
test_cmp forward_0_expected forward_0_actual
'
# Listing streams
test_expect_success "'ipfs p2p ls' succeeds" '
echo "/x/p2p-test /p2p/$PEERID_0 /ip4/127.0.0.1/tcp/10101" > expected &&
ipfsi 0 p2p ls > actual
'
test_expect_success "'ipfs p2p ls' output looks good" '
test_cmp expected actual
'
test_expect_success "Cannot re-register app handler" '
test_must_fail ipfsi 0 p2p listen /x/p2p-test /ip4/127.0.0.1/tcp/10101
'
test_expect_success "'ipfs p2p stream ls' output is empty" '
ipfsi 0 p2p stream ls > actual &&
test_must_be_empty actual
'
check_test_ports
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 /x/p2p-test /ip4/127.0.0.1/tcp/10102 /p2p/$PEERID_0 &&
ma-pipe-unidir --pidFile=client.pid recv /ip4/127.0.0.1/tcp/10102 &
test_wait_for_file 30 100ms listener.pid &&
test_wait_for_file 30 100ms client.pid &&
kill -0 $(cat listener.pid) && kill -0 $(cat client.pid)
'
test_expect_success "'ipfs p2p stream ls' succeeds" '
echo "3 /x/p2p-test /p2p/$PEERID_1 /ip4/127.0.0.1/tcp/10101" > expected
ipfsi 0 p2p stream ls > actual
'
test_expect_success "'ipfs p2p stream ls' output looks good" '
test_cmp expected actual
'
test_expect_success "'ipfs p2p stream close' closes stream" '
ipfsi 0 p2p stream close 3 &&
ipfsi 0 p2p stream ls > actual &&
[ ! -f listener.pid ] && [ ! -f client.pid ] &&
test_must_be_empty actual
'
test_expect_success "'ipfs p2p close' closes remote handler" '
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 /x/p2p-test &&
ipfsi 1 p2p ls > actual &&
test_must_be_empty actual
'
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 listen /x/p2p-test2 /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 /p2p/$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 &&
test_wait_for_file 30 100ms client.pid &&
kill -0 $(cat listener.pid) && kill -0 $(cat client.pid)
'
test_expect_success "'ipfs p2p stream ls' succeeds(2)" '
echo "4 /x/p2p-test2 /p2p/$PEERID_1 /ip4/127.0.0.1/tcp/10101" > expected
ipfsi 0 p2p stream ls > actual
test_cmp expected actual
'
test_expect_success "'ipfs p2p close -a' closes remote app handlers" '
ipfsi 0 p2p close -a &&
ipfsi 0 p2p ls > actual &&
test_must_be_empty actual
'
test_expect_success "'ipfs p2p close -a' closes local app handlers" '
ipfsi 1 p2p close -a &&
ipfsi 1 p2p ls > actual &&
test_must_be_empty actual
'
test_expect_success "'ipfs p2p stream close -a' closes streams" '
ipfsi 0 p2p stream close -a &&
ipfsi 0 p2p stream ls > actual &&
[ ! -f listener.pid ] && [ ! -f client.pid ] &&
test_must_be_empty actual
'
check_test_ports
test_expect_success "'ipfs p2p close' closes app numeric handlers" '
ipfsi 0 p2p listen /x/1234 /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 "'ipfs p2p close' closes by target addr" '
ipfsi 0 p2p listen /x/p2p-test /ip4/127.0.0.1/tcp/10101 &&
ipfsi 0 p2p close -t /ip4/127.0.0.1/tcp/10101 &&
ipfsi 0 p2p ls > actual &&
test_must_be_empty actual
'
test_expect_success "'ipfs p2p close' closes right listeners" '
ipfsi 0 p2p listen /x/p2p-test /ip4/127.0.0.1/tcp/10101 &&
ipfsi 0 p2p forward /x/p2p-test /ip4/127.0.0.1/tcp/10101 /p2p/$PEERID_1 &&
echo "/x/p2p-test /p2p/$PEERID_0 /ip4/127.0.0.1/tcp/10101" > expected &&
ipfsi 0 p2p close -l /ip4/127.0.0.1/tcp/10101 &&
ipfsi 0 p2p ls > actual &&
test_cmp expected actual
'
check_test_ports
test_expect_success "'ipfs p2p close' closes by listen addr" '
ipfsi 0 p2p close -l /p2p/$PEERID_0 &&
ipfsi 0 p2p ls > actual &&
test_must_be_empty actual
'
# Peer reporting
test_expect_success 'start p2p listener reporting peer' '
ipfsi 0 p2p listen /x/p2p-test /ip4/127.0.0.1/tcp/10101 --report-peer-id 2>&1 > listener-stdouterr.log
'
test_expect_success 'C->S Spawn receiving server' '
ma-pipe-unidir --listen --pidFile=listener.pid recv /ip4/127.0.0.1/tcp/10101 > server.out &
test_wait_for_file 30 100ms listener.pid &&
kill -0 $(cat listener.pid)
'
test_expect_success 'C->S Setup client side' '
ipfsi 1 p2p forward /x/p2p-test /ip4/127.0.0.1/tcp/10102 /p2p/${PEERID_0} 2>&1 > dialer-stdouterr.log
'
test_expect_success 'C->S Connect and receive data' '
ma-pipe-unidir send /ip4/127.0.0.1/tcp/10102 < test1.bin
'
test_expect_success 'C->S Ensure server finished' '
go-sleep 250ms &&
test ! -f listener.pid
'
test_expect_success 'C->S Output looks good' '
echo ${PEERID_1} > expected &&
cat test1.bin >> expected &&
test_cmp server.out expected
'
test_expect_success 'C->S Close listeners' '
ipfsi 1 p2p close -p /x/p2p-test &&
ipfsi 0 p2p close -p /x/p2p-test &&
ipfsi 0 p2p ls > actual &&
test_must_be_empty actual &&
ipfsi 1 p2p ls > actual &&
test_must_be_empty actual
'
test_expect_success "non /x/ scoped protocols are not allowed" '
test_must_fail ipfsi 0 p2p listen /its/not/a/x/path /ip4/127.0.0.1/tcp/10101 2> actual &&
echo "Error: protocol name must be within '"'"'/x/'"'"' namespace" > expected
test_cmp expected actual
'
check_test_ports
test_expect_success 'start p2p listener on custom proto' '
ipfsi 0 p2p listen --allow-custom-protocol /p2p-test /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log &&
test_must_be_empty listener-stdouterr.log
'
spawn_sending_server
test_expect_success 'S->C Setup client side (custom proto)' '
ipfsi 1 p2p forward --allow-custom-protocol /p2p-test /ip4/127.0.0.1/tcp/10102 /p2p/${PEERID_0} 2>&1 > dialer-stdouterr.log
'
test_server_to_client
test_expect_success 'C->S Close local listener' '
ipfsi 1 p2p close -p /p2p-test
ipfsi 1 p2p ls > actual &&
test_must_be_empty actual
'
check_test_ports
test_expect_success 'stop iptb' '
iptb stop
'
check_test_ports
test_done