mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
expanded Client_data to hold two addresses (IPv4, IPv6) instead of one
Compilerflag: CLIENT_ONETOONE_IP (to define in DHT.h, default unset i.e. NEW case: two addresses) Every function in DHT{_test}.c working on Client_data has been rewritten to store IPv4 addresses in assoc4, IPv6 addresses in assoc6. Loading/Storing of states defined with other compiler switch is transparently adjusting to the differences. DHT.h, DHT.c: - introduction and handling of the structure changes DHT_test.c, Messenger.c: - logging adapted to new structures util.h: - LOGGING isn't undefined per default anymore
This commit is contained in:
parent
beff2b6de6
commit
9de295374d
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
708
toxcore/DHT.c
708
toxcore/DHT.c
File diff suppressed because it is too large
Load Diff
|
@ -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 {
|
||||
|
|
|
@ -1296,18 +1296,23 @@ 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
|
||||
for (assoc = &cptr->assoc4; assoc != &cptr->assoc6; assoc = &cptr->assoc6)
|
||||
#endif
|
||||
if (ip_isset(&assoc->ip_port.ip)) {
|
||||
last_pinged = lastdump - assoc->last_pinged;
|
||||
|
||||
if (ip_isset(&cptr->ip_port.ip)) {
|
||||
last_pinged = lastdump - cptr->last_pinged;
|
||||
if (last_pinged > 999)
|
||||
last_pinged = 999;
|
||||
|
||||
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),
|
||||
last_pinged, ID2String(cptr->client_id));
|
||||
loglog(logbuffer);
|
||||
}
|
||||
snprintf(logbuffer, sizeof(logbuffer), "C[%2u] %s:%u [%3u] %s\n",
|
||||
client, ip_ntoa(&assoc->ip_port.ip), ntohs(assoc->ip_port.port),
|
||||
last_pinged, ID2String(cptr->client_id));
|
||||
loglog(logbuffer);
|
||||
}
|
||||
}
|
||||
|
||||
loglog(" = = = = = = = = \n");
|
||||
|
@ -1350,16 +1355,24 @@ 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
|
||||
for (assoc = &cptr->assoc4; assoc != &cptr->assoc6; assoc = &cptr->assoc6)
|
||||
#endif
|
||||
if (ip_isset(&assoc->ip_port.ip)) {
|
||||
last_pinged = lastdump - assoc->last_pinged;
|
||||
|
||||
if (last_pinged > 999)
|
||||
last_pinged = 999;
|
||||
if (last_pinged > 999)
|
||||
last_pinged = 999;
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user