summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxcore/net_crypto.c17
-rw-r--r--toxcore/net_crypto.h20
2 files changed, 21 insertions, 16 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index ead5a04c..fbf41552 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -55,11 +55,14 @@ typedef struct {
55 uint8_t sessionsecret_key[CRYPTO_SECRET_KEY_SIZE]; /* Our private key for this session. */ 55 uint8_t sessionsecret_key[CRYPTO_SECRET_KEY_SIZE]; /* Our private key for this session. */
56 uint8_t peersessionpublic_key[CRYPTO_PUBLIC_KEY_SIZE]; /* The public key of the peer. */ 56 uint8_t peersessionpublic_key[CRYPTO_PUBLIC_KEY_SIZE]; /* The public key of the peer. */
57 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; /* The precomputed shared key from encrypt_precompute. */ 57 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; /* The precomputed shared key from encrypt_precompute. */
58 uint8_t status; /* 0 if no connection, 1 we are sending cookie request packets, 58 /**
59 * 2 if we are sending handshake packets 59 * 0 if no connection,
60 * 3 if connection is not confirmed yet (we have received a handshake but no data packets yet), 60 * 1 we are sending cookie request packets,
61 * 4 if the connection is established. 61 * 2 if we are sending handshake packets,
62 */ 62 * 3 if connection is not confirmed yet (we have received a handshake but no data packets yet),
63 * 4 if the connection is established.
64 */
65 CRYPTO_CONN_STATE status;
63 uint64_t cookie_request_number; /* number used in the cookie request packets for this connection */ 66 uint64_t cookie_request_number; /* number used in the cookie request packets for this connection */
64 uint8_t dht_public_key[CRYPTO_PUBLIC_KEY_SIZE]; /* The dht public key of the peer */ 67 uint8_t dht_public_key[CRYPTO_PUBLIC_KEY_SIZE]; /* The dht public key of the peer */
65 68
@@ -2867,8 +2870,8 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id)
2867 * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't. 2870 * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't.
2868 * sets online_tcp_relays to the number of connected tcp relays this connection has. 2871 * sets online_tcp_relays to the number of connected tcp relays this connection has.
2869 */ 2872 */
2870unsigned int crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, bool *direct_connected, 2873CRYPTO_CONN_STATE crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, bool *direct_connected,
2871 unsigned int *online_tcp_relays) 2874 unsigned int *online_tcp_relays)
2872{ 2875{
2873 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2876 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2874 2877
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index ec55bf6f..f6b2648e 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -31,11 +31,13 @@
31 31
32#include <pthread.h> 32#include <pthread.h>
33 33
34#define CRYPTO_CONN_NO_CONNECTION 0 34typedef enum CRYPTO_CONN_STATE {
35#define CRYPTO_CONN_COOKIE_REQUESTING 1 //send cookie request packets 35 CRYPTO_CONN_NO_CONNECTION = 0,
36#define CRYPTO_CONN_HANDSHAKE_SENT 2 //send handshake packets 36 CRYPTO_CONN_COOKIE_REQUESTING = 1, // send cookie request packets
37#define CRYPTO_CONN_NOT_CONFIRMED 3 //send handshake packets, we have received one from the other 37 CRYPTO_CONN_HANDSHAKE_SENT = 2, // send handshake packets
38#define CRYPTO_CONN_ESTABLISHED 4 38 CRYPTO_CONN_NOT_CONFIRMED = 3, // send handshake packets, we have received one from the other
39 CRYPTO_CONN_ESTABLISHED = 4,
40} CRYPTO_CONN_STATE;
39 41
40/* Maximum size of receiving and sending packet buffers. */ 42/* Maximum size of receiving and sending packet buffers. */
41#define CRYPTO_PACKET_BUFFER_SIZE 32768 /* Must be a power of 2 */ 43#define CRYPTO_PACKET_BUFFER_SIZE 32768 /* Must be a power of 2 */
@@ -47,9 +49,9 @@
47#define CRYPTO_MIN_QUEUE_LENGTH 64 49#define CRYPTO_MIN_QUEUE_LENGTH 64
48 50
49/* Maximum total size of packets that net_crypto sends. */ 51/* Maximum total size of packets that net_crypto sends. */
50#define MAX_CRYPTO_PACKET_SIZE 1400 52#define MAX_CRYPTO_PACKET_SIZE (uint16_t)1400
51 53
52#define CRYPTO_DATA_PACKET_MIN_SIZE (1 + sizeof(uint16_t) + (sizeof(uint32_t) + sizeof(uint32_t)) + CRYPTO_MAC_SIZE) 54#define CRYPTO_DATA_PACKET_MIN_SIZE (uint16_t)(1 + sizeof(uint16_t) + (sizeof(uint32_t) + sizeof(uint32_t)) + CRYPTO_MAC_SIZE)
53 55
54/* Max size of data in packets */ 56/* Max size of data in packets */
55#define MAX_CRYPTO_DATA_SIZE (MAX_CRYPTO_PACKET_SIZE - CRYPTO_DATA_PACKET_MIN_SIZE) 57#define MAX_CRYPTO_DATA_SIZE (MAX_CRYPTO_PACKET_SIZE - CRYPTO_DATA_PACKET_MIN_SIZE)
@@ -276,8 +278,8 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id);
276 * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't. 278 * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't.
277 * sets online_tcp_relays to the number of connected tcp relays this connection has. 279 * sets online_tcp_relays to the number of connected tcp relays this connection has.
278 */ 280 */
279unsigned int crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, bool *direct_connected, 281CRYPTO_CONN_STATE crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, bool *direct_connected,
280 unsigned int *online_tcp_relays); 282 unsigned int *online_tcp_relays);
281 283
282/* Generate our public and private keys. 284/* Generate our public and private keys.
283 * Only call this function the first time the program starts. 285 * Only call this function the first time the program starts.