diff options
author | Coren[m] <Break@Ocean> | 2013-09-12 19:09:25 +0200 |
---|---|---|
committer | Coren[m] <Break@Ocean> | 2013-09-12 19:09:25 +0200 |
commit | b5db32585a89749ce8e91348d176292cdc20abfd (patch) | |
tree | dbbfda7d45545eeff19293df16587145bdafe7ee | |
parent | 55499933be7857642d970d32f359e765ff4a2cab (diff) |
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
-rw-r--r-- | other/DHT_bootstrap.c | 8 | ||||
-rw-r--r-- | toxcore/LAN_discovery.h | 2 | ||||
-rw-r--r-- | 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 @@ | |||
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | #include "../toxcore/DHT.h" | 33 | #include "../toxcore/DHT.h" |
34 | #include "../toxcore/LAN_discovery.h" | ||
34 | #include "../toxcore/friend_requests.h" | 35 | #include "../toxcore/friend_requests.h" |
35 | #include "../testing/misc_tools.c" | 36 | #include "../testing/misc_tools.c" |
36 | 37 | ||
@@ -123,6 +124,9 @@ int main(int argc, char *argv[]) | |||
123 | 124 | ||
124 | int is_waiting_for_dht_connection = 1; | 125 | int is_waiting_for_dht_connection = 1; |
125 | 126 | ||
127 | uint64_t last_LANdiscovery = 0; | ||
128 | LANdiscovery_init(dht); | ||
129 | |||
126 | while (1) { | 130 | while (1) { |
127 | if (is_waiting_for_dht_connection && DHT_isconnected(dht)) { | 131 | if (is_waiting_for_dht_connection && DHT_isconnected(dht)) { |
128 | printf("Connected to other bootstrap server successfully.\n"); | 132 | printf("Connected to other bootstrap server successfully.\n"); |
@@ -130,6 +134,10 @@ int main(int argc, char *argv[]) | |||
130 | } | 134 | } |
131 | 135 | ||
132 | do_DHT(dht); | 136 | do_DHT(dht); |
137 | if (last_LANdiscovery + (is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL) < unix_time()) { | ||
138 | send_LANdiscovery(htons(PORT), dht->c); | ||
139 | last_LANdiscovery = unix_time(); | ||
140 | } | ||
133 | 141 | ||
134 | networking_poll(dht->c->lossless_udp->net); | 142 | networking_poll(dht->c->lossless_udp->net); |
135 | 143 | ||
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 @@ | |||
35 | #include <linux/netdevice.h> | 35 | #include <linux/netdevice.h> |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | /* Interval in seconds between LAN discovery packet sending. */ | ||
39 | #define LAN_DISCOVERY_INTERVAL 60 | ||
38 | 40 | ||
39 | /* Send a LAN discovery pcaket to the broadcast address with port port. */ | 41 | /* Send a LAN discovery pcaket to the broadcast address with port port. */ |
40 | int send_LANdiscovery(uint16_t port, Net_Crypto *c); | 42 | 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 | |||
637 | return write_cryptpacket(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id, packet, length + 1); | 637 | return write_cryptpacket(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id, packet, length + 1); |
638 | } | 638 | } |
639 | 639 | ||
640 | /* Interval in seconds between LAN discovery packet sending. */ | ||
641 | #define LAN_DISCOVERY_INTERVAL 60 | ||
642 | #define PORT 33445 | 640 | #define PORT 33445 |
643 | 641 | ||
644 | /* Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds. */ | 642 | /* Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds. */ |