summaryrefslogtreecommitdiff
path: root/toxcore/TCP_client.h
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/TCP_client.h')
-rw-r--r--toxcore/TCP_client.h71
1 files changed, 68 insertions, 3 deletions
diff --git a/toxcore/TCP_client.h b/toxcore/TCP_client.h
index eb2aa39c..afb95392 100644
--- a/toxcore/TCP_client.h
+++ b/toxcore/TCP_client.h
@@ -24,7 +24,7 @@
24#ifndef TCP_CLIENT_H 24#ifndef TCP_CLIENT_H
25#define TCP_CLIENT_H 25#define TCP_CLIENT_H
26 26
27#include "net_crypto.h" 27#include "crypto_core.h"
28#include "TCP_server.h" 28#include "TCP_server.h"
29 29
30#define TCP_CONNECTION_TIMEOUT 10 30#define TCP_CONNECTION_TIMEOUT 10
@@ -40,6 +40,7 @@ typedef struct {
40 uint8_t status; 40 uint8_t status;
41 sock_t sock; 41 sock_t sock;
42 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* public key of the server */ 42 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* public key of the server */
43 IP_Port ip_port; /* The ip and port of the server */
43 uint8_t recv_nonce[crypto_box_NONCEBYTES]; /* Nonce of received packets. */ 44 uint8_t recv_nonce[crypto_box_NONCEBYTES]; /* Nonce of received packets. */
44 uint8_t sent_nonce[crypto_box_NONCEBYTES]; /* Nonce of sent packets. */ 45 uint8_t sent_nonce[crypto_box_NONCEBYTES]; /* Nonce of sent packets. */
45 uint8_t shared_key[crypto_box_BEFORENMBYTES]; 46 uint8_t shared_key[crypto_box_BEFORENMBYTES];
@@ -55,6 +56,25 @@ typedef struct {
55 56
56 uint64_t last_pinged; 57 uint64_t last_pinged;
57 uint64_t ping_id; 58 uint64_t ping_id;
59
60 void *net_crypto_pointer;
61 uint32_t net_crypto_location;
62 struct {
63 uint8_t status; /* 0 if not used, 1 if other is offline, 2 if other is online. */
64 uint8_t public_key[crypto_box_PUBLICKEYBYTES];
65 uint32_t number;
66 } connections[NUM_CLIENT_CONNECTIONS];
67 int (*response_callback)(void *object, uint8_t connection_id, uint8_t *public_key);
68 void *response_callback_object;
69 int (*status_callback)(void *object, uint32_t number, uint8_t connection_id, uint8_t status);
70 void *status_callback_object;
71 int (*data_callback)(void *object, uint32_t number, uint8_t connection_id, uint8_t *data, uint16_t length);
72 void *data_callback_object;
73 int (*oob_data_callback)(void *object, uint8_t *public_key, uint8_t *data, uint16_t length);
74 void *oob_data_callback_object;
75
76 int (*onion_callback)(void *object, uint8_t *data, uint16_t length);
77 void *onion_callback_object;
58} TCP_Client_Connection; 78} TCP_Client_Connection;
59 79
60/* Create new TCP connection to ip_port/public_key 80/* Create new TCP connection to ip_port/public_key
@@ -70,9 +90,54 @@ void do_TCP_connection(TCP_Client_Connection *TCP_connection);
70 */ 90 */
71void kill_TCP_connection(TCP_Client_Connection *TCP_connection); 91void kill_TCP_connection(TCP_Client_Connection *TCP_connection);
72 92
73int get_TCP_connection_status(TCP_Client_Connection *TCP_connection); 93/* return 1 on success.
94 * return 0 if could not send packet.
95 * return -1 on failure (connection must be killed).
96 */
97int send_onion_request(TCP_Client_Connection *con, uint8_t *data, uint16_t length);
98void onion_response_handler(TCP_Client_Connection *con, int (*onion_callback)(void *object, uint8_t *data,
99 uint16_t length), void *object);
74 100
75int read_TCP_connection(TCP_Client_Connection *TCP_connection, uint8_t *data); 101/* return 1 on success.
102 * return 0 if could not send packet.
103 * return -1 on failure (connection must be killed).
104 */
105int send_routing_request(TCP_Client_Connection *con, uint8_t *public_key);
106void routing_response_handler(TCP_Client_Connection *con, int (*response_callback)(void *object, uint8_t connection_id,
107 uint8_t *public_key), void *object);
108void routing_status_handler(TCP_Client_Connection *con, int (*status_callback)(void *object, uint32_t number,
109 uint8_t connection_id, uint8_t status), void *object);
110
111/* return 1 on success.
112 * return 0 if could not send packet.
113 * return -1 on failure (connection must be killed).
114 */
115int send_disconnect_request(TCP_Client_Connection *con, uint8_t con_id);
116
117/* Set the number that will be used as an argument in the callbacks related to con_id.
118 *
119 * When not set by this function, the number is ~0.
120 *
121 * return 0 on success.
122 * return -1 on failure.
123 */
124int set_tcp_connection_number(TCP_Client_Connection *con, uint8_t con_id, uint32_t number);
125
126/* return 1 on success.
127 * return 0 if could not send packet.
128 * return -1 on failure.
129 */
130int send_data(TCP_Client_Connection *con, uint8_t con_id, uint8_t *data, uint16_t length);
131void routing_data_handler(TCP_Client_Connection *con, int (*data_callback)(void *object, uint32_t number,
132 uint8_t connection_id, uint8_t *data, uint16_t length), void *object);
133
134/* return 1 on success.
135 * return 0 if could not send packet.
136 * return -1 on failure.
137 */
138int send_oob_packet(TCP_Client_Connection *con, uint8_t *public_key, uint8_t *data, uint16_t length);
139void oob_data_handler(TCP_Client_Connection *con, int (*oob_data_callback)(void *object, uint8_t *public_key,
140 uint8_t *data, uint16_t length), void *object);
76 141
77 142
78#endif 143#endif