diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Messenger.c | 2 | ||||
-rw-r--r-- | toxcore/Messenger.h | 1 | ||||
-rw-r--r-- | toxcore/friend_connection.c | 17 | ||||
-rw-r--r-- | toxcore/friend_connection.h | 4 | ||||
-rw-r--r-- | toxcore/tox.api.h | 7 | ||||
-rw-r--r-- | toxcore/tox.c | 3 | ||||
-rw-r--r-- | toxcore/tox.h | 12 |
7 files changed, 40 insertions, 6 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 79f28742..d5f544ed 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1954,7 +1954,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error) | |||
1954 | m->onion = new_onion(m->dht); | 1954 | m->onion = new_onion(m->dht); |
1955 | m->onion_a = new_onion_announce(m->dht); | 1955 | m->onion_a = new_onion_announce(m->dht); |
1956 | m->onion_c = new_onion_client(m->net_crypto); | 1956 | m->onion_c = new_onion_client(m->net_crypto); |
1957 | m->fr_c = new_friend_connections(m->onion_c); | 1957 | m->fr_c = new_friend_connections(m->onion_c, options->local_discovery_enabled); |
1958 | 1958 | ||
1959 | if (!(m->onion && m->onion_a && m->onion_c)) { | 1959 | if (!(m->onion && m->onion_a && m->onion_c)) { |
1960 | kill_friend_connections(m->fr_c); | 1960 | kill_friend_connections(m->fr_c); |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 9bc4c451..bd66739b 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -78,6 +78,7 @@ typedef struct { | |||
78 | uint16_t tcp_server_port; | 78 | uint16_t tcp_server_port; |
79 | 79 | ||
80 | uint8_t hole_punching_enabled; | 80 | uint8_t hole_punching_enabled; |
81 | bool local_discovery_enabled; | ||
81 | 82 | ||
82 | logger_cb *log_callback; | 83 | logger_cb *log_callback; |
83 | void *log_user_data; | 84 | void *log_user_data; |
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index f28720cb..2a99070b 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c | |||
@@ -811,7 +811,7 @@ int send_friend_request_packet(Friend_Connections *fr_c, int friendcon_id, uint3 | |||
811 | } | 811 | } |
812 | 812 | ||
813 | /* Create new friend_connections instance. */ | 813 | /* Create new friend_connections instance. */ |
814 | Friend_Connections *new_friend_connections(Onion_Client *onion_c) | 814 | Friend_Connections *new_friend_connections(Onion_Client *onion_c, bool local_discovery_enabled) |
815 | { | 815 | { |
816 | if (!onion_c) { | 816 | if (!onion_c) { |
817 | return NULL; | 817 | return NULL; |
@@ -826,9 +826,13 @@ Friend_Connections *new_friend_connections(Onion_Client *onion_c) | |||
826 | temp->dht = onion_c->dht; | 826 | temp->dht = onion_c->dht; |
827 | temp->net_crypto = onion_c->c; | 827 | temp->net_crypto = onion_c->c; |
828 | temp->onion_c = onion_c; | 828 | temp->onion_c = onion_c; |
829 | temp->local_discovery_enabled = local_discovery_enabled; | ||
829 | 830 | ||
830 | new_connection_handler(temp->net_crypto, &handle_new_connections, temp); | 831 | new_connection_handler(temp->net_crypto, &handle_new_connections, temp); |
831 | LANdiscovery_init(temp->dht); | 832 | |
833 | if (temp->local_discovery_enabled) { | ||
834 | LANdiscovery_init(temp->dht); | ||
835 | } | ||
832 | 836 | ||
833 | return temp; | 837 | return temp; |
834 | } | 838 | } |
@@ -889,7 +893,9 @@ void do_friend_connections(Friend_Connections *fr_c, void *userdata) | |||
889 | } | 893 | } |
890 | } | 894 | } |
891 | 895 | ||
892 | LANdiscovery(fr_c); | 896 | if (fr_c->local_discovery_enabled) { |
897 | LANdiscovery(fr_c); | ||
898 | } | ||
893 | } | 899 | } |
894 | 900 | ||
895 | /* Free everything related with friend_connections. */ | 901 | /* Free everything related with friend_connections. */ |
@@ -905,6 +911,9 @@ void kill_friend_connections(Friend_Connections *fr_c) | |||
905 | kill_friend_connection(fr_c, i); | 911 | kill_friend_connection(fr_c, i); |
906 | } | 912 | } |
907 | 913 | ||
908 | LANdiscovery_kill(fr_c->dht); | 914 | if (fr_c->local_discovery_enabled) { |
915 | LANdiscovery_kill(fr_c->dht); | ||
916 | } | ||
917 | |||
909 | free(fr_c); | 918 | free(fr_c); |
910 | } | 919 | } |
diff --git a/toxcore/friend_connection.h b/toxcore/friend_connection.h index b968c57d..4d6f841c 100644 --- a/toxcore/friend_connection.h +++ b/toxcore/friend_connection.h | |||
@@ -108,6 +108,8 @@ typedef struct { | |||
108 | void *fr_request_object; | 108 | void *fr_request_object; |
109 | 109 | ||
110 | uint64_t last_LANdiscovery; | 110 | uint64_t last_LANdiscovery; |
111 | |||
112 | bool local_discovery_enabled; | ||
111 | } Friend_Connections; | 113 | } Friend_Connections; |
112 | 114 | ||
113 | /* return friendcon_id corresponding to the real public key on success. | 115 | /* return friendcon_id corresponding to the real public key on success. |
@@ -197,7 +199,7 @@ void set_friend_request_callback(Friend_Connections *fr_c, int (*fr_request_call | |||
197 | const uint8_t *, uint16_t, void *), void *object); | 199 | const uint8_t *, uint16_t, void *), void *object); |
198 | 200 | ||
199 | /* Create new friend_connections instance. */ | 201 | /* Create new friend_connections instance. */ |
200 | Friend_Connections *new_friend_connections(Onion_Client *onion_c); | 202 | Friend_Connections *new_friend_connections(Onion_Client *onion_c, bool local_discovery_enabled); |
201 | 203 | ||
202 | /* main friend_connections loop. */ | 204 | /* main friend_connections loop. */ |
203 | void do_friend_connections(Friend_Connections *fr_c, void *userdata); | 205 | void do_friend_connections(Friend_Connections *fr_c, void *userdata); |
diff --git a/toxcore/tox.api.h b/toxcore/tox.api.h index 8cc35b8b..ee70bbd9 100644 --- a/toxcore/tox.api.h +++ b/toxcore/tox.api.h | |||
@@ -469,6 +469,13 @@ static class options { | |||
469 | */ | 469 | */ |
470 | bool udp_enabled; | 470 | bool udp_enabled; |
471 | 471 | ||
472 | /** | ||
473 | * Enable local network peer discovery. | ||
474 | * | ||
475 | * Disabling this will cause Tox to not look for peers on the local network. | ||
476 | */ | ||
477 | bool local_discovery_enabled; | ||
478 | |||
472 | namespace proxy { | 479 | namespace proxy { |
473 | /** | 480 | /** |
474 | * Pass communications through a proxy. | 481 | * Pass communications through a proxy. |
diff --git a/toxcore/tox.c b/toxcore/tox.c index 5d239be2..37ea4849 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -132,6 +132,7 @@ ACCESSORS(TOX_SAVEDATA_TYPE, savedata_, type) | |||
132 | ACCESSORS(size_t, savedata_, length) | 132 | ACCESSORS(size_t, savedata_, length) |
133 | ACCESSORS(tox_log_cb *, log_, callback) | 133 | ACCESSORS(tox_log_cb *, log_, callback) |
134 | ACCESSORS(void *, log_, user_data) | 134 | ACCESSORS(void *, log_, user_data) |
135 | ACCESSORS(bool, , local_discovery_enabled) | ||
135 | 136 | ||
136 | const uint8_t *tox_options_get_savedata_data(const struct Tox_Options *options) | 137 | const uint8_t *tox_options_get_savedata_data(const struct Tox_Options *options) |
137 | { | 138 | { |
@@ -153,6 +154,7 @@ void tox_options_default(struct Tox_Options *options) | |||
153 | options->udp_enabled = 1; | 154 | options->udp_enabled = 1; |
154 | options->proxy_type = TOX_PROXY_TYPE_NONE; | 155 | options->proxy_type = TOX_PROXY_TYPE_NONE; |
155 | options->hole_punching_enabled = true; | 156 | options->hole_punching_enabled = true; |
157 | options->local_discovery_enabled = true; | ||
156 | } | 158 | } |
157 | } | 159 | } |
158 | 160 | ||
@@ -218,6 +220,7 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error) | |||
218 | m_options.port_range[1] = options->end_port; | 220 | m_options.port_range[1] = options->end_port; |
219 | m_options.tcp_server_port = options->tcp_port; | 221 | m_options.tcp_server_port = options->tcp_port; |
220 | m_options.hole_punching_enabled = options->hole_punching_enabled; | 222 | m_options.hole_punching_enabled = options->hole_punching_enabled; |
223 | m_options.local_discovery_enabled = options->local_discovery_enabled; | ||
221 | 224 | ||
222 | m_options.log_callback = (logger_cb *)options->log_callback; | 225 | m_options.log_callback = (logger_cb *)options->log_callback; |
223 | m_options.log_user_data = options->log_user_data; | 226 | m_options.log_user_data = options->log_user_data; |
diff --git a/toxcore/tox.h b/toxcore/tox.h index 5057e148..934145a3 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -522,6 +522,14 @@ struct Tox_Options { | |||
522 | 522 | ||
523 | 523 | ||
524 | /** | 524 | /** |
525 | * Enable local network peer discovery. | ||
526 | * | ||
527 | * Disabling this will cause Tox to not look for peers on the local network. | ||
528 | */ | ||
529 | bool local_discovery_enabled; | ||
530 | |||
531 | |||
532 | /** | ||
525 | * Pass communications through a proxy. | 533 | * Pass communications through a proxy. |
526 | */ | 534 | */ |
527 | TOX_PROXY_TYPE proxy_type; | 535 | TOX_PROXY_TYPE proxy_type; |
@@ -635,6 +643,10 @@ bool tox_options_get_udp_enabled(const struct Tox_Options *options); | |||
635 | 643 | ||
636 | void tox_options_set_udp_enabled(struct Tox_Options *options, bool udp_enabled); | 644 | void tox_options_set_udp_enabled(struct Tox_Options *options, bool udp_enabled); |
637 | 645 | ||
646 | bool tox_options_get_local_discovery_enabled(const struct Tox_Options *options); | ||
647 | |||
648 | void tox_options_set_local_discovery_enabled(struct Tox_Options *options, bool local_discovery_enabled); | ||
649 | |||
638 | TOX_PROXY_TYPE tox_options_get_proxy_type(const struct Tox_Options *options); | 650 | TOX_PROXY_TYPE tox_options_get_proxy_type(const struct Tox_Options *options); |
639 | 651 | ||
640 | void tox_options_set_proxy_type(struct Tox_Options *options, TOX_PROXY_TYPE type); | 652 | void tox_options_set_proxy_type(struct Tox_Options *options, TOX_PROXY_TYPE type); |