@@ -159,7 +159,7 @@ Server.prototype._onHttpRequest = function (req, res) {
159159 }
160160
161161 var response
162- if ( params && params . request === 'announce' ) {
162+ if ( params && params . action === common . ACTIONS . ANNOUNCE ) {
163163 var swarm = self . _getSwarm ( params . info_hash )
164164 var peer = swarm . peers [ params . addr ]
165165
@@ -246,7 +246,7 @@ Server.prototype._onHttpRequest = function (req, res) {
246246 res . end ( bencode . encode ( response ) )
247247 debug ( 'sent response %s' , response )
248248
249- } else if ( params . request === 'scrape' ) { // unofficial scrape message
249+ } else if ( params . action === common . ACTIONS . SCRAPE ) { // unofficial scrape message
250250 if ( typeof params . info_hash === 'string' ) {
251251 params . info_hash = [ params . info_hash ]
252252 } else if ( params . info_hash == null ) {
@@ -307,13 +307,13 @@ Server.prototype._onUdpRequest = function (msg, rinfo) {
307307 var socket = dgram . createSocket ( 'udp4' )
308308
309309 var swarm
310- if ( params && params . request === 'connect' ) {
310+ if ( params && params . action === common . ACTIONS . CONNECT ) {
311311 send ( Buffer . concat ( [
312312 common . toUInt32 ( common . ACTIONS . CONNECT ) ,
313313 common . toUInt32 ( params . transactionId ) ,
314314 params . connectionId
315315 ] ) )
316- } else if ( params && params . request === 'announce' ) {
316+ } else if ( params && params . action === common . ACTIONS . ANNOUNCE ) {
317317 swarm = self . _getSwarm ( params . info_hash )
318318 var peer = swarm . peers [ params . addr ]
319319
@@ -397,7 +397,7 @@ Server.prototype._onUdpRequest = function (msg, rinfo) {
397397 peers
398398 ] ) )
399399
400- } else if ( params && params . request === 'scrape' ) { // scrape message
400+ } else if ( params && params . action === common . ACTIONS . SCRAPE ) { // scrape message
401401 swarm = self . _getSwarm ( params . info_hash )
402402
403403 send ( Buffer . concat ( [
@@ -463,7 +463,7 @@ function parseHttpRequest (req, options) {
463463 var params = common . querystringParse ( s [ 1 ] )
464464
465465 if ( s [ 0 ] === '/announce' ) {
466- params . request = 'announce'
466+ params . action = common . ACTIONS . ANNOUNCE
467467
468468 params . peer_id = typeof params . peer_id === 'string' && common . binaryToUtf8 ( params . peer_id )
469469 params . port = Number ( params . port )
@@ -489,7 +489,7 @@ function parseHttpRequest (req, options) {
489489
490490 return params
491491 } else if ( s [ 0 ] === '/scrape' ) { // unofficial scrape message
492- params . request = 'scrape'
492+ params . action = common . ACTIONS . SCRAPE
493493
494494 if ( typeof params . info_hash === 'string' ) {
495495 params . info_hash = [ params . info_hash ]
@@ -532,9 +532,8 @@ function parseUdpRequest (msg, rinfo) {
532532 }
533533
534534 if ( params . action === common . ACTIONS . CONNECT ) {
535- params . request = 'connect'
535+ // No further params
536536 } else if ( params . action === common . ACTIONS . ANNOUNCE ) {
537- params . request = 'announce'
538537 params . info_hash = msg . slice ( 16 , 36 ) . toString ( 'binary' ) // 20 bytes
539538 params . peer_id = msg . slice ( 36 , 56 ) . toString ( 'utf8' ) // 20 bytes
540539 params . downloaded = fromUInt64 ( msg . slice ( 56 , 64 ) ) // TODO: track this?
@@ -556,7 +555,6 @@ function parseUdpRequest (msg, rinfo) {
556555 params . addr = params . ip + ':' + params . port // TODO: ipv6 brackets
557556
558557 } else if ( params . action === common . ACTIONS . SCRAPE ) { // scrape message
559- params . request = 'scrape'
560558 params . info_hash = msg . slice ( 16 , 36 ) . toString ( 'binary' ) // 20 bytes
561559
562560 // TODO: support multiple info_hash scrape
0 commit comments