From 0a0ed452026129fc9055c35ab75cfadab6f0dc06 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 21 Apr 2015 14:30:39 -0400 Subject: If a net_crypto connection isn't using the TCP relays, disconnect from them. TCP_connections can now be put to sleep, a state where they store what they were connected to without being connected and then resumed from sleep. --- toxcore/TCP_connection.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'toxcore/TCP_connection.h') diff --git a/toxcore/TCP_connection.h b/toxcore/TCP_connection.h index 0b7aae64..c3cf4889 100644 --- a/toxcore/TCP_connection.h +++ b/toxcore/TCP_connection.h @@ -28,8 +28,13 @@ #define TCP_CONN_NONE 0 #define TCP_CONN_VALID 1 + +/* 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. */ +#define TCP_CONN_SLEEPING 3 + #define TCP_CONNECTIONS_STATUS_NONE 0 #define TCP_CONNECTIONS_STATUS_REGISTERED 1 #define TCP_CONNECTIONS_STATUS_ONLINE 2 @@ -64,7 +69,13 @@ typedef struct { TCP_Client_Connection *connection; uint64_t connected_time; uint32_t lock_count; + uint32_t sleep_count; _Bool onion; + + /* Only used when connection is sleeping. */ + IP_Port ip_port; + uint8_t relay_pk[crypto_box_PUBLICKEYBYTES]; + _Bool unsleep; /* set to 1 to unsleep connection. */ } TCP_con; typedef struct { @@ -153,6 +164,18 @@ int new_tcp_connection_to(TCP_Connections *tcp_c, const uint8_t *public_key, int */ int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number); +/* Set connection status. + * + * status of 1 means we are using the connection. + * status of 0 means we are not using it. + * + * Unused tcp connections will be disconnected from but kept in case they are needed. + * + * return 0 on success. + * return -1 on failure. + */ +int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number, _Bool status); + /* Add a TCP relay tied to a connection. * * NOTE: This can only be used during the tcp_oob_callback. -- cgit v1.2.3