+ case 6:
+ if(cumulative) {
+ result = -cmpu64(na->in_bytes + na->out_bytes, nb->in_bytes + nb->out_bytes);
+ } else {
+ result = -cmpfloat(na->in_bytes_rate + na->out_bytes_rate, nb->in_bytes_rate + nb->out_bytes_rate);
+ }
+
+ break;
+
+ default:
+ result = strcmp(na->name, nb->name);
+ break;
+ }
+
+ if(result) {
+ return result;
+ } else {
+ return na->i - nb->i;
+ }
+}
+
+static void redraw(void) {
+ erase();
+
+ mvprintw(0, 0, "Tinc %-16s Nodes: %4d Sort: %-10s %s", netname ? netname : "", node_list.count, sortname[sortmode], cumulative ? "Cumulative" : "Current");
+ attrset(A_REVERSE);
+ mvprintw(2, 0, "Node IN %s IN %s OUT %s OUT %s", punit, bunit, punit, bunit);
+ chgat(-1, A_REVERSE, 0, NULL);
+
+ static nodestats_t **sorted = 0;
+ static int n = 0;
+
+ if(changed) {
+ n = 0;
+ sorted = xrealloc(sorted, node_list.count * sizeof(*sorted));
+
+ for list_each(nodestats_t, ns, &node_list) {
+ sorted[n++] = ns;
+ }
+
+ changed = false;
+ }
+
+ for(int i = 0; i < n; i++) {
+ sorted[i]->i = i;
+ }
+
+ if(sorted) {
+ qsort(sorted, n, sizeof(*sorted), sortfunc);
+ }
+
+ for(int i = 0, row = 3; i < n; i++, row++) {
+ nodestats_t *node = sorted[i];
+
+ if(node->known)
+ if(node->in_packets_rate || node->out_packets_rate) {
+ attrset(A_BOLD);
+ } else {
+ attrset(A_NORMAL);
+ } else {
+ attrset(A_DIM);
+ }
+
+ if(cumulative)
+ mvprintw(row, 0, "%-16s %10.0f %10.0f %10.0f %10.0f",
+ node->name, node->in_packets * pscale, node->in_bytes * bscale, node->out_packets * pscale, node->out_bytes * bscale);
+ 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);
+ }
+
+ attrset(A_NORMAL);
+ move(1, 0);
+
+ refresh();
+}
+
+void top(int fd) {
+ initscr();
+ timeout(delay);
+ bool running = true;
+
+ while(running) {
+ if(!update(fd)) {
+ break;
+ }
+
+ redraw();
+
+ switch(getch()) {
+ case 's': {
+ timeout(-1);
+ float input = delay * 1e-3;
+ mvprintw(1, 0, "Change delay from %.1fs to: ", input);
+ scanw("%f", &input);
+
+ if(input < 0.1) {
+ input = 0.1;