]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Track the connection flags for completed handshakes
authorMatt Joiner <anacrolix@gmail.com>
Sat, 1 Aug 2015 18:06:22 +0000 (04:06 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 1 Aug 2015 18:06:22 +0000 (04:06 +1000)
client.go
connection.go

index b5a7222dbb437d92472981e11bca303a6234c79f..610b9fe4061d4daedd640f2fc410e544d910bd5a 100644 (file)
--- a/client.go
+++ b/client.go
@@ -66,7 +66,8 @@ var (
        acceptTCP    = expvar.NewInt("acceptTCP")
        acceptReject = expvar.NewInt("acceptReject")
 
-       peerExtensions = expvar.NewMap("peerExtensions")
+       peerExtensions                    = expvar.NewMap("peerExtensions")
+       completedHandshakeConnectionFlags = expvar.NewMap("completedHandshakeConnectionFlags")
        // Count of connections to peer with same client ID.
        connsToSelf = expvar.NewInt("connsToSelf")
        // Number of completed connections to a client we're already connected with.
@@ -1134,6 +1135,7 @@ func (cl *Client) runHandshookConn(c *connection, t *torrent) (err error) {
                deadlineReader{c.conn, c.rw},
                c.rw,
        }
+       completedHandshakeConnectionFlags.Add(c.connectionFlags(), 1)
        if !cl.addConnection(t, c) {
                return
        }
index 471d3f593ce1aa9e5519face50db62cb5682892d..e1ae70b6d60ac8e72e4207db4b8df497bc0dd730 100644 (file)
@@ -204,18 +204,10 @@ func eventAgeString(t time.Time) string {
        return fmt.Sprintf("%.2fs ago", time.Now().Sub(t).Seconds())
 }
 
-// Inspired by https://trac.transmissionbt.com/wiki/PeerStatusText
-func (cn *connection) statusFlags() (ret string) {
+func (cn *connection) connectionFlags() (ret string) {
        c := func(b byte) {
                ret += string([]byte{b})
        }
-       if cn.Interested {
-               c('i')
-       }
-       if cn.Choked {
-               c('c')
-       }
-       c('-')
        if cn.encrypted {
                c('E')
        }
@@ -225,6 +217,22 @@ func (cn *connection) statusFlags() (ret string) {
        if cn.uTP {
                c('T')
        }
+       return
+}
+
+// Inspired by https://trac.transmissionbt.com/wiki/PeerStatusText
+func (cn *connection) statusFlags() (ret string) {
+       c := func(b byte) {
+               ret += string([]byte{b})
+       }
+       if cn.Interested {
+               c('i')
+       }
+       if cn.Choked {
+               c('c')
+       }
+       c('-')
+       ret += cn.connectionFlags()
        c('-')
        if cn.PeerInterested {
                c('i')