@@ -75,19 +75,19 @@ function echo (stream) {
75
75
}
76
76
77
77
tape ( 'combined' , function ( t ) {
78
- var close = combined . server ( echo )
79
-
80
- combined . client ( combined . stringify ( 'device' ) , function ( err , stream ) {
81
- if ( err ) throw err
82
- pull (
83
- pull . values ( [ Buffer . from ( 'hello world' ) ] ) ,
84
- stream ,
85
- pull . collect ( function ( err , ary ) {
86
- if ( err ) throw err
87
- t . equal ( Buffer . concat ( ary ) . toString ( ) , 'HELLO WORLD' )
88
- close ( t . end )
89
- } )
90
- )
78
+ var close = combined . server ( echo , null , ( ) => {
79
+ combined . client ( combined . stringify ( 'device' ) , function ( err , stream ) {
80
+ if ( err ) throw err
81
+ pull (
82
+ pull . values ( [ Buffer . from ( 'hello world' ) ] ) ,
83
+ stream ,
84
+ pull . collect ( function ( err , ary ) {
85
+ if ( err ) throw err
86
+ t . equal ( Buffer . concat ( ary ) . toString ( ) , 'HELLO WORLD' )
87
+ close ( t . end )
88
+ } )
89
+ )
90
+ } )
91
91
} )
92
92
} )
93
93
@@ -100,22 +100,23 @@ if (has_ipv6)
100
100
} ) ,
101
101
shs
102
102
] )
103
- var close = combined . server ( echo )
104
- var addr = combined . stringify ( 'device' )
105
- console . log ( 'addr' , addr )
103
+ var close = combined . server ( echo , null , ( ) => {
104
+ var addr = combined . stringify ( 'device' )
105
+ console . log ( 'addr' , addr )
106
106
107
- combined . client ( addr , function ( err , stream ) {
108
- if ( err ) throw err
109
- t . ok ( stream . address , 'has an address' )
110
- pull (
111
- pull . values ( [ Buffer . from ( 'hello world' ) ] ) ,
112
- stream ,
113
- pull . collect ( function ( err , ary ) {
114
- if ( err ) throw err
115
- t . equal ( Buffer . concat ( ary ) . toString ( ) , 'HELLO WORLD' )
116
- close ( t . end )
117
- } )
118
- )
107
+ combined . client ( addr , function ( err , stream ) {
108
+ if ( err ) throw err
109
+ t . ok ( stream . address , 'has an address' )
110
+ pull (
111
+ pull . values ( [ Buffer . from ( 'hello world' ) ] ) ,
112
+ stream ,
113
+ pull . collect ( function ( err , ary ) {
114
+ if ( err ) throw err
115
+ t . equal ( Buffer . concat ( ary ) . toString ( ) , 'HELLO WORLD' )
116
+ close ( t . end )
117
+ } )
118
+ )
119
+ } )
119
120
} )
120
121
} )
121
122
@@ -148,24 +149,24 @@ tape('net: do not listen on all addresses', function (t) {
148
149
} ) ,
149
150
shs
150
151
] )
151
- var close = combined . server ( echo )
152
-
153
- //fake
154
- var fake_combined = Compose ( [
155
- Net ( {
156
- scope : 'local' ,
157
- port : 4851 ,
158
- //host: 'localhost',
159
- // external: scopes.host('local') // unroutable IP, but not localhost (e.g. 192.168 ...)
160
- } ) ,
161
- shs
162
- ] )
152
+ var close = combined . server ( echo , null , ( ) => {
153
+ //fake
154
+ var fake_combined = Compose ( [
155
+ Net ( {
156
+ scope : 'local' ,
157
+ port : 4851 ,
158
+ //host: 'localhost',
159
+ // external: scopes.host('local') // unroutable IP, but not localhost (e.g. 192.168 ...)
160
+ } ) ,
161
+ shs
162
+ ] )
163
163
164
- var addr = fake_combined . stringify ( 'local' ) // returns external
165
- console . log ( 'addr local scope' , addr )
166
- combined . client ( addr , function ( err , stream ) {
167
- t . ok ( err , 'should only listen on localhost' )
168
- close ( t . end )
164
+ var addr = fake_combined . stringify ( 'local' ) // returns external
165
+ console . log ( 'addr local scope' , addr )
166
+ combined . client ( addr , function ( err , stream ) {
167
+ t . ok ( err , 'should only listen on localhost' )
168
+ close ( t . end )
169
+ } )
169
170
} )
170
171
} )
171
172
@@ -178,7 +179,7 @@ tape('net: do not crash if listen() fails', function(t) {
178
179
} ) ,
179
180
shs
180
181
] )
181
- var close = combined . server ( echo , function ( ) { } , function ( err ) {
182
+ var close = combined . server ( echo , null , function ( err ) {
182
183
t . ok ( err , 'should propagate listen error up' )
183
184
t . match ( err . code , / ^ ( E N O T F O U N D | E A I _ A G A I N ) $ / , 'the error is expected' )
184
185
close ( ( ) => t . end ( ) )
@@ -207,22 +208,23 @@ tape('combined, unix', function (t) {
207
208
} ) ,
208
209
shs
209
210
] )
210
- var close = combined . server ( echo )
211
- var addr = combined . stringify ( 'device' )
212
- console . log ( 'unix addr' , addr )
211
+ var close = combined . server ( echo , null , ( ) => {
212
+ var addr = combined . stringify ( 'device' )
213
+ console . log ( 'unix addr' , addr )
213
214
214
- combined . client ( addr , function ( err , stream ) {
215
- if ( err ) throw err
216
- t . ok ( stream . address , 'has an address' )
217
- pull (
218
- pull . values ( [ Buffer . from ( 'hello world' ) ] ) ,
219
- stream ,
220
- pull . collect ( function ( err , ary ) {
221
- if ( err ) throw err
222
- t . equal ( Buffer . concat ( ary ) . toString ( ) , 'HELLO WORLD' )
223
- close ( t . end )
224
- } )
225
- )
215
+ combined . client ( addr , function ( err , stream ) {
216
+ if ( err ) throw err
217
+ t . ok ( stream . address , 'has an address' )
218
+ pull (
219
+ pull . values ( [ Buffer . from ( 'hello world' ) ] ) ,
220
+ stream ,
221
+ pull . collect ( function ( err , ary ) {
222
+ if ( err ) throw err
223
+ t . equal ( Buffer . concat ( ary ) . toString ( ) , 'HELLO WORLD' )
224
+ close ( t . end )
225
+ } )
226
+ )
227
+ } )
226
228
} )
227
229
} )
228
230
@@ -263,27 +265,28 @@ tape('error if try to connect on wrong protocol', function (t) {
263
265
} )
264
266
265
267
tape ( 'shs with seed' , function ( t ) {
266
- var close = combined . server ( echo )
267
-
268
- var seed = cl . crypto_hash_sha256 ( Buffer . from ( 'TEST SEED' ) )
269
- var bob = cl . crypto_sign_seed_keypair ( seed )
270
-
271
- var checked
272
- check = function ( id , cb ) {
273
- checked = id
274
- if ( id . toString ( 'base64' ) === bob . publicKey . toString ( 'base64' ) )
275
- cb ( null , true )
276
- else
277
- cb ( null , false )
278
- }
268
+ var close = combined . server ( echo , null , ( ) => {
269
+
270
+ var seed = cl . crypto_hash_sha256 ( Buffer . from ( 'TEST SEED' ) )
271
+ var bob = cl . crypto_sign_seed_keypair ( seed )
272
+
273
+ var checked
274
+ check = function ( id , cb ) {
275
+ checked = id
276
+ if ( id . toString ( 'base64' ) === bob . publicKey . toString ( 'base64' ) )
277
+ cb ( null , true )
278
+ else
279
+ cb ( null , false )
280
+ }
279
281
280
- var addr_with_seed = combined . stringify ( ) + ':' + seed . toString ( 'base64' )
282
+ var addr_with_seed = combined . stringify ( ) + ':' + seed . toString ( 'base64' )
281
283
282
- combined . client ( addr_with_seed , function ( err , stream ) {
283
- t . notOk ( err )
284
- t . deepEqual ( checked , bob . publicKey )
285
- stream . source ( true , function ( ) { } )
286
- close ( t . end )
284
+ combined . client ( addr_with_seed , function ( err , stream ) {
285
+ t . notOk ( err )
286
+ t . deepEqual ( checked , bob . publicKey )
287
+ stream . source ( true , function ( ) { } )
288
+ close ( t . end )
289
+ } )
287
290
} )
288
291
} )
289
292
@@ -386,23 +389,23 @@ function testAbort (name, combined) {
386
389
tape ( name + ', aborted' , function ( t ) {
387
390
var close = combined . server ( function onConnection ( ) {
388
391
throw new Error ( 'should never happen' )
389
- } )
390
-
391
- var abort = combined . client ( combined . stringify ( ) , function ( err , stream ) {
392
- t . ok ( err , 'the error is expected' )
392
+ } , null , ( ) => {
393
+ var abort = combined . client ( combined . stringify ( ) , function ( err , stream ) {
394
+ t . ok ( err , 'the error is expected' )
395
+
396
+ // NOTE: without the timeout, we try to close the server
397
+ // before it actually started listening, which fails and then
398
+ // the server keeps runnung, causing the next test to fail with EADDRINUSE
399
+ //
400
+ // This is messy, combined.server should be a proper async call
401
+ setTimeout ( function ( ) {
402
+ //console.log('Calling close')
403
+ close ( t . end )
404
+ } , 500 )
405
+ } )
393
406
394
- // NOTE: without the timeout, we try to close the server
395
- // before it actually started listening, which fails and then
396
- // the server keeps runnung, causing the next test to fail with EADDRINUSE
397
- //
398
- // This is messy, combined.server should be a proper async call
399
- setTimeout ( function ( ) {
400
- //console.log('Calling close')
401
- close ( t . end )
402
- } , 500 )
407
+ abort ( )
403
408
} )
404
-
405
- abort ( )
406
409
} )
407
410
}
408
411
@@ -422,7 +425,6 @@ tape('error should have client address on it', function (t) {
422
425
//the shs address won't actually parse, because it doesn't have the key in it
423
426
//because the key is not known in a wrong number.
424
427
} , function ( ) {
425
-
426
428
//very unlikely this is the address, which will give a wrong number at the server.
427
429
var addr = combined . stringify ( ) . replace ( / s h s : ......../ , 'shs:XXXXXXXX' )
428
430
combined . client ( addr , function ( err , stream ) {
0 commit comments