summaryrefslogtreecommitdiff
path: root/protocols/Tox/libtox/src/toxcore/TCP_connection.h
diff options
context:
space:
mode:
authordartraiden <wowemuh@gmail.com>2022-02-07 00:34:21 +0300
committerdartraiden <wowemuh@gmail.com>2022-02-07 00:35:37 +0300
commit223306302f39455970b67a97ba62e4a542224f7a (patch)
tree21da0622af231bea688b413d1238d15315d658ce /protocols/Tox/libtox/src/toxcore/TCP_connection.h
parent41317031f257ad6a06fa743860aff212074dc416 (diff)
Update libtox to 0.2.15
Diffstat (limited to 'protocols/Tox/libtox/src/toxcore/TCP_connection.h')
-rw-r--r--protocols/Tox/libtox/src/toxcore/TCP_connection.h89
1 files changed, 52 insertions, 37 deletions
diff --git a/protocols/Tox/libtox/src/toxcore/TCP_connection.h b/protocols/Tox/libtox/src/toxcore/TCP_connection.h
index 0ae3304541..84890b98d7 100644
--- a/protocols/Tox/libtox/src/toxcore/TCP_connection.h
+++ b/protocols/Tox/libtox/src/toxcore/TCP_connection.h
@@ -3,21 +3,25 @@
* Copyright © 2015 Tox project.
*/
-/*
+/**
* Handles TCP relay connections between two Tox clients.
*/
#ifndef C_TOXCORE_TOXCORE_TCP_CONNECTION_H
#define C_TOXCORE_TOXCORE_TCP_CONNECTION_H
+#include "DHT.h" // for Node_format
#include "TCP_client.h"
+#include "TCP_common.h"
+
+#include <stdbool.h>
#define TCP_CONN_NONE 0
#define TCP_CONN_VALID 1
-/* NOTE: only used by TCP_con */
+/** NOTE: only used by TCP_con */
#define TCP_CONN_CONNECTED 2
-/* Connection is not connected but can be quickly reconnected in case it is needed. */
+/** Connection is not connected but can be quickly reconnected in case it is needed. */
#define TCP_CONN_SLEEPING 3
#define TCP_CONNECTIONS_STATUS_NONE 0
@@ -26,20 +30,20 @@
#define MAX_FRIEND_TCP_CONNECTIONS 6
-/* Time until connection to friend gets killed (if it doesn't get locked within that time) */
+/** Time until connection to friend gets killed (if it doesn't get locked within that time) */
#define TCP_CONNECTION_ANNOUNCE_TIMEOUT TCP_CONNECTION_TIMEOUT
-/* The amount of recommended connections for each friend
+/** The amount of recommended connections for each friend
* NOTE: Must be at most (MAX_FRIEND_TCP_CONNECTIONS / 2) */
#define RECOMMENDED_FRIEND_TCP_CONNECTIONS (MAX_FRIEND_TCP_CONNECTIONS / 2)
-/* Number of TCP connections used for onion purposes. */
+/** Number of TCP connections used for onion purposes. */
#define NUM_ONION_TCP_CONNECTIONS RECOMMENDED_FRIEND_TCP_CONNECTIONS
typedef struct TCP_Conn_to {
uint32_t tcp_connection;
- unsigned int status;
- unsigned int connection_id;
+ uint8_t status;
+ uint8_t connection_id;
} TCP_Conn_to;
typedef struct TCP_Connection_to {
@@ -69,14 +73,20 @@ typedef struct TCP_Connections TCP_Connections;
const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c);
-/* Send a packet to the TCP connection.
+uint32_t tcp_connections_count(const TCP_Connections *tcp_c);
+
+/** Returns the number of connected TCP relays */
+uint32_t tcp_connected_relays_count(const TCP_Connections *tcp_c);
+
+/** Send a packet to the TCP connection.
*
* return -1 on failure.
* return 0 on success.
*/
-int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, const uint8_t *packet, uint16_t length);
+int send_packet_tcp_connection(const TCP_Connections *tcp_c, int connections_number, const uint8_t *packet,
+ uint16_t length);
-/* Return a random TCP connection number for use in send_tcp_onion_request.
+/** Return a random TCP connection number for use in send_tcp_onion_request.
*
* TODO(irungentoo): This number is just the index of an array that the elements
* can change without warning.
@@ -84,9 +94,9 @@ int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, c
* return TCP connection number on success.
* return -1 on failure.
*/
-int get_random_tcp_onion_conn_number(TCP_Connections *tcp_c);
+int get_random_tcp_onion_conn_number(const TCP_Connections *tcp_c);
-/* Send an onion packet via the TCP relay corresponding to tcp_connections_number.
+/** Send an onion packet via the TCP relay corresponding to tcp_connections_number.
*
* return 0 on success.
* return -1 on failure.
@@ -94,7 +104,7 @@ int get_random_tcp_onion_conn_number(TCP_Connections *tcp_c);
int tcp_send_onion_request(TCP_Connections *tcp_c, unsigned int tcp_connections_number, const uint8_t *data,
uint16_t length);
-/* Set if we want TCP_connection to allocate some connection for onion use.
+/** Set if we want TCP_connection to allocate some connection for onion use.
*
* If status is 1, allocate some connections. if status is 0, don't.
*
@@ -103,34 +113,37 @@ int tcp_send_onion_request(TCP_Connections *tcp_c, unsigned int tcp_connections_
*/
int set_tcp_onion_status(TCP_Connections *tcp_c, bool status);
-/* Send an oob packet via the TCP relay corresponding to tcp_connections_number.
+/** Send an oob packet via the TCP relay corresponding to tcp_connections_number.
*
* return 0 on success.
* return -1 on failure.
*/
-int tcp_send_oob_packet(TCP_Connections *tcp_c, unsigned int tcp_connections_number, const uint8_t *public_key,
+int tcp_send_oob_packet(const TCP_Connections *tcp_c, unsigned int tcp_connections_number, const uint8_t *public_key,
const uint8_t *packet, uint16_t length);
typedef int tcp_data_cb(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
-/* Set the callback for TCP data packets.
+int tcp_send_oob_packet_using_relay(const TCP_Connections *tcp_c, const uint8_t *relay_pk, const uint8_t *public_key,
+ const uint8_t *packet, uint16_t length);
+
+/** Set the callback for TCP data packets.
*/
void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_data_cb *tcp_data_callback, void *object);
typedef int tcp_onion_cb(void *object, const uint8_t *data, uint16_t length, void *userdata);
-/* Set the callback for TCP onion packets.
+/** Set the callback for TCP onion packets.
*/
void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_onion_cb *tcp_onion_callback, void *object);
typedef int tcp_oob_cb(void *object, const uint8_t *public_key, unsigned int tcp_connections_number,
const uint8_t *data, uint16_t length, void *userdata);
-/* Set the callback for TCP oob data packets.
+/** Set the callback for TCP oob data packets.
*/
void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_oob_cb *tcp_oob_callback, void *object);
-/* Create a new TCP connection to public_key.
+/** Create a new TCP connection to public_key.
*
* public_key must be the counterpart to the secret key that the other peer used with new_tcp_connections().
*
@@ -141,12 +154,12 @@ void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_oob_cb *
*/
int new_tcp_connection_to(TCP_Connections *tcp_c, const uint8_t *public_key, int id);
-/* return 0 on success.
+/** return 0 on success.
* return -1 on failure.
*/
int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number);
-/* Set connection status.
+/** Set connection status.
*
* status of 1 means we are using the connection.
* status of 0 means we are not using it.
@@ -156,59 +169,61 @@ int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number);
* return 0 on success.
* return -1 on failure.
*/
-int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number, bool status);
+int set_tcp_connection_to_status(const TCP_Connections *tcp_c, int connections_number, bool status);
-/* return number of online tcp relays tied to the connection on success.
+/** return number of online tcp relays tied to the connection on success.
* return 0 on failure.
*/
-unsigned int tcp_connection_to_online_tcp_relays(TCP_Connections *tcp_c, int connections_number);
+unsigned int tcp_connection_to_online_tcp_relays(const TCP_Connections *tcp_c, int connections_number);
-/* Add a TCP relay tied to a connection.
+/** Add a TCP relay tied to a connection.
*
* NOTE: This can only be used during the tcp_oob_callback.
*
* return 0 on success.
* return -1 on failure.
*/
-int add_tcp_number_relay_connection(TCP_Connections *tcp_c, int connections_number,
+int add_tcp_number_relay_connection(const TCP_Connections *tcp_c, int connections_number,
unsigned int tcp_connections_number);
-/* Add a TCP relay tied to a connection.
+/** Add a TCP relay tied to a connection.
*
* This should be called with the same relay by two peers who want to create a TCP connection with each other.
*
* return 0 on success.
* return -1 on failure.
*/
-int add_tcp_relay_connection(TCP_Connections *tcp_c, int connections_number, IP_Port ip_port, const uint8_t *relay_pk);
+int add_tcp_relay_connection(TCP_Connections *tcp_c, int connections_number, const IP_Port *ip_port,
+ const uint8_t *relay_pk);
-/* Add a TCP relay to the instance.
+/** Add a TCP relay to the TCP_Connections instance.
*
* return 0 on success.
* return -1 on failure.
*/
-int add_tcp_relay_global(TCP_Connections *tcp_c, IP_Port ip_port, const uint8_t *relay_pk);
+int add_tcp_relay_global(TCP_Connections *tcp_c, const IP_Port *ip_port, const uint8_t *relay_pk);
-/* Copy a maximum of max_num TCP relays we are connected to to tcp_relays.
+/** Copy a maximum of max_num TCP relays we are connected to to tcp_relays.
* NOTE that the family of the copied ip ports will be set to TCP_INET or TCP_INET6.
*
* return number of relays copied to tcp_relays on success.
* return 0 on failure.
*/
-uint32_t tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num);
+uint32_t tcp_copy_connected_relays(const TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num);
-/* Returns a new TCP_Connections object associated with the secret_key.
+/** Returns a new TCP_Connections object associated with the secret_key.
*
* In order for others to connect to this instance new_tcp_connection_to() must be called with the
* public_key associated with secret_key.
*
* Returns NULL on failure.
*/
-TCP_Connections *new_tcp_connections(Mono_Time *mono_time, const uint8_t *secret_key, TCP_Proxy_Info *proxy_info);
+TCP_Connections *new_tcp_connections(const Logger *logger, Mono_Time *mono_time, const uint8_t *secret_key,
+ const TCP_Proxy_Info *proxy_info);
-void do_tcp_connections(const Logger *logger, TCP_Connections *tcp_c, void *userdata);
+int kill_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number);
+void do_tcp_connections(const Logger *logger, TCP_Connections *tcp_c, void *userdata);
void kill_tcp_connections(TCP_Connections *tcp_c);
#endif
-