From b5db32585a89749ce8e91348d176292cdc20abfd Mon Sep 17 00:00:00 2001 From: "Coren[m]" Date: Thu, 12 Sep 2013 19:09:25 +0200 Subject: [PATCH] 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 --- other/DHT_bootstrap.c | 8 ++++++++ toxcore/LAN_discovery.h | 2 ++ toxcore/Messenger.c | 2 -- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 654b759f..aed17020 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -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); diff --git a/toxcore/LAN_discovery.h b/toxcore/LAN_discovery.h index 78990936..3e9d9de5 100644 --- a/toxcore/LAN_discovery.h +++ b/toxcore/LAN_discovery.h @@ -35,6 +35,8 @@ #include #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); diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index b712d142..2ff5634a 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -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. */