Patch to allow DHT_bootstrap to also do LAN discovery.

This patch inserts LAN discovery in DHT_bootstrap, allowing it to find clients even if it's run parameterless (and clients don't connect to it directly, e.g. because the port is already bound to a different client).

- moves the #define of LAN_DISCOVERY_INTERVAL from Messenger.c to LAN_discovery.h
- includes LAN_discovery.h into DHT_bootstrap.c
- DHT_bootstrap.c sends and accepts LAN_discovery packets
This commit is contained in:
Coren[m] 2013-09-12 19:09:25 +02:00
parent 55499933be
commit b5db32585a
3 changed files with 10 additions and 2 deletions

View File

@ -31,6 +31,7 @@
#endif
#include "../toxcore/DHT.h"
#include "../toxcore/LAN_discovery.h"
#include "../toxcore/friend_requests.h"
#include "../testing/misc_tools.c"
@ -123,6 +124,9 @@ int main(int argc, char *argv[])
int is_waiting_for_dht_connection = 1;
uint64_t last_LANdiscovery = 0;
LANdiscovery_init(dht);
while (1) {
if (is_waiting_for_dht_connection && DHT_isconnected(dht)) {
printf("Connected to other bootstrap server successfully.\n");
@ -130,6 +134,10 @@ int main(int argc, char *argv[])
}
do_DHT(dht);
if (last_LANdiscovery + (is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL) < unix_time()) {
send_LANdiscovery(htons(PORT), dht->c);
last_LANdiscovery = unix_time();
}
networking_poll(dht->c->lossless_udp->net);

View File

@ -35,6 +35,8 @@
#include <linux/netdevice.h>
#endif
/* Interval in seconds between LAN discovery packet sending. */
#define LAN_DISCOVERY_INTERVAL 60
/* Send a LAN discovery pcaket to the broadcast address with port port. */
int send_LANdiscovery(uint16_t port, Net_Crypto *c);

View File

@ -637,8 +637,6 @@ int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint
return write_cryptpacket(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id, packet, length + 1);
}
/* Interval in seconds between LAN discovery packet sending. */
#define LAN_DISCOVERY_INTERVAL 60
#define PORT 33445
/* Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds. */