summaryrefslogtreecommitdiff
path: root/toxcore/net_crypto.h
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-04-18 22:14:37 -0400
committerirungentoo <irungentoo@gmail.com>2015-04-18 22:14:37 -0400
commit1a2fa1b7e639e5e94612c774894baa50b3514265 (patch)
tree0868dafc7bc88ecb38fe401990123b0ec8078818 /toxcore/net_crypto.h
parentb4fc0809a7b42ba5d104793e909aecf85951f100 (diff)
Some changes to net crypto.
Should fix certain connection issues that sometimes happen. The dht public key of the peer must be known to create the connection. If the dht pk of the peer changes when a connection is active, it is killed to make way for the new one.
Diffstat (limited to 'toxcore/net_crypto.h')
-rw-r--r--toxcore/net_crypto.h27
1 files changed, 5 insertions, 22 deletions
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index c525c0c5..f6dd4702 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -34,7 +34,6 @@
34#define CRYPTO_CONN_HANDSHAKE_SENT 2 //send handshake packets 34#define CRYPTO_CONN_HANDSHAKE_SENT 2 //send handshake packets
35#define CRYPTO_CONN_NOT_CONFIRMED 3 //send handshake packets, we have received one from the other 35#define CRYPTO_CONN_NOT_CONFIRMED 3 //send handshake packets, we have received one from the other
36#define CRYPTO_CONN_ESTABLISHED 4 36#define CRYPTO_CONN_ESTABLISHED 4
37#define CRYPTO_CONN_TIMED_OUT 5
38 37
39/* Maximum size of receiving and sending packet buffers. */ 38/* Maximum size of receiving and sending packet buffers. */
40#define CRYPTO_PACKET_BUFFER_SIZE 16384 /* Must be a power of 2 */ 39#define CRYPTO_PACKET_BUFFER_SIZE 16384 /* Must be a power of 2 */
@@ -107,11 +106,9 @@ typedef struct {
107 * 2 if we are sending handshake packets 106 * 2 if we are sending handshake packets
108 * 3 if connection is not confirmed yet (we have received a handshake but no data packets yet), 107 * 3 if connection is not confirmed yet (we have received a handshake but no data packets yet),
109 * 4 if the connection is established. 108 * 4 if the connection is established.
110 * 5 if the connection is timed out.
111 */ 109 */
112 uint64_t cookie_request_number; /* number used in the cookie request packets for this connection */ 110 uint64_t cookie_request_number; /* number used in the cookie request packets for this connection */
113 uint8_t dht_public_key[crypto_box_PUBLICKEYBYTES]; /* The dht public key of the peer */ 111 uint8_t dht_public_key[crypto_box_PUBLICKEYBYTES]; /* The dht public key of the peer */
114 uint8_t dht_public_key_set; /* True if the dht public key is set, false if it isn't. */
115 112
116 uint8_t *temp_packet; /* Where the cookie request/handshake packet is stored while it is being sent. */ 113 uint8_t *temp_packet; /* Where the cookie request/handshake packet is stored while it is being sent. */
117 uint16_t temp_packet_length; 114 uint16_t temp_packet_length;
@@ -150,8 +147,6 @@ typedef struct {
150 long signed int last_num_packets_sent[CONGESTION_QUEUE_ARRAY_SIZE]; 147 long signed int last_num_packets_sent[CONGESTION_QUEUE_ARRAY_SIZE];
151 uint32_t packets_sent; 148 uint32_t packets_sent;
152 149
153 uint8_t killed; /* set to 1 to kill the connection. */
154
155 /* TCP_connection connection_number */ 150 /* TCP_connection connection_number */
156 unsigned int connection_number_tcp; 151 unsigned int connection_number_tcp;
157 152
@@ -225,21 +220,7 @@ int accept_crypto_connection(Net_Crypto *c, New_Connection *n_c);
225 * return -1 on failure. 220 * return -1 on failure.
226 * return connection id on success. 221 * return connection id on success.
227 */ 222 */
228int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key); 223int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const uint8_t *dht_public_key);
229
230/* Copy friends DHT public key into dht_key.
231 *
232 * return 0 on failure (no key copied).
233 * return 1 on success (key copied).
234 */
235unsigned int get_connection_dht_key(const Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key);
236
237/* Set the DHT public key of the crypto connection.
238 *
239 * return -1 on failure.
240 * return 0 on success.
241 */
242int set_connection_dht_public_key(Net_Crypto *c, int crypt_connection_id, const uint8_t *dht_public_key);
243 224
244/* Set the direct ip of the crypto connection. 225/* Set the direct ip of the crypto connection.
245 * 226 *
@@ -285,8 +266,10 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id,
285 int (*connection_lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length), void *object, 266 int (*connection_lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length), void *object,
286 int id); 267 int id);
287 268
288/* Set the function for this friend that will be callbacked with object and number 269/* Set the function for this friend that will be callbacked with object and number if
289 * when that friend gives us his DHT temporary public key. 270 * the friend sends us a different dht public key than we have associated to him.
271 *
272 * If this function is called, the connection should be recreated with the new public key.
290 * 273 *
291 * object and number will be passed as argument to this function. 274 * object and number will be passed as argument to this function.
292 * 275 *