summaryrefslogtreecommitdiff
path: root/testing/toxic/dhtstatus.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/toxic/dhtstatus.c')
-rw-r--r--testing/toxic/dhtstatus.c99
1 files changed, 0 insertions, 99 deletions
diff --git a/testing/toxic/dhtstatus.c b/testing/toxic/dhtstatus.c
deleted file mode 100644
index 33300772..00000000
--- a/testing/toxic/dhtstatus.c
+++ /dev/null
@@ -1,99 +0,0 @@
1#include "dhtstatus.h"
2#include "string.h"
3#include "../../core/network.h"
4#include "../../core/DHT.h"
5
6typedef uint8_t ipbuf[3 * 4 + 3 + 1];
7static int num_selected = 0;
8
9static void printip(ipbuf buf, IP ip)
10{
11 sprintf((char *)buf, "%u.%u.%u.%u", ip.c[0], ip.c[1], ip.c[2], ip.c[3]);
12}
13
14static void dhtstatus_onKey(ToxWindow *self, Messenger *m, wint_t key)
15{
16 switch (key) {
17 case KEY_UP:
18 case 'k':
19 if (--num_selected < 0)
20 num_selected = CLIENT_ID_SIZE - 1;
21
22 break;
23
24 case KEY_DOWN:
25 case 'j':
26 num_selected = (num_selected + 1) % CLIENT_ID_SIZE;
27 break;
28
29 case '\n':
30 break;
31
32 default:
33 break;
34 }
35}
36
37static void dhtstatus_onDraw(ToxWindow *self, Messenger *m)
38{
39 Client_data *close_clientlist = DHT_get_close_list(m->dht);
40 curs_set(0);
41 werase(self->window);
42
43 uint64_t now = unix_time();
44 uint32_t i, j;
45 ipbuf ipbuf;
46 wprintw(self->window,
47 "\n%llu ______________________ CLOSE LIST ________________________ ___ IP ADDR ___ _PRT_ LST PNG ____ SELF ____ _PRT_ LST\n\n",
48 now);
49
50 for (i = 0; i < 32; i++) { /*Number of nodes in closelist*/
51 Client_data *client = close_clientlist + i;
52
53 if (i == num_selected) wattron(self->window, COLOR_PAIR(3));
54
55 wprintw(self->window, "[%02i] ", i);
56 uint16_t port = ntohs(client->ip_port.port);
57
58 if (port) {
59 for (j = 0; j < CLIENT_ID_SIZE; j++)
60 wprintw(self->window, "%02hhx", client->client_id[j]);
61
62 printip(ipbuf, client->ip_port.ip);
63 wprintw(self->window, " %15s %5u ", ipbuf, port);
64 wprintw(self->window, " %3llu ", now - client->timestamp);
65 wprintw(self->window, " %3llu ", now - client->last_pinged);
66
67 port = ntohs(client->ret_ip_port.port);
68
69 if (port) {
70 printip(ipbuf, client->ret_ip_port.ip);
71 wprintw(self->window, " %15s %5u %3llu", ipbuf, port, now - close_clientlist[i].ret_timestamp);
72 }
73 }
74
75 wprintw(self->window, "\n");
76
77 if (i == num_selected) wattroff(self->window, COLOR_PAIR(3));
78 }
79
80 wrefresh(self->window);
81}
82
83static void dhtstatus_onInit(ToxWindow *self, Messenger *m)
84{
85
86}
87
88ToxWindow new_dhtstatus()
89{
90 ToxWindow ret;
91 memset(&ret, 0, sizeof(ret));
92
93 ret.onKey = &dhtstatus_onKey;
94 ret.onDraw = &dhtstatus_onDraw;
95 ret.onInit = &dhtstatus_onInit;
96
97 strcpy(ret.title, "[dht status]");
98 return ret;
99}