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)
// 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))
}
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
+}
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()
}