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:
Coren[m] 2013-09-27 03:27:52 +02:00
parent beff2b6de6
commit 9de295374d
5 changed files with 623 additions and 241 deletions

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -44,7 +44,6 @@
#define MAX_TOPING 16 #define MAX_TOPING 16
typedef struct { typedef struct {
uint8_t client_id[CLIENT_ID_SIZE];
IP_Port ip_port; IP_Port ip_port;
uint64_t timestamp; uint64_t timestamp;
uint64_t last_pinged; uint64_t last_pinged;
@ -52,19 +51,22 @@ typedef struct {
/* Returned by this node. Either our friend or us. */ /* Returned by this node. Either our friend or us. */
IP_Port ret_ip_port; IP_Port ret_ip_port;
uint64_t ret_timestamp; 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 { 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 */ /* 1 if currently hole punching, otherwise 0 */
uint8_t hole_punching; uint8_t hole_punching;
uint32_t punching_index; uint32_t punching_index;
@ -72,7 +74,38 @@ typedef struct {
uint64_t recvNATping_timestamp; uint64_t recvNATping_timestamp;
uint64_t NATping_id; uint64_t NATping_id;
uint64_t NATping_timestamp; 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 */ /* this must be kept even if IP_Port is expanded: wire compatibility */
typedef struct { typedef struct {

View File

@ -1296,15 +1296,20 @@ void doMessenger(Messenger *m)
for (client = 0; client < LCLIENT_LIST; client++) { for (client = 0; client < LCLIENT_LIST; client++) {
Client_data *cptr = &m->dht->close_clientlist[client]; Client_data *cptr = &m->dht->close_clientlist[client];
IPPTsPng *assoc = NULL;
if (ip_isset(&cptr->ip_port.ip)) { #ifdef CLIENT_ONETOONE_IP
last_pinged = lastdump - cptr->last_pinged; 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) if (last_pinged > 999)
last_pinged = 999; last_pinged = 999;
snprintf(logbuffer, sizeof(logbuffer), "C[%2u] %s:%u [%3u] %s\n", 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)); last_pinged, ID2String(cptr->client_id));
loglog(logbuffer); loglog(logbuffer);
} }
@ -1350,18 +1355,26 @@ void doMessenger(Messenger *m)
for (client = 0; client < MAX_FRIEND_CLIENTS; client++) { for (client = 0; client < MAX_FRIEND_CLIENTS; client++) {
Client_data *cptr = &dhtfptr->client_list[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) if (last_pinged > 999)
last_pinged = 999; last_pinged = 999;
snprintf(logbuffer, sizeof(logbuffer), "F[%2u] => C[%2u] %s:%u [%3u] %s\n", snprintf(logbuffer, sizeof(logbuffer), "F[%2u] => C[%2u] %s:%u [%3u] %s\n",
friend, client, ip_ntoa(&cptr->ip_port.ip), friend, client, ip_ntoa(&assoc->ip_port.ip),
ntohs(cptr->ip_port.port), last_pinged, ntohs(assoc->ip_port.port), last_pinged,
ID2String(cptr->client_id)); ID2String(cptr->client_id));
loglog(logbuffer); loglog(logbuffer);
} }
} }
}
loglog(" = = = = = = = = \n"); loglog(" = = = = = = = = \n");
} }

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, int load_state(load_state_callback_func load_state_callback, void *outer,
uint8_t *data, uint32_t length, uint16_t cookie_inner); uint8_t *data, uint32_t length, uint16_t cookie_inner);
#undef LOGGING
/* #define LOGGING */
#ifdef LOGGING #ifdef LOGGING
extern char logbuffer[512]; extern char logbuffer[512];
void loginit(uint16_t port); void loginit(uint16_t port);