]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix PeerConn outgoing field for webrtc
authorMatt Joiner <anacrolix@gmail.com>
Sun, 3 May 2020 08:37:26 +0000 (18:37 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 3 May 2020 08:37:26 +0000 (18:37 +1000)
Due to jumping straight into handshakes, outgoing=true was assumed. This didn't actually solve the issue I thought it might, but is important for determining "preferred" connection direction, which may result in dropping connections.

client.go
torrent.go

index 735d58cad063f8e8c75332d87cd9d030af34742a..416453677c14b6d5a4dfa4ddb82f7d5a7f6b8067 100644 (file)
--- a/client.go
+++ b/client.go
@@ -658,18 +658,17 @@ func (cl *Client) noLongerHalfOpen(t *Torrent, addr string) {
 
 // Performs initiator handshakes and returns a connection. Returns nil *connection if no connection
 // for valid reasons.
-func (cl *Client) handshakesConnection(
+func (cl *Client) initiateProtocolHandshakes(
        ctx context.Context,
        nc net.Conn,
        t *Torrent,
-       encryptHeader bool,
+       outgoing, encryptHeader bool,
        remoteAddr net.Addr,
-       network,
-       connString string,
+       network, connString string,
 ) (
        c *PeerConn, err error,
 ) {
-       c = cl.newConnection(nc, true, remoteAddr, network, connString)
+       c = cl.newConnection(nc, outgoing, remoteAddr, network, connString)
        c.headerEncrypted = encryptHeader
        ctx, cancel := context.WithTimeout(ctx, cl.config.HandshakesTimeout)
        defer cancel()
@@ -701,7 +700,7 @@ func (cl *Client) establishOutgoingConnEx(t *Torrent, addr net.Addr, obfuscatedH
                }
                return nil, errors.New("dial failed")
        }
-       c, err := cl.handshakesConnection(context.Background(), nc, t, obfuscatedHeader, addr, dr.Network, regularConnString(nc))
+       c, err := cl.initiateProtocolHandshakes(context.Background(), nc, t, true, obfuscatedHeader, addr, dr.Network, regularConnString(nc))
        if err != nil {
                nc.Close()
        }
index b4d1764807b473c1d098c6e386d8c12e02f93f82..0a8cfe4b6a6a7f15a94a6c1b3670676d27497ed2 100644 (file)
@@ -1287,10 +1287,11 @@ func (t *Torrent) onWebRtcConn(
        dcc webtorrent.DataChannelContext,
 ) {
        defer c.Close()
-       pc, err := t.cl.handshakesConnection(
+       pc, err := t.cl.initiateProtocolHandshakes(
                context.Background(),
                webrtcNetConn{c, dcc},
                t,
+               dcc.LocalOffered,
                false,
                webrtcNetAddr{dcc.Remote},
                webrtcNetwork,