diff options
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r-- | toxcore/DHT.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index bd1acf42..e21ff824 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -65,21 +65,21 @@ | |||
65 | /* Number of get node requests to send to quickly find close nodes. */ | 65 | /* Number of get node requests to send to quickly find close nodes. */ |
66 | #define MAX_BOOTSTRAP_TIMES 10 | 66 | #define MAX_BOOTSTRAP_TIMES 10 |
67 | 67 | ||
68 | /* Compares client_id1 and client_id2 with client_id. | 68 | /* Compares pk1 and pk2 with pk. |
69 | * | 69 | * |
70 | * return 0 if both are same distance. | 70 | * return 0 if both are same distance. |
71 | * return 1 if client_id1 is closer. | 71 | * return 1 if pk1 is closer. |
72 | * return 2 if client_id2 is closer. | 72 | * return 2 if pk2 is closer. |
73 | */ | 73 | */ |
74 | int id_closest(const uint8_t *id, const uint8_t *id1, const uint8_t *id2) | 74 | int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2) |
75 | { | 75 | { |
76 | size_t i; | 76 | size_t i; |
77 | uint8_t distance1, distance2; | 77 | uint8_t distance1, distance2; |
78 | 78 | ||
79 | for (i = 0; i < CLIENT_ID_SIZE; ++i) { | 79 | for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) { |
80 | 80 | ||
81 | distance1 = id[i] ^ id1[i]; | 81 | distance1 = pk[i] ^ pk1[i]; |
82 | distance2 = id[i] ^ id2[i]; | 82 | distance2 = pk[i] ^ pk2[i]; |
83 | 83 | ||
84 | if (distance1 < distance2) | 84 | if (distance1 < distance2) |
85 | return 1; | 85 | return 1; |
@@ -105,7 +105,7 @@ void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t | |||
105 | int index = public_key[30] * MAX_KEYS_PER_SLOT + i; | 105 | int index = public_key[30] * MAX_KEYS_PER_SLOT + i; |
106 | 106 | ||
107 | if (shared_keys->keys[index].stored) { | 107 | if (shared_keys->keys[index].stored) { |
108 | if (memcmp(public_key, shared_keys->keys[index].public_key, CLIENT_ID_SIZE) == 0) { | 108 | if (memcmp(public_key, shared_keys->keys[index].public_key, crypto_box_PUBLICKEYBYTES) == 0) { |
109 | memcpy(shared_key, shared_keys->keys[index].shared_key, crypto_box_BEFORENMBYTES); | 109 | memcpy(shared_key, shared_keys->keys[index].shared_key, crypto_box_BEFORENMBYTES); |
110 | ++shared_keys->keys[index].times_requested; | 110 | ++shared_keys->keys[index].times_requested; |
111 | shared_keys->keys[index].time_last_requested = unix_time(); | 111 | shared_keys->keys[index].time_last_requested = unix_time(); |
@@ -134,7 +134,7 @@ void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t | |||
134 | if (num != (uint32_t)~0) { | 134 | if (num != (uint32_t)~0) { |
135 | shared_keys->keys[curr].stored = 1; | 135 | shared_keys->keys[curr].stored = 1; |
136 | shared_keys->keys[curr].times_requested = 1; | 136 | shared_keys->keys[curr].times_requested = 1; |
137 | memcpy(shared_keys->keys[curr].public_key, public_key, CLIENT_ID_SIZE); | 137 | memcpy(shared_keys->keys[curr].public_key, public_key, crypto_box_PUBLICKEYBYTES); |
138 | memcpy(shared_keys->keys[curr].shared_key, shared_key, crypto_box_BEFORENMBYTES); | 138 | memcpy(shared_keys->keys[curr].shared_key, shared_key, crypto_box_BEFORENMBYTES); |
139 | shared_keys->keys[curr].time_last_requested = unix_time(); | 139 | shared_keys->keys[curr].time_last_requested = unix_time(); |
140 | } | 140 | } |
@@ -391,7 +391,7 @@ static int client_or_ip_port_in_list(Client_data *list, uint16_t length, const u | |||
391 | if ((ip_port.ip.family == AF_INET) && ipport_equal(&list[i].assoc4.ip_port, &ip_port)) { | 391 | if ((ip_port.ip.family == AF_INET) && ipport_equal(&list[i].assoc4.ip_port, &ip_port)) { |
392 | /* Initialize client timestamp. */ | 392 | /* Initialize client timestamp. */ |
393 | list[i].assoc4.timestamp = temp_time; | 393 | list[i].assoc4.timestamp = temp_time; |
394 | memcpy(list[i].public_key, public_key, CLIENT_ID_SIZE); | 394 | memcpy(list[i].public_key, public_key, crypto_box_PUBLICKEYBYTES); |
395 | 395 | ||
396 | LOGGER_DEBUG("coipil[%u]: switching public_key (ipv4)", i); | 396 | LOGGER_DEBUG("coipil[%u]: switching public_key (ipv4)", i); |
397 | 397 | ||
@@ -401,7 +401,7 @@ static int client_or_ip_port_in_list(Client_data *list, uint16_t length, const u | |||
401 | } else if ((ip_port.ip.family == AF_INET6) && ipport_equal(&list[i].assoc6.ip_port, &ip_port)) { | 401 | } else if ((ip_port.ip.family == AF_INET6) && ipport_equal(&list[i].assoc6.ip_port, &ip_port)) { |
402 | /* Initialize client timestamp. */ | 402 | /* Initialize client timestamp. */ |
403 | list[i].assoc6.timestamp = temp_time; | 403 | list[i].assoc6.timestamp = temp_time; |
404 | memcpy(list[i].public_key, public_key, CLIENT_ID_SIZE); | 404 | memcpy(list[i].public_key, public_key, crypto_box_PUBLICKEYBYTES); |
405 | 405 | ||
406 | LOGGER_DEBUG("coipil[%u]: switching public_key (ipv6)", i); | 406 | LOGGER_DEBUG("coipil[%u]: switching public_key (ipv6)", i); |
407 | 407 | ||