summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/TCP_server.c26
-rw-r--r--toxcore/TCP_server.h6
2 files changed, 16 insertions, 16 deletions
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c
index 578784d0..235fdf02 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,7 @@ 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, const uint8_t *self_secret_key)
393{ 393{
394 if (length != TCP_CLIENT_HANDSHAKE_SIZE) 394 if (length != TCP_CLIENT_HANDSHAKE_SIZE)
395 return -1; 395 return -1;
@@ -435,7 +435,7 @@ static int handle_TCP_handshake(TCP_Secure_Connection *con, uint8_t *data, uint1
435 * return 0 if we didn't get it yet. 435 * return 0 if we didn't get it yet.
436 * return -1 if the connection must be killed. 436 * return -1 if the connection must be killed.
437 */ 437 */
438static int read_connection_handshake(TCP_Secure_Connection *con, uint8_t *self_secret_key) 438static int read_connection_handshake(TCP_Secure_Connection *con, const uint8_t *self_secret_key)
439{ 439{
440 uint8_t data[TCP_CLIENT_HANDSHAKE_SIZE]; 440 uint8_t data[TCP_CLIENT_HANDSHAKE_SIZE];
441 int len = 0; 441 int len = 0;
@@ -451,7 +451,7 @@ static int read_connection_handshake(TCP_Secure_Connection *con, uint8_t *self_s
451 * return 0 if could not send packet. 451 * return 0 if could not send packet.
452 * return -1 on failure (connection must be killed). 452 * return -1 on failure (connection must be killed).
453 */ 453 */
454static int send_routing_response(TCP_Secure_Connection *con, uint8_t rpid, uint8_t *public_key) 454static int send_routing_response(TCP_Secure_Connection *con, uint8_t rpid, const uint8_t *public_key)
455{ 455{
456 uint8_t data[1 + 1 + crypto_box_PUBLICKEYBYTES]; 456 uint8_t data[1 + 1 + crypto_box_PUBLICKEYBYTES];
457 data[0] = TCP_PACKET_ROUTING_RESPONSE; 457 data[0] = TCP_PACKET_ROUTING_RESPONSE;
@@ -484,7 +484,7 @@ static int send_disconnect_notification(TCP_Secure_Connection *con, uint8_t id)
484/* return 0 on success. 484/* return 0 on success.
485 * return -1 on failure (connection must be killed). 485 * return -1 on failure (connection must be killed).
486 */ 486 */
487static int handle_TCP_routing_req(TCP_Server *TCP_server, uint32_t con_id, uint8_t *public_key) 487static int handle_TCP_routing_req(TCP_Server *TCP_server, uint32_t con_id, const uint8_t *public_key)
488{ 488{
489 uint32_t i; 489 uint32_t i;
490 uint32_t index = ~0; 490 uint32_t index = ~0;
@@ -562,7 +562,7 @@ static int handle_TCP_routing_req(TCP_Server *TCP_server, uint32_t con_id, uint8
562/* return 0 on success. 562/* return 0 on success.
563 * return -1 on failure (connection must be killed). 563 * return -1 on failure (connection must be killed).
564 */ 564 */
565static int handle_TCP_oob_send(TCP_Server *TCP_server, uint32_t con_id, uint8_t *public_key, uint8_t *data, 565static 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) 566 uint16_t length)
567{ 567{
568 if (length == 0 || length > TCP_MAX_OOB_DATA_LENGTH) 568 if (length == 0 || length > TCP_MAX_OOB_DATA_LENGTH)
@@ -645,7 +645,7 @@ static int handle_onion_recv_1(void *object, IP_Port dest, const uint8_t *data,
645/* return 0 on success 645/* return 0 on success
646 * return -1 on failure 646 * return -1 on failure
647 */ 647 */
648static int handle_TCP_packet(TCP_Server *TCP_server, uint32_t con_id, uint8_t *data, uint16_t length) 648static int handle_TCP_packet(TCP_Server *TCP_server, uint32_t con_id, const uint8_t *data, uint16_t length)
649{ 649{
650 if (length == 0) 650 if (length == 0)
651 return -1; 651 return -1;
@@ -764,7 +764,7 @@ static int handle_TCP_packet(TCP_Server *TCP_server, uint32_t con_id, uint8_t *d
764} 764}
765 765
766 766
767static int confirm_TCP_connection(TCP_Server *TCP_server, TCP_Secure_Connection *con, uint8_t *data, uint16_t length) 767static int confirm_TCP_connection(TCP_Server *TCP_server, TCP_Secure_Connection *con, const uint8_t *data, uint16_t length)
768{ 768{
769 int index = add_accepted(TCP_server, con); 769 int index = add_accepted(TCP_server, con);
770 770
@@ -838,8 +838,8 @@ static sock_t new_listening_TCP_socket(int family, uint16_t port)
838 return sock; 838 return sock;
839} 839}
840 840
841TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, uint16_t *ports, uint8_t *public_key, 841TCP_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) 842 const uint8_t *secret_key, Onion *onion)
843{ 843{
844 if (num_sockets == 0 || ports == NULL) 844 if (num_sockets == 0 || ports == NULL)
845 return NULL; 845 return NULL;
diff --git a/toxcore/TCP_server.h b/toxcore/TCP_server.h
index 40984778..def0a978 100644
--- a/toxcore/TCP_server.h
+++ b/toxcore/TCP_server.h
@@ -133,8 +133,8 @@ typedef struct {
133 133
134/* Create new TCP server instance. 134/* Create new TCP server instance.
135 */ 135 */
136TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, uint16_t *ports, uint8_t *public_key, 136TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uint16_t *ports, const uint8_t *public_key,
137 uint8_t *secret_key, Onion *onion); 137 const uint8_t *secret_key, Onion *onion);
138 138
139/* Run the TCP_server 139/* Run the TCP_server
140 */ 140 */
@@ -164,7 +164,7 @@ int read_TCP_packet(sock_t sock, uint8_t *data, uint16_t length);
164 * return 0 if could not read any packet. 164 * return 0 if could not read any packet.
165 * return -1 on failure (connection must be killed). 165 * return -1 on failure (connection must be killed).
166 */ 166 */
167int read_packet_TCP_secure_connection(sock_t sock, uint16_t *next_packet_length, uint8_t *shared_key, 167int read_packet_TCP_secure_connection(sock_t sock, uint16_t *next_packet_length, const uint8_t *shared_key,
168 uint8_t *recv_nonce, uint8_t *data, uint16_t max_len); 168 uint8_t *recv_nonce, uint8_t *data, uint16_t max_len);
169 169
170 170