mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2024-12-14 03:16:24 +00:00
Fixes for PR #39
- emit 'warning' instead of 'error' because it's not a fatal error, just a bad tracker response. - made the try block more concise so it only catches the errors from `string2compact`
This commit is contained in:
parent
7e081f88d1
commit
07850cdc13
20
client.js
20
client.js
@ -352,13 +352,15 @@ Tracker.prototype._requestUdp = function (requestUrl, opts) {
|
|||||||
incomplete: msg.readUInt32BE(12)
|
incomplete: msg.readUInt32BE(12)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var addrs
|
||||||
try {
|
try {
|
||||||
compact2string.multi(msg.slice(20)).forEach(function (addr) {
|
addrs = compact2string.multi(msg.slice(20))
|
||||||
self.client.emit('peer', addr)
|
|
||||||
})
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return self.client.emit('error', err)
|
return self.client.emit('warning', err)
|
||||||
}
|
}
|
||||||
|
addrs.forEach(function (addr) {
|
||||||
|
self.client.emit('peer', addr)
|
||||||
|
})
|
||||||
break
|
break
|
||||||
|
|
||||||
case 2: // scrape
|
case 2: // scrape
|
||||||
@ -482,13 +484,15 @@ Tracker.prototype._handleResponse = function (requestUrl, data) {
|
|||||||
|
|
||||||
if (Buffer.isBuffer(data.peers)) {
|
if (Buffer.isBuffer(data.peers)) {
|
||||||
// tracker returned compact response
|
// tracker returned compact response
|
||||||
|
var addrs
|
||||||
try {
|
try {
|
||||||
compact2string.multi(data.peers).forEach(function (addr) {
|
addrs = compact2string.multi(data.peers)
|
||||||
self.client.emit('peer', addr)
|
|
||||||
})
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return self.client.emit('error', err)
|
return self.client.emit('warning', err)
|
||||||
}
|
}
|
||||||
|
addrs.forEach(function (addr) {
|
||||||
|
self.client.emit('peer', addr)
|
||||||
|
})
|
||||||
} else if (Array.isArray(data.peers)) {
|
} else if (Array.isArray(data.peers)) {
|
||||||
// tracker returned normal response
|
// tracker returned normal response
|
||||||
data.peers.forEach(function (peer) {
|
data.peers.forEach(function (peer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user