summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-09-26 20:43:59 -0400
committerirungentoo <irungentoo@gmail.com>2014-09-26 20:43:59 -0400
commitc618263acd7e2ed76befe3c4b6211f8ba15ee79c (patch)
tree2ccb69fe9f6a5fa569e4c5580d74a5fe03e53e9c /toxcore
parentf2a313359e14ac3f4cf00421ad4ff0e4954c5a07 (diff)
Removed useless code from onion_client.
Astyled.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/Messenger.c9
-rw-r--r--toxcore/net_crypto.c3
-rw-r--r--toxcore/net_crypto.h3
-rw-r--r--toxcore/onion_client.c29
-rw-r--r--toxcore/onion_client.h10
5 files changed, 26 insertions, 28 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 8229c270..c98b9d95 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -211,8 +211,9 @@ static void dht_pk_callback(void *data, int32_t number, const uint8_t *dht_publi
211 friend_new_connection(m, number, m->friendlist[number].client_id); 211 friend_new_connection(m, number, m->friendlist[number].client_id);
212 } 212 }
213 213
214 set_connection_dht_public_key(m->net_crypto, m->friendlist[number].crypt_connection_id, dht_public_key, current_time_monotonic()); 214 set_connection_dht_public_key(m->net_crypto, m->friendlist[number].crypt_connection_id, dht_public_key,
215 onion_set_friend_DHT_pubkey(m->onion_c, m->friendlist[number].onion_friendnum, dht_public_key, current_time_monotonic()); 215 current_time_monotonic());
216 onion_set_friend_DHT_pubkey(m->onion_c, m->friendlist[number].onion_friendnum, dht_public_key);
216 217
217 memcpy(m->friendlist[number].dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES); 218 memcpy(m->friendlist[number].dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES);
218} 219}
@@ -389,6 +390,7 @@ int m_delfriend(Messenger *m, int32_t friendnumber)
389 remove_online_friend(m, friendnumber); 390 remove_online_friend(m, friendnumber);
390 391
391 onion_delfriend(m->onion_c, m->friendlist[friendnumber].onion_friendnum); 392 onion_delfriend(m->onion_c, m->friendlist[friendnumber].onion_friendnum);
393
392 if (m->friendlist[friendnumber].dht_lock) { 394 if (m->friendlist[friendnumber].dht_lock) {
393 DHT_delfriend(m->dht, m->friendlist[friendnumber].dht_temp_pk, m->friendlist[friendnumber].dht_lock); 395 DHT_delfriend(m->dht, m->friendlist[friendnumber].dht_temp_pk, m->friendlist[friendnumber].dht_lock);
394 } 396 }
@@ -2399,7 +2401,8 @@ void do_friends(Messenger *m)
2399 check_friend_request_timed_out(m, i, temp_time); 2401 check_friend_request_timed_out(m, i, temp_time);
2400 2402
2401 if (m->friendlist[i].dht_lock) 2403 if (m->friendlist[i].dht_lock)
2402 set_connection_dht_public_key(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_temp_pk, current_time_monotonic()); 2404 set_connection_dht_public_key(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_temp_pk,
2405 current_time_monotonic());
2403 2406
2404 set_direct_ip_port(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_ip_port); 2407 set_direct_ip_port(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_ip_port);
2405 2408
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 1d93bc6a..a286df2a 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -2260,7 +2260,8 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id,
2260 * return -1 on failure. 2260 * return -1 on failure.
2261 * return 0 on success. 2261 * return 0 on success.
2262 */ 2262 */
2263int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(void *data, int32_t number, const uint8_t *dht_public_key), void *object, uint32_t number) 2263int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(void *data, int32_t number,
2264 const uint8_t *dht_public_key), void *object, uint32_t number)
2264{ 2265{
2265 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2266 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2266 2267
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index 8c77a7a1..cfa7c576 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -306,7 +306,8 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id,
306 * return -1 on failure. 306 * return -1 on failure.
307 * return 0 on success. 307 * return 0 on success.
308 */ 308 */
309int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(void *data, int32_t number, const uint8_t *dht_public_key), void *object, uint32_t number); 309int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(void *data, int32_t number,
310 const uint8_t *dht_public_key), void *object, uint32_t number);
310 311
311/* returns the number of packet slots left in the sendbuffer. 312/* returns the number of packet slots left in the sendbuffer.
312 * return 0 if failure. 313 * return 0 if failure.
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index 56c79cc5..97afeb79 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -638,9 +638,12 @@ static int handle_fakeid_announce(void *object, const uint8_t *source_pubkey, co
638 return 1; 638 return 1;
639 639
640 onion_c->friends_list[friend_num].last_noreplay = no_replay; 640 onion_c->friends_list[friend_num].last_noreplay = no_replay;
641
641 if (onion_c->friends_list[friend_num].dht_pk_callback) 642 if (onion_c->friends_list[friend_num].dht_pk_callback)
642 onion_c->friends_list[friend_num].dht_pk_callback(onion_c->friends_list[friend_num].dht_pk_callback_object, onion_c->friends_list[friend_num].dht_pk_callback_number, data + 1 + sizeof(uint64_t)); 643 onion_c->friends_list[friend_num].dht_pk_callback(onion_c->friends_list[friend_num].dht_pk_callback_object,
643 //onion_set_friend_DHT_pubkey(onion_c, friend_num, data + 1 + sizeof(uint64_t), current_time_monotonic()); 644 onion_c->friends_list[friend_num].dht_pk_callback_number, data + 1 + sizeof(uint64_t));
645
646 onion_set_friend_DHT_pubkey(onion_c, friend_num, data + 1 + sizeof(uint64_t));
644 onion_c->friends_list[friend_num].last_seen = unix_time(); 647 onion_c->friends_list[friend_num].last_seen = unix_time();
645 648
646 uint16_t len_nodes = length - FAKEID_DATA_MIN_LENGTH; 649 uint16_t len_nodes = length - FAKEID_DATA_MIN_LENGTH;
@@ -1006,7 +1009,8 @@ int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*tcp_rela
1006 * return -1 on failure. 1009 * return -1 on failure.
1007 * return 0 on success. 1010 * return 0 on success.
1008 */ 1011 */
1009int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, void (*function)(void *data, int32_t number, const uint8_t *dht_public_key), void *object, uint32_t number) 1012int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, void (*function)(void *data, int32_t number,
1013 const uint8_t *dht_public_key), void *object, uint32_t number)
1010{ 1014{
1011 if ((uint32_t)friend_num >= onion_c->num_friends) 1015 if ((uint32_t)friend_num >= onion_c->num_friends)
1012 return -1; 1016 return -1;
@@ -1018,13 +1022,11 @@ int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, void (*function
1018} 1022}
1019 1023
1020/* Set a friends DHT public key. 1024/* Set a friends DHT public key.
1021 * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to
1022 * the other peer.
1023 * 1025 *
1024 * return -1 on failure. 1026 * return -1 on failure.
1025 * return 0 on success. 1027 * return 0 on success.
1026 */ 1028 */
1027int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key, uint64_t timestamp) 1029int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key)
1028{ 1030{
1029 if ((uint32_t)friend_num >= onion_c->num_friends) 1031 if ((uint32_t)friend_num >= onion_c->num_friends)
1030 return -1; 1032 return -1;
@@ -1032,25 +1034,16 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin
1032 if (onion_c->friends_list[friend_num].status == 0) 1034 if (onion_c->friends_list[friend_num].status == 0)
1033 return -1; 1035 return -1;
1034 1036
1035 if (onion_c->friends_list[friend_num].fake_client_id_timestamp >= timestamp)
1036 return -1;
1037
1038 if (onion_c->friends_list[friend_num].is_fake_clientid) { 1037 if (onion_c->friends_list[friend_num].is_fake_clientid) {
1039 if (memcmp(dht_key, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES) == 0) { 1038 if (memcmp(dht_key, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES) == 0) {
1040 return -1; 1039 return -1;
1041 } 1040 }
1042 1041
1043 //DHT_delfriend(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id, 0);
1044 onion_c->friends_list[friend_num].is_fake_clientid = 0; 1042 onion_c->friends_list[friend_num].is_fake_clientid = 0;
1045 } 1043 }
1046 1044
1047 //if (DHT_addfriend(onion_c->dht, dht_key, 0, 0, 0, 0) == -1) {
1048 // return -1;
1049 //}
1050
1051 onion_c->friends_list[friend_num].last_seen = unix_time(); 1045 onion_c->friends_list[friend_num].last_seen = unix_time();
1052 onion_c->friends_list[friend_num].is_fake_clientid = 1; 1046 onion_c->friends_list[friend_num].is_fake_clientid = 1;
1053 onion_c->friends_list[friend_num].fake_client_id_timestamp = timestamp;
1054 memcpy(onion_c->friends_list[friend_num].fake_client_id, dht_key, crypto_box_PUBLICKEYBYTES); 1047 memcpy(onion_c->friends_list[friend_num].fake_client_id, dht_key, crypto_box_PUBLICKEYBYTES);
1055 1048
1056 return 0; 1049 return 0;
@@ -1059,9 +1052,9 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin
1059/* Copy friends DHT public key into dht_key. 1052/* Copy friends DHT public key into dht_key.
1060 * 1053 *
1061 * return 0 on failure (no key copied). 1054 * return 0 on failure (no key copied).
1062 * return timestamp on success (key copied). 1055 * return 1 on success (key copied).
1063 */ 1056 */
1064uint64_t onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key) 1057unsigned int onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key)
1065{ 1058{
1066 if ((uint32_t)friend_num >= onion_c->num_friends) 1059 if ((uint32_t)friend_num >= onion_c->num_friends)
1067 return 0; 1060 return 0;
@@ -1073,7 +1066,7 @@ uint64_t onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num,
1073 return 0; 1066 return 0;
1074 1067
1075 memcpy(dht_key, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES); 1068 memcpy(dht_key, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES);
1076 return onion_c->friends_list[friend_num].fake_client_id_timestamp; 1069 return 1;
1077} 1070}
1078 1071
1079/* Get the ip of friend friendnum and put it in ip_port 1072/* Get the ip of friend friendnum and put it in ip_port
diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h
index 5b89a8d9..3143f93a 100644
--- a/toxcore/onion_client.h
+++ b/toxcore/onion_client.h
@@ -79,7 +79,6 @@ typedef struct {
79 uint8_t is_online; /* Set by the onion_set_friend_status function. */ 79 uint8_t is_online; /* Set by the onion_set_friend_status function. */
80 80
81 uint8_t is_fake_clientid; /* 0 if we don't know the fake client id of the other 1 if we do. */ 81 uint8_t is_fake_clientid; /* 0 if we don't know the fake client id of the other 1 if we do. */
82 uint64_t fake_client_id_timestamp;
83 uint8_t fake_client_id[crypto_box_PUBLICKEYBYTES]; 82 uint8_t fake_client_id[crypto_box_PUBLICKEYBYTES];
84 uint8_t real_client_id[crypto_box_PUBLICKEYBYTES]; 83 uint8_t real_client_id[crypto_box_PUBLICKEYBYTES];
85 84
@@ -218,7 +217,8 @@ int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*tcp_rela
218 * return -1 on failure. 217 * return -1 on failure.
219 * return 0 on success. 218 * return 0 on success.
220 */ 219 */
221int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, void (*function)(void *data, int32_t number, const uint8_t *dht_public_key), void *object, uint32_t number); 220int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, void (*function)(void *data, int32_t number,
221 const uint8_t *dht_public_key), void *object, uint32_t number);
222 222
223/* Set a friends DHT public key. 223/* Set a friends DHT public key.
224 * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to 224 * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to
@@ -227,14 +227,14 @@ int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, void (*function
227 * return -1 on failure. 227 * return -1 on failure.
228 * return 0 on success. 228 * return 0 on success.
229 */ 229 */
230int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key, uint64_t timestamp); 230int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key);
231 231
232/* Copy friends DHT public key into dht_key. 232/* Copy friends DHT public key into dht_key.
233 * 233 *
234 * return 0 on failure (no key copied). 234 * return 0 on failure (no key copied).
235 * return timestamp on success (key copied). 235 * return 1 on success (key copied).
236 */ 236 */
237uint64_t onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key); 237unsigned int onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key);
238 238
239#define ONION_DATA_IN_RESPONSE_MIN_SIZE (crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES) 239#define ONION_DATA_IN_RESPONSE_MIN_SIZE (crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES)
240#define ONION_CLIENT_MAX_DATA_SIZE (MAX_DATA_REQUEST_SIZE - ONION_DATA_IN_RESPONSE_MIN_SIZE) 240#define ONION_CLIENT_MAX_DATA_SIZE (MAX_DATA_REQUEST_SIZE - ONION_DATA_IN_RESPONSE_MIN_SIZE)