From 23cfe49ea4fff5c12df7dd572e798febc5c1ebdc Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 1 Jul 2014 00:04:28 +1000 Subject: [PATCH] Record if a connection was incoming --- client.go | 3 +++ connection.go | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) 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) } -- 2.48.1