1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-07-06 04:17:56 +02:00
toxic/src/dhtstatus.c

105 lines
2.6 KiB
C
Raw Normal View History

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
2013-08-11 04:48:02 +02:00
#include "dhtstatus.h"
#include "string.h"
2013-08-16 19:11:09 +02:00
typedef uint8_t ipbuf[3 * 4 + 3 + 1];
2013-08-11 04:48:02 +02:00
static int num_selected = 0;
2013-08-23 23:03:44 +02:00
static void printip(ipbuf buf, tox_IP ip)
2013-08-11 04:48:02 +02:00
{
2013-08-16 19:11:09 +02:00
sprintf((char *)buf, "%u.%u.%u.%u", ip.c[0], ip.c[1], ip.c[2], ip.c[3]);
2013-08-11 04:48:02 +02:00
}
2013-08-23 23:03:44 +02:00
static void dhtstatus_onKey(ToxWindow *self, Tox *m, wint_t key)
2013-08-11 04:48:02 +02:00
{
2013-08-16 19:11:09 +02:00
switch (key) {
case KEY_UP:
case 'k':
if (--num_selected < 0)
2013-08-23 23:03:44 +02:00
num_selected = TOX_CLIENT_ID_SIZE - 1;
2013-08-16 19:11:09 +02:00
break;
case KEY_DOWN:
case 'j':
2013-08-23 23:03:44 +02:00
num_selected = (num_selected + 1) % TOX_CLIENT_ID_SIZE;
2013-08-16 19:11:09 +02:00
break;
case '\n':
break;
default:
break;
}
2013-08-11 04:48:02 +02:00
}
2013-08-23 23:03:44 +02:00
static void dhtstatus_onDraw(ToxWindow *self, Tox *m)
2013-08-11 04:48:02 +02:00
{
2013-08-23 23:03:44 +02:00
/*
Client_data *close_clientlist = DHT_get_close_list(m->dht);
2013-08-16 19:11:09 +02:00
curs_set(0);
werase(self->window);
uint64_t now = unix_time();
uint32_t i, j;
ipbuf ipbuf;
wprintw(self->window,
"\n%llu ______________________ CLOSE LIST ________________________ ___ IP ADDR ___ _PRT_ LST PNG ____ SELF ____ _PRT_ LST\n\n",
now);
for (i = 0; i < 32; i++) { /*Number of nodes in closelist*/
2013-08-23 23:03:44 +02:00
/*
2013-08-16 19:11:09 +02:00
Client_data *client = close_clientlist + i;
if (i == num_selected) wattron(self->window, COLOR_PAIR(3));
wprintw(self->window, "[%02i] ", i);
uint16_t port = ntohs(client->ip_port.port);
if (port) {
for (j = 0; j < CLIENT_ID_SIZE; j++)
wprintw(self->window, "%02hhx", client->client_id[j]);
printip(ipbuf, client->ip_port.ip);
wprintw(self->window, " %15s %5u ", ipbuf, port);
wprintw(self->window, " %3llu ", now - client->timestamp);
wprintw(self->window, " %3llu ", now - client->last_pinged);
port = ntohs(client->ret_ip_port.port);
if (port) {
printip(ipbuf, client->ret_ip_port.ip);
wprintw(self->window, " %15s %5u %3llu", ipbuf, port, now - close_clientlist[i].ret_timestamp);
}
}
wprintw(self->window, "\n");
if (i == num_selected) wattroff(self->window, COLOR_PAIR(3));
2013-08-11 04:48:02 +02:00
}
2013-08-16 19:11:09 +02:00
wrefresh(self->window);
2013-08-23 23:03:44 +02:00
*/
2013-08-11 04:48:02 +02:00
}
2013-08-23 23:03:44 +02:00
static void dhtstatus_onInit(ToxWindow *self, Tox *m)
2013-08-11 04:48:02 +02:00
{
}
2013-08-16 19:11:09 +02:00
ToxWindow new_dhtstatus()
2013-08-11 04:48:02 +02:00
{
2013-08-16 19:11:09 +02:00
ToxWindow ret;
memset(&ret, 0, sizeof(ret));
2013-08-11 04:48:02 +02:00
2013-08-16 19:11:09 +02:00
ret.onKey = &dhtstatus_onKey;
ret.onDraw = &dhtstatus_onDraw;
ret.onInit = &dhtstatus_onInit;
2013-08-11 04:48:02 +02:00
2013-08-16 19:11:09 +02:00
strcpy(ret.title, "[dht status]");
return ret;
2013-08-11 04:48:02 +02:00
}