]> Sergey Matveev's repositories - btrtrc.git/blobdiff - wstracker.go
Rename tracker/http package
[btrtrc.git] / wstracker.go
index 396b5aa5f28d0033c5054b2c5b19e2d88da656ad..9b1a92016a6e59fa96683d7c12650e769ffc1903 100644 (file)
@@ -1,16 +1,19 @@
 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 {
@@ -38,15 +41,16 @@ type websocketTrackers 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,
@@ -73,6 +77,7 @@ func (me *websocketTrackers) Get(url string) (*webtorrent.TrackerClient, func())
        return &value.TrackerClient, func() {
                me.mu.Lock()
                defer me.mu.Unlock()
+               value.TrackerClient.CloseOffersForInfohash(infoHash)
                value.refCount--
                if value.refCount == 0 {
                        value.TrackerClient.Close()