summaryrefslogtreecommitdiff
path: root/toxcore/TCP_server.c
diff options
context:
space:
mode:
authormannol <eniz_vukovic@hotmail.com>2014-07-03 17:08:38 +0200
committermannol <eniz_vukovic@hotmail.com>2014-07-03 17:08:38 +0200
commitf8a2a865dc32bfa626cc150a509d30d897e1181b (patch)
tree5bb6b234149cdf2a79422815dc59a0c53cb3cb0e /toxcore/TCP_server.c
parenta9a7f6a5952d0385904ec9df078ac065a3f5887f (diff)
parentc4f0650ae33e1669bfc994ef4f76c6c31e4d63c0 (diff)
Resolved conflicts when merging upstream
Diffstat (limited to 'toxcore/TCP_server.c')
-rw-r--r--toxcore/TCP_server.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c
index 578784d0..7487ad4f 100644
--- a/toxcore/TCP_server.c
+++ b/toxcore/TCP_server.c
@@ -97,7 +97,7 @@ static int realloc_connection(TCP_Server *TCP_server, uint32_t num)
97/* return index corresponding to connection with peer on success 97/* return index corresponding to connection with peer on success
98 * return -1 on failure. 98 * return -1 on failure.
99 */ 99 */
100static int get_TCP_connection_index(TCP_Server *TCP_server, uint8_t *public_key) 100static int get_TCP_connection_index(const TCP_Server *TCP_server, const uint8_t *public_key)
101{ 101{
102 return bs_list_find(&TCP_server->accepted_key_list, public_key); 102 return bs_list_find(&TCP_server->accepted_key_list, public_key);
103} 103}
@@ -110,7 +110,7 @@ static int kill_accepted(TCP_Server *TCP_server, int index);
110 * return index on success 110 * return index on success
111 * return -1 on failure 111 * return -1 on failure
112 */ 112 */
113static int add_accepted(TCP_Server *TCP_server, TCP_Secure_Connection *con) 113static int add_accepted(TCP_Server *TCP_server, const TCP_Secure_Connection *con)
114{ 114{
115 int index = get_TCP_connection_index(TCP_server, con->public_key); 115 int index = get_TCP_connection_index(TCP_server, con->public_key);
116 116
@@ -249,7 +249,7 @@ int read_TCP_packet(sock_t sock, uint8_t *data, uint16_t length)
249 * return 0 if could not read any packet. 249 * return 0 if could not read any packet.
250 * return -1 on failure (connection must be killed). 250 * return -1 on failure (connection must be killed).
251 */ 251 */
252int read_packet_TCP_secure_connection(sock_t sock, uint16_t *next_packet_length, uint8_t *shared_key, 252int read_packet_TCP_secure_connection(sock_t sock, uint16_t *next_packet_length, const uint8_t *shared_key,
253 uint8_t *recv_nonce, uint8_t *data, uint16_t max_len) 253 uint8_t *recv_nonce, uint8_t *data, uint16_t max_len)
254{ 254{
255 if (*next_packet_length == 0) { 255 if (*next_packet_length == 0) {
@@ -318,7 +318,7 @@ static int send_pending_data(TCP_Secure_Connection *con)
318 * return 0 if could not send packet. 318 * return 0 if could not send packet.
319 * return -1 on failure (connection must be killed). 319 * return -1 on failure (connection must be killed).
320 */ 320 */
321static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, uint8_t *data, uint16_t length) 321static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, const uint8_t *data, uint16_t length)
322{ 322{
323 if (length + crypto_box_MACBYTES > MAX_PACKET_SIZE) 323 if (length + crypto_box_MACBYTES > MAX_PACKET_SIZE)
324 return -1; 324 return -1;
@@ -389,7 +389,8 @@ static int kill_accepted(TCP_Server *TCP_server, int index)
389/* return 1 if everything went well. 389/* return 1 if everything went well.
390 * return -1 if the connection must be killed. 390 * return -1 if the connection must be killed.
391 */ 391 */
392static int handle_TCP_handshake(TCP_Secure_Connection *con, uint8_t *data, uint16_t length, uint8_t *self_secret_key) 392static int handle_TCP_handshake(TCP_Secure_Connection *con, const uint8_t *data, uint16_t length,
393 const uint8_t *self_secret_key)
393{ 394{
394 if (length != TCP_CLIENT_HANDSHAKE_SIZE) 395 if (length != TCP_CLIENT_HANDSHAKE_SIZE)
395 return -1; 396 return -1;
@@ -435,7 +436,7 @@ static int handle_TCP_handshake(TCP_Secure_Connection *con, uint8_t *data, uint1
435 * return 0 if we didn't get it yet. 436 * return 0 if we didn't get it yet.
436 * return -1 if the connection must be killed. 437 * return -1 if the connection must be killed.
437 */ 438 */
438static int read_connection_handshake(TCP_Secure_Connection *con, uint8_t *self_secret_key) 439static int read_connection_handshake(TCP_Secure_Connection *con, const uint8_t *self_secret_key)
439{ 440{
440 uint8_t data[TCP_CLIENT_HANDSHAKE_SIZE]; 441 uint8_t data[TCP_CLIENT_HANDSHAKE_SIZE];
441 int len = 0; 442 int len = 0;
@@ -451,7 +452,7 @@ static int read_connection_handshake(TCP_Secure_Connection *con, uint8_t *self_s
451 * return 0 if could not send packet. 452 * return 0 if could not send packet.
452 * return -1 on failure (connection must be killed). 453 * return -1 on failure (connection must be killed).
453 */ 454 */
454static int send_routing_response(TCP_Secure_Connection *con, uint8_t rpid, uint8_t *public_key) 455static int send_routing_response(TCP_Secure_Connection *con, uint8_t rpid, const uint8_t *public_key)
455{ 456{
456 uint8_t data[1 + 1 + crypto_box_PUBLICKEYBYTES]; 457 uint8_t data[1 + 1 + crypto_box_PUBLICKEYBYTES];
457 data[0] = TCP_PACKET_ROUTING_RESPONSE; 458 data[0] = TCP_PACKET_ROUTING_RESPONSE;
@@ -484,7 +485,7 @@ static int send_disconnect_notification(TCP_Secure_Connection *con, uint8_t id)
484/* return 0 on success. 485/* return 0 on success.
485 * return -1 on failure (connection must be killed). 486 * return -1 on failure (connection must be killed).
486 */ 487 */
487static int handle_TCP_routing_req(TCP_Server *TCP_server, uint32_t con_id, uint8_t *public_key) 488static int handle_TCP_routing_req(TCP_Server *TCP_server, uint32_t con_id, const uint8_t *public_key)
488{ 489{
489 uint32_t i; 490 uint32_t i;
490 uint32_t index = ~0; 491 uint32_t index = ~0;
@@ -562,7 +563,7 @@ static int handle_TCP_routing_req(TCP_Server *TCP_server, uint32_t con_id, uint8
562/* return 0 on success. 563/* return 0 on success.
563 * return -1 on failure (connection must be killed). 564 * return -1 on failure (connection must be killed).
564 */ 565 */
565static int handle_TCP_oob_send(TCP_Server *TCP_server, uint32_t con_id, uint8_t *public_key, uint8_t *data, 566static int handle_TCP_oob_send(TCP_Server *TCP_server, uint32_t con_id, const uint8_t *public_key, const uint8_t *data,
566 uint16_t length) 567 uint16_t length)
567{ 568{
568 if (length == 0 || length > TCP_MAX_OOB_DATA_LENGTH) 569 if (length == 0 || length > TCP_MAX_OOB_DATA_LENGTH)
@@ -645,7 +646,7 @@ static int handle_onion_recv_1(void *object, IP_Port dest, const uint8_t *data,
645/* return 0 on success 646/* return 0 on success
646 * return -1 on failure 647 * return -1 on failure
647 */ 648 */
648static int handle_TCP_packet(TCP_Server *TCP_server, uint32_t con_id, uint8_t *data, uint16_t length) 649static int handle_TCP_packet(TCP_Server *TCP_server, uint32_t con_id, const uint8_t *data, uint16_t length)
649{ 650{
650 if (length == 0) 651 if (length == 0)
651 return -1; 652 return -1;
@@ -764,7 +765,8 @@ static int handle_TCP_packet(TCP_Server *TCP_server, uint32_t con_id, uint8_t *d
764} 765}
765 766
766 767
767static int confirm_TCP_connection(TCP_Server *TCP_server, TCP_Secure_Connection *con, uint8_t *data, uint16_t length) 768static int confirm_TCP_connection(TCP_Server *TCP_server, TCP_Secure_Connection *con, const uint8_t *data,
769 uint16_t length)
768{ 770{
769 int index = add_accepted(TCP_server, con); 771 int index = add_accepted(TCP_server, con);
770 772
@@ -838,8 +840,8 @@ static sock_t new_listening_TCP_socket(int family, uint16_t port)
838 return sock; 840 return sock;
839} 841}
840 842
841TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, uint16_t *ports, uint8_t *public_key, 843TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uint16_t *ports, const uint8_t *public_key,
842 uint8_t *secret_key, Onion *onion) 844 const uint8_t *secret_key, Onion *onion)
843{ 845{
844 if (num_sockets == 0 || ports == NULL) 846 if (num_sockets == 0 || ports == NULL)
845 return NULL; 847 return NULL;