package torrent
import (
+ "context"
"fmt"
- "github.com/anacrolix/log"
- "github.com/anacrolix/torrent/tracker/http"
- "github.com/gorilla/websocket"
+ "net"
"net/url"
"sync"
+ "github.com/anacrolix/log"
+ "github.com/gorilla/websocket"
+ "github.com/pion/datachannel"
+
"github.com/anacrolix/torrent/tracker"
+ "github.com/anacrolix/torrent/tracker/http"
"github.com/anacrolix/torrent/webtorrent"
- "github.com/pion/datachannel"
)
type websocketTrackerStatus struct {
OnConn func(datachannel.ReadWriteCloser, webtorrent.DataChannelContext)
mu sync.Mutex
clients map[string]*refCountedWebtorrentTrackerClient
- Proxy http.ProxyFunc
+ Proxy httpTracker.ProxyFunc
+ DialContext func(ctx context.Context, network, addr string) (net.Conn, error)
}
-func (me *websocketTrackers) Get(url string) (*webtorrent.TrackerClient, func()) {
+func (me *websocketTrackers) Get(url string, infoHash [20]byte) (*webtorrent.TrackerClient, func()) {
me.mu.Lock()
defer me.mu.Unlock()
value, ok := me.clients[url]
if !ok {
- dialer := &websocket.Dialer{Proxy: me.Proxy, HandshakeTimeout: websocket.DefaultDialer.HandshakeTimeout}
+ dialer := &websocket.Dialer{Proxy: me.Proxy, NetDialContext: me.DialContext, HandshakeTimeout: websocket.DefaultDialer.HandshakeTimeout}
value = &refCountedWebtorrentTrackerClient{
TrackerClient: webtorrent.TrackerClient{
Dialer: dialer,
return &value.TrackerClient, func() {
me.mu.Lock()
defer me.mu.Unlock()
+ value.TrackerClient.CloseOffersForInfohash(infoHash)
value.refCount--
if value.refCount == 0 {
value.TrackerClient.Close()