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