@@ -8,25 +8,33 @@ var parseTorrent = require('parse-torrent')
88var Server = require ( '../' ) . Server
99var test = require ( 'tape' )
1010
11- function hexToBinary ( str ) {
12- return new Buffer ( str , 'hex' ) . toString ( 'binary' )
13- }
14-
1511var infoHash1 = 'aaa67059ed6bd08362da625b3ae77f6f4a075aaa'
16- var binaryInfoHash1 = hexToBinary ( infoHash1 )
12+ var binaryInfoHash1 = commonLib . hexToBinary ( infoHash1 )
1713var infoHash2 = 'bbb67059ed6bd08362da625b3ae77f6f4a075bbb'
18- var binaryInfoHash2 = hexToBinary ( infoHash2 )
14+ var binaryInfoHash2 = commonLib . hexToBinary ( infoHash2 )
1915
2016var bitlove = fs . readFileSync ( __dirname + '/torrents/bitlove-intro.torrent' )
2117var parsedBitlove = parseTorrent ( bitlove )
22- var binaryBitlove = hexToBinary ( parsedBitlove . infoHash )
18+ var binaryBitlove = commonLib . hexToBinary ( parsedBitlove . infoHash )
2319
2420var peerId = new Buffer ( '01234567890123456789' )
2521
2622function testSingle ( t , serverType ) {
2723 commonTest . createServer ( t , serverType , function ( server , announceUrl ) {
28- Client . scrape ( announceUrl , infoHash1 , function ( err , data ) {
24+ parsedBitlove . announce = [ announceUrl ]
25+ var client = new Client ( peerId , 6881 , parsedBitlove )
26+
27+ client . on ( 'error' , function ( err ) {
28+ t . error ( err )
29+ } )
30+
31+ client . on ( 'warning' , function ( err ) {
2932 t . error ( err )
33+ } )
34+
35+ client . scrape ( )
36+
37+ client . on ( 'scrape' , function ( data ) {
3038 t . equal ( data . announce , announceUrl )
3139 t . equal ( typeof data . complete , 'number' )
3240 t . equal ( typeof data . incomplete , 'number' )
@@ -69,9 +77,37 @@ test('udp: scrape using Client.scrape static method', function (t) {
6977 clientScrapeStatic ( t , 'udp' )
7078} )
7179
72- // TODO: test client for multiple scrape for UDP trackers
80+ function clientScrapeMulti ( t , serverType ) {
81+ commonTest . createServer ( t , serverType , function ( server , announceUrl ) {
82+ Client . scrape ( announceUrl , [ infoHash1 , infoHash2 ] , function ( err , results ) {
83+ t . error ( err )
84+
85+ t . equal ( results [ infoHash1 ] . announce , announceUrl )
86+ t . equal ( typeof results [ infoHash1 ] . complete , 'number' )
87+ t . equal ( typeof results [ infoHash1 ] . incomplete , 'number' )
88+ t . equal ( typeof results [ infoHash1 ] . downloaded , 'number' )
89+
90+ t . equal ( results [ infoHash2 ] . announce , announceUrl )
91+ t . equal ( typeof results [ infoHash2 ] . complete , 'number' )
92+ t . equal ( typeof results [ infoHash2 ] . incomplete , 'number' )
93+ t . equal ( typeof results [ infoHash2 ] . downloaded , 'number' )
94+
95+ server . close ( function ( ) {
96+ t . end ( )
97+ } )
98+ } )
99+ } )
100+ }
101+
102+ test ( 'http: MULTI scrape using Client.scrape static method' , function ( t ) {
103+ clientScrapeMulti ( t , 'http' )
104+ } )
105+
106+ test ( 'udp: MULTI scrape using Client.scrape static method' , function ( t ) {
107+ clientScrapeMulti ( t , 'udp' )
108+ } )
73109
74- test ( 'server: multiple info_hash scrape' , function ( t ) {
110+ test ( 'server: multiple info_hash scrape (manual http request) ' , function ( t ) {
75111 var server = new Server ( { udp : false } )
76112 server . on ( 'error' , function ( err ) {
77113 t . error ( err )
0 commit comments