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