@@ -54,20 +54,20 @@ function Server (opts) {
5454 // default to starting an http server unless the user explictly says no
5555 if ( opts . http !== false ) {
5656 self . _httpServer = http . createServer ( )
57- self . _httpServer . on ( 'request' , self . _onHttpRequest . bind ( self ) )
57+ self . _httpServer . on ( 'request' , self . onHttpRequest . bind ( self ) )
5858 self . _httpServer . on ( 'error' , self . _onError . bind ( self ) )
5959 self . _httpServer . on ( 'listening' , onListening )
6060 }
6161
6262 // default to starting a udp server unless the user explicitly says no
6363 if ( opts . udp !== false ) {
64- self . _udpServer = dgram . createSocket ( 'udp4' )
65- self . _udpServer . on ( 'message' , self . _onUdpRequest . bind ( self ) )
66- self . _udpServer . on ( 'error' , self . _onError . bind ( self ) )
67- self . _udpServer . on ( 'listening' , onListening )
64+ self . _udpSocket = dgram . createSocket ( 'udp4' )
65+ self . _udpSocket . on ( 'message' , self . _onUdpRequest . bind ( self ) )
66+ self . _udpSocket . on ( 'error' , self . _onError . bind ( self ) )
67+ self . _udpSocket . on ( 'listening' , onListening )
6868 }
6969
70- var num = ! ! self . _httpServer + ! ! self . _udpServer
70+ var num = ! ! self . _httpServer + ! ! self . _udpSocket
7171 function onListening ( ) {
7272 num -= 1
7373 if ( num === 0 ) {
@@ -98,7 +98,7 @@ Server.prototype.listen = function (port, onlistening) {
9898 // binding to :: only receives IPv4 connections if the bindv6only
9999 // sysctl is set 0, which is the default on many operating systems.
100100 self . _httpServer && self . _httpServer . listen ( port . http || port , '::' )
101- self . _udpServer && self . _udpServer . bind ( port . udp || port )
101+ self . _udpSocket && self . _udpSocket . bind ( port . udp || port )
102102 }
103103
104104 if ( port ) onPort ( null , port )
@@ -108,8 +108,8 @@ Server.prototype.listen = function (port, onlistening) {
108108Server . prototype . close = function ( cb ) {
109109 var self = this
110110 cb = cb || function ( ) { }
111- if ( self . _udpServer ) {
112- self . _udpServer . close ( )
111+ if ( self . _udpSocket ) {
112+ self . _udpSocket . close ( )
113113 }
114114 if ( self . _httpServer ) {
115115 self . _httpServer . close ( cb )
@@ -126,7 +126,7 @@ Server.prototype.getSwarm = function (infoHash) {
126126 return swarm
127127}
128128
129- Server . prototype . _onHttpRequest = function ( req , res ) {
129+ Server . prototype . onHttpRequest = function ( req , res ) {
130130 var self = this
131131
132132 var params
@@ -180,11 +180,10 @@ Server.prototype._onUdpRequest = function (msg, rinfo) {
180180 }
181181 }
182182
183- var socket = dgram . createSocket ( 'udp4' )
184183 response . transactionId = params . transactionId
185184 response . connectionId = params . connectionId
186185 var buf = makeUdpPacket ( response )
187- socket . send ( buf , 0 , buf . length , rinfo . port , rinfo . address , function ( ) {
186+ self . _udpSocket . send ( buf , 0 , buf . length , rinfo . port , rinfo . address , function ( ) {
188187 try {
189188 socket . close ( )
190189 } catch ( err ) { }
@@ -211,7 +210,7 @@ Server.prototype._onAnnounce = function (params, cb) {
211210 if ( response ) {
212211 if ( ! response . action ) response . action = common . ACTIONS . ANNOUNCE
213212 if ( ! response . intervalMs ) response . intervalMs = self . _intervalMs
214-
213+
215214 if ( params . compact === 1 ) {
216215 var peers = response . peers
217216 // Find IPv4 peers
0 commit comments