]> Sergey Matveev's repositories - btrtrc.git/blobdiff - client.go
Drop support for go 1.20
[btrtrc.git] / client.go
index a87e44391f657508406c243b74df06602c81b030..1ea1d610482551bfef1d621f0ba03bd5cf6f3667 100644 (file)
--- a/client.go
+++ b/client.go
@@ -203,13 +203,16 @@ func (cl *Client) init(cfg *ClientConfig) {
        cl.event.L = cl.locker()
        cl.ipBlockList = cfg.IPBlocklist
        cl.httpClient = &http.Client{
-               Transport: &http.Transport{
+               Transport: cfg.WebTransport,
+       }
+       if cl.httpClient.Transport == nil {
+               cl.httpClient.Transport = &http.Transport{
                        Proxy:       cfg.HTTPProxy,
                        DialContext: cfg.HTTPDialContext,
                        // I think this value was observed from some webseeds. It seems reasonable to extend it
                        // to other uses of HTTP from the client.
                        MaxConnsPerHost: 10,
-               },
+               }
        }
 }
 
@@ -498,6 +501,22 @@ func (cl *Client) acceptConnections(l Listener) {
        for {
                conn, err := l.Accept()
                torrent.Add("client listener accepts", 1)
+               if err == nil {
+                       holepunchAddr, holepunchErr := addrPortFromPeerRemoteAddr(conn.RemoteAddr())
+                       if holepunchErr == nil {
+                               cl.lock()
+                               if g.MapContains(cl.undialableWithoutHolepunch, holepunchAddr) {
+                                       setAdd(&cl.accepted, holepunchAddr)
+                               }
+                               if g.MapContains(
+                                       cl.undialableWithoutHolepunchDialedAfterHolepunchConnect,
+                                       holepunchAddr,
+                               ) {
+                                       setAdd(&cl.probablyOnlyConnectedDueToHolepunch, holepunchAddr)
+                               }
+                               cl.unlock()
+                       }
+               }
                conn = pproffd.WrapNetConn(conn)
                cl.rLock()
                closed := cl.closed.IsSet()
@@ -516,20 +535,6 @@ func (cl *Client) acceptConnections(l Listener) {
                        log.Fmsg("error accepting connection: %s", err).LogLevel(log.Debug, cl.logger)
                        continue
                }
-               {
-                       holepunchAddr, holepunchErr := addrPortFromPeerRemoteAddr(conn.RemoteAddr())
-                       if holepunchErr == nil {
-                               cl.lock()
-                               if g.MapContains(
-                                       cl.undialableWithoutHolepunchDialedAfterHolepunchConnect,
-                                       holepunchAddr,
-                               ) {
-                                       g.MakeMapIfNil(&cl.probablyOnlyConnectedDueToHolepunch)
-                                       g.MapInsert(cl.probablyOnlyConnectedDueToHolepunch, holepunchAddr, struct{}{})
-                               }
-                               cl.unlock()
-                       }
-               }
                go func() {
                        if reject != nil {
                                torrent.Add("rejected accepted connections", 1)
@@ -761,17 +766,6 @@ func (cl *Client) dialAndCompleteHandshake(opts outgoingConnOpts) (c *PeerConn,
                }
        }
        holepunchAddr, holepunchAddrErr := addrPortFromPeerRemoteAddr(addr)
-       if holepunchAddrErr == nil && opts.receivedHolepunchConnect {
-               cl.lock()
-               if g.MapContains(cl.undialableWithoutHolepunch, holepunchAddr) {
-                       g.MakeMapIfNilAndSet(
-                               &cl.undialableWithoutHolepunchDialedAfterHolepunchConnect,
-                               holepunchAddr,
-                               struct{}{},
-                       )
-               }
-               cl.unlock()
-       }
        headerObfuscationPolicy := opts.HeaderObfuscationPolicy
        obfuscatedHeaderFirst := headerObfuscationPolicy.Preferred
        firstDialResult := dialPool.getFirst()