@@ -115,13 +115,11 @@ Server.prototype.close = function (cb) {
115115 }
116116}
117117
118- Server . prototype . getSwarm = function ( binaryInfoHash ) {
118+ Server . prototype . getSwarm = function ( infoHash ) {
119119 var self = this
120- if ( Buffer . isBuffer ( binaryInfoHash ) ) binaryInfoHash = binaryInfoHash . toString ( 'binary' )
121- var swarm = self . torrents [ binaryInfoHash ]
122- if ( ! swarm ) {
123- swarm = self . torrents [ binaryInfoHash ] = new Swarm ( binaryInfoHash , this )
124- }
120+ if ( Buffer . isBuffer ( infoHash ) ) infoHash = infoHash . toString ( 'hex' )
121+ var swarm = self . torrents [ infoHash ]
122+ if ( ! swarm ) swarm = self . torrents [ infoHash ] = new Swarm ( infoHash , this )
125123 return swarm
126124}
127125
@@ -130,9 +128,7 @@ Server.prototype._onHttpRequest = function (req, res) {
130128
131129 var params
132130 try {
133- params = parseHttpRequest ( req , {
134- trustProxy : self . _trustProxy
135- } )
131+ params = parseHttpRequest ( req , { trustProxy : self . _trustProxy } )
136132 } catch ( err ) {
137133 debug ( 'sent error %s' , err . message )
138134 res . end ( bencode . encode ( {
@@ -142,7 +138,7 @@ Server.prototype._onHttpRequest = function (req, res) {
142138 // even though it's an error for the client, it's just a warning for the server.
143139 // don't crash the server because a client sent bad data :)
144140 self . emit ( 'warning' , err )
145-
141+
146142 return
147143 }
148144
@@ -225,28 +221,12 @@ Server.prototype._onAnnounce = function (params, cb) {
225221Server . prototype . _onScrape = function ( params , cb ) {
226222 var self = this
227223
228- if ( typeof params . info_hash === 'string' ) {
229- params . info_hash = [ params . info_hash ]
230- } else if ( params . info_hash == null ) {
224+ if ( params . info_hash == null ) {
231225 // if info_hash param is omitted, stats for all torrents are returned
232226 // TODO: make this configurable!
233227 params . info_hash = Object . keys ( self . torrents )
234228 }
235229
236- if ( ! Array . isArray ( params . info_hash ) ) {
237- var err = new Error ( 'invalid info_hash' )
238- self . emit ( 'warning' , err )
239- return cb ( err )
240- }
241-
242- var response = {
243- action : common . ACTIONS . SCRAPE ,
244- files : { } ,
245- flags : {
246- min_request_interval : self . _intervalMs
247- }
248- }
249-
250230 series ( params . info_hash . map ( function ( infoHash ) {
251231 var swarm = self . getSwarm ( infoHash )
252232 return function ( cb ) {
@@ -261,8 +241,14 @@ Server.prototype._onScrape = function (params, cb) {
261241 } ) , function ( err , results ) {
262242 if ( err ) return cb ( err )
263243
244+ var response = {
245+ action : common . ACTIONS . SCRAPE ,
246+ files : { } ,
247+ flags : { min_request_interval : self . _intervalMs }
248+ }
249+
264250 results . forEach ( function ( result ) {
265- response . files [ result . infoHash ] = {
251+ response . files [ common . hexToBinary ( result . infoHash ) ] = {
266252 complete : result . complete ,
267253 incomplete : result . incomplete ,
268254 downloaded : result . complete // TODO: this only provides a lower-bound
@@ -273,7 +259,6 @@ Server.prototype._onScrape = function (params, cb) {
273259 } )
274260}
275261
276-
277262function makeUdpPacket ( params ) {
278263 switch ( params . action ) {
279264 case common . ACTIONS . CONNECT :
0 commit comments