diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/DHT.c | 22 | ||||
-rw-r--r-- | toxcore/DHT.h | 42 |
2 files changed, 32 insertions, 32 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 | ||
diff --git a/toxcore/DHT.h b/toxcore/DHT.h index c437bbb0..a36ea252 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h | |||
@@ -104,7 +104,7 @@ typedef struct { | |||
104 | } IPPTsPng; | 104 | } IPPTsPng; |
105 | 105 | ||
106 | typedef struct { | 106 | typedef struct { |
107 | uint8_t public_key[CLIENT_ID_SIZE]; | 107 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; |
108 | IPPTsPng assoc4; | 108 | IPPTsPng assoc4; |
109 | IPPTsPng assoc6; | 109 | IPPTsPng assoc6; |
110 | } Client_data; | 110 | } Client_data; |
@@ -127,7 +127,7 @@ typedef struct { | |||
127 | #define DHT_FRIEND_MAX_LOCKS 32 | 127 | #define DHT_FRIEND_MAX_LOCKS 32 |
128 | 128 | ||
129 | typedef struct { | 129 | typedef struct { |
130 | uint8_t public_key[CLIENT_ID_SIZE]; | 130 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; |
131 | Client_data client_list[MAX_FRIEND_CLIENTS]; | 131 | Client_data client_list[MAX_FRIEND_CLIENTS]; |
132 | 132 | ||
133 | /* Time at which the last get_nodes request was sent. */ | 133 | /* Time at which the last get_nodes request was sent. */ |
@@ -182,7 +182,7 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed | |||
182 | #define KEYS_TIMEOUT 600 | 182 | #define KEYS_TIMEOUT 600 |
183 | typedef struct { | 183 | typedef struct { |
184 | struct { | 184 | struct { |
185 | uint8_t public_key[CLIENT_ID_SIZE]; | 185 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; |
186 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; | 186 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; |
187 | uint32_t times_requested; | 187 | uint32_t times_requested; |
188 | uint8_t stored; /* 0 if not, 1 if is */ | 188 | uint8_t stored; /* 0 if not, 1 if is */ |
@@ -257,7 +257,7 @@ void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *publi | |||
257 | void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id); | 257 | void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id); |
258 | 258 | ||
259 | /* Add a new friend to the friends list. | 259 | /* Add a new friend to the friends list. |
260 | * client_id must be CLIENT_ID_SIZE bytes long. | 260 | * public_key must be crypto_box_PUBLICKEYBYTES bytes long. |
261 | * | 261 | * |
262 | * ip_callback is the callback of a function that will be called when the ip address | 262 | * ip_callback is the callback of a function that will be called when the ip address |
263 | * is found along with arguments data and number. | 263 | * is found along with arguments data and number. |
@@ -268,39 +268,39 @@ void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, con | |||
268 | * return 0 if success. | 268 | * return 0 if success. |
269 | * return -1 if failure (friends list is full). | 269 | * return -1 if failure (friends list is full). |
270 | */ | 270 | */ |
271 | int DHT_addfriend(DHT *dht, const uint8_t *client_id, void (*ip_callback)(void *data, int32_t number, IP_Port), | 271 | int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void *data, int32_t number, IP_Port), |
272 | void *data, int32_t number, uint16_t *lock_count); | 272 | void *data, int32_t number, uint16_t *lock_count); |
273 | 273 | ||
274 | /* Delete a friend from the friends list. | 274 | /* Delete a friend from the friends list. |
275 | * client_id must be CLIENT_ID_SIZE bytes long. | 275 | * public_key must be crypto_box_PUBLICKEYBYTES bytes long. |
276 | * | 276 | * |
277 | * return 0 if success. | 277 | * return 0 if success. |
278 | * return -1 if failure (client_id not in friends list). | 278 | * return -1 if failure (public_key not in friends list). |
279 | */ | 279 | */ |
280 | int DHT_delfriend(DHT *dht, const uint8_t *client_id, uint16_t lock_count); | 280 | int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count); |
281 | 281 | ||
282 | /* Get ip of friend. | 282 | /* Get ip of friend. |
283 | * client_id must be CLIENT_ID_SIZE bytes long. | 283 | * public_key must be crypto_box_PUBLICKEYBYTES bytes long. |
284 | * ip must be 4 bytes long. | 284 | * ip must be 4 bytes long. |
285 | * port must be 2 bytes long. | 285 | * port must be 2 bytes long. |
286 | * | 286 | * |
287 | * int DHT_getfriendip(DHT *dht, uint8_t *client_id, IP_Port *ip_port); | 287 | * int DHT_getfriendip(DHT *dht, uint8_t *public_key, IP_Port *ip_port); |
288 | * | 288 | * |
289 | * return -1, -- if client_id does NOT refer to a friend | 289 | * return -1, -- if public_key does NOT refer to a friend |
290 | * return 0, -- if client_id refers to a friend and we failed to find the friend (yet) | 290 | * return 0, -- if public_key refers to a friend and we failed to find the friend (yet) |
291 | * return 1, ip if client_id refers to a friend and we found him | 291 | * return 1, ip if public_key refers to a friend and we found him |
292 | */ | 292 | */ |
293 | int DHT_getfriendip(const DHT *dht, const uint8_t *client_id, IP_Port *ip_port); | 293 | int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port); |
294 | 294 | ||
295 | /* Compares client_id1 and client_id2 with client_id. | 295 | /* Compares pk1 and pk2 with pk. |
296 | * | 296 | * |
297 | * return 0 if both are same distance. | 297 | * return 0 if both are same distance. |
298 | * return 1 if client_id1 is closer. | 298 | * return 1 if pk1 is closer. |
299 | * return 2 if client_id2 is closer. | 299 | * return 2 if pk2 is closer. |
300 | */ | 300 | */ |
301 | int id_closest(const uint8_t *id, const uint8_t *id1, const uint8_t *id2); | 301 | int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2); |
302 | 302 | ||
303 | /* Get the (maximum MAX_SENT_NODES) closest nodes to client_id we know | 303 | /* Get the (maximum MAX_SENT_NODES) closest nodes to public_key we know |
304 | * and put them in nodes_list (must be MAX_SENT_NODES big). | 304 | * and put them in nodes_list (must be MAX_SENT_NODES big). |
305 | * | 305 | * |
306 | * sa_family = family (IPv4 or IPv6) (0 if we don't care)? | 306 | * sa_family = family (IPv4 or IPv6) (0 if we don't care)? |
@@ -310,7 +310,7 @@ int id_closest(const uint8_t *id, const uint8_t *id1, const uint8_t *id2); | |||
310 | * return the number of nodes returned. | 310 | * return the number of nodes returned. |
311 | * | 311 | * |
312 | */ | 312 | */ |
313 | int get_close_nodes(const DHT *dht, const uint8_t *client_id, Node_format *nodes_list, sa_family_t sa_family, | 313 | int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, sa_family_t sa_family, |
314 | uint8_t is_LAN, uint8_t want_good); | 314 | uint8_t is_LAN, uint8_t want_good); |
315 | 315 | ||
316 | 316 | ||
@@ -400,7 +400,7 @@ int DHT_isconnected(const DHT *dht); | |||
400 | int DHT_non_lan_connected(const DHT *dht); | 400 | int DHT_non_lan_connected(const DHT *dht); |
401 | 401 | ||
402 | 402 | ||
403 | int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id); | 403 | int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key); |
404 | 404 | ||
405 | #endif | 405 | #endif |
406 | 406 | ||