udp: support both BEP15 and old opentracker v6 announces
This commit is contained in:
parent
0edd6382d5
commit
fa19d1125c
3 changed files with 15 additions and 10 deletions
|
@ -306,7 +306,7 @@ func (t *Frontend) handleRequest(r Request, w ResponseWriter) (actionName string
|
||||||
return
|
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)
|
go t.logic.AfterAnnounce(ctx, req, resp)
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,9 @@ const (
|
||||||
announceActionID
|
announceActionID
|
||||||
scrapeActionID
|
scrapeActionID
|
||||||
errorActionID
|
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
|
announceV6ActionID
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -57,11 +60,12 @@ type ParseOptions struct {
|
||||||
|
|
||||||
// ParseAnnounce parses an AnnounceRequest from a UDP request.
|
// ParseAnnounce parses an AnnounceRequest from a UDP request.
|
||||||
//
|
//
|
||||||
// If v6 is true, the announce is parsed the "opentracker way":
|
// If v6Action is true, the announce is parsed the
|
||||||
// http://opentracker.blog.h3q.com/2007/12/28/the-ipv6-situation/
|
// "old opentracker way":
|
||||||
func ParseAnnounce(r Request, v6 bool, opts ParseOptions) (*bittorrent.AnnounceRequest, error) {
|
// 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
|
ipEnd := 84 + net.IPv4len
|
||||||
if v6 {
|
if v6Action {
|
||||||
ipEnd = 84 + net.IPv6len
|
ipEnd = 84 + net.IPv6len
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,12 +26,13 @@ func WriteError(w io.Writer, txID []byte, err error) {
|
||||||
|
|
||||||
// WriteAnnounce encodes an announce response according to BEP 15.
|
// WriteAnnounce encodes an announce response according to BEP 15.
|
||||||
// The peers returned will be resp.IPv6Peers or resp.IPv4Peers, depending on
|
// The peers returned will be resp.IPv6Peers or resp.IPv4Peers, depending on
|
||||||
// whether v6 is set. The action ID will be 4, according to
|
// whether v6Peers is set.
|
||||||
// http://opentracker.blog.h3q.com/2007/12/28/the-ipv6-situation/.
|
// If v6Action is set, the action will be 4, according to
|
||||||
func WriteAnnounce(w io.Writer, txID []byte, resp *bittorrent.AnnounceResponse, v6 bool) {
|
// 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()
|
buf := newBuffer()
|
||||||
|
|
||||||
if v6 {
|
if v6Action {
|
||||||
writeHeader(buf, txID, announceV6ActionID)
|
writeHeader(buf, txID, announceV6ActionID)
|
||||||
} else {
|
} else {
|
||||||
writeHeader(buf, txID, announceActionID)
|
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)
|
binary.Write(buf, binary.BigEndian, resp.Complete)
|
||||||
|
|
||||||
peers := resp.IPv4Peers
|
peers := resp.IPv4Peers
|
||||||
if v6 {
|
if v6Peers {
|
||||||
peers = resp.IPv6Peers
|
peers = resp.IPv6Peers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue