Skip to content

Commit 97ba2f7

Browse files
committed
Less packet spam.
1 parent c1e00c5 commit 97ba2f7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

toxcore/net_crypto.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,14 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t
490490
}
491491

492492
//TODO: a better way of sending packets directly to confirm the others ip.
493-
if (length < 96 || data[0] == NET_PACKET_COOKIE_REQUEST || data[0] == NET_PACKET_CRYPTO_HS) {
494-
if ((uint32_t)sendpacket(c->dht->net, ip_port, data, length) == length)
493+
uint64_t current_time = unix_time();
494+
495+
if ((((UDP_DIRECT_TIMEOUT / 2) + conn->direct_send_attempt_time) > current_time && length < 96)
496+
|| data[0] == NET_PACKET_COOKIE_REQUEST || data[0] == NET_PACKET_CRYPTO_HS) {
497+
if ((uint32_t)sendpacket(c->dht->net, ip_port, data, length) == length) {
495498
direct_send_attempt = 1;
499+
conn->direct_send_attempt_time = unix_time();
500+
}
496501
}
497502
}
498503

toxcore/net_crypto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ typedef struct {
143143
int connection_lossy_data_callback_id;
144144

145145
uint64_t last_request_packet_sent;
146+
uint64_t direct_send_attempt_time;
146147

147148
uint32_t packet_counter;
148149
double packet_recv_rate;

0 commit comments

Comments
 (0)