cleanup: Don't pass the whole DHT object to lan discovery.

It only needs net and dht public key.
This commit is contained in:
iphydf 2022-02-03 20:39:33 +00:00
parent 014cc42249
commit 28dc8c1ded
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
6 changed files with 18 additions and 16 deletions

View File

@ -230,7 +230,7 @@ int main(int argc, char *argv[])
do_dht(dht);
if (mono_time_is_timeout(mono_time, last_LANdiscovery, is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL)) {
lan_discovery_send(net_htons(PORT), dht);
lan_discovery_send(dht_get_net(dht), dht_get_self_public_key(dht), net_htons(PORT));
last_LANdiscovery = mono_time_get(mono_time);
}

View File

@ -1 +1 @@
87ab42da03d54cf33815b364a974d1548a2a673415bd82e86ffbd6511483eb81 /usr/local/bin/tox-bootstrapd
de00572e0a22b67defb05759a4d5aac6bf0e107bfd6834a1edc20ffb0379528d /usr/local/bin/tox-bootstrapd

View File

@ -503,7 +503,7 @@ int main(int argc, char *argv[])
do_dht(dht);
if (enable_lan_discovery && mono_time_is_timeout(mono_time, last_LANdiscovery, LAN_DISCOVERY_INTERVAL)) {
lan_discovery_send(net_htons_port, dht);
lan_discovery_send(dht_get_net(dht), dht_get_self_public_key(dht), net_htons_port);
last_LANdiscovery = mono_time_get(mono_time);
}

View File

@ -367,35 +367,35 @@ static int handle_LANdiscovery(void *object, const IP_Port *source, const uint8_
}
int lan_discovery_send(uint16_t port, const DHT *dht)
bool lan_discovery_send(Networking_Core *net, const uint8_t *dht_pk, uint16_t port)
{
uint8_t data[CRYPTO_PUBLIC_KEY_SIZE + 1];
data[0] = NET_PACKET_LAN_DISCOVERY;
id_copy(data + 1, dht_get_self_public_key(dht));
id_copy(data + 1, dht_pk);
send_broadcasts(dht_get_net(dht), port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE);
send_broadcasts(net, port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE);
int res = -1;
bool res = false;
IP_Port ip_port;
ip_port.port = port;
/* IPv6 multicast */
if (net_family_is_ipv6(net_family(dht_get_net(dht)))) {
if (net_family_is_ipv6(net_family(net))) {
ip_port.ip = broadcast_ip(net_family_ipv6, net_family_ipv6);
if (ip_isset(&ip_port.ip)) {
if (sendpacket(dht_get_net(dht), &ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE) > 0) {
res = 1;
if (sendpacket(net, &ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE) > 0) {
res = true;
}
}
}
/* IPv4 broadcast (has to be IPv4-in-IPv6 mapping if socket is IPv6 */
ip_port.ip = broadcast_ip(net_family(dht_get_net(dht)), net_family_ipv4);
ip_port.ip = broadcast_ip(net_family(net), net_family_ipv4);
if (ip_isset(&ip_port.ip)) {
if (sendpacket(dht_get_net(dht), &ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE)) {
res = 1;
if (sendpacket(net, &ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE)) {
res = true;
}
}

View File

@ -18,8 +18,10 @@
/**
* Send a LAN discovery pcaket to the broadcast address with port port.
*
* @return true on success, false on failure.
*/
int32_t lan_discovery_send(uint16_t port, const DHT *dht);
bool lan_discovery_send(Networking_Core *net, const uint8_t *dht_pk, uint16_t port);
/**
* Sets up packet handlers.

View File

@ -897,11 +897,11 @@ static void lan_discovery(Friend_Connections *fr_c)
last = last > TOX_PORTRANGE_TO ? TOX_PORTRANGE_TO : last;
// Always send to default port
lan_discovery_send(net_htons(TOX_PORT_DEFAULT), fr_c->dht);
lan_discovery_send(dht_get_net(fr_c->dht), dht_get_self_public_key(fr_c->dht), net_htons(TOX_PORT_DEFAULT));
// And check some extra ports
for (uint16_t port = first; port < last; ++port) {
lan_discovery_send(net_htons(port), fr_c->dht);
lan_discovery_send(dht_get_net(fr_c->dht), dht_get_self_public_key(fr_c->dht), net_htons(port));
}
// Don't include default port in port range