From ce1c957e8796a097068ba546975ab1e8bc662ed1 Mon Sep 17 00:00:00 2001 From: thorkill Date: Fri, 10 Jul 2015 23:57:20 +0200 Subject: [PATCH] Added information about current node in tinc's top The information is of grate value when monitoring multiple nodes in one window. Without it the user is forced to quit top, exit tinc and go back to shell to refresh his memory about which node is in what window. --- src/node.c | 4 ++-- src/top.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/node.c b/src/node.c index c9ffc393..e3fbeeda 100644 --- a/src/node.c +++ b/src/node.c @@ -209,8 +209,8 @@ bool dump_nodes(connection_t *c) { bool dump_traffic(connection_t *c) { for splay_each(node_t, n, node_tree) - send_request(c, "%d %d %s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, CONTROL, REQ_DUMP_TRAFFIC, - n->name, n->in_packets, n->in_bytes, n->out_packets, n->out_bytes); + send_request(c, "%d %d %s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %d", CONTROL, REQ_DUMP_TRAFFIC, + n->name, n->in_packets, n->in_bytes, n->out_packets, n->out_bytes, n == myself ? 1 : 0); return send_request(c, "%d %d", CONTROL, REQ_DUMP_TRAFFIC); } diff --git a/src/top.c b/src/top.c index 40b80479..b24b38ec 100644 --- a/src/top.c +++ b/src/top.c @@ -43,6 +43,7 @@ typedef struct nodestats_t { float out_packets_rate; float out_bytes_rate; bool known; + bool myself; } nodestats_t; static const char *const sortname[] = { @@ -85,17 +86,18 @@ static bool update(int fd) { uint64_t in_bytes; uint64_t out_packets; uint64_t out_bytes; + bool myself; for list_each(nodestats_t, ns, &node_list) ns->known = false; while(recvline(fd, line, sizeof line)) { - int n = sscanf(line, "%d %d %s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, &code, &req, name, &in_packets, &in_bytes, &out_packets, &out_bytes); + int n = sscanf(line, "%d %d %s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %d", &code, &req, name, &in_packets, &in_bytes, &out_packets, &out_bytes, &myself); if(n == 2) return true; - if(n != 7) + if(n != 8) return false; nodestats_t *found = NULL; @@ -119,6 +121,7 @@ static bool update(int fd) { if(!found) { found = xzalloc(sizeof *found); found->name = xstrdup(name); + found->myself = myself; list_insert_tail(&node_list, found); changed = true; } @@ -234,6 +237,11 @@ static void redraw(void) { else mvprintw(row, 0, "%-16s %10.0f %10.0f %10.0f %10.0f", node->name, node->in_packets_rate * pscale, node->in_bytes_rate * bscale, node->out_packets_rate * pscale, node->out_bytes_rate * bscale); + + if (node->myself) { + attrset(A_NORMAL); + mvprintw(1, 0, "Node: %-16s", node->name); + } } attrset(A_NORMAL);