From: Matt Joiner Date: Sat, 7 May 2016 08:57:38 +0000 (+1000) Subject: Move some behaviour into Client.newConnection X-Git-Tag: v1.0.0~746 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=69643860ea29079b306186547abacabe40889116;p=btrtrc.git Move some behaviour into Client.newConnection --- diff --git a/client.go b/client.go index 33f5b293..48843c85 100644 --- a/client.go +++ b/client.go @@ -369,9 +369,7 @@ func (cl *Client) incomingConnection(nc net.Conn, utp bool) { if tc, ok := nc.(*net.TCPConn); ok { tc.SetLinger(0) } - c := newConnection() - c.conn = nc - c.rw = nc + c := cl.newConnection(nc) c.Discovery = peerSourceIncoming c.uTP = utp err := cl.runReceivedConn(c) @@ -515,9 +513,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() - c.conn = nc - c.rw = nc + c = cl.newConnection(nc) c.encrypted = encrypted c.uTP = utp err = nc.SetDeadline(time.Now().Add(handshakesTimeout)) diff --git a/connection.go b/connection.go index e7b6ffe7..5c105c72 100644 --- a/connection.go +++ b/connection.go @@ -95,8 +95,11 @@ func (cn *connection) mu() sync.Locker { return &cn.t.cl.mu } -func newConnection() (c *connection) { +func (cl *Client) newConnection(nc net.Conn) (c *connection) { c = &connection{ + conn: nc, + rw: nc, + Choked: true, PeerChoked: true, PeerMaxRequests: 250,