summaryrefslogtreecommitdiff
path: root/toxcore/TCP_connection.h
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-07-12 17:22:20 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-07-12 20:21:42 +0000
commitbeeb9b4335d9ca6f947a52528453753a51f194f3 (patch)
tree242cad42e2e90ebf5ed04283fd79f42f4e3afa60 /toxcore/TCP_connection.h
parentcbda01021c561bd061cb03a1c1bab58199ac2307 (diff)
Style fixes in TCP code; remove MIN and PAIR from util.h.
* Moved PAIR to toxav, where it's used (but really this should die). * Replace most MIN calls with typed `min_*` calls. Didn't replace the ones where the desired semantics are unclear. Moved the MIN macro to the one place where it's still used. * Avoid assignments in `while` loops. Instead, factored out the loop body into a separate `bool`-returning function. * Use named types for callbacks (`_cb` types). * Avoid assignments in `if` conditions. * Removed `MAKE_REALLOC` and expanded its two calls. We can't have templates in C, and this fake templating is ugly and hard to analyse and debug (it expands on a single line). * Moved epoll system include to the .c file, out of the .h file. * Avoid assignments in expressions (`a = b = c;`). * Avoid multiple declarators per struct member declaration. * Fix naming inconsistencies. * Replace `net_to_host` macro with function.
Diffstat (limited to 'toxcore/TCP_connection.h')
-rw-r--r--toxcore/TCP_connection.h33
1 files changed, 19 insertions, 14 deletions
diff --git a/toxcore/TCP_connection.h b/toxcore/TCP_connection.h
index a45129a7..658ee1f4 100644
--- a/toxcore/TCP_connection.h
+++ b/toxcore/TCP_connection.h
@@ -51,20 +51,22 @@
51/* Number of TCP connections used for onion purposes. */ 51/* Number of TCP connections used for onion purposes. */
52#define NUM_ONION_TCP_CONNECTIONS RECOMMENDED_FRIEND_TCP_CONNECTIONS 52#define NUM_ONION_TCP_CONNECTIONS RECOMMENDED_FRIEND_TCP_CONNECTIONS
53 53
54typedef struct { 54typedef struct TCP_Conn_to {
55 uint32_t tcp_connection;
56 unsigned int status;
57 unsigned int connection_id;
58} TCP_Conn_to;
59
60typedef struct TCP_Connection_to {
55 uint8_t status; 61 uint8_t status;
56 uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; /* The dht public key of the peer */ 62 uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; /* The dht public key of the peer */
57 63
58 struct { 64 TCP_Conn_to connections[MAX_FRIEND_TCP_CONNECTIONS];
59 uint32_t tcp_connection;
60 unsigned int status;
61 unsigned int connection_id;
62 } connections[MAX_FRIEND_TCP_CONNECTIONS];
63 65
64 int id; /* id used in callbacks. */ 66 int id; /* id used in callbacks. */
65} TCP_Connection_to; 67} TCP_Connection_to;
66 68
67typedef struct { 69typedef struct TCP_con {
68 uint8_t status; 70 uint8_t status;
69 TCP_Client_Connection *connection; 71 TCP_Client_Connection *connection;
70 uint64_t connected_time; 72 uint64_t connected_time;
@@ -124,21 +126,24 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status);
124int tcp_send_oob_packet(TCP_Connections *tcp_c, unsigned int tcp_connections_number, const uint8_t *public_key, 126int tcp_send_oob_packet(TCP_Connections *tcp_c, unsigned int tcp_connections_number, const uint8_t *public_key,
125 const uint8_t *packet, uint16_t length); 127 const uint8_t *packet, uint16_t length);
126 128
129typedef int tcp_data_cb(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
130
127/* Set the callback for TCP data packets. 131/* Set the callback for TCP data packets.
128 */ 132 */
129void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_data_callback)(void *object, int id, 133void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_data_cb *tcp_data_callback, void *object);
130 const uint8_t *data, uint16_t length, void *userdata), void *object); 134
135typedef int tcp_onion_cb(void *object, const uint8_t *data, uint16_t length, void *userdata);
131 136
132/* Set the callback for TCP onion packets. 137/* Set the callback for TCP onion packets.
133 */ 138 */
134void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_onion_callback)(void *object, 139void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_onion_cb *tcp_onion_callback, void *object);
135 const uint8_t *data, uint16_t length, void *userdata), void *object); 140
141typedef int tcp_oob_cb(void *object, const uint8_t *public_key, unsigned int tcp_connections_number,
142 const uint8_t *data, uint16_t length, void *userdata);
136 143
137/* Set the callback for TCP oob data packets. 144/* Set the callback for TCP oob data packets.
138 */ 145 */
139void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_oob_callback)(void *object, 146void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_oob_cb *tcp_oob_callback, void *object);
140 const uint8_t *public_key, unsigned int tcp_connections_number, const uint8_t *data, uint16_t length, void *userdata),
141 void *object);
142 147
143/* Create a new TCP connection to public_key. 148/* Create a new TCP connection to public_key.
144 * 149 *