]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Record if a connection was incoming
authorMatt Joiner <anacrolix@gmail.com>
Mon, 30 Jun 2014 14:04:28 +0000 (00:04 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 30 Jun 2014 14:04:28 +0000 (00:04 +1000)
client.go
connection.go

index c0542fc3ac1660f3545c0ddf396d8b259346240b..f19d58182a7f8f1518e6408757dd40135aba50dc 100644 (file)
--- 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,
index 32f81480dea4f10185cc0f35e4c54e80f775bbd5..f986c5cbcd01643948b95b0771ddd1d14994d376 100644 (file)
@@ -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)
 }