client.go | 8 ++------ connection.go | 5 ++++- diff --git a/client.go b/client.go index 33f5b29333ff8e47ad44a6cb71f72e801be2b98b..48843c85e06c40927d423f17318544d725c3c577 100644 --- a/client.go +++ b/client.go @@ -369,9 +369,7 @@ defer nc.Close() 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 @@ // 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 e7b6ffe72eb34c2ce04453f582f5658aa7ef67c2..5c105c72679b79c20e05c372075328213d536b05 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,