From 06dede5690dc285b1b895c8703b922c41b8ef4e4 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 2 Aug 2015 04:06:22 +1000 Subject: [PATCH] Track the connection flags for completed handshakes --- client.go | 4 +++- connection.go | 26 +++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/client.go b/client.go index b5a7222d..610b9fe4 100644 --- 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 } diff --git a/connection.go b/connection.go index 471d3f59..e1ae70b6 100644 --- a/connection.go +++ b/connection.go @@ -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') -- 2.48.1