client.go | 4 +++- connection.go | 26 +++++++++++++++++--------- diff --git a/client.go b/client.go index b5a7222dbb437d92472981e11bca303a6234c79f..610b9fe4061d4daedd640f2fc410e544d910bd5a 100644 --- a/client.go +++ b/client.go @@ -66,7 +66,8 @@ acceptUTP = expvar.NewInt("acceptUTP") 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 @@ c.rw = readWriter{ 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 471d3f593ce1aa9e5519face50db62cb5682892d..e1ae70b6d60ac8e72e4207db4b8df497bc0dd730 100644 --- a/connection.go +++ b/connection.go @@ -204,18 +204,10 @@ } 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 @@ } 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')