mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Spread packets over many TCP relays instead of just using the first one.
This commit is contained in:
parent
733c519601
commit
9c84b5401c
|
@ -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;
|
||||
|
||||
unsigned int r = rand();
|
||||
|
||||
for (i = 0; i < MAX_TCP_CONNECTIONS; ++i) {
|
||||
if (conn->status_tcp[i] == 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 (conn->status_tcp[(i + r) % MAX_TCP_CONNECTIONS] == STATUS_TCP_ONLINE) {/* friend is connected to this relay. */
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_TCP_CONNECTIONS; ++i) {
|
||||
if (conn->status_tcp[i] == STATUS_TCP_INVISIBLE) {
|
||||
if (send_oob_packet(c->tcp_connections[i], conn->dht_public_key, data, length) == 1)
|
||||
if (conn->status_tcp[(i + r) % MAX_TCP_CONNECTIONS] == STATUS_TCP_INVISIBLE) {
|
||||
if (send_oob_packet(c->tcp_connections[(i + r) % MAX_TCP_CONNECTIONS], conn->dht_public_key, data, length) == 1)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user