@@ -116,16 +116,9 @@ Server.prototype.close = function (cb) {
116116 }
117117}
118118
119- Server . prototype . getSwarm = function ( infoHash ) {
120- var self = this
121- var binaryInfoHash = Buffer . isBuffer ( infoHash )
122- ? infoHash . toString ( 'binary' )
123- : new Buffer ( infoHash , 'hex' ) . toString ( 'binary' )
124- return self . _getSwarm ( binaryInfoHash )
125- }
126-
127- Server . prototype . _getSwarm = function ( binaryInfoHash ) {
119+ Server . prototype . getSwarm = function ( binaryInfoHash ) {
128120 var self = this
121+ if ( Buffer . isBuffer ( binaryInfoHash ) ) binaryInfoHash = binaryInfoHash . toString ( 'binary' )
129122 var swarm = self . torrents [ binaryInfoHash ]
130123 if ( ! swarm ) {
131124 swarm = self . torrents [ binaryInfoHash ] = {
@@ -224,7 +217,7 @@ Server.prototype._onRequest = function (params, cb) {
224217Server . prototype . _onAnnounce = function ( params , cb ) {
225218 var self = this
226219
227- var swarm = self . _getSwarm ( params . info_hash )
220+ var swarm = self . getSwarm ( params . info_hash )
228221 var peer = swarm . peers [ params . addr ]
229222
230223 var start = function ( ) {
@@ -335,7 +328,7 @@ Server.prototype._onScrape = function (params, cb) {
335328 }
336329
337330 params . info_hash . some ( function ( infoHash ) {
338- var swarm = self . _getSwarm ( infoHash )
331+ var swarm = self . getSwarm ( infoHash )
339332
340333 response . files [ infoHash ] = {
341334 complete : swarm . complete ,
@@ -414,12 +407,14 @@ function parseHttpRequest (req, options) {
414407 }
415408
416409 if ( params . info_hash ) {
417- if ( ! Array . isArray ( params . info_hash ) ) throw new Error ( 'invalid info_hash' )
410+ if ( ! Array . isArray ( params . info_hash ) ) throw new Error ( 'invalid info_hash array ' )
418411
419- params . info_hash . some ( function ( infoHash ) {
412+ params . info_hash = params . info_hash . map ( function ( infoHash ) {
420413 if ( infoHash . length !== 20 ) {
421414 throw new Error ( 'invalid info_hash' )
422415 }
416+
417+ return infoHash
423418 } )
424419 }
425420
0 commit comments