diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-07-12 17:22:20 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-07-12 20:21:42 +0000 |
commit | beeb9b4335d9ca6f947a52528453753a51f194f3 (patch) | |
tree | 242cad42e2e90ebf5ed04283fd79f42f4e3afa60 /toxcore/TCP_connection.h | |
parent | cbda01021c561bd061cb03a1c1bab58199ac2307 (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.h | 33 |
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 | ||
54 | typedef struct { | 54 | typedef struct TCP_Conn_to { |
55 | uint32_t tcp_connection; | ||
56 | unsigned int status; | ||
57 | unsigned int connection_id; | ||
58 | } TCP_Conn_to; | ||
59 | |||
60 | typedef 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 | ||
67 | typedef struct { | 69 | typedef 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); | |||
124 | int tcp_send_oob_packet(TCP_Connections *tcp_c, unsigned int tcp_connections_number, const uint8_t *public_key, | 126 | int 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 | ||
129 | typedef 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 | */ |
129 | void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_data_callback)(void *object, int id, | 133 | void 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 | |
135 | typedef 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 | */ |
134 | void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_onion_callback)(void *object, | 139 | void 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 | |
141 | typedef 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 | */ |
139 | void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_oob_callback)(void *object, | 146 | void 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 | * |