8 "github.com/anacrolix/log"
10 trHttp "github.com/anacrolix/torrent/tracker/http"
11 "github.com/anacrolix/torrent/tracker/udp"
14 type Client interface {
15 Announce(context.Context, AnnounceRequest, AnnounceOpt) (AnnounceResponse, error)
19 type AnnounceOpt = trHttp.AnnounceOpt
21 type NewClientOpts struct {
22 Http trHttp.NewClientOpts
23 // Overrides the network in the scheme. Probably a legacy thing.
26 ListenPacket func(network, addr string) (net.PacketConn, error)
29 func NewClient(urlStr string, opts NewClientOpts) (Client, error) {
30 _url, err := url.Parse(urlStr)
36 return trHttp.NewClient(_url, opts.Http), nil
37 case "udp", "udp4", "udp6":
38 network := _url.Scheme
39 if opts.UdpNetwork != "" {
40 network = opts.UdpNetwork
42 cc, err := udp.NewConnClient(udp.NewConnClientOpts{
46 ListenPacket: opts.ListenPacket,
53 requestUri: _url.RequestURI(),
56 return nil, ErrBadScheme