summaryrefslogtreecommitdiff
path: root/toxcore/net_crypto.h
diff options
context:
space:
mode:
authorsudden6 <sudden6@gmx.at>2019-09-07 00:02:26 +0200
committersudden6 <sudden6@gmx.at>2019-12-23 23:48:15 +0100
commit6338cb46ad99dbc2806976aefabbf2e98476ebda (patch)
tree07789a78fe147e8ffb183e38968cf5398fd4cd71 /toxcore/net_crypto.h
parentabfd90d25b38581db1e831ba5d1aba35c2d8147a (diff)
fix invalid use of mutex
- Moving a pthread_mutex in memory (e.g. via realloc()) is undefined behavior. - add a state for allocated but not yet used crypto connections - change crypto_connection_status signature
Diffstat (limited to 'toxcore/net_crypto.h')
-rw-r--r--toxcore/net_crypto.h16
1 files changed, 3 insertions, 13 deletions
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index 45e1a05e..6917301b 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -81,16 +81,6 @@
81#define PACKET_ID_REJOIN_CONFERENCE 100 81#define PACKET_ID_REJOIN_CONFERENCE 100
82#define PACKET_ID_LOSSY_CONFERENCE 199 82#define PACKET_ID_LOSSY_CONFERENCE 199
83 83
84/*** Crypto connections. ***/
85
86typedef enum Crypto_Conn_State {
87 CRYPTO_CONN_NO_CONNECTION = 0,
88 CRYPTO_CONN_COOKIE_REQUESTING = 1, // send cookie request packets
89 CRYPTO_CONN_HANDSHAKE_SENT = 2, // send handshake packets
90 CRYPTO_CONN_NOT_CONFIRMED = 3, // send handshake packets, we have received one from the other
91 CRYPTO_CONN_ESTABLISHED = 4,
92} Crypto_Conn_State;
93
94/* Maximum size of receiving and sending packet buffers. */ 84/* Maximum size of receiving and sending packet buffers. */
95#define CRYPTO_PACKET_BUFFER_SIZE 32768 // Must be a power of 2 85#define CRYPTO_PACKET_BUFFER_SIZE 32768 // Must be a power of 2
96 86
@@ -319,13 +309,13 @@ unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, u
319 */ 309 */
320int crypto_kill(Net_Crypto *c, int crypt_connection_id); 310int crypto_kill(Net_Crypto *c, int crypt_connection_id);
321 311
322/* return one of CRYPTO_CONN_* values indicating the state of the connection. 312/* return true if connection is valid, false otherwise
323 * 313 *
324 * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't. 314 * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't.
325 * sets online_tcp_relays to the number of connected tcp relays this connection has. 315 * sets online_tcp_relays to the number of connected tcp relays this connection has.
326 */ 316 */
327Crypto_Conn_State crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, bool *direct_connected, 317bool crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, bool *direct_connected,
328 unsigned int *online_tcp_relays); 318 unsigned int *online_tcp_relays);
329 319
330/* Generate our public and private keys. 320/* Generate our public and private keys.
331 * Only call this function the first time the program starts. 321 * Only call this function the first time the program starts.