Spread packets over many TCP relays instead of just using the first one.

This commit is contained in:
irungentoo 2014-07-18 21:34:22 -04:00
parent 733c519601
commit 9c84b5401c
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98

View File

@ -426,19 +426,22 @@ static int send_packet_to(const Net_Crypto *c, int crypt_connection_id, const ui
} }
//TODO: spread packets over many relays, detect and kill bad relays. //TODO: detect and kill bad relays.
uint32_t i; uint32_t i;
unsigned int r = rand();
for (i = 0; i < MAX_TCP_CONNECTIONS; ++i) { for (i = 0; i < MAX_TCP_CONNECTIONS; ++i) {
if (conn->status_tcp[i] == STATUS_TCP_ONLINE) {/* friend is connected to this relay. */ if (conn->status_tcp[(i + r) % MAX_TCP_CONNECTIONS] == STATUS_TCP_ONLINE) {/* friend is connected to this relay. */
if (send_data(c->tcp_connections[i], conn->con_number_tcp[i], data, length) == 1) if (send_data(c->tcp_connections[(i + r) % MAX_TCP_CONNECTIONS], conn->con_number_tcp[(i + r) % MAX_TCP_CONNECTIONS],
data, length) == 1)
return 0; return 0;
} }
} }
for (i = 0; i < MAX_TCP_CONNECTIONS; ++i) { for (i = 0; i < MAX_TCP_CONNECTIONS; ++i) {
if (conn->status_tcp[i] == STATUS_TCP_INVISIBLE) { if (conn->status_tcp[(i + r) % MAX_TCP_CONNECTIONS] == STATUS_TCP_INVISIBLE) {
if (send_oob_packet(c->tcp_connections[i], conn->dht_public_key, data, length) == 1) if (send_oob_packet(c->tcp_connections[(i + r) % MAX_TCP_CONNECTIONS], conn->dht_public_key, data, length) == 1)
return 0; return 0;
} }
} }