mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
cleanup: Don't pass the whole DHT object to lan discovery.
It only needs net and dht public key.
This commit is contained in:
parent
014cc42249
commit
28dc8c1ded
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
87ab42da03d54cf33815b364a974d1548a2a673415bd82e86ffbd6511483eb81 /usr/local/bin/tox-bootstrapd
|
||||
de00572e0a22b67defb05759a4d5aac6bf0e107bfd6834a1edc20ffb0379528d /usr/local/bin/tox-bootstrapd
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user