Merge branch 'FullName-ClientData46'

This commit is contained in:
irungentoo 2013-09-28 10:42:14 -04:00
commit 0e2173367a
8 changed files with 708 additions and 242 deletions

View File

@ -52,26 +52,40 @@
#define PORT 33445
void print_assoc(IPPTsPng *assoc, uint8_t ours)
{
IP_Port *ipp = &assoc->ip_port;
printf("\nIP: %s Port: %u", ip_ntoa(&ipp->ip), ntohs(ipp->port));
printf("\nTimestamp: %llu", (long long unsigned int) assoc->timestamp);
printf("\nLast pinged: %llu\n", (long long unsigned int) assoc->last_pinged);
ipp = &assoc->ret_ip_port;
if (ours)
printf("OUR IP: %s Port: %u\n", ip_ntoa(&ipp->ip), ntohs(ipp->port));
else
printf("RET IP: %s Port: %u\n", ip_ntoa(&ipp->ip), ntohs(ipp->port));
printf("Timestamp: %llu\n", (long long unsigned int) assoc->ret_timestamp);
}
void print_clientlist(DHT *dht)
{
uint32_t i, j;
IP_Port p_ip;
printf("___________________CLOSE________________________________\n");
for (i = 0; i < LCLIENT_LIST; i++) {
Client_data *client = &dht->close_clientlist[i];
printf("ClientID: ");
for (j = 0; j < CLIENT_ID_SIZE; j++) {
printf("%02hhX", dht->close_clientlist[i].client_id[j]);
printf("%02hhX", client->client_id[j]);
}
p_ip = dht->close_clientlist[i].ip_port;
printf("\nIP: %s Port: %u", ip_ntoa(&p_ip.ip), ntohs(p_ip.port));
printf("\nTimestamp: %llu", (long long unsigned int) dht->close_clientlist[i].timestamp);
printf("\nLast pinged: %llu\n", (long long unsigned int) dht->close_clientlist[i].last_pinged);
p_ip = dht->close_clientlist[i].ret_ip_port;
printf("OUR IP: %s Port: %u\n", ip_ntoa(&p_ip.ip), ntohs(p_ip.port));
printf("Timestamp: %llu\n", (long long unsigned int) dht->close_clientlist[i].ret_timestamp);
#ifdef CLIENT_ONETOONE_IP
print_assoc(&client->assoc, 1);
#else
print_assoc(&client->assoc4, 1);
print_assoc(&client->assoc6, 1);
#endif
}
}
@ -95,22 +109,22 @@ void print_friendlist(DHT *dht)
printf("\nCLIENTS IN LIST:\n\n");
for (i = 0; i < MAX_FRIEND_CLIENTS; i++) {
Client_data *client = &dht->friends_list[k].client_list[i];
printf("ClientID: ");
for (j = 0; j < CLIENT_ID_SIZE; j++) {
if (dht->friends_list[k].client_list[i].client_id[j] < 16)
if (client->client_id[j] < 16)
printf("0");
printf("%hhX", dht->friends_list[k].client_list[i].client_id[j]);
printf("%hhX", client->client_id[j]);
}
p_ip = dht->friends_list[k].client_list[i].ip_port;
printf("\nIP: %s:%u", ip_ntoa(&p_ip.ip), ntohs(p_ip.port));
printf("\nTimestamp: %llu", (long long unsigned int) dht->friends_list[k].client_list[i].timestamp);
printf("\nLast pinged: %llu\n", (long long unsigned int) dht->friends_list[k].client_list[i].last_pinged);
p_ip = dht->friends_list[k].client_list[i].ret_ip_port;
printf("ret IP: %s:%u\n", ip_ntoa(&p_ip.ip), ntohs(p_ip.port));
printf("Timestamp: %llu\n", (long long unsigned int)dht->friends_list[k].client_list[i].ret_timestamp);
#ifdef CLIENT_ONETOONE_IP
print_assoc(&client->assoc, 0);
#else
print_assoc(&client->assoc4, 0);
print_assoc(&client->assoc6, 0);
#endif
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -44,7 +44,6 @@
#define MAX_TOPING 16
typedef struct {
uint8_t client_id[CLIENT_ID_SIZE];
IP_Port ip_port;
uint64_t timestamp;
uint64_t last_pinged;
@ -52,19 +51,22 @@ typedef struct {
/* Returned by this node. Either our friend or us. */
IP_Port ret_ip_port;
uint64_t ret_timestamp;
} Client_data;
} IPPTsPng;
typedef struct {
uint8_t client_id[CLIENT_ID_SIZE];
IPPTsPng assoc;
} Client_data_old;
typedef struct {
uint8_t client_id[CLIENT_ID_SIZE];
IPPTsPng assoc4;
IPPTsPng assoc6;
} Client_data_new;
/*----------------------------------------------------------------------------------*/
typedef struct {
uint8_t client_id[CLIENT_ID_SIZE];
Client_data client_list[MAX_FRIEND_CLIENTS];
/* Time at which the last get_nodes request was sent. */
uint64_t lastgetnode;
/* Symetric NAT hole punching stuff. */
/* 1 if currently hole punching, otherwise 0 */
uint8_t hole_punching;
uint32_t punching_index;
@ -72,7 +74,38 @@ typedef struct {
uint64_t recvNATping_timestamp;
uint64_t NATping_id;
uint64_t NATping_timestamp;
} DHT_Friend;
} NAT;
typedef struct {
uint8_t client_id[CLIENT_ID_SIZE];
Client_data_old client_list[MAX_FRIEND_CLIENTS];
/* Time at which the last get_nodes request was sent. */
uint64_t lastgetnode;
/* Symetric NAT hole punching stuff. */
NAT nat;
} DHT_Friend_old;
typedef struct {
uint8_t client_id[CLIENT_ID_SIZE];
Client_data_new client_list[MAX_FRIEND_CLIENTS];
/* Time at which the last get_nodes request was sent. */
uint64_t lastgetnode;
/* Symetric NAT hole punching stuff. */
NAT nat;
} DHT_Friend_new;
/* #define CLIENT_ONETOONE_IP */
#ifdef CLIENT_ONETOONE_IP
typedef Client_data_old Client_data;
typedef DHT_Friend_old DHT_Friend;
#else
typedef Client_data_new Client_data;
typedef DHT_Friend_new DHT_Friend;
#endif
/* this must be kept even if IP_Port is expanded: wire compatibility */
typedef struct {

View File

@ -130,7 +130,7 @@ static IP broadcast_ip(sa_family_t family_socket, sa_family_t family_broadcast)
/* return 0 if ip is a LAN ip.
* return -1 if it is not.
*/
static int LAN_ip(IP ip)
int LAN_ip(IP ip)
{
#ifdef TOX_ENABLE_IPV6

View File

@ -41,10 +41,15 @@
/* Send a LAN discovery pcaket to the broadcast address with port port. */
int send_LANdiscovery(uint16_t port, Net_Crypto *c);
/* Sets up packet handlers. */
void LANdiscovery_init(DHT *dht);
/* checks if a given IP isn't routable
*
* return 0 if ip is a LAN ip.
* return -1 if it is not.
*/
int LAN_ip(IP ip);
#endif

View File

@ -517,8 +517,10 @@ static int send_userstatus(Messenger *m, int friendnumber, USERSTATUS status)
static int send_ping(Messenger *m, int friendnumber)
{
int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_PING, 0, 0);
if (ret == 1)
m->friendlist[friendnumber].ping_lastsent = unix_time();
m->friendlist[friendnumber].ping_lastsent = unix_time();
return ret;
}
@ -1187,7 +1189,7 @@ void doFriends(Messenger *m)
if (m->group_invite)
(*m->group_invite)(m, i, data, m->group_invite_userdata);
break;
}
@ -1204,10 +1206,10 @@ void doFriends(Messenger *m)
break;
group_newpeer(m->chats[groupnum], data + crypto_box_PUBLICKEYBYTES);
break;
}
default: {
break;
}
@ -1296,15 +1298,22 @@ void doMessenger(Messenger *m)
for (client = 0; client < LCLIENT_LIST; client++) {
Client_data *cptr = &m->dht->close_clientlist[client];
IPPTsPng *assoc = NULL;
#ifdef CLIENT_ONETOONE_IP
assoc = &cptr->assoc;
#else
uint32_t a;
if (ip_isset(&cptr->ip_port.ip)) {
last_pinged = lastdump - cptr->last_pinged;
for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6)
#endif
if (ip_isset(&assoc->ip_port.ip)) {
last_pinged = lastdump - assoc->last_pinged;
if (last_pinged > 999)
last_pinged = 999;
snprintf(logbuffer, sizeof(logbuffer), "C[%2u] %s:%u [%3u] %s\n",
client, ip_ntoa(&cptr->ip_port.ip), ntohs(cptr->ip_port.port),
client, ip_ntoa(&assoc->ip_port.ip), ntohs(assoc->ip_port.port),
last_pinged, ID2String(cptr->client_id));
loglog(logbuffer);
}
@ -1350,16 +1359,26 @@ void doMessenger(Messenger *m)
for (client = 0; client < MAX_FRIEND_CLIENTS; client++) {
Client_data *cptr = &dhtfptr->client_list[client];
last_pinged = lastdump - cptr->last_pinged;
IPPTsPng *assoc = NULL;
#ifdef CLIENT_ONETOONE_IP
assoc = &cptr->assoc;
#else
uint32_t a;
if (last_pinged > 999)
last_pinged = 999;
for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6)
#endif
if (ip_isset(&assoc->ip_port.ip)) {
last_pinged = lastdump - assoc->last_pinged;
snprintf(logbuffer, sizeof(logbuffer), "F[%2u] => C[%2u] %s:%u [%3u] %s\n",
friend, client, ip_ntoa(&cptr->ip_port.ip),
ntohs(cptr->ip_port.port), last_pinged,
ID2String(cptr->client_id));
loglog(logbuffer);
if (last_pinged > 999)
last_pinged = 999;
snprintf(logbuffer, sizeof(logbuffer), "F[%2u] => C[%2u] %s:%u [%3u] %s\n",
friend, client, ip_ntoa(&assoc->ip_port.ip),
ntohs(assoc->ip_port.port), last_pinged,
ID2String(cptr->client_id));
loglog(logbuffer);
}
}
}

View File

@ -108,11 +108,14 @@ void loginit(uint16_t port)
starttime = now();
struct tm *tm = localtime(&starttime);
if (strftime(logbuffer + 32, sizeof(logbuffer) - 32, "%F %T", tm))
sprintf(logbuffer, "%u-%s.log", ntohs(port), logbuffer + 32);
else
sprintf(logbuffer, "%u-%lu.log", ntohs(port), starttime);
logfile = fopen(logbuffer, "w");
if (logbufferpredata) {
if (logfile)
fprintf(logfile, logbufferpredata);
@ -135,6 +138,7 @@ void loglog(char *text)
/* log messages before file was opened: store */
size_t len = strlen(text);
if (!starttime) {
starttime = now();
logbufferprelen = 1024 + len - (len % 1024);

View File

@ -20,8 +20,6 @@ typedef int (*load_state_callback_func)(void *outer, uint8_t *data, uint32_t len
int load_state(load_state_callback_func load_state_callback, void *outer,
uint8_t *data, uint32_t length, uint16_t cookie_inner);
#undef LOGGING
/* #define LOGGING */
#ifdef LOGGING
extern char logbuffer[512];
void loginit(uint16_t port);