diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/friend_connection.c | 17 | ||||
-rw-r--r-- | toxcore/friend_connection.h | 1 |
2 files changed, 18 insertions, 0 deletions
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index ccf1621f..2610c13f 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c | |||
@@ -29,6 +29,8 @@ | |||
29 | 29 | ||
30 | #include "util.h" | 30 | #include "util.h" |
31 | 31 | ||
32 | #define PORTS_PER_DISCOVERY 10 | ||
33 | |||
32 | /* return 1 if the friendcon_id is not valid. | 34 | /* return 1 if the friendcon_id is not valid. |
33 | * return 0 if the friendcon_id is valid. | 35 | * return 0 if the friendcon_id is valid. |
34 | */ | 36 | */ |
@@ -827,6 +829,8 @@ Friend_Connections *new_friend_connections(Onion_Client *onion_c, bool local_dis | |||
827 | temp->net_crypto = onion_c->c; | 829 | temp->net_crypto = onion_c->c; |
828 | temp->onion_c = onion_c; | 830 | temp->onion_c = onion_c; |
829 | temp->local_discovery_enabled = local_discovery_enabled; | 831 | temp->local_discovery_enabled = local_discovery_enabled; |
832 | // Don't include default port in port range | ||
833 | temp->next_LANport = TOX_PORTRANGE_FROM + 1; | ||
830 | 834 | ||
831 | new_connection_handler(temp->net_crypto, &handle_new_connections, temp); | 835 | new_connection_handler(temp->net_crypto, &handle_new_connections, temp); |
832 | 836 | ||
@@ -841,7 +845,20 @@ Friend_Connections *new_friend_connections(Onion_Client *onion_c, bool local_dis | |||
841 | static void LANdiscovery(Friend_Connections *fr_c) | 845 | static void LANdiscovery(Friend_Connections *fr_c) |
842 | { | 846 | { |
843 | if (fr_c->last_LANdiscovery + LAN_DISCOVERY_INTERVAL < unix_time()) { | 847 | if (fr_c->last_LANdiscovery + LAN_DISCOVERY_INTERVAL < unix_time()) { |
848 | const uint16_t first = fr_c->next_LANport; | ||
849 | uint16_t last = first + PORTS_PER_DISCOVERY; | ||
850 | last = last > TOX_PORTRANGE_TO ? TOX_PORTRANGE_TO : last; | ||
851 | |||
852 | // Always send to default port | ||
844 | send_LANdiscovery(net_htons(TOX_PORT_DEFAULT), fr_c->dht); | 853 | send_LANdiscovery(net_htons(TOX_PORT_DEFAULT), fr_c->dht); |
854 | |||
855 | // And check some extra ports | ||
856 | for (uint16_t port = first; port < last; port++) { | ||
857 | send_LANdiscovery(net_htons(port), fr_c->dht); | ||
858 | } | ||
859 | |||
860 | // Don't include default port in port range | ||
861 | fr_c->next_LANport = last != TOX_PORTRANGE_TO ? last : TOX_PORTRANGE_FROM + 1; | ||
845 | fr_c->last_LANdiscovery = unix_time(); | 862 | fr_c->last_LANdiscovery = unix_time(); |
846 | } | 863 | } |
847 | } | 864 | } |
diff --git a/toxcore/friend_connection.h b/toxcore/friend_connection.h index 3fa2ebce..e993a103 100644 --- a/toxcore/friend_connection.h +++ b/toxcore/friend_connection.h | |||
@@ -107,6 +107,7 @@ typedef struct { | |||
107 | void *fr_request_object; | 107 | void *fr_request_object; |
108 | 108 | ||
109 | uint64_t last_LANdiscovery; | 109 | uint64_t last_LANdiscovery; |
110 | uint16_t next_LANport; | ||
110 | 111 | ||
111 | bool local_discovery_enabled; | 112 | bool local_discovery_enabled; |
112 | } Friend_Connections; | 113 | } Friend_Connections; |