1- const { Buffer } = require ( 'safe-buffer' )
21const bencode = require ( 'bencode' )
32const debug = require ( 'debug' ) ( 'bittorrent-tracker:server' )
43const dgram = require ( 'dgram' )
@@ -15,6 +14,8 @@ const parseHttpRequest = require('./lib/server/parse-http')
1514const parseUdpRequest = require ( './lib/server/parse-udp' )
1615const parseWebSocketRequest = require ( './lib/server/parse-websocket' )
1716
17+ const hasOwnProperty = Object . prototype . hasOwnProperty
18+
1819/**
1920 * BitTorrent tracker server.
2021 *
@@ -147,7 +148,7 @@ class Server extends EventEmitter {
147148 let key
148149
149150 for ( key in allPeers ) {
150- if ( allPeers . hasOwnProperty ( key ) && filterFunction ( allPeers [ key ] ) ) {
151+ if ( hasOwnProperty . call ( allPeers , key ) && filterFunction ( allPeers [ key ] ) ) {
151152 count ++
152153 }
153154 }
@@ -158,7 +159,7 @@ class Server extends EventEmitter {
158159 function groupByClient ( ) {
159160 const clients = { }
160161 for ( const key in allPeers ) {
161- if ( allPeers . hasOwnProperty ( key ) ) {
162+ if ( hasOwnProperty . call ( allPeers , key ) ) {
162163 const peer = allPeers [ key ]
163164
164165 if ( ! clients [ peer . client . client ] ) {
@@ -179,10 +180,10 @@ class Server extends EventEmitter {
179180 function printClients ( clients ) {
180181 let html = '<ul>\n'
181182 for ( const name in clients ) {
182- if ( clients . hasOwnProperty ( name ) ) {
183+ if ( hasOwnProperty . call ( clients , name ) ) {
183184 const client = clients [ name ]
184185 for ( const version in client ) {
185- if ( client . hasOwnProperty ( version ) ) {
186+ if ( hasOwnProperty . call ( client , version ) ) {
186187 html += `<li><strong>${ name } </strong> ${ version } : ${ client [ version ] } </li>\n`
187188 }
188189 }
@@ -203,7 +204,7 @@ class Server extends EventEmitter {
203204 const peer = peers . peek ( peerId )
204205 if ( peer == null ) return // peers.peek() can evict the peer
205206
206- if ( ! allPeers . hasOwnProperty ( peerId ) ) {
207+ if ( ! hasOwnProperty . call ( allPeers , peerId ) ) {
207208 allPeers [ peerId ] = {
208209 ipv4 : false ,
209210 ipv6 : false ,
@@ -247,7 +248,7 @@ class Server extends EventEmitter {
247248 clients : groupByClient ( )
248249 }
249250
250- if ( req . url === '/stats.json' || req . headers [ ' accept' ] === 'application/json' ) {
251+ if ( req . url === '/stats.json' || req . headers . accept === 'application/json' ) {
251252 res . write ( JSON . stringify ( stats ) )
252253 res . end ( )
253254 } else if ( req . url === '/stats' ) {
0 commit comments