Move some behaviour into Client.newConnection

This commit is contained in:
Matt Joiner 2016-05-07 18:57:38 +10:00
parent 0fd73396fd
commit 69643860ea
2 changed files with 6 additions and 7 deletions

View File

@ -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))

View 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,