diff options
Diffstat (limited to 'toxcore/net_crypto.h')
-rw-r--r-- | toxcore/net_crypto.h | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index 0389f283..7c090aaa 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h | |||
@@ -35,18 +35,37 @@ | |||
35 | #define CRYPTO_CONN_ESTABLISHED 4 | 35 | #define CRYPTO_CONN_ESTABLISHED 4 |
36 | #define CRYPTO_CONN_TIMED_OUT 5 | 36 | #define CRYPTO_CONN_TIMED_OUT 5 |
37 | 37 | ||
38 | #define CRYPTO_PACKET_BUFFER_SIZE 64 | 38 | #define CRYPTO_PACKET_BUFFER_SIZE 64 /* Must be a power of 2 */ |
39 | 39 | ||
40 | #define MAX_CRYPTO_PACKET_SIZE 1400 | 40 | #define MAX_CRYPTO_PACKET_SIZE 1400 |
41 | 41 | ||
42 | #define CRYPTO_DATA_PACKET_MIN_SIZE (1 + sizeof(uint16_t) + (sizeof(uint32_t) + sizeof(uint32_t)) + crypto_box_MACBYTES) | ||
43 | |||
42 | /* Max size of data in packets TODO*/ | 44 | /* Max size of data in packets TODO*/ |
43 | #define MAX_CRYPTO_DATA_SIZE (MAX_CRYPTO_PACKET_SIZE - (1 + sizeof(uint16_t) + crypto_box_MACBYTES)) | 45 | #define MAX_CRYPTO_DATA_SIZE (MAX_CRYPTO_PACKET_SIZE - CRYPTO_DATA_PACKET_MIN_SIZE) |
44 | 46 | ||
45 | /* Interval in ms between sending cookie request/handshake packets. */ | 47 | /* Interval in ms between sending cookie request/handshake packets. */ |
46 | #define CRYPTO_SEND_PACKET_INTERVAL 500 | 48 | #define CRYPTO_SEND_PACKET_INTERVAL 500 |
47 | /* The maximum number of times we try to send the cookie request and handshake | 49 | /* The maximum number of times we try to send the cookie request and handshake |
48 | before giving up. */ | 50 | before giving up. */ |
49 | #define MAX_NUM_SENDPACKET_TRIES 10 | 51 | #define MAX_NUM_SENDPACKET_TRIES 8 |
52 | |||
53 | #define PACKET_ID_PADDING 0 | ||
54 | #define PACKET_ID_REQUEST 1 | ||
55 | |||
56 | #define CRYPTO_RESERVED_PACKETS 16 | ||
57 | |||
58 | typedef struct { | ||
59 | uint64_t time; | ||
60 | uint16_t length; | ||
61 | uint8_t data[MAX_CRYPTO_DATA_SIZE]; | ||
62 | } Packet_Data; | ||
63 | |||
64 | typedef struct { | ||
65 | Packet_Data *buffer[CRYPTO_PACKET_BUFFER_SIZE]; | ||
66 | uint32_t buffer_start; | ||
67 | uint32_t buffer_end; /* packet numbers in array: {buffer_start, buffer_end) */ | ||
68 | } Packets_Array; | ||
50 | 69 | ||
51 | typedef struct { | 70 | typedef struct { |
52 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* The real public key of the peer. */ | 71 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* The real public key of the peer. */ |
@@ -74,6 +93,8 @@ typedef struct { | |||
74 | IP_Port ip_port; /* The ip and port to contact this guy directly.*/ | 93 | IP_Port ip_port; /* The ip and port to contact this guy directly.*/ |
75 | uint64_t direct_lastrecv_time; /* The Time at which we last received a direct packet in ms. */ | 94 | uint64_t direct_lastrecv_time; /* The Time at which we last received a direct packet in ms. */ |
76 | 95 | ||
96 | Packets_Array send_array; | ||
97 | Packets_Array recv_array; | ||
77 | 98 | ||
78 | int (*connection_status_callback)(void *object, int id, uint8_t status); | 99 | int (*connection_status_callback)(void *object, int id, uint8_t status); |
79 | void *connection_status_callback_object; | 100 | void *connection_status_callback_object; |
@@ -99,6 +120,7 @@ typedef struct { | |||
99 | DHT *dht; | 120 | DHT *dht; |
100 | 121 | ||
101 | Crypto_Connection *crypto_connections; | 122 | Crypto_Connection *crypto_connections; |
123 | //TCP_Client_Connection *tcp_connections; | ||
102 | 124 | ||
103 | uint32_t crypto_connections_length; /* Length of connections array. */ | 125 | uint32_t crypto_connections_length; /* Length of connections array. */ |
104 | 126 | ||
@@ -182,10 +204,10 @@ int connection_data_handler(Net_Crypto *c, int crypt_connection_id, int (*connec | |||
182 | */ | 204 | */ |
183 | uint32_t crypto_num_free_sendqueue_slots(Net_Crypto *c, int crypt_connection_id); | 205 | uint32_t crypto_num_free_sendqueue_slots(Net_Crypto *c, int crypt_connection_id); |
184 | 206 | ||
185 | /* return 0 if data could not be put in packet queue. | 207 | /* return -1 if data could not be put in packet queue. |
186 | * return 1 if data was put into the queue. | 208 | * return positive packet number if data was put into the queue. |
187 | */ | 209 | */ |
188 | int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length); | 210 | int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length); |
189 | 211 | ||
190 | 212 | ||
191 | /* Kill a crypto connection. | 213 | /* Kill a crypto connection. |