summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-07-18 21:34:22 -0400
committerirungentoo <irungentoo@gmail.com>2014-07-18 21:34:22 -0400
commit9c84b5401cdfb621b2e77751ad869b7fea786885 (patch)
treec6343d0af96ef9fb3ec23b8917829d8b9bba6133 /toxcore
parent733c5196011a79ec02851c9d268df4f4181850f3 (diff)
Spread packets over many TCP relays instead of just using the first one.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/net_crypto.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index c44d09c4..18dd3b05 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -426,19 +426,22 @@ static int send_packet_to(const Net_Crypto *c, int crypt_connection_id, const ui
426 426
427 } 427 }
428 428
429 //TODO: spread packets over many relays, detect and kill bad relays. 429 //TODO: detect and kill bad relays.
430 uint32_t i; 430 uint32_t i;
431 431
432 unsigned int r = rand();
433
432 for (i = 0; i < MAX_TCP_CONNECTIONS; ++i) { 434 for (i = 0; i < MAX_TCP_CONNECTIONS; ++i) {
433 if (conn->status_tcp[i] == STATUS_TCP_ONLINE) {/* friend is connected to this relay. */ 435 if (conn->status_tcp[(i + r) % MAX_TCP_CONNECTIONS] == STATUS_TCP_ONLINE) {/* friend is connected to this relay. */
434 if (send_data(c->tcp_connections[i], conn->con_number_tcp[i], data, length) == 1) 436 if (send_data(c->tcp_connections[(i + r) % MAX_TCP_CONNECTIONS], conn->con_number_tcp[(i + r) % MAX_TCP_CONNECTIONS],
437 data, length) == 1)
435 return 0; 438 return 0;
436 } 439 }
437 } 440 }
438 441
439 for (i = 0; i < MAX_TCP_CONNECTIONS; ++i) { 442 for (i = 0; i < MAX_TCP_CONNECTIONS; ++i) {
440 if (conn->status_tcp[i] == STATUS_TCP_INVISIBLE) { 443 if (conn->status_tcp[(i + r) % MAX_TCP_CONNECTIONS] == STATUS_TCP_INVISIBLE) {
441 if (send_oob_packet(c->tcp_connections[i], conn->dht_public_key, data, length) == 1) 444 if (send_oob_packet(c->tcp_connections[(i + r) % MAX_TCP_CONNECTIONS], conn->dht_public_key, data, length) == 1)
442 return 0; 445 return 0;
443 } 446 }
444 } 447 }