summaryrefslogtreecommitdiff
path: root/toxcore/net_crypto.h
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/net_crypto.h')
-rw-r--r--toxcore/net_crypto.h36
1 files changed, 28 insertions, 8 deletions
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index b2b9f4f5..85aeede6 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -30,10 +30,15 @@
30#define CRYPTO_HANDSHAKE_TIMEOUT (CONNECTION_TIMEOUT * 2) 30#define CRYPTO_HANDSHAKE_TIMEOUT (CONNECTION_TIMEOUT * 2)
31 31
32#define CRYPTO_CONN_NO_CONNECTION 0 32#define CRYPTO_CONN_NO_CONNECTION 0
33#define CRYPTO_CONN_HANDSHAKE_SENT 1 33#define CRYPTO_CONN_COOKIE_REQUESTED 1 //send cookie request packets
34#define CRYPTO_CONN_NOT_CONFIRMED 2 34#define CRYPTO_CONN_HANDSHAKE_SENT 2 //send handshake packets
35#define CRYPTO_CONN_ESTABLISHED 3 35#define CRYPTO_CONN_NOT_CONFIRMED 3 //send handshake packets
36#define CRYPTO_CONN_TIMED_OUT 4 36#define CRYPTO_CONN_ESTABLISHED 4
37#define CRYPTO_CONN_TIMED_OUT 5
38
39#define CRYPTO_PACKET_BUFFER_SIZE 64
40
41#define MAX_CRYPTO_PACKET_SIZE 1400
37 42
38typedef struct { 43typedef struct {
39 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* The real public key of the peer. */ 44 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* The real public key of the peer. */
@@ -43,15 +48,27 @@ typedef struct {
43 uint8_t sessionsecret_key[crypto_box_SECRETKEYBYTES]; /* Our private key for this session. */ 48 uint8_t sessionsecret_key[crypto_box_SECRETKEYBYTES]; /* Our private key for this session. */
44 uint8_t peersessionpublic_key[crypto_box_PUBLICKEYBYTES]; /* The public key of the peer. */ 49 uint8_t peersessionpublic_key[crypto_box_PUBLICKEYBYTES]; /* The public key of the peer. */
45 uint8_t shared_key[crypto_box_BEFORENMBYTES]; /* The precomputed shared key from encrypt_precompute. */ 50 uint8_t shared_key[crypto_box_BEFORENMBYTES]; /* The precomputed shared key from encrypt_precompute. */
46 uint8_t status; /* 0 if no connection, 1 we have sent a handshake, 2 if connection is not confirmed yet 51 uint8_t status; /* 0 if no connection, 1 we are sending cookie request packets,
47 * (we have received a handshake but no empty data packet), 3 if the connection is established. 52 * 2 if we are sending handshake packets
48 * 4 if the connection is timed out. 53 * 3 if connection is not confirmed yet (we have received a handshake but no data packets yet),
54 * 4 if the connection is established.
55 * 5 if the connection is timed out.
49 */ 56 */
50 uint16_t number; /* Lossless_UDP connection number corresponding to this connection. */ 57 uint16_t number; /* Lossless_UDP connection number corresponding to this connection. */
51 uint64_t timeout; 58 uint64_t timeout;
52 59
60 uint8_t *temp_packet; /* Where the cookie request/handshake packet is stored while it is being sent. */
61 uint16_t temp_packet_length;
62 uint64_t temp_packet_sent_time; /* The time at which the last temp_packet was sent in ms. */
53} Crypto_Connection; 63} Crypto_Connection;
54 64
65typedef struct {
66 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* The real public key of the peer. */
67 uint8_t recv_nonce[crypto_box_NONCEBYTES]; /* Nonce of received packets. */
68 uint8_t peersessionpublic_key[crypto_box_PUBLICKEYBYTES]; /* The public key of the peer. */
69 uint8_t *cookie;
70 uint8_t cookie_length;
71} New_Connection;
55 72
56typedef struct { 73typedef struct {
57 Lossless_UDP *lossless_udp; 74 Lossless_UDP *lossless_udp;
@@ -67,9 +84,12 @@ typedef struct {
67 84
68 /* The secret key used for cookies */ 85 /* The secret key used for cookies */
69 uint8_t secret_symmetric_key[crypto_box_KEYBYTES]; 86 uint8_t secret_symmetric_key[crypto_box_KEYBYTES];
87
88 int (*new_connection_callback)(void *object, New_Connection *n_c);
89 void *new_connection_callback_object;
70} Net_Crypto; 90} Net_Crypto;
71 91
72#include "DHT.h" 92
73 93
74/* return 0 if there is no received data in the buffer. 94/* return 0 if there is no received data in the buffer.
75 * return -1 if the packet was discarded. 95 * return -1 if the packet was discarded.