pass TrackerDialContext to webtorrent trackers (#785)

This commit is contained in:
Raphaël Thériault 2022-11-14 00:20:08 -08:00 committed by GitHub
parent 8e53dbaeb8
commit 455913c752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -298,7 +298,8 @@ func NewClient(cfg *ClientConfig) (cl *Client, err error) {
}
return t.announceRequest(event), nil
},
Proxy: cl.config.HTTPProxy,
Proxy: cl.config.HTTPProxy,
DialContext: cl.config.TrackerDialContext,
OnConn: func(dc datachannel.ReadWriteCloser, dcc webtorrent.DataChannelContext) {
cl.lock()
defer cl.unlock()

View File

@ -1,7 +1,9 @@
package torrent
import (
"context"
"fmt"
"net"
"net/url"
"sync"
@ -40,6 +42,7 @@ type websocketTrackers struct {
mu sync.Mutex
clients map[string]*refCountedWebtorrentTrackerClient
Proxy http.ProxyFunc
DialContext func(ctx context.Context, network, addr string) (net.Conn, error)
}
func (me *websocketTrackers) Get(url string, infoHash [20]byte) (*webtorrent.TrackerClient, func()) {
@ -47,7 +50,7 @@ func (me *websocketTrackers) Get(url string, infoHash [20]byte) (*webtorrent.Tra
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,