From: Matt Joiner Date: Wed, 18 Mar 2015 07:38:29 +0000 (+1100) Subject: Improve connection status info, especially flags X-Git-Tag: v1.0.0~1264 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=466b5f0623b343da77a2be67a968b0339bd19d82;p=btrtrc.git Improve connection status info, especially flags --- diff --git a/connection.go b/connection.go index 16e9db05..756729ae 100644 --- a/connection.go +++ b/connection.go @@ -187,28 +187,20 @@ func eventAgeString(t time.Time) string { return fmt.Sprintf("%.2fs ago", time.Now().Sub(t).Seconds()) } -func (cn *connection) WriteStatus(w io.Writer, t *torrent) { - // \t isn't preserved in
 blocks?
-	fmt.Fprintf(w, "%s\n    %s completed, good chunks: %d/%d reqs: %d-%d, last msg: %s, connected: %s, last useful chunk: %s, flags: ", fmt.Sprintf("%q: %s-%s", cn.PeerID, cn.localAddr(), cn.remoteAddr()), cn.completedString(t), cn.UsefulChunksReceived, cn.UnwantedChunksReceived+cn.UsefulChunksReceived, len(cn.Requests), len(cn.PeerRequests), eventAgeString(cn.lastMessageReceived), eventAgeString(cn.completedHandshake), eventAgeString(cn.lastUsefulChunkReceived))
+// Inspired by https://trac.transmissionbt.com/wiki/PeerStatusText
+func (cn *connection) statusFlags() (ret string) {
 	c := func(b byte) {
-		fmt.Fprintf(w, "%c", b)
-	}
-	// Inspired by https://trac.transmissionbt.com/wiki/PeerStatusText
-	if len(cn.Requests) != 0 {
-		c('D')
-	}
-	if !cn.Interested {
-		c('z')
+		ret += string([]byte{b})
 	}
-	if cn.PeerChoked && cn.Interested {
+	if cn.Interested {
 		c('i')
 	}
-	if !cn.Choked {
-		if cn.PeerInterested {
-			c('U')
-		} else {
-			c('u')
-		}
+	if cn.Choked {
+		c('c')
+	}
+	c('-')
+	if cn.encrypted {
+		c('E')
 	}
 	if cn.Discovery != 0 {
 		c(byte(cn.Discovery))
@@ -216,7 +208,30 @@ func (cn *connection) WriteStatus(w io.Writer, t *torrent) {
 	if cn.uTP {
 		c('T')
 	}
-	fmt.Fprintln(w)
+	c('-')
+	if cn.PeerInterested {
+		c('i')
+	}
+	if cn.PeerChoked {
+		c('c')
+	}
+	return
+}
+
+func (cn *connection) WriteStatus(w io.Writer, t *torrent) {
+	// \t isn't preserved in 
 blocks?
+	fmt.Fprintf(w, "%q: %s-%s\n", cn.PeerID, cn.localAddr(), cn.remoteAddr())
+	fmt.Fprintf(w, "    last msg: %s, connected: %s, last useful chunk: %s\n",
+		eventAgeString(cn.lastMessageReceived),
+		eventAgeString(cn.completedHandshake),
+		eventAgeString(cn.lastUsefulChunkReceived))
+	fmt.Fprintf(w, "    %s completed, good chunks: %d/%d reqs: %d-%d, flags: %s\n",
+		cn.completedString(t),
+		cn.UsefulChunksReceived,
+		cn.UnwantedChunksReceived+cn.UsefulChunksReceived,
+		len(cn.Requests),
+		len(cn.PeerRequests),
+		cn.statusFlags())
 }
 
 func (c *connection) Close() {