]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Move some behaviour into Client.newConnection
authorMatt Joiner <anacrolix@gmail.com>
Sat, 7 May 2016 08:57:38 +0000 (18:57 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 7 May 2016 08:57:38 +0000 (18:57 +1000)
client.go
connection.go

index 33f5b29333ff8e47ad44a6cb71f72e801be2b98b..48843c85e06c40927d423f17318544d725c3c577 100644 (file)
--- 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))
index e7b6ffe72eb34c2ce04453f582f5658aa7ef67c2..5c105c72679b79c20e05c372075328213d536b05 100644 (file)
@@ -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,