diff --git a/frontend/udp/frontend.go b/frontend/udp/frontend.go index 82e246c..929e2ae 100644 --- a/frontend/udp/frontend.go +++ b/frontend/udp/frontend.go @@ -306,7 +306,7 @@ func (t *Frontend) handleRequest(r Request, w ResponseWriter) (actionName string return } - WriteAnnounce(w, txID, resp, actionID == announceV6ActionID) + WriteAnnounce(w, txID, resp, actionID == announceV6ActionID, req.IP.AddressFamily == bittorrent.IPv6) go t.logic.AfterAnnounce(ctx, req, resp) diff --git a/frontend/udp/parser.go b/frontend/udp/parser.go index 5a668f6..b5e4830 100644 --- a/frontend/udp/parser.go +++ b/frontend/udp/parser.go @@ -15,6 +15,9 @@ const ( announceActionID scrapeActionID errorActionID + // action == 4 is the "old" IPv6 action used by opentracker, with a packet + // format specified at + // https://web.archive.org/web/20170503181830/http://opentracker.blog.h3q.com/2007/12/28/the-ipv6-situation/ announceV6ActionID ) @@ -57,11 +60,12 @@ type ParseOptions struct { // ParseAnnounce parses an AnnounceRequest from a UDP request. // -// If v6 is true, the announce is parsed the "opentracker way": -// http://opentracker.blog.h3q.com/2007/12/28/the-ipv6-situation/ -func ParseAnnounce(r Request, v6 bool, opts ParseOptions) (*bittorrent.AnnounceRequest, error) { +// If v6Action is true, the announce is parsed the +// "old opentracker way": +// https://web.archive.org/web/20170503181830/http://opentracker.blog.h3q.com/2007/12/28/the-ipv6-situation/ +func ParseAnnounce(r Request, v6Action bool, opts ParseOptions) (*bittorrent.AnnounceRequest, error) { ipEnd := 84 + net.IPv4len - if v6 { + if v6Action { ipEnd = 84 + net.IPv6len } diff --git a/frontend/udp/writer.go b/frontend/udp/writer.go index 7fc882e..c23619f 100644 --- a/frontend/udp/writer.go +++ b/frontend/udp/writer.go @@ -26,12 +26,13 @@ func WriteError(w io.Writer, txID []byte, err error) { // WriteAnnounce encodes an announce response according to BEP 15. // The peers returned will be resp.IPv6Peers or resp.IPv4Peers, depending on -// whether v6 is set. The action ID will be 4, according to -// http://opentracker.blog.h3q.com/2007/12/28/the-ipv6-situation/. -func WriteAnnounce(w io.Writer, txID []byte, resp *bittorrent.AnnounceResponse, v6 bool) { +// whether v6Peers is set. +// If v6Action is set, the action will be 4, according to +// https://web.archive.org/web/20170503181830/http://opentracker.blog.h3q.com/2007/12/28/the-ipv6-situation/ +func WriteAnnounce(w io.Writer, txID []byte, resp *bittorrent.AnnounceResponse, v6Action, v6Peers bool) { buf := newBuffer() - if v6 { + if v6Action { writeHeader(buf, txID, announceV6ActionID) } else { writeHeader(buf, txID, announceActionID) @@ -41,7 +42,7 @@ func WriteAnnounce(w io.Writer, txID []byte, resp *bittorrent.AnnounceResponse, binary.Write(buf, binary.BigEndian, resp.Complete) peers := resp.IPv4Peers - if v6 { + if v6Peers { peers = resp.IPv6Peers }