@@ -8,6 +8,8 @@ var test = require('tape')
88var torrent = fs . readFileSync ( __dirname + '/torrents/bitlove-intro.torrent' )
99var parsedTorrent = parseTorrent ( torrent )
1010var peerId1 = new Buffer ( '01234567890123456789' )
11+ var peerId2 = new Buffer ( '12345678901234567890' )
12+ var peerId3 = new Buffer ( '23456789012345678901' )
1113var announceUrl = ''
1214var port = 6881
1315
@@ -195,4 +197,44 @@ test('udp: client.scrape()', function (t) {
195197 testClientScrape ( t , 'udp' )
196198} )
197199
200+ function testClientAnnounceWithNumWant ( t , serverType ) {
201+ t . plan ( 1 )
202+ createServer ( t , serverType , function ( server ) {
203+ var client1 = new Client ( peerId1 , port , parsedTorrent )
204+ client1 . on ( 'error' , function ( err ) {
205+ t . error ( err )
206+ } )
207+
208+ client1 . start ( )
209+ client1 . once ( 'update' , function ( data ) {
210+ var client2 = new Client ( peerId2 , port + 1 , parsedTorrent )
211+ client2 . on ( 'error' , function ( err ) {
212+ t . error ( err )
213+ } )
214+ client2 . start ( )
215+ client2 . once ( 'update' , function ( ) {
216+ var client3 = new Client ( peerId3 , port + 2 , parsedTorrent , { numWant : 1 } )
217+ client3 . on ( 'error' , function ( err ) {
218+ t . error ( err )
219+ } )
220+ client3 . start ( )
221+ client3 . on ( 'peer' , function ( ) {
222+ t . pass ( 'got one peer (this should only fire once)' )
223+
224+ client1 . stop ( )
225+ client2 . stop ( )
226+ client3 . stop ( )
227+ server . close ( )
228+ } )
229+ } )
230+ } )
231+ } )
232+ }
233+
234+ test ( 'http: client announce with numWant' , function ( t ) {
235+ testClientAnnounceWithNumWant ( t , 'http' )
236+ } )
237+
238+ test ( 'udp: client announce with numWant' , function ( t ) {
239+ testClientAnnounceWithNumWant ( t , 'udp' )
198240} )
0 commit comments