client IPv6 support [BEP-7]

This commit is contained in:
Astro 2014-11-25 02:18:52 +01:00 committed by Feross Aboukhadijeh
parent 54b8d7112a
commit 1ca387f2fe

View File

@ -499,6 +499,27 @@ Tracker.prototype._handleResponse = function (requestUrl, data) {
self.client.emit('peer', peer.ip + ':' + peer.port)
})
}
if (Buffer.isBuffer(data.peers6)) {
// tracker returned compact response
var addrs
try {
addrs = compact2string.multi6(data.peers6)
} catch (err) {
return self.client.emit('warning', err)
}
addrs.forEach(function (addr) {
self.client.emit('peer', addr)
})
} else if (Array.isArray(data.peers6)) {
// tracker returned normal response
data.peers.forEach(function (peer) {
var ip = /:/.test(peer.ip) ?
'[' + peer.ip + ']' :
peer.ip
self.client.emit('peer', ip + ':' + peer.port)
})
}
} else if (requestUrl === self._scrapeUrl) {
// NOTE: the unofficial spec says to use the 'files' key but i've seen 'host' in practice
data = data.files || data.host || {}