From: Matt Joiner Date: Mon, 10 Oct 2016 05:55:56 +0000 (+1100) Subject: Make newConnection a method on Client X-Git-Tag: v1.0.0~558 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=ed0dbba3847164510e608f554ddb3b39004349d4;p=btrtrc.git Make newConnection a method on Client --- diff --git a/client.go b/client.go index 12f19973..51aaf193 100644 --- 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 +} diff --git a/connection.go b/connection.go index a0b20f44..a61d42a4 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() }