Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion other/DHT_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
87ab42da03d54cf33815b364a974d1548a2a673415bd82e86ffbd6511483eb81 /usr/local/bin/tox-bootstrapd
de00572e0a22b67defb05759a4d5aac6bf0e107bfd6834a1edc20ffb0379528d /usr/local/bin/tox-bootstrapd
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/src/tox-bootstrapd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
20 changes: 10 additions & 10 deletions toxcore/LAN_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
4 changes: 3 additions & 1 deletion toxcore/LAN_discovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions toxcore/friend_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down