diff options
author | irungentoo <irungentoo@gmail.com> | 2015-04-21 14:30:39 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-04-21 14:30:39 -0400 |
commit | 0a0ed452026129fc9055c35ab75cfadab6f0dc06 (patch) | |
tree | 5367d65cde7398bf39a45e3622a02f3b7fad9247 /toxcore/TCP_connection.h | |
parent | e4ae993a80261d12cf7adb7f797a56579c39ea91 (diff) |
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.
Diffstat (limited to 'toxcore/TCP_connection.h')
-rw-r--r-- | toxcore/TCP_connection.h | 23 |
1 files changed, 23 insertions, 0 deletions
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 @@ | |||
28 | 28 | ||
29 | #define TCP_CONN_NONE 0 | 29 | #define TCP_CONN_NONE 0 |
30 | #define TCP_CONN_VALID 1 | 30 | #define TCP_CONN_VALID 1 |
31 | |||
32 | /* NOTE: only used by TCP_con */ | ||
31 | #define TCP_CONN_CONNECTED 2 | 33 | #define TCP_CONN_CONNECTED 2 |
32 | 34 | ||
35 | /* Connection is not connected but can be quickly reconnected in case it is needed. */ | ||
36 | #define TCP_CONN_SLEEPING 3 | ||
37 | |||
33 | #define TCP_CONNECTIONS_STATUS_NONE 0 | 38 | #define TCP_CONNECTIONS_STATUS_NONE 0 |
34 | #define TCP_CONNECTIONS_STATUS_REGISTERED 1 | 39 | #define TCP_CONNECTIONS_STATUS_REGISTERED 1 |
35 | #define TCP_CONNECTIONS_STATUS_ONLINE 2 | 40 | #define TCP_CONNECTIONS_STATUS_ONLINE 2 |
@@ -64,7 +69,13 @@ typedef struct { | |||
64 | TCP_Client_Connection *connection; | 69 | TCP_Client_Connection *connection; |
65 | uint64_t connected_time; | 70 | uint64_t connected_time; |
66 | uint32_t lock_count; | 71 | uint32_t lock_count; |
72 | uint32_t sleep_count; | ||
67 | _Bool onion; | 73 | _Bool onion; |
74 | |||
75 | /* Only used when connection is sleeping. */ | ||
76 | IP_Port ip_port; | ||
77 | uint8_t relay_pk[crypto_box_PUBLICKEYBYTES]; | ||
78 | _Bool unsleep; /* set to 1 to unsleep connection. */ | ||
68 | } TCP_con; | 79 | } TCP_con; |
69 | 80 | ||
70 | typedef struct { | 81 | typedef struct { |
@@ -153,6 +164,18 @@ int new_tcp_connection_to(TCP_Connections *tcp_c, const uint8_t *public_key, int | |||
153 | */ | 164 | */ |
154 | int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number); | 165 | int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number); |
155 | 166 | ||
167 | /* Set connection status. | ||
168 | * | ||
169 | * status of 1 means we are using the connection. | ||
170 | * status of 0 means we are not using it. | ||
171 | * | ||
172 | * Unused tcp connections will be disconnected from but kept in case they are needed. | ||
173 | * | ||
174 | * return 0 on success. | ||
175 | * return -1 on failure. | ||
176 | */ | ||
177 | int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number, _Bool status); | ||
178 | |||
156 | /* Add a TCP relay tied to a connection. | 179 | /* Add a TCP relay tied to a connection. |
157 | * | 180 | * |
158 | * NOTE: This can only be used during the tcp_oob_callback. | 181 | * NOTE: This can only be used during the tcp_oob_callback. |