diff options
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r-- | toxcore/DHT.c | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index ac43371e..5041cc4e 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -2335,54 +2335,54 @@ void DHT_save(DHT *dht, uint8_t *data) | |||
2335 | 2335 | ||
2336 | static void DHT_bootstrap_loaded_clients(DHT *dht) | 2336 | static void DHT_bootstrap_loaded_clients(DHT *dht) |
2337 | { | 2337 | { |
2338 | uint32_t i; | 2338 | uint32_t i; |
2339 | 2339 | ||
2340 | Client_data *client_list = dht->loaded_clients_list; | 2340 | Client_data *client_list = dht->loaded_clients_list; |
2341 | uint32_t client_count = dht->loaded_num_clients; | 2341 | uint32_t client_count = dht->loaded_num_clients; |
2342 | 2342 | ||
2343 | for (i = 0; i < client_count; ++i) { | 2343 | for (i = 0; i < client_count; ++i) { |
2344 | if (client_list[i].assoc4.timestamp != 0) | 2344 | if (client_list[i].assoc4.timestamp != 0) |
2345 | DHT_bootstrap(dht, client_list[i].assoc4.ip_port, client_list[i].client_id); | 2345 | DHT_bootstrap(dht, client_list[i].assoc4.ip_port, client_list[i].client_id); |
2346 | 2346 | ||
2347 | if (client_list[i].assoc6.timestamp != 0) | 2347 | if (client_list[i].assoc6.timestamp != 0) |
2348 | DHT_bootstrap(dht, client_list[i].assoc6.ip_port, client_list[i].client_id); | 2348 | DHT_bootstrap(dht, client_list[i].assoc6.ip_port, client_list[i].client_id); |
2349 | } | 2349 | } |
2350 | } | 2350 | } |
2351 | 2351 | ||
2352 | static void getnodes_of_loaded_friend_clients(DHT *dht) | 2352 | static void getnodes_of_loaded_friend_clients(DHT *dht) |
2353 | { | 2353 | { |
2354 | uint32_t i, j; | 2354 | uint32_t i, j; |
2355 | 2355 | ||
2356 | DHT_Friend *friend_list = dht->loaded_friends_list; | 2356 | DHT_Friend *friend_list = dht->loaded_friends_list; |
2357 | uint32_t friend_count = dht->loaded_num_friends; | 2357 | uint32_t friend_count = dht->loaded_num_friends; |
2358 | 2358 | ||
2359 | for (i = 0; i < friend_count; ++i) { | 2359 | for (i = 0; i < friend_count; ++i) { |
2360 | for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { | 2360 | for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { |
2361 | Client_data *client = &friend_list[i].client_list[j]; | 2361 | Client_data *client = &friend_list[i].client_list[j]; |
2362 | 2362 | ||
2363 | if (client->assoc4.timestamp != 0) | 2363 | if (client->assoc4.timestamp != 0) |
2364 | getnodes(dht, client->assoc4.ip_port, client->client_id, friend_list[i].client_id, NULL); | 2364 | getnodes(dht, client->assoc4.ip_port, client->client_id, friend_list[i].client_id, NULL); |
2365 | 2365 | ||
2366 | if (client->assoc6.timestamp != 0) | 2366 | if (client->assoc6.timestamp != 0) |
2367 | getnodes(dht, client->assoc6.ip_port, client->client_id, friend_list[i].client_id, NULL); | 2367 | getnodes(dht, client->assoc6.ip_port, client->client_id, friend_list[i].client_id, NULL); |
2368 | } | 2368 | } |
2369 | } | 2369 | } |
2370 | } | 2370 | } |
2371 | 2371 | ||
2372 | /* Start sending packets after DHT loaded_friends_list and loaded_clients_list are set */ | 2372 | /* Start sending packets after DHT loaded_friends_list and loaded_clients_list are set */ |
2373 | int DHT_connect_after_load(DHT *dht) | 2373 | int DHT_connect_after_load(DHT *dht) |
2374 | { | 2374 | { |
2375 | if(dht == NULL || dht->loaded_friends_list == NULL || dht->loaded_clients_list == NULL) | 2375 | if(dht == NULL || dht->loaded_friends_list == NULL || dht->loaded_clients_list == NULL) |
2376 | return -1; | 2376 | return -1; |
2377 | 2377 | ||
2378 | getnodes_of_loaded_friend_clients(dht); | 2378 | getnodes_of_loaded_friend_clients(dht); |
2379 | DHT_bootstrap_loaded_clients(dht); | 2379 | DHT_bootstrap_loaded_clients(dht); |
2380 | 2380 | ||
2381 | // Loaded lists were allocd, free them | 2381 | // Loaded lists were allocd, free them |
2382 | free(dht->loaded_friends_list); | 2382 | free(dht->loaded_friends_list); |
2383 | free(dht->loaded_clients_list); | 2383 | free(dht->loaded_clients_list); |
2384 | 2384 | ||
2385 | return 0; | 2385 | return 0; |
2386 | } | 2386 | } |
2387 | 2387 | ||
2388 | static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type) | 2388 | static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type) |
@@ -2399,11 +2399,11 @@ static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t le | |||
2399 | DHT_Friend *friend_list = (DHT_Friend *)data; | 2399 | DHT_Friend *friend_list = (DHT_Friend *)data; |
2400 | num = length / sizeof(DHT_Friend); | 2400 | num = length / sizeof(DHT_Friend); |
2401 | 2401 | ||
2402 | // Copy to loaded_friends_list | 2402 | // Copy to loaded_friends_list |
2403 | dht->loaded_friends_list = calloc(num, sizeof(DHT_Friend)); | 2403 | dht->loaded_friends_list = calloc(num, sizeof(DHT_Friend)); |
2404 | for(i = 0; i < num; i++) | 2404 | for(i = 0; i < num; i++) |
2405 | memcpy(&(dht->loaded_friends_list[i]), &(friend_list[i]), sizeof(DHT_Friend)); | 2405 | memcpy(&(dht->loaded_friends_list[i]), &(friend_list[i]), sizeof(DHT_Friend)); |
2406 | dht->loaded_num_friends = num; | 2406 | dht->loaded_num_friends = num; |
2407 | 2407 | ||
2408 | } /* localize declarations */ | 2408 | } /* localize declarations */ |
2409 | 2409 | ||
@@ -2417,11 +2417,11 @@ static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t le | |||
2417 | num = length / sizeof(Client_data); | 2417 | num = length / sizeof(Client_data); |
2418 | Client_data *client_list = (Client_data *)data; | 2418 | Client_data *client_list = (Client_data *)data; |
2419 | 2419 | ||
2420 | // Copy to loaded_clients_list | 2420 | // Copy to loaded_clients_list |
2421 | dht->loaded_clients_list = calloc(num, sizeof(Client_data)); | 2421 | dht->loaded_clients_list = calloc(num, sizeof(Client_data)); |
2422 | for(i = 0; i < num; i++) | 2422 | for(i = 0; i < num; i++) |
2423 | memcpy(&(dht->loaded_clients_list[i]), &(client_list[i]), sizeof(Client_data)); | 2423 | memcpy(&(dht->loaded_clients_list[i]), &(client_list[i]), sizeof(Client_data)); |
2424 | dht->loaded_num_clients = num; | 2424 | dht->loaded_num_clients = num; |
2425 | 2425 | ||
2426 | } /* localize declarations */ | 2426 | } /* localize declarations */ |
2427 | 2427 | ||