summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-04-18 10:27:19 -0400
committerirungentoo <irungentoo@gmail.com>2015-04-18 10:27:19 -0400
commiteb0f50d29769ed44dc9fd9fd0665bd7a0aa989e0 (patch)
treebc4625e86ec291edf2bca3d1519ea0be7cabec0b
parent0886b4f7b81b53a38563289f98d56f4943522a0a (diff)
Send oob packets to all relays tied to the connection.
Don't fallback to sending oob packets if pipe for normal connection is clogged.
-rw-r--r--toxcore/TCP_connection.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c
index 4da4c9b9..ebf41592 100644
--- a/toxcore/TCP_connection.c
+++ b/toxcore/TCP_connection.c
@@ -213,6 +213,8 @@ int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, c
213 unsigned int i; 213 unsigned int i;
214 int ret = -1; 214 int ret = -1;
215 215
216 _Bool limit_reached = 0;
217
216 for (i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { 218 for (i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) {
217 uint32_t tcp_con_num = con_to->connections[i].tcp_connection; 219 uint32_t tcp_con_num = con_to->connections[i].tcp_connection;
218 uint8_t status = con_to->connections[i].status; 220 uint8_t status = con_to->connections[i].status;
@@ -228,6 +230,10 @@ int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, c
228 230
229 ret = send_data(tcp_con->connection, connection_id, packet, length); 231 ret = send_data(tcp_con->connection, connection_id, packet, length);
230 232
233 if (ret == 0) {
234 limit_reached = 1;
235 }
236
231 if (ret == 1) { 237 if (ret == 1) {
232 break; 238 break;
233 } 239 }
@@ -236,7 +242,10 @@ int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, c
236 242
237 if (ret == 1) { 243 if (ret == 1) {
238 return 0; 244 return 0;
239 } else { 245 } else if (!limit_reached) {
246 ret = 0;
247
248 /* Send oob packets to all relays tied to the connection. */
240 for (i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { 249 for (i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) {
241 uint32_t tcp_con_num = con_to->connections[i].tcp_connection; 250 uint32_t tcp_con_num = con_to->connections[i].tcp_connection;
242 uint8_t status = con_to->connections[i].status; 251 uint8_t status = con_to->connections[i].status;
@@ -250,19 +259,19 @@ int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, c
250 continue; 259 continue;
251 } 260 }
252 261
253 ret = send_oob_packet(tcp_con->connection, con_to->public_key, packet, length); 262 if (send_oob_packet(tcp_con->connection, con_to->public_key, packet, length) == 1) {
254 263 ret += 1;
255 if (ret == 1) {
256 break;
257 } 264 }
258 } 265 }
259 } 266 }
260 267
261 if (ret == 1) { 268 if (ret >= 1) {
262 return 0; 269 return 0;
263 } else { 270 } else {
264 return -1; 271 return -1;
265 } 272 }
273 } else {
274 return -1;
266 } 275 }
267} 276}
268 277
@@ -280,6 +289,7 @@ int get_random_tcp_onion_conn_number(TCP_Connections *tcp_c)
280 289
281 for (i = 0; i < tcp_c->tcp_connections_length; ++i) { 290 for (i = 0; i < tcp_c->tcp_connections_length; ++i) {
282 unsigned int index = ((i + r) % tcp_c->tcp_connections_length); 291 unsigned int index = ((i + r) % tcp_c->tcp_connections_length);
292
283 if (tcp_c->tcp_connections[index].onion && tcp_c->tcp_connections[index].status == TCP_CONN_CONNECTED) { 293 if (tcp_c->tcp_connections[index].onion && tcp_c->tcp_connections[index].status == TCP_CONN_CONNECTED) {
284 return index; 294 return index;
285 } 295 }