Skip to content

Commit

Permalink
pass TrackerDialContext to webtorrent trackers (#785)
Browse files Browse the repository at this point in the history
  • Loading branch information
raftario authored Nov 14, 2022
1 parent 8e53dba commit 455913c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion wstracker.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package torrent

import (
"context"
"fmt"
"net"
"net/url"
"sync"

Expand Down Expand Up @@ -40,14 +42,15 @@ 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()) {
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,
Expand Down

0 comments on commit 455913c

Please sign in to comment.