diff options
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r-- | toxcore/net_crypto.c | 13 |
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 | } |