client.go | 16 ++++++++++++++-- connection.go | 12 ------------ diff --git a/client.go b/client.go index 12f1997326880e09c9bb78d0cbf08fd4ca6e5626..51aaf193238a6504e4b87ffeadf7fd9618a087fb 100644 --- a/client.go +++ b/client.go @@ -435,7 +435,7 @@ defer nc.Close() if tc, ok := nc.(*net.TCPConn); ok { tc.SetLinger(0) } - c := newConnection(nc, &cl.mu) + c := cl.newConnection(nc) c.Discovery = peerSourceIncoming c.uTP = utp cl.runReceivedConn(c) @@ -575,7 +575,7 @@ // Performs initiator handshakes and returns a connection. Returns nil // *connection if no connection for valid reasons. func (cl *Client) handshakesConnection(nc net.Conn, t *Torrent, encrypted, utp bool) (c *connection, err error) { - c = newConnection(nc, &cl.mu) + c = cl.newConnection(nc) c.encrypted = encrypted c.uTP = utp err = nc.SetDeadline(time.Now().Add(handshakesTimeout)) @@ -1573,3 +1573,15 @@ cl.badPeerIPs = make(map[string]struct{}) } cl.badPeerIPs[ip.String()] = struct{}{} } + +func (cl *Client) newConnection(nc net.Conn) (c *connection) { + c = &connection{ + conn: nc, + + Choked: true, + PeerChoked: true, + PeerMaxRequests: 250, + } + c.setRW(connStatsReadWriter{nc, &cl.mu, c}) + return +} diff --git a/connection.go b/connection.go index a0b20f44b4cc1188aa9352f399161558bfc5a6ee..a61d42a444d7b67b49fbf4872680324843aafb11 100644 --- a/connection.go +++ b/connection.go @@ -106,18 +106,6 @@ func (cn *connection) mu() sync.Locker { return &cn.t.cl.mu } -func newConnection(nc net.Conn, l sync.Locker) (c *connection) { - c = &connection{ - conn: nc, - - Choked: true, - PeerChoked: true, - PeerMaxRequests: 250, - } - c.setRW(connStatsReadWriter{nc, l, c}) - return -} - func (cn *connection) remoteAddr() net.Addr { return cn.conn.RemoteAddr() }