From 23fbdf4ddfcdc276b97d7f1ce10bcb075a10495a Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 30 Jul 2015 21:24:38 -0400 Subject: client_id -> public_key --- toxcore/DHT.c | 22 +++++++++++----------- 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 @@ /* Number of get node requests to send to quickly find close nodes. */ #define MAX_BOOTSTRAP_TIMES 10 -/* Compares client_id1 and client_id2 with client_id. +/* Compares pk1 and pk2 with pk. * * return 0 if both are same distance. - * return 1 if client_id1 is closer. - * return 2 if client_id2 is closer. + * return 1 if pk1 is closer. + * return 2 if pk2 is closer. */ -int id_closest(const uint8_t *id, const uint8_t *id1, const uint8_t *id2) +int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2) { size_t i; uint8_t distance1, distance2; - for (i = 0; i < CLIENT_ID_SIZE; ++i) { + for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) { - distance1 = id[i] ^ id1[i]; - distance2 = id[i] ^ id2[i]; + distance1 = pk[i] ^ pk1[i]; + distance2 = pk[i] ^ pk2[i]; if (distance1 < distance2) return 1; @@ -105,7 +105,7 @@ void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t int index = public_key[30] * MAX_KEYS_PER_SLOT + i; if (shared_keys->keys[index].stored) { - if (memcmp(public_key, shared_keys->keys[index].public_key, CLIENT_ID_SIZE) == 0) { + if (memcmp(public_key, shared_keys->keys[index].public_key, crypto_box_PUBLICKEYBYTES) == 0) { memcpy(shared_key, shared_keys->keys[index].shared_key, crypto_box_BEFORENMBYTES); ++shared_keys->keys[index].times_requested; 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 if (num != (uint32_t)~0) { shared_keys->keys[curr].stored = 1; shared_keys->keys[curr].times_requested = 1; - memcpy(shared_keys->keys[curr].public_key, public_key, CLIENT_ID_SIZE); + memcpy(shared_keys->keys[curr].public_key, public_key, crypto_box_PUBLICKEYBYTES); memcpy(shared_keys->keys[curr].shared_key, shared_key, crypto_box_BEFORENMBYTES); shared_keys->keys[curr].time_last_requested = unix_time(); } @@ -391,7 +391,7 @@ static int client_or_ip_port_in_list(Client_data *list, uint16_t length, const u if ((ip_port.ip.family == AF_INET) && ipport_equal(&list[i].assoc4.ip_port, &ip_port)) { /* Initialize client timestamp. */ list[i].assoc4.timestamp = temp_time; - memcpy(list[i].public_key, public_key, CLIENT_ID_SIZE); + memcpy(list[i].public_key, public_key, crypto_box_PUBLICKEYBYTES); LOGGER_DEBUG("coipil[%u]: switching public_key (ipv4)", i); @@ -401,7 +401,7 @@ static int client_or_ip_port_in_list(Client_data *list, uint16_t length, const u } else if ((ip_port.ip.family == AF_INET6) && ipport_equal(&list[i].assoc6.ip_port, &ip_port)) { /* Initialize client timestamp. */ list[i].assoc6.timestamp = temp_time; - memcpy(list[i].public_key, public_key, CLIENT_ID_SIZE); + memcpy(list[i].public_key, public_key, crypto_box_PUBLICKEYBYTES); LOGGER_DEBUG("coipil[%u]: switching public_key (ipv6)", i); 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 { } IPPTsPng; typedef struct { - uint8_t public_key[CLIENT_ID_SIZE]; + uint8_t public_key[crypto_box_PUBLICKEYBYTES]; IPPTsPng assoc4; IPPTsPng assoc6; } Client_data; @@ -127,7 +127,7 @@ typedef struct { #define DHT_FRIEND_MAX_LOCKS 32 typedef struct { - uint8_t public_key[CLIENT_ID_SIZE]; + uint8_t public_key[crypto_box_PUBLICKEYBYTES]; Client_data client_list[MAX_FRIEND_CLIENTS]; /* 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 #define KEYS_TIMEOUT 600 typedef struct { struct { - uint8_t public_key[CLIENT_ID_SIZE]; + uint8_t public_key[crypto_box_PUBLICKEYBYTES]; uint8_t shared_key[crypto_box_BEFORENMBYTES]; uint32_t times_requested; 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 void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id); /* Add a new friend to the friends list. - * client_id must be CLIENT_ID_SIZE bytes long. + * public_key must be crypto_box_PUBLICKEYBYTES bytes long. * * ip_callback is the callback of a function that will be called when the ip address * 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 * return 0 if success. * return -1 if failure (friends list is full). */ -int DHT_addfriend(DHT *dht, const uint8_t *client_id, void (*ip_callback)(void *data, int32_t number, IP_Port), +int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void *data, int32_t number, IP_Port), void *data, int32_t number, uint16_t *lock_count); /* Delete a friend from the friends list. - * client_id must be CLIENT_ID_SIZE bytes long. + * public_key must be crypto_box_PUBLICKEYBYTES bytes long. * * return 0 if success. - * return -1 if failure (client_id not in friends list). + * return -1 if failure (public_key not in friends list). */ -int DHT_delfriend(DHT *dht, const uint8_t *client_id, uint16_t lock_count); +int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count); /* Get ip of friend. - * client_id must be CLIENT_ID_SIZE bytes long. + * public_key must be crypto_box_PUBLICKEYBYTES bytes long. * ip must be 4 bytes long. * port must be 2 bytes long. * - * int DHT_getfriendip(DHT *dht, uint8_t *client_id, IP_Port *ip_port); + * int DHT_getfriendip(DHT *dht, uint8_t *public_key, IP_Port *ip_port); * - * return -1, -- if client_id does NOT refer to a friend - * return 0, -- if client_id refers to a friend and we failed to find the friend (yet) - * return 1, ip if client_id refers to a friend and we found him + * return -1, -- if public_key does NOT refer to a friend + * return 0, -- if public_key refers to a friend and we failed to find the friend (yet) + * return 1, ip if public_key refers to a friend and we found him */ -int DHT_getfriendip(const DHT *dht, const uint8_t *client_id, IP_Port *ip_port); +int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port); -/* Compares client_id1 and client_id2 with client_id. +/* Compares pk1 and pk2 with pk. * * return 0 if both are same distance. - * return 1 if client_id1 is closer. - * return 2 if client_id2 is closer. + * return 1 if pk1 is closer. + * return 2 if pk2 is closer. */ -int id_closest(const uint8_t *id, const uint8_t *id1, const uint8_t *id2); +int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2); -/* Get the (maximum MAX_SENT_NODES) closest nodes to client_id we know +/* Get the (maximum MAX_SENT_NODES) closest nodes to public_key we know * and put them in nodes_list (must be MAX_SENT_NODES big). * * 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); * return the number of nodes returned. * */ -int get_close_nodes(const DHT *dht, const uint8_t *client_id, Node_format *nodes_list, sa_family_t sa_family, +int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, sa_family_t sa_family, uint8_t is_LAN, uint8_t want_good); @@ -400,7 +400,7 @@ int DHT_isconnected(const DHT *dht); int DHT_non_lan_connected(const DHT *dht); -int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id); +int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key); #endif -- cgit v1.2.3