diff options
author | irungentoo <irungentoo@gmail.com> | 2014-09-26 21:22:07 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-09-26 21:22:07 -0400 |
commit | 03d6f9571345cb79e5a2b78d598a928ddea2a5bc (patch) | |
tree | ab5bd15d4634ac7debcb729da745ad90117ff1b8 | |
parent | 33e5c34aaf6dd9f4b7af17538cc334bf7a8bfaba (diff) |
Remove timestamp from set_connection_dht_public_key().
-rw-r--r-- | toxcore/Messenger.c | 6 | ||||
-rw-r--r-- | toxcore/net_crypto.c | 21 | ||||
-rw-r--r-- | toxcore/net_crypto.h | 10 |
3 files changed, 12 insertions, 25 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 9383af68..df736ebe 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -213,8 +213,7 @@ static void dht_pk_callback(void *data, int32_t number, const uint8_t *dht_publi | |||
213 | friend_new_connection(m, number, m->friendlist[number].client_id); | 213 | friend_new_connection(m, number, m->friendlist[number].client_id); |
214 | } | 214 | } |
215 | 215 | ||
216 | set_connection_dht_public_key(m->net_crypto, m->friendlist[number].crypt_connection_id, dht_public_key, | 216 | set_connection_dht_public_key(m->net_crypto, m->friendlist[number].crypt_connection_id, dht_public_key); |
217 | current_time_monotonic()); | ||
218 | onion_set_friend_DHT_pubkey(m->onion_c, m->friendlist[number].onion_friendnum, dht_public_key); | 217 | onion_set_friend_DHT_pubkey(m->onion_c, m->friendlist[number].onion_friendnum, dht_public_key); |
219 | 218 | ||
220 | memcpy(m->friendlist[number].dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES); | 219 | memcpy(m->friendlist[number].dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES); |
@@ -2415,8 +2414,7 @@ void do_friends(Messenger *m) | |||
2415 | 2414 | ||
2416 | if (friend_new_connection(m, i, m->friendlist[i].client_id) == 0) { | 2415 | if (friend_new_connection(m, i, m->friendlist[i].client_id) == 0) { |
2417 | if (m->friendlist[i].dht_lock) | 2416 | if (m->friendlist[i].dht_lock) |
2418 | set_connection_dht_public_key(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_temp_pk, | 2417 | set_connection_dht_public_key(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_temp_pk); |
2419 | current_time_monotonic()); | ||
2420 | 2418 | ||
2421 | set_direct_ip_port(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_ip_port); | 2419 | set_direct_ip_port(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_ip_port); |
2422 | } | 2420 | } |
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 59f6ee9a..63012ce6 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -1238,7 +1238,7 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons | |||
1238 | 1238 | ||
1239 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; | 1239 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; |
1240 | /* Status needs to be CRYPTO_CONN_NOT_CONFIRMED for this to work. */ | 1240 | /* Status needs to be CRYPTO_CONN_NOT_CONFIRMED for this to work. */ |
1241 | set_connection_dht_public_key(c, crypt_connection_id, dht_public_key, current_time_monotonic()); | 1241 | set_connection_dht_public_key(c, crypt_connection_id, dht_public_key); |
1242 | 1242 | ||
1243 | if (conn->dht_pk_callback) | 1243 | if (conn->dht_pk_callback) |
1244 | conn->dht_pk_callback(conn->dht_pk_callback_object, conn->dht_pk_callback_number, dht_public_key); | 1244 | conn->dht_pk_callback(conn->dht_pk_callback_object, conn->dht_pk_callback_number, dht_public_key); |
@@ -1477,7 +1477,7 @@ static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, const | |||
1477 | if (create_send_handshake(c, crypt_connection_id, n_c.cookie, n_c.dht_public_key) == 0) { | 1477 | if (create_send_handshake(c, crypt_connection_id, n_c.cookie, n_c.dht_public_key) == 0) { |
1478 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; | 1478 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; |
1479 | /* Status needs to be CRYPTO_CONN_NOT_CONFIRMED for this to work. */ | 1479 | /* Status needs to be CRYPTO_CONN_NOT_CONFIRMED for this to work. */ |
1480 | set_connection_dht_public_key(c, crypt_connection_id, n_c.dht_public_key, current_time_monotonic()); | 1480 | set_connection_dht_public_key(c, crypt_connection_id, n_c.dht_public_key); |
1481 | 1481 | ||
1482 | if (conn->dht_pk_callback) | 1482 | if (conn->dht_pk_callback) |
1483 | conn->dht_pk_callback(conn->dht_pk_callback_object, conn->dht_pk_callback_number, n_c.dht_public_key); | 1483 | conn->dht_pk_callback(conn->dht_pk_callback_object, conn->dht_pk_callback_number, n_c.dht_public_key); |
@@ -1530,7 +1530,7 @@ int accept_crypto_connection(Net_Crypto *c, New_Connection *n_c) | |||
1530 | 1530 | ||
1531 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; | 1531 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; |
1532 | /* Status needs to be CRYPTO_CONN_NOT_CONFIRMED for this to work. */ | 1532 | /* Status needs to be CRYPTO_CONN_NOT_CONFIRMED for this to work. */ |
1533 | set_connection_dht_public_key(c, crypt_connection_id, n_c->dht_public_key, current_time_monotonic()); | 1533 | set_connection_dht_public_key(c, crypt_connection_id, n_c->dht_public_key); |
1534 | conn->packet_send_rate = CRYPTO_PACKET_MIN_RATE; | 1534 | conn->packet_send_rate = CRYPTO_PACKET_MIN_RATE; |
1535 | conn->packets_left = CRYPTO_MIN_QUEUE_LENGTH; | 1535 | conn->packets_left = CRYPTO_MIN_QUEUE_LENGTH; |
1536 | crypto_connection_add_source(c, crypt_connection_id, n_c->source); | 1536 | crypto_connection_add_source(c, crypt_connection_id, n_c->source); |
@@ -1626,9 +1626,9 @@ static int connect_peer_tcp(Net_Crypto *c, int crypt_connection_id) | |||
1626 | /* Copy friends DHT public key into dht_key. | 1626 | /* Copy friends DHT public key into dht_key. |
1627 | * | 1627 | * |
1628 | * return 0 on failure (no key copied). | 1628 | * return 0 on failure (no key copied). |
1629 | * return timestamp on success (key copied). | 1629 | * return 1 on success (key copied). |
1630 | */ | 1630 | */ |
1631 | uint64_t get_connection_dht_key(const Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key) | 1631 | unsigned int get_connection_dht_key(const Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key) |
1632 | { | 1632 | { |
1633 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1633 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1634 | 1634 | ||
@@ -1639,28 +1639,22 @@ uint64_t get_connection_dht_key(const Net_Crypto *c, int crypt_connection_id, ui | |||
1639 | return 0; | 1639 | return 0; |
1640 | 1640 | ||
1641 | memcpy(dht_public_key, conn->dht_public_key, crypto_box_PUBLICKEYBYTES); | 1641 | memcpy(dht_public_key, conn->dht_public_key, crypto_box_PUBLICKEYBYTES); |
1642 | return conn->dht_public_key_timestamp; | 1642 | return 1; |
1643 | } | 1643 | } |
1644 | 1644 | ||
1645 | 1645 | ||
1646 | /* Set the DHT public key of the crypto connection. | 1646 | /* Set the DHT public key of the crypto connection. |
1647 | * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to | ||
1648 | * the other peer. | ||
1649 | * | 1647 | * |
1650 | * return -1 on failure. | 1648 | * return -1 on failure. |
1651 | * return 0 on success. | 1649 | * return 0 on success. |
1652 | */ | 1650 | */ |
1653 | int set_connection_dht_public_key(Net_Crypto *c, int crypt_connection_id, const uint8_t *dht_public_key, | 1651 | int set_connection_dht_public_key(Net_Crypto *c, int crypt_connection_id, const uint8_t *dht_public_key) |
1654 | uint64_t timestamp) | ||
1655 | { | 1652 | { |
1656 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1653 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1657 | 1654 | ||
1658 | if (conn == 0) | 1655 | if (conn == 0) |
1659 | return -1; | 1656 | return -1; |
1660 | 1657 | ||
1661 | if (timestamp <= conn->dht_public_key_timestamp) | ||
1662 | return -1; | ||
1663 | |||
1664 | if (conn->dht_public_key_set == 1 && memcmp(conn->dht_public_key, dht_public_key, crypto_box_PUBLICKEYBYTES) == 0) | 1658 | if (conn->dht_public_key_set == 1 && memcmp(conn->dht_public_key, dht_public_key, crypto_box_PUBLICKEYBYTES) == 0) |
1665 | return -1; | 1659 | return -1; |
1666 | 1660 | ||
@@ -1670,7 +1664,6 @@ int set_connection_dht_public_key(Net_Crypto *c, int crypt_connection_id, const | |||
1670 | 1664 | ||
1671 | memcpy(conn->dht_public_key, dht_public_key, crypto_box_PUBLICKEYBYTES); | 1665 | memcpy(conn->dht_public_key, dht_public_key, crypto_box_PUBLICKEYBYTES); |
1672 | conn->dht_public_key_set = 1; | 1666 | conn->dht_public_key_set = 1; |
1673 | conn->dht_public_key_timestamp = timestamp; | ||
1674 | 1667 | ||
1675 | if (conn->status == CRYPTO_CONN_COOKIE_REQUESTING) { | 1668 | if (conn->status == CRYPTO_CONN_COOKIE_REQUESTING) { |
1676 | conn->cookie_request_number = random_64b(); | 1669 | conn->cookie_request_number = random_64b(); |
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index cfa7c576..3245b6a2 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h | |||
@@ -111,7 +111,6 @@ typedef struct { | |||
111 | uint64_t cookie_request_number; /* number used in the cookie request packets for this connection */ | 111 | uint64_t cookie_request_number; /* number used in the cookie request packets for this connection */ |
112 | uint8_t dht_public_key[crypto_box_PUBLICKEYBYTES]; /* The dht public key of the peer */ | 112 | uint8_t dht_public_key[crypto_box_PUBLICKEYBYTES]; /* The dht public key of the peer */ |
113 | uint8_t dht_public_key_set; /* True if the dht public key is set, false if it isn't. */ | 113 | uint8_t dht_public_key_set; /* True if the dht public key is set, false if it isn't. */ |
114 | uint64_t dht_public_key_timestamp; /* Timestamp of the last time we confirmed the key was correct. */ | ||
115 | 114 | ||
116 | uint8_t *temp_packet; /* Where the cookie request/handshake packet is stored while it is being sent. */ | 115 | uint8_t *temp_packet; /* Where the cookie request/handshake packet is stored while it is being sent. */ |
117 | uint16_t temp_packet_length; | 116 | uint16_t temp_packet_length; |
@@ -240,19 +239,16 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key); | |||
240 | /* Copy friends DHT public key into dht_key. | 239 | /* Copy friends DHT public key into dht_key. |
241 | * | 240 | * |
242 | * return 0 on failure (no key copied). | 241 | * return 0 on failure (no key copied). |
243 | * return timestamp on success (key copied). | 242 | * return 1 on success (key copied). |
244 | */ | 243 | */ |
245 | uint64_t get_connection_dht_key(const Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key); | 244 | unsigned int get_connection_dht_key(const Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key); |
246 | 245 | ||
247 | /* Set the DHT public key of the crypto connection. | 246 | /* Set the DHT public key of the crypto connection. |
248 | * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to | ||
249 | * the other peer. | ||
250 | * | 247 | * |
251 | * return -1 on failure. | 248 | * return -1 on failure. |
252 | * return 0 on success. | 249 | * return 0 on success. |
253 | */ | 250 | */ |
254 | int set_connection_dht_public_key(Net_Crypto *c, int crypt_connection_id, const uint8_t *dht_public_key, | 251 | int set_connection_dht_public_key(Net_Crypto *c, int crypt_connection_id, const uint8_t *dht_public_key); |
255 | uint64_t timestamp); | ||
256 | 252 | ||
257 | /* Set the direct ip of the crypto connection. | 253 | /* Set the direct ip of the crypto connection. |
258 | * | 254 | * |