client.go | 2 +- socket.go | 25 +++++++++++++++++++++++-- diff --git a/client.go b/client.go index 866aa2358578243fd4ab422c3a4dc34022b0ca2e..b2c8c78dd25652df3d71ff68ec3a9f72c41f57a8 100644 --- a/client.go +++ b/client.go @@ -438,7 +438,7 @@ } return } if err != nil { - cl.logger.Printf("error accepting connection: %s", err) + log.Fmsg("error accepting connection: %s", err).AddValue(debugLogValue).Log(cl.logger) continue } go func() { diff --git a/socket.go b/socket.go index 6c16e588a874c334979e05da0f09592b0da1b6b5..56b3eba5f162e6ead772707910887bce774a8a97 100644 --- a/socket.go +++ b/socket.go @@ -2,6 +2,7 @@ package torrent import ( "context" + "fmt" "net" "net/url" "strconv" @@ -55,11 +56,14 @@ // If we don't need the proxy - then we should return default net.Dialer, // otherwise, let's try to parse the proxyURL and return proxy.Dialer if len(proxyURL) != 0 { + + dl := disabledListener{l} + // TODO: The error should be propagated, as proxy may be in use for // security or privacy reasons. Also just pass proxy.Dialer in from // the Config. if dialer, err := getProxyDialer(proxyURL); err == nil { - return tcpSocket{l, func(ctx context.Context, addr string) (conn net.Conn, err error) { + return tcpSocket{dl, func(ctx context.Context, addr string) (conn net.Conn, err error) { defer perf.ScopeTimerErr(&err)() return dialer.Dial(network, addr) }}, nil @@ -72,6 +76,14 @@ return dialer.DialContext(ctx, network, addr) }}, nil } +type disabledListener struct { + net.Listener +} + +func (dl disabledListener) Accept() (net.Conn, error) { + return nil, fmt.Errorf("tcp listener disabled due to proxy") +} + type tcpSocket struct { net.Listener d func(ctx context.Context, addr string) (net.Conn, error) @@ -141,12 +153,21 @@ // If we don't need the proxy - then we should return default net.Dialer, // otherwise, let's try to parse the proxyURL and return proxy.Dialer if len(proxyURL) != 0 { + ds := disabledUtpSocket{us} if dialer, err := getProxyDialer(proxyURL); err == nil { - return utpSocketSocket{us, network, dialer}, nil + return utpSocketSocket{ds, network, dialer}, nil } } return utpSocketSocket{us, network, nil}, nil +} + +type disabledUtpSocket struct { + utpSocket +} + +func (ds disabledUtpSocket) Accept() (net.Conn, error) { + return nil, fmt.Errorf("utp listener disabled due to proxy") } type utpSocketSocket struct {