mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Improve LAN discovery
Issue: If another tox instance started on the not default port, LAN discovery will be failed. Now tox will iterate though all possible ports to find another tox instances.
This commit is contained in:
parent
987ad5eac1
commit
acb6b2d854
|
@ -29,6 +29,8 @@
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
#define PORTS_PER_DISCOVERY 10
|
||||||
|
|
||||||
/* return 1 if the friendcon_id is not valid.
|
/* return 1 if the friendcon_id is not valid.
|
||||||
* return 0 if the friendcon_id is valid.
|
* return 0 if the friendcon_id is valid.
|
||||||
*/
|
*/
|
||||||
|
@ -827,6 +829,8 @@ Friend_Connections *new_friend_connections(Onion_Client *onion_c, bool local_dis
|
||||||
temp->net_crypto = onion_c->c;
|
temp->net_crypto = onion_c->c;
|
||||||
temp->onion_c = onion_c;
|
temp->onion_c = onion_c;
|
||||||
temp->local_discovery_enabled = local_discovery_enabled;
|
temp->local_discovery_enabled = local_discovery_enabled;
|
||||||
|
// Don't include default port in port range
|
||||||
|
temp->next_LANport = TOX_PORTRANGE_FROM + 1;
|
||||||
|
|
||||||
new_connection_handler(temp->net_crypto, &handle_new_connections, temp);
|
new_connection_handler(temp->net_crypto, &handle_new_connections, temp);
|
||||||
|
|
||||||
|
@ -841,7 +845,20 @@ Friend_Connections *new_friend_connections(Onion_Client *onion_c, bool local_dis
|
||||||
static void LANdiscovery(Friend_Connections *fr_c)
|
static void LANdiscovery(Friend_Connections *fr_c)
|
||||||
{
|
{
|
||||||
if (fr_c->last_LANdiscovery + LAN_DISCOVERY_INTERVAL < unix_time()) {
|
if (fr_c->last_LANdiscovery + LAN_DISCOVERY_INTERVAL < unix_time()) {
|
||||||
|
const uint16_t first = fr_c->next_LANport;
|
||||||
|
uint16_t last = first + PORTS_PER_DISCOVERY;
|
||||||
|
last = last > TOX_PORTRANGE_TO ? TOX_PORTRANGE_TO : last;
|
||||||
|
|
||||||
|
// Always send to default port
|
||||||
send_LANdiscovery(net_htons(TOX_PORT_DEFAULT), fr_c->dht);
|
send_LANdiscovery(net_htons(TOX_PORT_DEFAULT), fr_c->dht);
|
||||||
|
|
||||||
|
// And check some extra ports
|
||||||
|
for (uint16_t port = first; port < last; port++) {
|
||||||
|
send_LANdiscovery(net_htons(port), fr_c->dht);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't include default port in port range
|
||||||
|
fr_c->next_LANport = last != TOX_PORTRANGE_TO ? last : TOX_PORTRANGE_FROM + 1;
|
||||||
fr_c->last_LANdiscovery = unix_time();
|
fr_c->last_LANdiscovery = unix_time();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,6 +107,7 @@ typedef struct {
|
||||||
void *fr_request_object;
|
void *fr_request_object;
|
||||||
|
|
||||||
uint64_t last_LANdiscovery;
|
uint64_t last_LANdiscovery;
|
||||||
|
uint16_t next_LANport;
|
||||||
|
|
||||||
bool local_discovery_enabled;
|
bool local_discovery_enabled;
|
||||||
} Friend_Connections;
|
} Friend_Connections;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user