-
-
Notifications
You must be signed in to change notification settings - Fork 335
client IPv6 support [BEP-7] #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -501,6 +501,27 @@ Tracker.prototype._handleResponse = function (requestUrl, data) { | |
| self.client.emit('peer', addr) | ||
| }) | ||
| } | ||
|
|
||
| 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) ? | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there ever a time when an IPv6 address won't have a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my reading of the spec, the
And IPv6 addresses seem to always have I'll remove it for now, but let me know if it's important and we can re-add it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was adding some tolerance in #40, and because the non-compact format essentially allows free-form hostnames, why not check if this is an IPv6 address at all? It's not important to me and might lead interoperating people to assume a false level of flexibility in the HTTP tracker protocol.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see what you're saying. It's not hard to check if it's a domain, so let's do it. |
||
| '[' + 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 || {} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoa! Discovered a bigger bug. This should be
data.peers6.forEach! Will fix. ;)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oopsie. Ideally, we'd cover this with tests...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we support ipv6 on the server (#43) we can easily add a test that tests both sides of this. :)