diff options
Diffstat (limited to 'toxcore/net_crypto.h')
-rw-r--r-- | toxcore/net_crypto.h | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index e6a4efd7..2ed35883 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h | |||
@@ -31,13 +31,13 @@ | |||
31 | 31 | ||
32 | #include <pthread.h> | 32 | #include <pthread.h> |
33 | 33 | ||
34 | typedef enum CRYPTO_CONN_STATE { | 34 | typedef enum Crypto_Conn_State { |
35 | CRYPTO_CONN_NO_CONNECTION = 0, | 35 | CRYPTO_CONN_NO_CONNECTION = 0, |
36 | CRYPTO_CONN_COOKIE_REQUESTING = 1, // send cookie request packets | 36 | CRYPTO_CONN_COOKIE_REQUESTING = 1, // send cookie request packets |
37 | CRYPTO_CONN_HANDSHAKE_SENT = 2, // send handshake packets | 37 | CRYPTO_CONN_HANDSHAKE_SENT = 2, // send handshake packets |
38 | CRYPTO_CONN_NOT_CONFIRMED = 3, // send handshake packets, we have received one from the other | 38 | CRYPTO_CONN_NOT_CONFIRMED = 3, // send handshake packets, we have received one from the other |
39 | CRYPTO_CONN_ESTABLISHED = 4, | 39 | CRYPTO_CONN_ESTABLISHED = 4, |
40 | } CRYPTO_CONN_STATE; | 40 | } Crypto_Conn_State; |
41 | 41 | ||
42 | /* Maximum size of receiving and sending packet buffers. */ | 42 | /* Maximum size of receiving and sending packet buffers. */ |
43 | #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 */ |
@@ -108,14 +108,19 @@ typedef struct New_Connection { | |||
108 | uint8_t cookie_length; | 108 | uint8_t cookie_length; |
109 | } New_Connection; | 109 | } New_Connection; |
110 | 110 | ||
111 | typedef int connection_status_cb(void *object, int id, uint8_t status, void *userdata); | ||
112 | typedef int connection_data_cb(void *object, int id, const uint8_t *data, uint16_t length, void *userdata); | ||
113 | typedef int connection_lossy_data_cb(void *object, int id, const uint8_t *data, uint16_t length, void *userdata); | ||
114 | typedef void dht_pk_cb(void *data, int32_t number, const uint8_t *dht_public_key, void *userdata); | ||
115 | typedef int new_connection_cb(void *object, New_Connection *n_c); | ||
116 | |||
111 | /* Set function to be called when someone requests a new connection to us. | 117 | /* Set function to be called when someone requests a new connection to us. |
112 | * | 118 | * |
113 | * The set function should return -1 on failure and 0 on success. | 119 | * The set function should return -1 on failure and 0 on success. |
114 | * | 120 | * |
115 | * n_c is only valid for the duration of the function call. | 121 | * n_c is only valid for the duration of the function call. |
116 | */ | 122 | */ |
117 | void new_connection_handler(Net_Crypto *c, int (*new_connection_callback)(void *object, New_Connection *n_c), | 123 | void new_connection_handler(Net_Crypto *c, new_connection_cb *new_connection_callback, void *object); |
118 | void *object); | ||
119 | 124 | ||
120 | /* Accept a crypto connection. | 125 | /* Accept a crypto connection. |
121 | * | 126 | * |
@@ -152,7 +157,7 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, | |||
152 | * return 0 on success. | 157 | * return 0 on success. |
153 | */ | 158 | */ |
154 | int connection_status_handler(const Net_Crypto *c, int crypt_connection_id, | 159 | int connection_status_handler(const Net_Crypto *c, int crypt_connection_id, |
155 | int (*connection_status_callback)(void *object, int id, uint8_t status, void *userdata), void *object, int id); | 160 | connection_status_cb *connection_status_callback, void *object, int id); |
156 | 161 | ||
157 | /* Set function to be called when connection with crypt_connection_id receives a lossless data packet of length. | 162 | /* Set function to be called when connection with crypt_connection_id receives a lossless data packet of length. |
158 | * | 163 | * |
@@ -162,8 +167,8 @@ int connection_status_handler(const Net_Crypto *c, int crypt_connection_id, | |||
162 | * return -1 on failure. | 167 | * return -1 on failure. |
163 | * return 0 on success. | 168 | * return 0 on success. |
164 | */ | 169 | */ |
165 | int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (*connection_data_callback)(void *object, | 170 | int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, |
166 | int id, const uint8_t *data, uint16_t length, void *userdata), void *object, int id); | 171 | connection_data_cb *connection_data_callback, void *object, int id); |
167 | 172 | ||
168 | 173 | ||
169 | /* Set function to be called when connection with crypt_connection_id receives a lossy data packet of length. | 174 | /* Set function to be called when connection with crypt_connection_id receives a lossy data packet of length. |
@@ -175,9 +180,7 @@ int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (* | |||
175 | * return 0 on success. | 180 | * return 0 on success. |
176 | */ | 181 | */ |
177 | int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id, | 182 | int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id, |
178 | int (*connection_lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length, void *userdata), | 183 | connection_lossy_data_cb *connection_lossy_data_callback, void *object, int id); |
179 | void *object, | ||
180 | int id); | ||
181 | 184 | ||
182 | /* Set the function for this friend that will be callbacked with object and number if | 185 | /* Set the function for this friend that will be callbacked with object and number if |
183 | * the friend sends us a different dht public key than we have associated to him. | 186 | * the friend sends us a different dht public key than we have associated to him. |
@@ -189,8 +192,7 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id, | |||
189 | * return -1 on failure. | 192 | * return -1 on failure. |
190 | * return 0 on success. | 193 | * return 0 on success. |
191 | */ | 194 | */ |
192 | int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(void *data, int32_t number, | 195 | int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, dht_pk_cb *function, void *object, uint32_t number); |
193 | const uint8_t *dht_public_key, void *userdata), void *object, uint32_t number); | ||
194 | 196 | ||
195 | /* returns the number of packet slots left in the sendbuffer. | 197 | /* returns the number of packet slots left in the sendbuffer. |
196 | * return 0 if failure. | 198 | * return 0 if failure. |
@@ -278,7 +280,7 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id); | |||
278 | * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't. | 280 | * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't. |
279 | * sets online_tcp_relays to the number of connected tcp relays this connection has. | 281 | * sets online_tcp_relays to the number of connected tcp relays this connection has. |
280 | */ | 282 | */ |
281 | CRYPTO_CONN_STATE crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, bool *direct_connected, | 283 | Crypto_Conn_State crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, bool *direct_connected, |
282 | unsigned int *online_tcp_relays); | 284 | unsigned int *online_tcp_relays); |
283 | 285 | ||
284 | /* Generate our public and private keys. | 286 | /* Generate our public and private keys. |