diff options
author | irungentoo <irungentoo@gmail.com> | 2015-01-27 20:56:39 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-01-27 20:56:39 -0500 |
commit | 10ef3a674f16a02045c5135b4d568d3a2b53b8c4 (patch) | |
tree | 32c29fb928b5e567486d6e8339bcfe0cad639adf /toxcore | |
parent | 548d87794bb334647adbf1b9ef136095ed399f9d (diff) |
client_id is a bad name for the long term public key.
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Messenger.c | 70 | ||||
-rw-r--r-- | toxcore/Messenger.h | 14 | ||||
-rw-r--r-- | toxcore/tox.c | 2 |
3 files changed, 43 insertions, 43 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index b3663fe6..0b1c609e 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -89,32 +89,32 @@ int realloc_friendlist(Messenger *m, uint32_t num) | |||
89 | /* return the friend id associated to that public key. | 89 | /* return the friend id associated to that public key. |
90 | * return -1 if no such friend. | 90 | * return -1 if no such friend. |
91 | */ | 91 | */ |
92 | int32_t getfriend_id(const Messenger *m, const uint8_t *client_id) | 92 | int32_t getfriend_id(const Messenger *m, const uint8_t *real_pk) |
93 | { | 93 | { |
94 | uint32_t i; | 94 | uint32_t i; |
95 | 95 | ||
96 | for (i = 0; i < m->numfriends; ++i) { | 96 | for (i = 0; i < m->numfriends; ++i) { |
97 | if (m->friendlist[i].status > 0) | 97 | if (m->friendlist[i].status > 0) |
98 | if (id_equal(client_id, m->friendlist[i].client_id)) | 98 | if (id_equal(real_pk, m->friendlist[i].real_pk)) |
99 | return i; | 99 | return i; |
100 | } | 100 | } |
101 | 101 | ||
102 | return -1; | 102 | return -1; |
103 | } | 103 | } |
104 | 104 | ||
105 | /* Copies the public key associated to that friend id into client_id buffer. | 105 | /* Copies the public key associated to that friend id into real_pk buffer. |
106 | * Make sure that client_id is of size CLIENT_ID_SIZE. | 106 | * Make sure that real_pk is of size crypto_box_PUBLICKEYBYTES. |
107 | * | 107 | * |
108 | * return 0 if success. | 108 | * return 0 if success. |
109 | * return -1 if failure. | 109 | * return -1 if failure. |
110 | */ | 110 | */ |
111 | int getclient_id(const Messenger *m, int32_t friendnumber, uint8_t *client_id) | 111 | int get_real_pk(const Messenger *m, int32_t friendnumber, uint8_t *real_pk) |
112 | { | 112 | { |
113 | if (friend_not_valid(m, friendnumber)) | 113 | if (friend_not_valid(m, friendnumber)) |
114 | return -1; | 114 | return -1; |
115 | 115 | ||
116 | if (m->friendlist[friendnumber].status > 0) { | 116 | if (m->friendlist[friendnumber].status > 0) { |
117 | memcpy(client_id, m->friendlist[friendnumber].client_id, CLIENT_ID_SIZE); | 117 | memcpy(real_pk, m->friendlist[friendnumber].real_pk, crypto_box_PUBLICKEYBYTES); |
118 | return 0; | 118 | return 0; |
119 | } | 119 | } |
120 | 120 | ||
@@ -149,7 +149,7 @@ static uint16_t address_checksum(const uint8_t *address, uint32_t len) | |||
149 | return check; | 149 | return check; |
150 | } | 150 | } |
151 | 151 | ||
152 | /* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] | 152 | /* Format: [real_pk (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] |
153 | * | 153 | * |
154 | * return FRIEND_ADDRESS_SIZE byte address to give to others. | 154 | * return FRIEND_ADDRESS_SIZE byte address to give to others. |
155 | */ | 155 | */ |
@@ -183,7 +183,7 @@ static int handle_status(void *object, int i, uint8_t status); | |||
183 | static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len); | 183 | static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len); |
184 | static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length); | 184 | static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length); |
185 | 185 | ||
186 | static int32_t init_new_friend(Messenger *m, const uint8_t *client_id, uint8_t status) | 186 | static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t status) |
187 | { | 187 | { |
188 | /* Resize the friend list if necessary. */ | 188 | /* Resize the friend list if necessary. */ |
189 | if (realloc_friendlist(m, m->numfriends + 1) != 0) | 189 | if (realloc_friendlist(m, m->numfriends + 1) != 0) |
@@ -191,7 +191,7 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *client_id, uint8_t s | |||
191 | 191 | ||
192 | memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend)); | 192 | memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend)); |
193 | 193 | ||
194 | int friendcon_id = new_friend_connection(m->fr_c, client_id); | 194 | int friendcon_id = new_friend_connection(m->fr_c, real_pk); |
195 | 195 | ||
196 | if (friendcon_id == -1) | 196 | if (friendcon_id == -1) |
197 | return FAERR_UNKNOWN; | 197 | return FAERR_UNKNOWN; |
@@ -203,7 +203,7 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *client_id, uint8_t s | |||
203 | m->friendlist[i].status = status; | 203 | m->friendlist[i].status = status; |
204 | m->friendlist[i].friendcon_id = friendcon_id; | 204 | m->friendlist[i].friendcon_id = friendcon_id; |
205 | m->friendlist[i].friendrequest_lastsent = 0; | 205 | m->friendlist[i].friendrequest_lastsent = 0; |
206 | id_copy(m->friendlist[i].client_id, client_id); | 206 | id_copy(m->friendlist[i].real_pk, real_pk); |
207 | m->friendlist[i].statusmessage = calloc(1, 1); | 207 | m->friendlist[i].statusmessage = calloc(1, 1); |
208 | m->friendlist[i].statusmessage_length = 1; | 208 | m->friendlist[i].statusmessage_length = 1; |
209 | m->friendlist[i].userstatus = USERSTATUS_NONE; | 209 | m->friendlist[i].userstatus = USERSTATUS_NONE; |
@@ -253,10 +253,10 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u | |||
253 | if (length > MAX_FRIEND_REQUEST_DATA_SIZE) | 253 | if (length > MAX_FRIEND_REQUEST_DATA_SIZE) |
254 | return FAERR_TOOLONG; | 254 | return FAERR_TOOLONG; |
255 | 255 | ||
256 | uint8_t client_id[crypto_box_PUBLICKEYBYTES]; | 256 | uint8_t real_pk[crypto_box_PUBLICKEYBYTES]; |
257 | id_copy(client_id, address); | 257 | id_copy(real_pk, address); |
258 | 258 | ||
259 | if (!public_key_valid(client_id)) | 259 | if (!public_key_valid(real_pk)) |
260 | return FAERR_BADCHECKSUM; | 260 | return FAERR_BADCHECKSUM; |
261 | 261 | ||
262 | uint16_t check, checksum = address_checksum(address, FRIEND_ADDRESS_SIZE - sizeof(checksum)); | 262 | uint16_t check, checksum = address_checksum(address, FRIEND_ADDRESS_SIZE - sizeof(checksum)); |
@@ -268,10 +268,10 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u | |||
268 | if (length < 1) | 268 | if (length < 1) |
269 | return FAERR_NOMESSAGE; | 269 | return FAERR_NOMESSAGE; |
270 | 270 | ||
271 | if (id_equal(client_id, m->net_crypto->self_public_key)) | 271 | if (id_equal(real_pk, m->net_crypto->self_public_key)) |
272 | return FAERR_OWNKEY; | 272 | return FAERR_OWNKEY; |
273 | 273 | ||
274 | int32_t friend_id = getfriend_id(m, client_id); | 274 | int32_t friend_id = getfriend_id(m, real_pk); |
275 | 275 | ||
276 | if (friend_id != -1) { | 276 | if (friend_id != -1) { |
277 | if (m->friendlist[friend_id].status >= FRIEND_CONFIRMED) | 277 | if (m->friendlist[friend_id].status >= FRIEND_CONFIRMED) |
@@ -287,7 +287,7 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u | |||
287 | return FAERR_SETNEWNOSPAM; | 287 | return FAERR_SETNEWNOSPAM; |
288 | } | 288 | } |
289 | 289 | ||
290 | int32_t ret = init_new_friend(m, client_id, FRIEND_ADDED); | 290 | int32_t ret = init_new_friend(m, real_pk, FRIEND_ADDED); |
291 | 291 | ||
292 | if (ret < 0) { | 292 | if (ret < 0) { |
293 | return ret; | 293 | return ret; |
@@ -301,18 +301,18 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u | |||
301 | return ret; | 301 | return ret; |
302 | } | 302 | } |
303 | 303 | ||
304 | int32_t m_addfriend_norequest(Messenger *m, const uint8_t *client_id) | 304 | int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk) |
305 | { | 305 | { |
306 | if (getfriend_id(m, client_id) != -1) | 306 | if (getfriend_id(m, real_pk) != -1) |
307 | return -1; | 307 | return -1; |
308 | 308 | ||
309 | if (!public_key_valid(client_id)) | 309 | if (!public_key_valid(real_pk)) |
310 | return -1; | 310 | return -1; |
311 | 311 | ||
312 | if (id_equal(client_id, m->net_crypto->self_public_key)) | 312 | if (id_equal(real_pk, m->net_crypto->self_public_key)) |
313 | return -1; | 313 | return -1; |
314 | 314 | ||
315 | int32_t ret = init_new_friend(m, client_id, FRIEND_CONFIRMED); | 315 | int32_t ret = init_new_friend(m, real_pk, FRIEND_CONFIRMED); |
316 | 316 | ||
317 | if (ret < 0) { | 317 | if (ret < 0) { |
318 | return -1; | 318 | return -1; |
@@ -336,7 +336,7 @@ int m_delfriend(Messenger *m, int32_t friendnumber) | |||
336 | 336 | ||
337 | free(m->friendlist[friendnumber].statusmessage); | 337 | free(m->friendlist[friendnumber].statusmessage); |
338 | free(m->friendlist[friendnumber].avatar_recv_data); | 338 | free(m->friendlist[friendnumber].avatar_recv_data); |
339 | remove_request_received(&(m->fr), m->friendlist[friendnumber].client_id); | 339 | remove_request_received(&(m->fr), m->friendlist[friendnumber].real_pk); |
340 | friend_connection_callbacks(m->fr_c, m->friendlist[friendnumber].friendcon_id, MESSENGER_CALLBACK_INDEX, 0, 0, 0, 0, 0); | 340 | friend_connection_callbacks(m->fr_c, m->friendlist[friendnumber].friendcon_id, MESSENGER_CALLBACK_INDEX, 0, 0, 0, 0, 0); |
341 | kill_friend_connection(m->fr_c, m->friendlist[friendnumber].friendcon_id); | 341 | kill_friend_connection(m->fr_c, m->friendlist[friendnumber].friendcon_id); |
342 | 342 | ||
@@ -1518,11 +1518,11 @@ int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const | |||
1518 | } | 1518 | } |
1519 | 1519 | ||
1520 | /* Function to filter out some friend requests*/ | 1520 | /* Function to filter out some friend requests*/ |
1521 | static int friend_already_added(const uint8_t *client_id, void *data) | 1521 | static int friend_already_added(const uint8_t *real_pk, void *data) |
1522 | { | 1522 | { |
1523 | const Messenger *m = data; | 1523 | const Messenger *m = data; |
1524 | 1524 | ||
1525 | if (getfriend_id(m, client_id) == -1) | 1525 | if (getfriend_id(m, real_pk) == -1) |
1526 | return 0; | 1526 | return 0; |
1527 | 1527 | ||
1528 | return -1; | 1528 | return -1; |
@@ -2316,15 +2316,15 @@ void do_friends(Messenger *m) | |||
2316 | #ifdef LOGGING | 2316 | #ifdef LOGGING |
2317 | #define DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS 60UL | 2317 | #define DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS 60UL |
2318 | static time_t lastdump = 0; | 2318 | static time_t lastdump = 0; |
2319 | static char IDString[CLIENT_ID_SIZE * 2 + 1]; | 2319 | static char IDString[crypto_box_PUBLICKEYBYTES * 2 + 1]; |
2320 | static char *ID2String(const uint8_t *client_id) | 2320 | static char *ID2String(const uint8_t *pk) |
2321 | { | 2321 | { |
2322 | uint32_t i; | 2322 | uint32_t i; |
2323 | 2323 | ||
2324 | for (i = 0; i < CLIENT_ID_SIZE; i++) | 2324 | for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++) |
2325 | sprintf(&IDString[i * 2], "%02X", client_id[i]); | 2325 | sprintf(&IDString[i * 2], "%02X", pk[i]); |
2326 | 2326 | ||
2327 | IDString[CLIENT_ID_SIZE * 2] = 0; | 2327 | IDString[crypto_box_PUBLICKEYBYTES * 2] = 0; |
2328 | return IDString; | 2328 | return IDString; |
2329 | } | 2329 | } |
2330 | #endif | 2330 | #endif |
@@ -2421,7 +2421,7 @@ void do_messenger(Messenger *m) | |||
2421 | continue; | 2421 | continue; |
2422 | 2422 | ||
2423 | for (dhtfriend = 0; dhtfriend < m->dht->num_friends; dhtfriend++) | 2423 | for (dhtfriend = 0; dhtfriend < m->dht->num_friends; dhtfriend++) |
2424 | if (id_equal(m->friendlist[friend].client_id, m->dht->friends_list[dhtfriend].client_id)) { | 2424 | if (id_equal(m->friendlist[friend].real_pk, m->dht->friends_list[dhtfriend].client_id)) { |
2425 | m2dht[friend] = dhtfriend; | 2425 | m2dht[friend] = dhtfriend; |
2426 | break; | 2426 | break; |
2427 | } | 2427 | } |
@@ -2455,7 +2455,7 @@ void do_messenger(Messenger *m) | |||
2455 | 2455 | ||
2456 | LOGGER_TRACE("F[%2u:%2u] <%s> [%03u] %s", | 2456 | LOGGER_TRACE("F[%2u:%2u] <%s> [%03u] %s", |
2457 | dht2m[friend], friend, msgfptr->name, | 2457 | dht2m[friend], friend, msgfptr->name, |
2458 | ping_lastrecv, ID2String(msgfptr->client_id)); | 2458 | ping_lastrecv, ID2String(msgfptr->real_pk)); |
2459 | } else { | 2459 | } else { |
2460 | LOGGER_TRACE("F[--:%2u] %s", friend, ID2String(dhtfptr->client_id)); | 2460 | LOGGER_TRACE("F[--:%2u] %s", friend, ID2String(dhtfptr->client_id)); |
2461 | } | 2461 | } |
@@ -2502,7 +2502,7 @@ void do_messenger(Messenger *m) | |||
2502 | #define NUM_SAVED_PATH_NODES 8 | 2502 | #define NUM_SAVED_PATH_NODES 8 |
2503 | struct SAVED_FRIEND { | 2503 | struct SAVED_FRIEND { |
2504 | uint8_t status; | 2504 | uint8_t status; |
2505 | uint8_t client_id[CLIENT_ID_SIZE]; | 2505 | uint8_t real_pk[crypto_box_PUBLICKEYBYTES]; |
2506 | uint8_t info[SAVED_FRIEND_REQUEST_SIZE]; // the data that is sent during the friend requests we do. | 2506 | uint8_t info[SAVED_FRIEND_REQUEST_SIZE]; // the data that is sent during the friend requests we do. |
2507 | uint16_t info_size; // Length of the info. | 2507 | uint16_t info_size; // Length of the info. |
2508 | uint8_t name[MAX_NAME_LENGTH]; | 2508 | uint8_t name[MAX_NAME_LENGTH]; |
@@ -2529,7 +2529,7 @@ static uint32_t friends_list_save(const Messenger *m, uint8_t *data) | |||
2529 | struct SAVED_FRIEND temp; | 2529 | struct SAVED_FRIEND temp; |
2530 | memset(&temp, 0, sizeof(struct SAVED_FRIEND)); | 2530 | memset(&temp, 0, sizeof(struct SAVED_FRIEND)); |
2531 | temp.status = m->friendlist[i].status; | 2531 | temp.status = m->friendlist[i].status; |
2532 | memcpy(temp.client_id, m->friendlist[i].client_id, CLIENT_ID_SIZE); | 2532 | memcpy(temp.real_pk, m->friendlist[i].real_pk, crypto_box_PUBLICKEYBYTES); |
2533 | 2533 | ||
2534 | if (temp.status < 3) { | 2534 | if (temp.status < 3) { |
2535 | if (m->friendlist[i].info_size > SAVED_FRIEND_REQUEST_SIZE) { | 2535 | if (m->friendlist[i].info_size > SAVED_FRIEND_REQUEST_SIZE) { |
@@ -2575,7 +2575,7 @@ static int friends_list_load(Messenger *m, const uint8_t *data, uint32_t length) | |||
2575 | memcpy(&temp, data + i * sizeof(struct SAVED_FRIEND), sizeof(struct SAVED_FRIEND)); | 2575 | memcpy(&temp, data + i * sizeof(struct SAVED_FRIEND), sizeof(struct SAVED_FRIEND)); |
2576 | 2576 | ||
2577 | if (temp.status >= 3) { | 2577 | if (temp.status >= 3) { |
2578 | int fnum = m_addfriend_norequest(m, temp.client_id); | 2578 | int fnum = m_addfriend_norequest(m, temp.real_pk); |
2579 | 2579 | ||
2580 | if (fnum < 0) | 2580 | if (fnum < 0) |
2581 | continue; | 2581 | continue; |
@@ -2590,7 +2590,7 @@ static int friends_list_load(Messenger *m, const uint8_t *data, uint32_t length) | |||
2590 | } else if (temp.status != 0) { | 2590 | } else if (temp.status != 0) { |
2591 | /* TODO: This is not a good way to do this. */ | 2591 | /* TODO: This is not a good way to do this. */ |
2592 | uint8_t address[FRIEND_ADDRESS_SIZE]; | 2592 | uint8_t address[FRIEND_ADDRESS_SIZE]; |
2593 | id_copy(address, temp.client_id); | 2593 | id_copy(address, temp.real_pk); |
2594 | memcpy(address + crypto_box_PUBLICKEYBYTES, &(temp.friendrequest_nospam), sizeof(uint32_t)); | 2594 | memcpy(address + crypto_box_PUBLICKEYBYTES, &(temp.friendrequest_nospam), sizeof(uint32_t)); |
2595 | uint16_t checksum = address_checksum(address, FRIEND_ADDRESS_SIZE - sizeof(checksum)); | 2595 | uint16_t checksum = address_checksum(address, FRIEND_ADDRESS_SIZE - sizeof(checksum)); |
2596 | memcpy(address + crypto_box_PUBLICKEYBYTES + sizeof(uint32_t), &checksum, sizeof(checksum)); | 2596 | memcpy(address + crypto_box_PUBLICKEYBYTES + sizeof(uint32_t), &checksum, sizeof(checksum)); |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 3851edf7..a9931d1f 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -191,7 +191,7 @@ enum { | |||
191 | typedef struct Messenger Messenger; | 191 | typedef struct Messenger Messenger; |
192 | 192 | ||
193 | typedef struct { | 193 | typedef struct { |
194 | uint8_t client_id[crypto_box_PUBLICKEYBYTES]; | 194 | uint8_t real_pk[crypto_box_PUBLICKEYBYTES]; |
195 | int friendcon_id; | 195 | int friendcon_id; |
196 | 196 | ||
197 | uint64_t friendrequest_lastsent; // Time at which the last friend request was sent. | 197 | uint64_t friendrequest_lastsent; // Time at which the last friend request was sent. |
@@ -313,7 +313,7 @@ struct Messenger { | |||
313 | Messenger_Options options; | 313 | Messenger_Options options; |
314 | }; | 314 | }; |
315 | 315 | ||
316 | /* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] | 316 | /* Format: [real_pk (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] |
317 | * | 317 | * |
318 | * return FRIEND_ADDRESS_SIZE byte address to give to others. | 318 | * return FRIEND_ADDRESS_SIZE byte address to give to others. |
319 | */ | 319 | */ |
@@ -342,20 +342,20 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u | |||
342 | * return the friend number if success. | 342 | * return the friend number if success. |
343 | * return -1 if failure. | 343 | * return -1 if failure. |
344 | */ | 344 | */ |
345 | int32_t m_addfriend_norequest(Messenger *m, const uint8_t *client_id); | 345 | int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk); |
346 | 346 | ||
347 | /* return the friend number associated to that client id. | 347 | /* return the friend number associated to that client id. |
348 | * return -1 if no such friend. | 348 | * return -1 if no such friend. |
349 | */ | 349 | */ |
350 | int32_t getfriend_id(const Messenger *m, const uint8_t *client_id); | 350 | int32_t getfriend_id(const Messenger *m, const uint8_t *real_pk); |
351 | 351 | ||
352 | /* Copies the public key associated to that friend id into client_id buffer. | 352 | /* Copies the public key associated to that friend id into real_pk buffer. |
353 | * Make sure that client_id is of size CLIENT_ID_SIZE. | 353 | * Make sure that real_pk is of size crypto_box_PUBLICKEYBYTES. |
354 | * | 354 | * |
355 | * return 0 if success | 355 | * return 0 if success |
356 | * return -1 if failure | 356 | * return -1 if failure |
357 | */ | 357 | */ |
358 | int getclient_id(const Messenger *m, int32_t friendnumber, uint8_t *client_id); | 358 | int get_real_pk(const Messenger *m, int32_t friendnumber, uint8_t *real_pk); |
359 | 359 | ||
360 | /* return friend connection id on success. | 360 | /* return friend connection id on success. |
361 | * return -1 if failure. | 361 | * return -1 if failure. |
diff --git a/toxcore/tox.c b/toxcore/tox.c index a4a73838..5a3c3440 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -97,7 +97,7 @@ int32_t tox_get_friend_number(const Tox *tox, const uint8_t *client_id) | |||
97 | int tox_get_client_id(const Tox *tox, int32_t friendnumber, uint8_t *client_id) | 97 | int tox_get_client_id(const Tox *tox, int32_t friendnumber, uint8_t *client_id) |
98 | { | 98 | { |
99 | const Messenger *m = tox; | 99 | const Messenger *m = tox; |
100 | return getclient_id(m, friendnumber, client_id); | 100 | return get_real_pk(m, friendnumber, client_id); |
101 | } | 101 | } |
102 | 102 | ||
103 | /* Remove a friend. */ | 103 | /* Remove a friend. */ |