]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Make newConnection a method on Client
authorMatt Joiner <anacrolix@gmail.com>
Mon, 10 Oct 2016 05:55:56 +0000 (16:55 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 10 Oct 2016 05:55:56 +0000 (16:55 +1100)
client.go
connection.go

index 12f1997326880e09c9bb78d0cbf08fd4ca6e5626..51aaf193238a6504e4b87ffeadf7fd9618a087fb 100644 (file)
--- a/client.go
+++ b/client.go
@@ -435,7 +435,7 @@ func (cl *Client) incomingConnection(nc net.Conn, utp bool) {
        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 @@ 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(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 @@ func (cl *Client) banPeerIP(ip net.IP) {
        }
        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
+}
index a0b20f44b4cc1188aa9352f399161558bfc5a6ee..a61d42a444d7b67b49fbf4872680324843aafb11 100644 (file)
@@ -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()
 }