From: Matt Joiner Date: Mon, 30 Jun 2014 14:04:28 +0000 (+1000) Subject: Record if a connection was incoming X-Git-Tag: v1.0.0~1690 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=23cfe49ea4fff5c12df7dd572e798febc5c1ebdc;p=btrtrc.git Record if a connection was incoming --- diff --git a/client.go b/client.go index c0542fc3..f19d5818 100644 --- a/client.go +++ b/client.go @@ -224,6 +224,7 @@ func (cl *Client) acceptConnections() { conn, err := cl.Listener.Accept() select { case <-cl.quit: + conn.Close() return default: } @@ -231,6 +232,7 @@ func (cl *Client) acceptConnections() { log.Print(err) return } + log.Printf("accepted connection from %s", conn.RemoteAddr()) go func() { if err := cl.runConnection(conn, nil); err != nil { log.Print(err) @@ -309,6 +311,7 @@ func (cl *Client) incomingPeerPort() int { func (me *Client) runConnection(sock net.Conn, torrent *torrent) (err error) { conn := &connection{ + Incoming: torrent == nil, Socket: sock, Choked: true, PeerChoked: true, diff --git a/connection.go b/connection.go index 32f81480..f986c5cb 100644 --- a/connection.go +++ b/connection.go @@ -15,11 +15,12 @@ import ( // Maintains the state of a connection with a peer. type connection struct { - Socket net.Conn - closed bool - mu sync.Mutex // Only for closing. - post chan peer_protocol.Message - write chan []byte + Socket net.Conn + Incoming bool + closed bool + mu sync.Mutex // Only for closing. + post chan peer_protocol.Message + write chan []byte // Stuff controlled by the local peer. Interested bool @@ -76,6 +77,9 @@ func (cn *connection) WriteStatus(w io.Writer) { if !cn.Choked && !cn.PeerInterested { c('?') } + if cn.Incoming { + c('I') + } fmt.Fprintln(w) }