diff options
author | iphydf <iphydf@users.noreply.github.com> | 2017-06-04 12:59:34 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2017-06-04 17:48:23 +0000 |
commit | 1e8fa85aadf602bdca3a540de09a8184f7139a6c (patch) | |
tree | 4caab80957f7f9a2098fb97e776be763defc44ab /toxcore | |
parent | 03f99bde2ecee3722d47a5b6a1031fc88e7210b7 (diff) |
Add a monolith_test that includes all toxcore sources.
This requires that every symbol, even if static (file-scope), is unique.
The idea is that we can easily run "whole" program static analysis on
programs that include monolith.h ("whole" is in quotes, as we don't
include dependencies like libsodium in this static analysis).
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/DHT.c | 18 | ||||
-rw-r--r-- | toxcore/Messenger.c | 44 | ||||
-rw-r--r-- | toxcore/TCP_client.c | 64 | ||||
-rw-r--r-- | toxcore/TCP_connection.c | 14 | ||||
-rw-r--r-- | toxcore/TCP_server.c | 48 | ||||
-rw-r--r-- | toxcore/TCP_server.h | 4 | ||||
-rw-r--r-- | toxcore/group.c | 8 | ||||
-rw-r--r-- | toxcore/onion_client.c | 14 |
8 files changed, 107 insertions, 107 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 5ef24564..30e0b816 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -798,13 +798,13 @@ int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *node | |||
798 | typedef struct { | 798 | typedef struct { |
799 | const uint8_t *base_public_key; | 799 | const uint8_t *base_public_key; |
800 | Client_data entry; | 800 | Client_data entry; |
801 | } Cmp_data; | 801 | } DHT_Cmp_data; |
802 | 802 | ||
803 | static int cmp_dht_entry(const void *a, const void *b) | 803 | static int cmp_dht_entry(const void *a, const void *b) |
804 | { | 804 | { |
805 | Cmp_data cmp1, cmp2; | 805 | DHT_Cmp_data cmp1, cmp2; |
806 | memcpy(&cmp1, a, sizeof(Cmp_data)); | 806 | memcpy(&cmp1, a, sizeof(DHT_Cmp_data)); |
807 | memcpy(&cmp2, b, sizeof(Cmp_data)); | 807 | memcpy(&cmp2, b, sizeof(DHT_Cmp_data)); |
808 | Client_data entry1 = cmp1.entry; | 808 | Client_data entry1 = cmp1.entry; |
809 | Client_data entry2 = cmp2.entry; | 809 | Client_data entry2 = cmp2.entry; |
810 | const uint8_t *cmp_public_key = cmp1.base_public_key; | 810 | const uint8_t *cmp_public_key = cmp1.base_public_key; |
@@ -871,14 +871,14 @@ static void sort_client_list(Client_data *list, unsigned int length, const uint8 | |||
871 | { | 871 | { |
872 | // Pass comp_public_key to qsort with each Client_data entry, so the | 872 | // Pass comp_public_key to qsort with each Client_data entry, so the |
873 | // comparison function can use it as the base of comparison. | 873 | // comparison function can use it as the base of comparison. |
874 | VLA(Cmp_data, cmp_list, length); | 874 | VLA(DHT_Cmp_data, cmp_list, length); |
875 | 875 | ||
876 | for (uint32_t i = 0; i < length; i++) { | 876 | for (uint32_t i = 0; i < length; i++) { |
877 | cmp_list[i].base_public_key = comp_public_key; | 877 | cmp_list[i].base_public_key = comp_public_key; |
878 | cmp_list[i].entry = list[i]; | 878 | cmp_list[i].entry = list[i]; |
879 | } | 879 | } |
880 | 880 | ||
881 | qsort(cmp_list, length, sizeof(Cmp_data), cmp_dht_entry); | 881 | qsort(cmp_list, length, sizeof(DHT_Cmp_data), cmp_dht_entry); |
882 | 882 | ||
883 | for (uint32_t i = 0; i < length; i++) { | 883 | for (uint32_t i = 0; i < length; i++) { |
884 | list[i] = cmp_list[i].entry; | 884 | list[i] = cmp_list[i].entry; |
@@ -2736,7 +2736,7 @@ uint32_t DHT_size(const DHT *dht) | |||
2736 | return size32 + sizesubhead + (packed_node_size(AF_INET) * numv4) + (packed_node_size(AF_INET6) * numv6); | 2736 | return size32 + sizesubhead + (packed_node_size(AF_INET) * numv4) + (packed_node_size(AF_INET6) * numv6); |
2737 | } | 2737 | } |
2738 | 2738 | ||
2739 | static uint8_t *z_state_save_subheader(uint8_t *data, uint32_t len, uint16_t type) | 2739 | static uint8_t *DHT_save_subheader(uint8_t *data, uint32_t len, uint16_t type) |
2740 | { | 2740 | { |
2741 | host_to_lendian32(data, len); | 2741 | host_to_lendian32(data, len); |
2742 | data += sizeof(uint32_t); | 2742 | data += sizeof(uint32_t); |
@@ -2757,7 +2757,7 @@ void DHT_save(DHT *dht, uint8_t *data) | |||
2757 | uint8_t *old_data = data; | 2757 | uint8_t *old_data = data; |
2758 | 2758 | ||
2759 | /* get right offset. we write the actual header later. */ | 2759 | /* get right offset. we write the actual header later. */ |
2760 | data = z_state_save_subheader(data, 0, 0); | 2760 | data = DHT_save_subheader(data, 0, 0); |
2761 | 2761 | ||
2762 | Node_format clients[MAX_SAVED_DHT_NODES]; | 2762 | Node_format clients[MAX_SAVED_DHT_NODES]; |
2763 | 2763 | ||
@@ -2793,7 +2793,7 @@ void DHT_save(DHT *dht, uint8_t *data) | |||
2793 | } | 2793 | } |
2794 | } | 2794 | } |
2795 | 2795 | ||
2796 | z_state_save_subheader(old_data, pack_nodes(data, sizeof(Node_format) * num, clients, num), DHT_STATE_TYPE_NODES); | 2796 | DHT_save_subheader(old_data, pack_nodes(data, sizeof(Node_format) * num, clients, num), DHT_STATE_TYPE_NODES); |
2797 | } | 2797 | } |
2798 | 2798 | ||
2799 | /* Bootstrap from this number of nodes every time DHT_connect_after_load() is called */ | 2799 | /* Bootstrap from this number of nodes every time DHT_connect_after_load() is called */ |
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 5dda5b30..7f21d367 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -166,10 +166,10 @@ static int send_offline_packet(Messenger *m, int friendcon_id) | |||
166 | sizeof(packet), 0) != -1; | 166 | sizeof(packet), 0) != -1; |
167 | } | 167 | } |
168 | 168 | ||
169 | static int handle_status(void *object, int i, uint8_t status, void *userdata); | 169 | static int m_handle_status(void *object, int i, uint8_t status, void *userdata); |
170 | static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len, void *userdata); | 170 | static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t len, void *userdata); |
171 | static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length, | 171 | static int m_handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length, |
172 | void *userdata); | 172 | void *userdata); |
173 | 173 | ||
174 | static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t status) | 174 | static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t status) |
175 | { | 175 | { |
@@ -198,8 +198,8 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t sta | |||
198 | m->friendlist[i].userstatus = USERSTATUS_NONE; | 198 | m->friendlist[i].userstatus = USERSTATUS_NONE; |
199 | m->friendlist[i].is_typing = 0; | 199 | m->friendlist[i].is_typing = 0; |
200 | m->friendlist[i].message_id = 0; | 200 | m->friendlist[i].message_id = 0; |
201 | friend_connection_callbacks(m->fr_c, friendcon_id, MESSENGER_CALLBACK_INDEX, &handle_status, &handle_packet, | 201 | friend_connection_callbacks(m->fr_c, friendcon_id, MESSENGER_CALLBACK_INDEX, &m_handle_status, &m_handle_packet, |
202 | &handle_custom_lossy_packet, m, i); | 202 | &m_handle_custom_lossy_packet, m, i); |
203 | 203 | ||
204 | if (m->numfriends == i) { | 204 | if (m->numfriends == i) { |
205 | ++m->numfriends; | 205 | ++m->numfriends; |
@@ -1757,8 +1757,8 @@ int m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, | |||
1757 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length, 0); | 1757 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length, 0); |
1758 | } | 1758 | } |
1759 | 1759 | ||
1760 | static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length, | 1760 | static int m_handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length, |
1761 | void *userdata) | 1761 | void *userdata) |
1762 | { | 1762 | { |
1763 | Messenger *m = (Messenger *)object; | 1763 | Messenger *m = (Messenger *)object; |
1764 | 1764 | ||
@@ -2080,7 +2080,7 @@ static void check_friend_request_timed_out(Messenger *m, uint32_t i, uint64_t t, | |||
2080 | } | 2080 | } |
2081 | } | 2081 | } |
2082 | 2082 | ||
2083 | static int handle_status(void *object, int i, uint8_t status, void *userdata) | 2083 | static int m_handle_status(void *object, int i, uint8_t status, void *userdata) |
2084 | { | 2084 | { |
2085 | Messenger *m = (Messenger *)object; | 2085 | Messenger *m = (Messenger *)object; |
2086 | 2086 | ||
@@ -2095,7 +2095,7 @@ static int handle_status(void *object, int i, uint8_t status, void *userdata) | |||
2095 | return 0; | 2095 | return 0; |
2096 | } | 2096 | } |
2097 | 2097 | ||
2098 | static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len, void *userdata) | 2098 | static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t len, void *userdata) |
2099 | { | 2099 | { |
2100 | if (len == 0) { | 2100 | if (len == 0) { |
2101 | return -1; | 2101 | return -1; |
@@ -2902,7 +2902,7 @@ uint32_t messenger_size(const Messenger *m) | |||
2902 | + sizesubhead; | 2902 | + sizesubhead; |
2903 | } | 2903 | } |
2904 | 2904 | ||
2905 | static uint8_t *z_state_save_subheader(uint8_t *data, uint32_t len, uint16_t type) | 2905 | static uint8_t *messenger_save_subheader(uint8_t *data, uint32_t len, uint16_t type) |
2906 | { | 2906 | { |
2907 | host_to_lendian32(data, len); | 2907 | host_to_lendian32(data, len); |
2908 | data += sizeof(uint32_t); | 2908 | data += sizeof(uint32_t); |
@@ -2928,69 +2928,69 @@ void messenger_save(const Messenger *m, uint8_t *data) | |||
2928 | assert(sizeof(get_nospam(&m->fr)) == sizeof(uint32_t)); | 2928 | assert(sizeof(get_nospam(&m->fr)) == sizeof(uint32_t)); |
2929 | len = size32 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE; | 2929 | len = size32 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE; |
2930 | type = MESSENGER_STATE_TYPE_NOSPAMKEYS; | 2930 | type = MESSENGER_STATE_TYPE_NOSPAMKEYS; |
2931 | data = z_state_save_subheader(data, len, type); | 2931 | data = messenger_save_subheader(data, len, type); |
2932 | *(uint32_t *)data = get_nospam(&(m->fr)); | 2932 | *(uint32_t *)data = get_nospam(&(m->fr)); |
2933 | save_keys(m->net_crypto, data + size32); | 2933 | save_keys(m->net_crypto, data + size32); |
2934 | data += len; | 2934 | data += len; |
2935 | 2935 | ||
2936 | len = saved_friendslist_size(m); | 2936 | len = saved_friendslist_size(m); |
2937 | type = MESSENGER_STATE_TYPE_FRIENDS; | 2937 | type = MESSENGER_STATE_TYPE_FRIENDS; |
2938 | data = z_state_save_subheader(data, len, type); | 2938 | data = messenger_save_subheader(data, len, type); |
2939 | friends_list_save(m, data); | 2939 | friends_list_save(m, data); |
2940 | data += len; | 2940 | data += len; |
2941 | 2941 | ||
2942 | len = m->name_length; | 2942 | len = m->name_length; |
2943 | type = MESSENGER_STATE_TYPE_NAME; | 2943 | type = MESSENGER_STATE_TYPE_NAME; |
2944 | data = z_state_save_subheader(data, len, type); | 2944 | data = messenger_save_subheader(data, len, type); |
2945 | memcpy(data, m->name, len); | 2945 | memcpy(data, m->name, len); |
2946 | data += len; | 2946 | data += len; |
2947 | 2947 | ||
2948 | len = m->statusmessage_length; | 2948 | len = m->statusmessage_length; |
2949 | type = MESSENGER_STATE_TYPE_STATUSMESSAGE; | 2949 | type = MESSENGER_STATE_TYPE_STATUSMESSAGE; |
2950 | data = z_state_save_subheader(data, len, type); | 2950 | data = messenger_save_subheader(data, len, type); |
2951 | memcpy(data, m->statusmessage, len); | 2951 | memcpy(data, m->statusmessage, len); |
2952 | data += len; | 2952 | data += len; |
2953 | 2953 | ||
2954 | len = 1; | 2954 | len = 1; |
2955 | type = MESSENGER_STATE_TYPE_STATUS; | 2955 | type = MESSENGER_STATE_TYPE_STATUS; |
2956 | data = z_state_save_subheader(data, len, type); | 2956 | data = messenger_save_subheader(data, len, type); |
2957 | *data = m->userstatus; | 2957 | *data = m->userstatus; |
2958 | data += len; | 2958 | data += len; |
2959 | 2959 | ||
2960 | len = DHT_size(m->dht); | 2960 | len = DHT_size(m->dht); |
2961 | type = MESSENGER_STATE_TYPE_DHT; | 2961 | type = MESSENGER_STATE_TYPE_DHT; |
2962 | data = z_state_save_subheader(data, len, type); | 2962 | data = messenger_save_subheader(data, len, type); |
2963 | DHT_save(m->dht, data); | 2963 | DHT_save(m->dht, data); |
2964 | data += len; | 2964 | data += len; |
2965 | 2965 | ||
2966 | Node_format relays[NUM_SAVED_TCP_RELAYS]; | 2966 | Node_format relays[NUM_SAVED_TCP_RELAYS]; |
2967 | type = MESSENGER_STATE_TYPE_TCP_RELAY; | 2967 | type = MESSENGER_STATE_TYPE_TCP_RELAY; |
2968 | uint8_t *temp_data = data; | 2968 | uint8_t *temp_data = data; |
2969 | data = z_state_save_subheader(temp_data, 0, type); | 2969 | data = messenger_save_subheader(temp_data, 0, type); |
2970 | unsigned int num = copy_connected_tcp_relays(m->net_crypto, relays, NUM_SAVED_TCP_RELAYS); | 2970 | unsigned int num = copy_connected_tcp_relays(m->net_crypto, relays, NUM_SAVED_TCP_RELAYS); |
2971 | int l = pack_nodes(data, NUM_SAVED_TCP_RELAYS * packed_node_size(TCP_INET6), relays, num); | 2971 | int l = pack_nodes(data, NUM_SAVED_TCP_RELAYS * packed_node_size(TCP_INET6), relays, num); |
2972 | 2972 | ||
2973 | if (l > 0) { | 2973 | if (l > 0) { |
2974 | len = l; | 2974 | len = l; |
2975 | data = z_state_save_subheader(temp_data, len, type); | 2975 | data = messenger_save_subheader(temp_data, len, type); |
2976 | data += len; | 2976 | data += len; |
2977 | } | 2977 | } |
2978 | 2978 | ||
2979 | Node_format nodes[NUM_SAVED_PATH_NODES]; | 2979 | Node_format nodes[NUM_SAVED_PATH_NODES]; |
2980 | type = MESSENGER_STATE_TYPE_PATH_NODE; | 2980 | type = MESSENGER_STATE_TYPE_PATH_NODE; |
2981 | temp_data = data; | 2981 | temp_data = data; |
2982 | data = z_state_save_subheader(data, 0, type); | 2982 | data = messenger_save_subheader(data, 0, type); |
2983 | memset(nodes, 0, sizeof(nodes)); | 2983 | memset(nodes, 0, sizeof(nodes)); |
2984 | num = onion_backup_nodes(m->onion_c, nodes, NUM_SAVED_PATH_NODES); | 2984 | num = onion_backup_nodes(m->onion_c, nodes, NUM_SAVED_PATH_NODES); |
2985 | l = pack_nodes(data, NUM_SAVED_PATH_NODES * packed_node_size(TCP_INET6), nodes, num); | 2985 | l = pack_nodes(data, NUM_SAVED_PATH_NODES * packed_node_size(TCP_INET6), nodes, num); |
2986 | 2986 | ||
2987 | if (l > 0) { | 2987 | if (l > 0) { |
2988 | len = l; | 2988 | len = l; |
2989 | data = z_state_save_subheader(temp_data, len, type); | 2989 | data = messenger_save_subheader(temp_data, len, type); |
2990 | data += len; | 2990 | data += len; |
2991 | } | 2991 | } |
2992 | 2992 | ||
2993 | z_state_save_subheader(data, 0, MESSENGER_STATE_TYPE_END); | 2993 | messenger_save_subheader(data, 0, MESSENGER_STATE_TYPE_END); |
2994 | } | 2994 | } |
2995 | 2995 | ||
2996 | static int messenger_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type) | 2996 | static int messenger_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type) |
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index 3e6de14a..e584b265 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c | |||
@@ -244,7 +244,7 @@ static int handle_handshake(TCP_Client_Connection *TCP_conn, const uint8_t *data | |||
244 | /* return 0 if pending data was sent completely | 244 | /* return 0 if pending data was sent completely |
245 | * return -1 if it wasn't | 245 | * return -1 if it wasn't |
246 | */ | 246 | */ |
247 | static int send_pending_data_nonpriority(TCP_Client_Connection *con) | 247 | static int client_send_pending_data_nonpriority(TCP_Client_Connection *con) |
248 | { | 248 | { |
249 | if (con->last_packet_length == 0) { | 249 | if (con->last_packet_length == 0) { |
250 | return 0; | 250 | return 0; |
@@ -270,10 +270,10 @@ static int send_pending_data_nonpriority(TCP_Client_Connection *con) | |||
270 | /* return 0 if pending data was sent completely | 270 | /* return 0 if pending data was sent completely |
271 | * return -1 if it wasn't | 271 | * return -1 if it wasn't |
272 | */ | 272 | */ |
273 | static int send_pending_data(TCP_Client_Connection *con) | 273 | static int client_send_pending_data(TCP_Client_Connection *con) |
274 | { | 274 | { |
275 | /* finish sending current non-priority packet */ | 275 | /* finish sending current non-priority packet */ |
276 | if (send_pending_data_nonpriority(con) == -1) { | 276 | if (client_send_pending_data_nonpriority(con) == -1) { |
277 | return -1; | 277 | return -1; |
278 | } | 278 | } |
279 | 279 | ||
@@ -309,7 +309,7 @@ static int send_pending_data(TCP_Client_Connection *con) | |||
309 | /* return 0 on failure (only if malloc fails) | 309 | /* return 0 on failure (only if malloc fails) |
310 | * return 1 on success | 310 | * return 1 on success |
311 | */ | 311 | */ |
312 | static bool add_priority(TCP_Client_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent) | 312 | static bool client_add_priority(TCP_Client_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent) |
313 | { | 313 | { |
314 | TCP_Priority_List *p = con->priority_queue_end; | 314 | TCP_Priority_List *p = con->priority_queue_end; |
315 | TCP_Priority_List *new_list = (TCP_Priority_List *)malloc(sizeof(TCP_Priority_List) + size); | 315 | TCP_Priority_List *new_list = (TCP_Priority_List *)malloc(sizeof(TCP_Priority_List) + size); |
@@ -348,7 +348,7 @@ static void wipe_priority_list(TCP_Client_Connection *con) | |||
348 | * return 0 if could not send packet. | 348 | * return 0 if could not send packet. |
349 | * return -1 on failure (connection must be killed). | 349 | * return -1 on failure (connection must be killed). |
350 | */ | 350 | */ |
351 | static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, const uint8_t *data, uint16_t length, | 351 | static int write_packet_TCP_client_secure_connection(TCP_Client_Connection *con, const uint8_t *data, uint16_t length, |
352 | bool priority) | 352 | bool priority) |
353 | { | 353 | { |
354 | if (length + CRYPTO_MAC_SIZE > MAX_PACKET_SIZE) { | 354 | if (length + CRYPTO_MAC_SIZE > MAX_PACKET_SIZE) { |
@@ -357,7 +357,7 @@ static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, const | |||
357 | 357 | ||
358 | bool sendpriority = 1; | 358 | bool sendpriority = 1; |
359 | 359 | ||
360 | if (send_pending_data(con) == -1) { | 360 | if (client_send_pending_data(con) == -1) { |
361 | if (priority) { | 361 | if (priority) { |
362 | sendpriority = 0; | 362 | sendpriority = 0; |
363 | } else { | 363 | } else { |
@@ -388,7 +388,7 @@ static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, const | |||
388 | return 1; | 388 | return 1; |
389 | } | 389 | } |
390 | 390 | ||
391 | return add_priority(con, packet, SIZEOF_VLA(packet), len); | 391 | return client_add_priority(con, packet, SIZEOF_VLA(packet), len); |
392 | } | 392 | } |
393 | 393 | ||
394 | len = send(con->sock, (const char *)packet, SIZEOF_VLA(packet), MSG_NOSIGNAL); | 394 | len = send(con->sock, (const char *)packet, SIZEOF_VLA(packet), MSG_NOSIGNAL); |
@@ -418,7 +418,7 @@ int send_routing_request(TCP_Client_Connection *con, uint8_t *public_key) | |||
418 | uint8_t packet[1 + CRYPTO_PUBLIC_KEY_SIZE]; | 418 | uint8_t packet[1 + CRYPTO_PUBLIC_KEY_SIZE]; |
419 | packet[0] = TCP_PACKET_ROUTING_REQUEST; | 419 | packet[0] = TCP_PACKET_ROUTING_REQUEST; |
420 | memcpy(packet + 1, public_key, CRYPTO_PUBLIC_KEY_SIZE); | 420 | memcpy(packet + 1, public_key, CRYPTO_PUBLIC_KEY_SIZE); |
421 | return write_packet_TCP_secure_connection(con, packet, sizeof(packet), 1); | 421 | return write_packet_TCP_client_secure_connection(con, packet, sizeof(packet), 1); |
422 | } | 422 | } |
423 | 423 | ||
424 | void routing_response_handler(TCP_Client_Connection *con, int (*response_callback)(void *object, uint8_t connection_id, | 424 | void routing_response_handler(TCP_Client_Connection *con, int (*response_callback)(void *object, uint8_t connection_id, |
@@ -435,8 +435,8 @@ void routing_status_handler(TCP_Client_Connection *con, int (*status_callback)(v | |||
435 | con->status_callback_object = object; | 435 | con->status_callback_object = object; |
436 | } | 436 | } |
437 | 437 | ||
438 | static int send_ping_response(TCP_Client_Connection *con); | 438 | static int tcp_send_ping_response(TCP_Client_Connection *con); |
439 | static int send_ping_request(TCP_Client_Connection *con); | 439 | static int tcp_send_ping_request(TCP_Client_Connection *con); |
440 | 440 | ||
441 | /* return 1 on success. | 441 | /* return 1 on success. |
442 | * return 0 if could not send packet. | 442 | * return 0 if could not send packet. |
@@ -452,14 +452,14 @@ int send_data(TCP_Client_Connection *con, uint8_t con_id, const uint8_t *data, u | |||
452 | return -1; | 452 | return -1; |
453 | } | 453 | } |
454 | 454 | ||
455 | if (send_ping_response(con) == 0 || send_ping_request(con) == 0) { | 455 | if (tcp_send_ping_response(con) == 0 || tcp_send_ping_request(con) == 0) { |
456 | return 0; | 456 | return 0; |
457 | } | 457 | } |
458 | 458 | ||
459 | VLA(uint8_t, packet, 1 + length); | 459 | VLA(uint8_t, packet, 1 + length); |
460 | packet[0] = con_id + NUM_RESERVED_PORTS; | 460 | packet[0] = con_id + NUM_RESERVED_PORTS; |
461 | memcpy(packet + 1, data, length); | 461 | memcpy(packet + 1, data, length); |
462 | return write_packet_TCP_secure_connection(con, packet, SIZEOF_VLA(packet), 0); | 462 | return write_packet_TCP_client_secure_connection(con, packet, SIZEOF_VLA(packet), 0); |
463 | } | 463 | } |
464 | 464 | ||
465 | /* return 1 on success. | 465 | /* return 1 on success. |
@@ -476,7 +476,7 @@ int send_oob_packet(TCP_Client_Connection *con, const uint8_t *public_key, const | |||
476 | packet[0] = TCP_PACKET_OOB_SEND; | 476 | packet[0] = TCP_PACKET_OOB_SEND; |
477 | memcpy(packet + 1, public_key, CRYPTO_PUBLIC_KEY_SIZE); | 477 | memcpy(packet + 1, public_key, CRYPTO_PUBLIC_KEY_SIZE); |
478 | memcpy(packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, data, length); | 478 | memcpy(packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, data, length); |
479 | return write_packet_TCP_secure_connection(con, packet, SIZEOF_VLA(packet), 0); | 479 | return write_packet_TCP_client_secure_connection(con, packet, SIZEOF_VLA(packet), 0); |
480 | } | 480 | } |
481 | 481 | ||
482 | 482 | ||
@@ -519,19 +519,19 @@ void oob_data_handler(TCP_Client_Connection *con, int (*oob_data_callback)(void | |||
519 | * return 0 if could not send packet. | 519 | * return 0 if could not send packet. |
520 | * return -1 on failure (connection must be killed). | 520 | * return -1 on failure (connection must be killed). |
521 | */ | 521 | */ |
522 | static int send_disconnect_notification(TCP_Client_Connection *con, uint8_t id) | 522 | static int client_send_disconnect_notification(TCP_Client_Connection *con, uint8_t id) |
523 | { | 523 | { |
524 | uint8_t packet[1 + 1]; | 524 | uint8_t packet[1 + 1]; |
525 | packet[0] = TCP_PACKET_DISCONNECT_NOTIFICATION; | 525 | packet[0] = TCP_PACKET_DISCONNECT_NOTIFICATION; |
526 | packet[1] = id; | 526 | packet[1] = id; |
527 | return write_packet_TCP_secure_connection(con, packet, sizeof(packet), 1); | 527 | return write_packet_TCP_client_secure_connection(con, packet, sizeof(packet), 1); |
528 | } | 528 | } |
529 | 529 | ||
530 | /* return 1 on success. | 530 | /* return 1 on success. |
531 | * return 0 if could not send packet. | 531 | * return 0 if could not send packet. |
532 | * return -1 on failure (connection must be killed). | 532 | * return -1 on failure (connection must be killed). |
533 | */ | 533 | */ |
534 | static int send_ping_request(TCP_Client_Connection *con) | 534 | static int tcp_send_ping_request(TCP_Client_Connection *con) |
535 | { | 535 | { |
536 | if (!con->ping_request_id) { | 536 | if (!con->ping_request_id) { |
537 | return 1; | 537 | return 1; |
@@ -542,7 +542,7 @@ static int send_ping_request(TCP_Client_Connection *con) | |||
542 | memcpy(packet + 1, &con->ping_request_id, sizeof(uint64_t)); | 542 | memcpy(packet + 1, &con->ping_request_id, sizeof(uint64_t)); |
543 | int ret; | 543 | int ret; |
544 | 544 | ||
545 | if ((ret = write_packet_TCP_secure_connection(con, packet, sizeof(packet), 1)) == 1) { | 545 | if ((ret = write_packet_TCP_client_secure_connection(con, packet, sizeof(packet), 1)) == 1) { |
546 | con->ping_request_id = 0; | 546 | con->ping_request_id = 0; |
547 | } | 547 | } |
548 | 548 | ||
@@ -553,7 +553,7 @@ static int send_ping_request(TCP_Client_Connection *con) | |||
553 | * return 0 if could not send packet. | 553 | * return 0 if could not send packet. |
554 | * return -1 on failure (connection must be killed). | 554 | * return -1 on failure (connection must be killed). |
555 | */ | 555 | */ |
556 | static int send_ping_response(TCP_Client_Connection *con) | 556 | static int tcp_send_ping_response(TCP_Client_Connection *con) |
557 | { | 557 | { |
558 | if (!con->ping_response_id) { | 558 | if (!con->ping_response_id) { |
559 | return 1; | 559 | return 1; |
@@ -564,7 +564,7 @@ static int send_ping_response(TCP_Client_Connection *con) | |||
564 | memcpy(packet + 1, &con->ping_response_id, sizeof(uint64_t)); | 564 | memcpy(packet + 1, &con->ping_response_id, sizeof(uint64_t)); |
565 | int ret; | 565 | int ret; |
566 | 566 | ||
567 | if ((ret = write_packet_TCP_secure_connection(con, packet, sizeof(packet), 1)) == 1) { | 567 | if ((ret = write_packet_TCP_client_secure_connection(con, packet, sizeof(packet), 1)) == 1) { |
568 | con->ping_response_id = 0; | 568 | con->ping_response_id = 0; |
569 | } | 569 | } |
570 | 570 | ||
@@ -583,7 +583,7 @@ int send_disconnect_request(TCP_Client_Connection *con, uint8_t con_id) | |||
583 | 583 | ||
584 | con->connections[con_id].status = 0; | 584 | con->connections[con_id].status = 0; |
585 | con->connections[con_id].number = 0; | 585 | con->connections[con_id].number = 0; |
586 | return send_disconnect_notification(con, con_id + NUM_RESERVED_PORTS); | 586 | return client_send_disconnect_notification(con, con_id + NUM_RESERVED_PORTS); |
587 | } | 587 | } |
588 | 588 | ||
589 | /* return 1 on success. | 589 | /* return 1 on success. |
@@ -595,7 +595,7 @@ int send_onion_request(TCP_Client_Connection *con, const uint8_t *data, uint16_t | |||
595 | VLA(uint8_t, packet, 1 + length); | 595 | VLA(uint8_t, packet, 1 + length); |
596 | packet[0] = TCP_PACKET_ONION_REQUEST; | 596 | packet[0] = TCP_PACKET_ONION_REQUEST; |
597 | memcpy(packet + 1, data, length); | 597 | memcpy(packet + 1, data, length); |
598 | return write_packet_TCP_secure_connection(con, packet, SIZEOF_VLA(packet), 0); | 598 | return write_packet_TCP_client_secure_connection(con, packet, SIZEOF_VLA(packet), 0); |
599 | } | 599 | } |
600 | 600 | ||
601 | void onion_response_handler(TCP_Client_Connection *con, int (*onion_callback)(void *object, const uint8_t *data, | 601 | void onion_response_handler(TCP_Client_Connection *con, int (*onion_callback)(void *object, const uint8_t *data, |
@@ -692,7 +692,7 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public | |||
692 | /* return 0 on success | 692 | /* return 0 on success |
693 | * return -1 on failure | 693 | * return -1 on failure |
694 | */ | 694 | */ |
695 | static int handle_TCP_packet(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length, void *userdata) | 695 | static int handle_TCP_client_packet(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length, void *userdata) |
696 | { | 696 | { |
697 | if (length <= 1) { | 697 | if (length <= 1) { |
698 | return -1; | 698 | return -1; |
@@ -787,7 +787,7 @@ static int handle_TCP_packet(TCP_Client_Connection *conn, const uint8_t *data, u | |||
787 | uint64_t ping_id; | 787 | uint64_t ping_id; |
788 | memcpy(&ping_id, data + 1, sizeof(uint64_t)); | 788 | memcpy(&ping_id, data + 1, sizeof(uint64_t)); |
789 | conn->ping_response_id = ping_id; | 789 | conn->ping_response_id = ping_id; |
790 | send_ping_response(conn); | 790 | tcp_send_ping_response(conn); |
791 | return 0; | 791 | return 0; |
792 | } | 792 | } |
793 | 793 | ||
@@ -847,9 +847,9 @@ static int handle_TCP_packet(TCP_Client_Connection *conn, const uint8_t *data, u | |||
847 | 847 | ||
848 | static int do_confirmed_TCP(TCP_Client_Connection *conn, void *userdata) | 848 | static int do_confirmed_TCP(TCP_Client_Connection *conn, void *userdata) |
849 | { | 849 | { |
850 | send_pending_data(conn); | 850 | client_send_pending_data(conn); |
851 | send_ping_response(conn); | 851 | tcp_send_ping_response(conn); |
852 | send_ping_request(conn); | 852 | tcp_send_ping_request(conn); |
853 | 853 | ||
854 | uint8_t packet[MAX_PACKET_SIZE]; | 854 | uint8_t packet[MAX_PACKET_SIZE]; |
855 | int len; | 855 | int len; |
@@ -862,7 +862,7 @@ static int do_confirmed_TCP(TCP_Client_Connection *conn, void *userdata) | |||
862 | } | 862 | } |
863 | 863 | ||
864 | conn->ping_request_id = conn->ping_id = ping_id; | 864 | conn->ping_request_id = conn->ping_id = ping_id; |
865 | send_ping_request(conn); | 865 | tcp_send_ping_request(conn); |
866 | conn->last_pinged = unix_time(); | 866 | conn->last_pinged = unix_time(); |
867 | } | 867 | } |
868 | 868 | ||
@@ -878,7 +878,7 @@ static int do_confirmed_TCP(TCP_Client_Connection *conn, void *userdata) | |||
878 | break; | 878 | break; |
879 | } | 879 | } |
880 | 880 | ||
881 | if (handle_TCP_packet(conn, packet, len, userdata) == -1) { | 881 | if (handle_TCP_client_packet(conn, packet, len, userdata) == -1) { |
882 | conn->status = TCP_CLIENT_DISCONNECTED; | 882 | conn->status = TCP_CLIENT_DISCONNECTED; |
883 | break; | 883 | break; |
884 | } | 884 | } |
@@ -898,7 +898,7 @@ void do_TCP_connection(TCP_Client_Connection *TCP_connection, void *userdata) | |||
898 | } | 898 | } |
899 | 899 | ||
900 | if (TCP_connection->status == TCP_CLIENT_PROXY_HTTP_CONNECTING) { | 900 | if (TCP_connection->status == TCP_CLIENT_PROXY_HTTP_CONNECTING) { |
901 | if (send_pending_data(TCP_connection) == 0) { | 901 | if (client_send_pending_data(TCP_connection) == 0) { |
902 | int ret = proxy_http_read_connection_response(TCP_connection); | 902 | int ret = proxy_http_read_connection_response(TCP_connection); |
903 | 903 | ||
904 | if (ret == -1) { | 904 | if (ret == -1) { |
@@ -914,7 +914,7 @@ void do_TCP_connection(TCP_Client_Connection *TCP_connection, void *userdata) | |||
914 | } | 914 | } |
915 | 915 | ||
916 | if (TCP_connection->status == TCP_CLIENT_PROXY_SOCKS5_CONNECTING) { | 916 | if (TCP_connection->status == TCP_CLIENT_PROXY_SOCKS5_CONNECTING) { |
917 | if (send_pending_data(TCP_connection) == 0) { | 917 | if (client_send_pending_data(TCP_connection) == 0) { |
918 | int ret = socks5_read_handshake_response(TCP_connection); | 918 | int ret = socks5_read_handshake_response(TCP_connection); |
919 | 919 | ||
920 | if (ret == -1) { | 920 | if (ret == -1) { |
@@ -930,7 +930,7 @@ void do_TCP_connection(TCP_Client_Connection *TCP_connection, void *userdata) | |||
930 | } | 930 | } |
931 | 931 | ||
932 | if (TCP_connection->status == TCP_CLIENT_PROXY_SOCKS5_UNCONFIRMED) { | 932 | if (TCP_connection->status == TCP_CLIENT_PROXY_SOCKS5_UNCONFIRMED) { |
933 | if (send_pending_data(TCP_connection) == 0) { | 933 | if (client_send_pending_data(TCP_connection) == 0) { |
934 | int ret = proxy_socks5_read_connection_response(TCP_connection); | 934 | int ret = proxy_socks5_read_connection_response(TCP_connection); |
935 | 935 | ||
936 | if (ret == -1) { | 936 | if (ret == -1) { |
@@ -946,7 +946,7 @@ void do_TCP_connection(TCP_Client_Connection *TCP_connection, void *userdata) | |||
946 | } | 946 | } |
947 | 947 | ||
948 | if (TCP_connection->status == TCP_CLIENT_CONNECTING) { | 948 | if (TCP_connection->status == TCP_CLIENT_CONNECTING) { |
949 | if (send_pending_data(TCP_connection) == 0) { | 949 | if (client_send_pending_data(TCP_connection) == 0) { |
950 | TCP_connection->status = TCP_CLIENT_UNCONFIRMED; | 950 | TCP_connection->status = TCP_CLIENT_UNCONFIRMED; |
951 | } | 951 | } |
952 | } | 952 | } |
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index 18c1e76e..b9c75afe 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c | |||
@@ -973,8 +973,8 @@ static int tcp_status_callback(void *object, uint32_t number, uint8_t connection | |||
973 | return 0; | 973 | return 0; |
974 | } | 974 | } |
975 | 975 | ||
976 | static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length, | 976 | static int tcp_conn_data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, |
977 | void *userdata) | 977 | uint16_t length, void *userdata) |
978 | { | 978 | { |
979 | if (length == 0) { | 979 | if (length == 0) { |
980 | return -1; | 980 | return -1; |
@@ -1003,8 +1003,8 @@ static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_i | |||
1003 | return 0; | 1003 | return 0; |
1004 | } | 1004 | } |
1005 | 1005 | ||
1006 | static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length, | 1006 | static int tcp_conn_oob_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length, |
1007 | void *userdata) | 1007 | void *userdata) |
1008 | { | 1008 | { |
1009 | if (length == 0) { | 1009 | if (length == 0) { |
1010 | return -1; | 1010 | return -1; |
@@ -1026,7 +1026,7 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8 | |||
1026 | TCP_Connection_to *con_to = get_connection(tcp_c, connections_number); | 1026 | TCP_Connection_to *con_to = get_connection(tcp_c, connections_number); |
1027 | 1027 | ||
1028 | if (con_to && tcp_connection_in_conn(con_to, tcp_connections_number)) { | 1028 | if (con_to && tcp_connection_in_conn(con_to, tcp_connections_number)) { |
1029 | return tcp_data_callback(object, connections_number, 0, data, length, userdata); | 1029 | return tcp_conn_data_callback(object, connections_number, 0, data, length, userdata); |
1030 | } | 1030 | } |
1031 | 1031 | ||
1032 | if (tcp_c->tcp_oob_callback) { | 1032 | if (tcp_c->tcp_oob_callback) { |
@@ -1067,8 +1067,8 @@ static int tcp_relay_set_callbacks(TCP_Connections *tcp_c, int tcp_connections_n | |||
1067 | onion_response_handler(con, &tcp_onion_callback, tcp_c); | 1067 | onion_response_handler(con, &tcp_onion_callback, tcp_c); |
1068 | routing_response_handler(con, &tcp_response_callback, con); | 1068 | routing_response_handler(con, &tcp_response_callback, con); |
1069 | routing_status_handler(con, &tcp_status_callback, con); | 1069 | routing_status_handler(con, &tcp_status_callback, con); |
1070 | routing_data_handler(con, &tcp_data_callback, con); | 1070 | routing_data_handler(con, &tcp_conn_data_callback, con); |
1071 | oob_data_handler(con, &tcp_oob_callback, con); | 1071 | oob_data_handler(con, &tcp_conn_oob_callback, con); |
1072 | 1072 | ||
1073 | return 0; | 1073 | return 0; |
1074 | } | 1074 | } |
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index d2b08206..3f2e554f 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c | |||
@@ -45,9 +45,9 @@ struct TCP_Server { | |||
45 | 45 | ||
46 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; | 46 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
47 | uint8_t secret_key[CRYPTO_SECRET_KEY_SIZE]; | 47 | uint8_t secret_key[CRYPTO_SECRET_KEY_SIZE]; |
48 | TCP_Secure_Connection incomming_connection_queue[MAX_INCOMMING_CONNECTIONS]; | 48 | TCP_Secure_Connection incoming_connection_queue[MAX_INCOMING_CONNECTIONS]; |
49 | uint16_t incomming_connection_queue_index; | 49 | uint16_t incoming_connection_queue_index; |
50 | TCP_Secure_Connection unconfirmed_connection_queue[MAX_INCOMMING_CONNECTIONS]; | 50 | TCP_Secure_Connection unconfirmed_connection_queue[MAX_INCOMING_CONNECTIONS]; |
51 | uint16_t unconfirmed_connection_queue_index; | 51 | uint16_t unconfirmed_connection_queue_index; |
52 | 52 | ||
53 | TCP_Secure_Connection *accepted_connection_array; | 53 | TCP_Secure_Connection *accepted_connection_array; |
@@ -477,7 +477,7 @@ static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, const | |||
477 | 477 | ||
478 | /* Kill a TCP_Secure_Connection | 478 | /* Kill a TCP_Secure_Connection |
479 | */ | 479 | */ |
480 | static void kill_TCP_connection(TCP_Secure_Connection *con) | 480 | static void kill_TCP_secure_connection(TCP_Secure_Connection *con) |
481 | { | 481 | { |
482 | kill_sock(con->sock); | 482 | kill_sock(con->sock); |
483 | crypto_memzero(con, sizeof(TCP_Secure_Connection)); | 483 | crypto_memzero(con, sizeof(TCP_Secure_Connection)); |
@@ -927,7 +927,7 @@ static int confirm_TCP_connection(TCP_Server *TCP_server, TCP_Secure_Connection | |||
927 | int index = add_accepted(TCP_server, con); | 927 | int index = add_accepted(TCP_server, con); |
928 | 928 | ||
929 | if (index == -1) { | 929 | if (index == -1) { |
930 | kill_TCP_connection(con); | 930 | kill_TCP_secure_connection(con); |
931 | return -1; | 931 | return -1; |
932 | } | 932 | } |
933 | 933 | ||
@@ -960,19 +960,19 @@ static int accept_connection(TCP_Server *TCP_server, Socket sock) | |||
960 | return -1; | 960 | return -1; |
961 | } | 961 | } |
962 | 962 | ||
963 | uint16_t index = TCP_server->incomming_connection_queue_index % MAX_INCOMMING_CONNECTIONS; | 963 | uint16_t index = TCP_server->incoming_connection_queue_index % MAX_INCOMING_CONNECTIONS; |
964 | 964 | ||
965 | TCP_Secure_Connection *conn = &TCP_server->incomming_connection_queue[index]; | 965 | TCP_Secure_Connection *conn = &TCP_server->incoming_connection_queue[index]; |
966 | 966 | ||
967 | if (conn->status != TCP_STATUS_NO_STATUS) { | 967 | if (conn->status != TCP_STATUS_NO_STATUS) { |
968 | kill_TCP_connection(conn); | 968 | kill_TCP_secure_connection(conn); |
969 | } | 969 | } |
970 | 970 | ||
971 | conn->status = TCP_STATUS_CONNECTED; | 971 | conn->status = TCP_STATUS_CONNECTED; |
972 | conn->sock = sock; | 972 | conn->sock = sock; |
973 | conn->next_packet_length = 0; | 973 | conn->next_packet_length = 0; |
974 | 974 | ||
975 | ++TCP_server->incomming_connection_queue_index; | 975 | ++TCP_server->incoming_connection_queue_index; |
976 | return index; | 976 | return index; |
977 | } | 977 | } |
978 | 978 | ||
@@ -1107,21 +1107,21 @@ static void do_TCP_accept_new(TCP_Server *TCP_server) | |||
1107 | 1107 | ||
1108 | static int do_incoming(TCP_Server *TCP_server, uint32_t i) | 1108 | static int do_incoming(TCP_Server *TCP_server, uint32_t i) |
1109 | { | 1109 | { |
1110 | if (TCP_server->incomming_connection_queue[i].status != TCP_STATUS_CONNECTED) { | 1110 | if (TCP_server->incoming_connection_queue[i].status != TCP_STATUS_CONNECTED) { |
1111 | return -1; | 1111 | return -1; |
1112 | } | 1112 | } |
1113 | 1113 | ||
1114 | int ret = read_connection_handshake(&TCP_server->incomming_connection_queue[i], TCP_server->secret_key); | 1114 | int ret = read_connection_handshake(&TCP_server->incoming_connection_queue[i], TCP_server->secret_key); |
1115 | 1115 | ||
1116 | if (ret == -1) { | 1116 | if (ret == -1) { |
1117 | kill_TCP_connection(&TCP_server->incomming_connection_queue[i]); | 1117 | kill_TCP_secure_connection(&TCP_server->incoming_connection_queue[i]); |
1118 | } else if (ret == 1) { | 1118 | } else if (ret == 1) { |
1119 | int index_new = TCP_server->unconfirmed_connection_queue_index % MAX_INCOMMING_CONNECTIONS; | 1119 | int index_new = TCP_server->unconfirmed_connection_queue_index % MAX_INCOMING_CONNECTIONS; |
1120 | TCP_Secure_Connection *conn_old = &TCP_server->incomming_connection_queue[i]; | 1120 | TCP_Secure_Connection *conn_old = &TCP_server->incoming_connection_queue[i]; |
1121 | TCP_Secure_Connection *conn_new = &TCP_server->unconfirmed_connection_queue[index_new]; | 1121 | TCP_Secure_Connection *conn_new = &TCP_server->unconfirmed_connection_queue[index_new]; |
1122 | 1122 | ||
1123 | if (conn_new->status != TCP_STATUS_NO_STATUS) { | 1123 | if (conn_new->status != TCP_STATUS_NO_STATUS) { |
1124 | kill_TCP_connection(conn_new); | 1124 | kill_TCP_secure_connection(conn_new); |
1125 | } | 1125 | } |
1126 | 1126 | ||
1127 | memcpy(conn_new, conn_old, sizeof(TCP_Secure_Connection)); | 1127 | memcpy(conn_new, conn_old, sizeof(TCP_Secure_Connection)); |
@@ -1151,7 +1151,7 @@ static int do_unconfirmed(TCP_Server *TCP_server, uint32_t i) | |||
1151 | } | 1151 | } |
1152 | 1152 | ||
1153 | if (len == -1) { | 1153 | if (len == -1) { |
1154 | kill_TCP_connection(conn); | 1154 | kill_TCP_secure_connection(conn); |
1155 | return -1; | 1155 | return -1; |
1156 | } | 1156 | } |
1157 | 1157 | ||
@@ -1179,11 +1179,11 @@ static void do_confirmed_recv(TCP_Server *TCP_server, uint32_t i) | |||
1179 | } | 1179 | } |
1180 | } | 1180 | } |
1181 | 1181 | ||
1182 | static void do_TCP_incomming(TCP_Server *TCP_server) | 1182 | static void do_TCP_incoming(TCP_Server *TCP_server) |
1183 | { | 1183 | { |
1184 | uint32_t i; | 1184 | uint32_t i; |
1185 | 1185 | ||
1186 | for (i = 0; i < MAX_INCOMMING_CONNECTIONS; ++i) { | 1186 | for (i = 0; i < MAX_INCOMING_CONNECTIONS; ++i) { |
1187 | do_incoming(TCP_server, i); | 1187 | do_incoming(TCP_server, i); |
1188 | } | 1188 | } |
1189 | } | 1189 | } |
@@ -1192,7 +1192,7 @@ static void do_TCP_unconfirmed(TCP_Server *TCP_server) | |||
1192 | { | 1192 | { |
1193 | uint32_t i; | 1193 | uint32_t i; |
1194 | 1194 | ||
1195 | for (i = 0; i < MAX_INCOMMING_CONNECTIONS; ++i) { | 1195 | for (i = 0; i < MAX_INCOMING_CONNECTIONS; ++i) { |
1196 | do_unconfirmed(TCP_server, i); | 1196 | do_unconfirmed(TCP_server, i); |
1197 | } | 1197 | } |
1198 | } | 1198 | } |
@@ -1276,12 +1276,12 @@ static void do_TCP_epoll(TCP_Server *TCP_server) | |||
1276 | } | 1276 | } |
1277 | 1277 | ||
1278 | case TCP_SOCKET_INCOMING: { | 1278 | case TCP_SOCKET_INCOMING: { |
1279 | kill_TCP_connection(&TCP_server->incomming_connection_queue[index]); | 1279 | kill_TCP_secure_connection(&TCP_server->incoming_connection_queue[index]); |
1280 | break; | 1280 | break; |
1281 | } | 1281 | } |
1282 | 1282 | ||
1283 | case TCP_SOCKET_UNCONFIRMED: { | 1283 | case TCP_SOCKET_UNCONFIRMED: { |
1284 | kill_TCP_connection(&TCP_server->unconfirmed_connection_queue[index]); | 1284 | kill_TCP_secure_connection(&TCP_server->unconfirmed_connection_queue[index]); |
1285 | break; | 1285 | break; |
1286 | } | 1286 | } |
1287 | 1287 | ||
@@ -1324,7 +1324,7 @@ static void do_TCP_epoll(TCP_Server *TCP_server) | |||
1324 | }; | 1324 | }; |
1325 | 1325 | ||
1326 | if (epoll_ctl(TCP_server->efd, EPOLL_CTL_ADD, sock_new, &ev) == -1) { | 1326 | if (epoll_ctl(TCP_server->efd, EPOLL_CTL_ADD, sock_new, &ev) == -1) { |
1327 | kill_TCP_connection(&TCP_server->incomming_connection_queue[index_new]); | 1327 | kill_TCP_secure_connection(&TCP_server->incoming_connection_queue[index_new]); |
1328 | continue; | 1328 | continue; |
1329 | } | 1329 | } |
1330 | } | 1330 | } |
@@ -1340,7 +1340,7 @@ static void do_TCP_epoll(TCP_Server *TCP_server) | |||
1340 | events[n].data.u64 = sock | ((uint64_t)TCP_SOCKET_UNCONFIRMED << 32) | ((uint64_t)index_new << 40); | 1340 | events[n].data.u64 = sock | ((uint64_t)TCP_SOCKET_UNCONFIRMED << 32) | ((uint64_t)index_new << 40); |
1341 | 1341 | ||
1342 | if (epoll_ctl(TCP_server->efd, EPOLL_CTL_MOD, sock, &events[n]) == -1) { | 1342 | if (epoll_ctl(TCP_server->efd, EPOLL_CTL_MOD, sock, &events[n]) == -1) { |
1343 | kill_TCP_connection(&TCP_server->unconfirmed_connection_queue[index_new]); | 1343 | kill_TCP_secure_connection(&TCP_server->unconfirmed_connection_queue[index_new]); |
1344 | break; | 1344 | break; |
1345 | } | 1345 | } |
1346 | } | 1346 | } |
@@ -1386,7 +1386,7 @@ void do_TCP_server(TCP_Server *TCP_server) | |||
1386 | 1386 | ||
1387 | #else | 1387 | #else |
1388 | do_TCP_accept_new(TCP_server); | 1388 | do_TCP_accept_new(TCP_server); |
1389 | do_TCP_incomming(TCP_server); | 1389 | do_TCP_incoming(TCP_server); |
1390 | do_TCP_unconfirmed(TCP_server); | 1390 | do_TCP_unconfirmed(TCP_server); |
1391 | #endif | 1391 | #endif |
1392 | 1392 | ||
diff --git a/toxcore/TCP_server.h b/toxcore/TCP_server.h index 7c1db65e..ddb204c2 100644 --- a/toxcore/TCP_server.h +++ b/toxcore/TCP_server.h | |||
@@ -36,9 +36,9 @@ | |||
36 | #define MSG_NOSIGNAL 0 | 36 | #define MSG_NOSIGNAL 0 |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | #define MAX_INCOMMING_CONNECTIONS 256 | 39 | #define MAX_INCOMING_CONNECTIONS 256 |
40 | 40 | ||
41 | #define TCP_MAX_BACKLOG MAX_INCOMMING_CONNECTIONS | 41 | #define TCP_MAX_BACKLOG MAX_INCOMING_CONNECTIONS |
42 | 42 | ||
43 | #define MAX_PACKET_SIZE 2048 | 43 | #define MAX_PACKET_SIZE 2048 |
44 | 44 | ||
diff --git a/toxcore/group.c b/toxcore/group.c index 73aca875..d3f068df 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -659,7 +659,7 @@ static void set_conns_status_groups(Group_Chats *g_c, int friendcon_id, uint8_t | |||
659 | } | 659 | } |
660 | } | 660 | } |
661 | 661 | ||
662 | static int handle_status(void *object, int friendcon_id, uint8_t status, void *userdata) | 662 | static int g_handle_status(void *object, int friendcon_id, uint8_t status, void *userdata) |
663 | { | 663 | { |
664 | Group_Chats *g_c = (Group_Chats *)object; | 664 | Group_Chats *g_c = (Group_Chats *)object; |
665 | 665 | ||
@@ -673,7 +673,7 @@ static int handle_status(void *object, int friendcon_id, uint8_t status, void *u | |||
673 | return 0; | 673 | return 0; |
674 | } | 674 | } |
675 | 675 | ||
676 | static int handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata); | 676 | static int g_handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata); |
677 | static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata); | 677 | static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata); |
678 | 678 | ||
679 | /* Add friend to group chat. | 679 | /* Add friend to group chat. |
@@ -715,7 +715,7 @@ static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, int groupnu | |||
715 | g->close[ind].number = friendcon_id; | 715 | g->close[ind].number = friendcon_id; |
716 | g->close[ind].closest = closest; | 716 | g->close[ind].closest = closest; |
717 | // TODO(irungentoo): | 717 | // TODO(irungentoo): |
718 | friend_connection_callbacks(g_c->m->fr_c, friendcon_id, GROUPCHAT_CALLBACK_INDEX, &handle_status, &handle_packet, | 718 | friend_connection_callbacks(g_c->m->fr_c, friendcon_id, GROUPCHAT_CALLBACK_INDEX, &g_handle_status, &g_handle_packet, |
719 | &handle_lossy, g_c, friendcon_id); | 719 | &handle_lossy, g_c, friendcon_id); |
720 | 720 | ||
721 | return ind; | 721 | return ind; |
@@ -2124,7 +2124,7 @@ static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const | |||
2124 | send_message_all_close(g_c, groupnumber, data, length, -1/* TODO(irungentoo) close_index */); | 2124 | send_message_all_close(g_c, groupnumber, data, length, -1/* TODO(irungentoo) close_index */); |
2125 | } | 2125 | } |
2126 | 2126 | ||
2127 | static int handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata) | 2127 | static int g_handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata) |
2128 | { | 2128 | { |
2129 | Group_Chats *g_c = (Group_Chats *)object; | 2129 | Group_Chats *g_c = (Group_Chats *)object; |
2130 | 2130 | ||
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index ddae84e5..3c14a101 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -474,13 +474,13 @@ static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, IP_ | |||
474 | typedef struct { | 474 | typedef struct { |
475 | const uint8_t *base_public_key; | 475 | const uint8_t *base_public_key; |
476 | Onion_Node entry; | 476 | Onion_Node entry; |
477 | } Cmp_data; | 477 | } Onion_Client_Cmp_data; |
478 | 478 | ||
479 | static int cmp_entry(const void *a, const void *b) | 479 | static int onion_client_cmp_entry(const void *a, const void *b) |
480 | { | 480 | { |
481 | Cmp_data cmp1, cmp2; | 481 | Onion_Client_Cmp_data cmp1, cmp2; |
482 | memcpy(&cmp1, a, sizeof(Cmp_data)); | 482 | memcpy(&cmp1, a, sizeof(Onion_Client_Cmp_data)); |
483 | memcpy(&cmp2, b, sizeof(Cmp_data)); | 483 | memcpy(&cmp2, b, sizeof(Onion_Client_Cmp_data)); |
484 | Onion_Node entry1 = cmp1.entry; | 484 | Onion_Node entry1 = cmp1.entry; |
485 | Onion_Node entry2 = cmp2.entry; | 485 | Onion_Node entry2 = cmp2.entry; |
486 | const uint8_t *cmp_public_key = cmp1.base_public_key; | 486 | const uint8_t *cmp_public_key = cmp1.base_public_key; |
@@ -517,14 +517,14 @@ static void sort_onion_node_list(Onion_Node *list, unsigned int length, const ui | |||
517 | { | 517 | { |
518 | // Pass comp_public_key to qsort with each Client_data entry, so the | 518 | // Pass comp_public_key to qsort with each Client_data entry, so the |
519 | // comparison function can use it as the base of comparison. | 519 | // comparison function can use it as the base of comparison. |
520 | VLA(Cmp_data, cmp_list, length); | 520 | VLA(Onion_Client_Cmp_data, cmp_list, length); |
521 | 521 | ||
522 | for (uint32_t i = 0; i < length; i++) { | 522 | for (uint32_t i = 0; i < length; i++) { |
523 | cmp_list[i].base_public_key = comp_public_key; | 523 | cmp_list[i].base_public_key = comp_public_key; |
524 | cmp_list[i].entry = list[i]; | 524 | cmp_list[i].entry = list[i]; |
525 | } | 525 | } |
526 | 526 | ||
527 | qsort(cmp_list, length, sizeof(Cmp_data), cmp_entry); | 527 | qsort(cmp_list, length, sizeof(Onion_Client_Cmp_data), onion_client_cmp_entry); |
528 | 528 | ||
529 | for (uint32_t i = 0; i < length; i++) { | 529 | for (uint32_t i = 0; i < length; i++) { |
530 | list[i] = cmp_list[i].entry; | 530 | list[i] = cmp_list[i].entry; |