diff options
author | Gregory Mullen (grayhatter) <greg@grayhatter.com> | 2016-11-11 03:10:24 -0800 |
---|---|---|
committer | Gregory Mullen (grayhatter) <greg@grayhatter.com> | 2016-11-24 17:38:34 -0800 |
commit | ad517eb1df8841db52a45c7ac9ecf5976a290d57 (patch) | |
tree | 6e0d82599a6c1b0fd819ecf84e4abc82aa41b02e /toxcore | |
parent | 19711d0fd0e2c181c3fe9df692b15f57390420d1 (diff) |
add NAT hole punching level to Tox API
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/DHT.c | 9 | ||||
-rw-r--r-- | toxcore/DHT.h | 4 | ||||
-rw-r--r-- | toxcore/Messenger.c | 2 | ||||
-rw-r--r-- | toxcore/Messenger.h | 2 | ||||
-rw-r--r-- | toxcore/tox.api.h | 5 | ||||
-rw-r--r-- | toxcore/tox.c | 3 | ||||
-rw-r--r-- | toxcore/tox.h | 10 |
7 files changed, 32 insertions, 3 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 9a6996b2..5185353e 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -2088,6 +2088,10 @@ static uint16_t NAT_getports(uint16_t *portlist, IP_Port *ip_portlist, uint16_t | |||
2088 | 2088 | ||
2089 | static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, uint16_t friend_num) | 2089 | static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, uint16_t friend_num) |
2090 | { | 2090 | { |
2091 | if (!dht->hole_punching_enabled) { | ||
2092 | return; | ||
2093 | } | ||
2094 | |||
2091 | if (numports > MAX_FRIEND_CLIENTS || numports == 0) { | 2095 | if (numports > MAX_FRIEND_CLIENTS || numports == 0) { |
2092 | return; | 2096 | return; |
2093 | } | 2097 | } |
@@ -2577,7 +2581,7 @@ static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *pack | |||
2577 | 2581 | ||
2578 | /*----------------------------------------------------------------------------------*/ | 2582 | /*----------------------------------------------------------------------------------*/ |
2579 | 2583 | ||
2580 | DHT *new_DHT(Logger *log, Networking_Core *net) | 2584 | DHT *new_DHT(Logger *log, Networking_Core *net, bool holepunching_enabled) |
2581 | { | 2585 | { |
2582 | /* init time */ | 2586 | /* init time */ |
2583 | unix_time_update(); | 2587 | unix_time_update(); |
@@ -2594,6 +2598,9 @@ DHT *new_DHT(Logger *log, Networking_Core *net) | |||
2594 | 2598 | ||
2595 | dht->log = log; | 2599 | dht->log = log; |
2596 | dht->net = net; | 2600 | dht->net = net; |
2601 | |||
2602 | dht->hole_punching_enabled = holepunching_enabled; | ||
2603 | |||
2597 | dht->ping = new_ping(dht); | 2604 | dht->ping = new_ping(dht); |
2598 | 2605 | ||
2599 | if (dht->ping == NULL) { | 2606 | if (dht->ping == NULL) { |
diff --git a/toxcore/DHT.h b/toxcore/DHT.h index 54ab9121..db05fecc 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h | |||
@@ -238,6 +238,8 @@ typedef struct { | |||
238 | Logger *log; | 238 | Logger *log; |
239 | Networking_Core *net; | 239 | Networking_Core *net; |
240 | 240 | ||
241 | bool hole_punching_enabled; | ||
242 | |||
241 | Client_data close_clientlist[LCLIENT_LIST]; | 243 | Client_data close_clientlist[LCLIENT_LIST]; |
242 | uint64_t close_lastgetnodes; | 244 | uint64_t close_lastgetnodes; |
243 | uint32_t close_bootstrap_times; | 245 | uint32_t close_bootstrap_times; |
@@ -435,7 +437,7 @@ void DHT_save(DHT *dht, uint8_t *data); | |||
435 | int DHT_load(DHT *dht, const uint8_t *data, uint32_t length); | 437 | int DHT_load(DHT *dht, const uint8_t *data, uint32_t length); |
436 | 438 | ||
437 | /* Initialize DHT. */ | 439 | /* Initialize DHT. */ |
438 | DHT *new_DHT(Logger *log, Networking_Core *net); | 440 | DHT *new_DHT(Logger *log, Networking_Core *net, bool holepunching_enabled); |
439 | 441 | ||
440 | void kill_DHT(DHT *dht); | 442 | void kill_DHT(DHT *dht); |
441 | 443 | ||
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index d4c4526e..be311fa1 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1934,7 +1934,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error) | |||
1934 | return NULL; | 1934 | return NULL; |
1935 | } | 1935 | } |
1936 | 1936 | ||
1937 | m->dht = new_DHT(m->log, m->net); | 1937 | m->dht = new_DHT(m->log, m->net, options->hole_punching_enabled); |
1938 | 1938 | ||
1939 | if (m->dht == NULL) { | 1939 | if (m->dht == NULL) { |
1940 | kill_networking(m->net); | 1940 | kill_networking(m->net); |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 23bd0009..8f9a83a9 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -77,6 +77,8 @@ typedef struct { | |||
77 | uint16_t port_range[2]; | 77 | uint16_t port_range[2]; |
78 | uint16_t tcp_server_port; | 78 | uint16_t tcp_server_port; |
79 | 79 | ||
80 | uint8_t hole_punching_enabled; | ||
81 | |||
80 | logger_cb *log_callback; | 82 | logger_cb *log_callback; |
81 | void *log_user_data; | 83 | void *log_user_data; |
82 | } Messenger_Options; | 84 | } Messenger_Options; |
diff --git a/toxcore/tox.api.h b/toxcore/tox.api.h index 40031830..33481cce 100644 --- a/toxcore/tox.api.h +++ b/toxcore/tox.api.h | |||
@@ -519,6 +519,11 @@ static class options { | |||
519 | */ | 519 | */ |
520 | uint16_t tcp_port; | 520 | uint16_t tcp_port; |
521 | 521 | ||
522 | /** | ||
523 | * Enables or disables UDP hole-punching in toxcore. (Default: enabled). | ||
524 | */ | ||
525 | bool hole_punching_enabled; | ||
526 | |||
522 | namespace savedata { | 527 | namespace savedata { |
523 | /** | 528 | /** |
524 | * The type of savedata to load from. | 529 | * The type of savedata to load from. |
diff --git a/toxcore/tox.c b/toxcore/tox.c index c7d90871..6317d126 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -131,6 +131,7 @@ ACCESSORS(uint16_t, proxy_ , port) | |||
131 | ACCESSORS(uint16_t, , start_port) | 131 | ACCESSORS(uint16_t, , start_port) |
132 | ACCESSORS(uint16_t, , end_port) | 132 | ACCESSORS(uint16_t, , end_port) |
133 | ACCESSORS(uint16_t, , tcp_port) | 133 | ACCESSORS(uint16_t, , tcp_port) |
134 | ACCESSORS(bool, , hole_punching_enabled) | ||
134 | ACCESSORS(TOX_SAVEDATA_TYPE, savedata_, type) | 135 | ACCESSORS(TOX_SAVEDATA_TYPE, savedata_, type) |
135 | ACCESSORS(size_t, savedata_, length) | 136 | ACCESSORS(size_t, savedata_, length) |
136 | ACCESSORS(tox_log_cb *, log_, callback) | 137 | ACCESSORS(tox_log_cb *, log_, callback) |
@@ -155,6 +156,7 @@ void tox_options_default(struct Tox_Options *options) | |||
155 | options->ipv6_enabled = 1; | 156 | options->ipv6_enabled = 1; |
156 | options->udp_enabled = 1; | 157 | options->udp_enabled = 1; |
157 | options->proxy_type = TOX_PROXY_TYPE_NONE; | 158 | options->proxy_type = TOX_PROXY_TYPE_NONE; |
159 | options->hole_punching_enabled = true; | ||
158 | } | 160 | } |
159 | } | 161 | } |
160 | 162 | ||
@@ -219,6 +221,7 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error) | |||
219 | m_options.port_range[0] = options->start_port; | 221 | m_options.port_range[0] = options->start_port; |
220 | m_options.port_range[1] = options->end_port; | 222 | m_options.port_range[1] = options->end_port; |
221 | m_options.tcp_server_port = options->tcp_port; | 223 | m_options.tcp_server_port = options->tcp_port; |
224 | m_options.hole_punching_enabled = options->hole_punching_enabled; | ||
222 | 225 | ||
223 | m_options.log_callback = (logger_cb *)options->log_callback; | 226 | m_options.log_callback = (logger_cb *)options->log_callback; |
224 | m_options.log_user_data = options->log_user_data; | 227 | m_options.log_user_data = options->log_user_data; |
diff --git a/toxcore/tox.h b/toxcore/tox.h index ef738422..d6f6fb2f 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -576,6 +576,12 @@ struct Tox_Options { | |||
576 | 576 | ||
577 | 577 | ||
578 | /** | 578 | /** |
579 | * Enables or disables UDP hole-punching in toxcore. (Default: enabled). | ||
580 | */ | ||
581 | bool hole_punching_enabled; | ||
582 | |||
583 | |||
584 | /** | ||
579 | * The type of savedata to load from. | 585 | * The type of savedata to load from. |
580 | */ | 586 | */ |
581 | TOX_SAVEDATA_TYPE savedata_type; | 587 | TOX_SAVEDATA_TYPE savedata_type; |
@@ -642,6 +648,10 @@ uint16_t tox_options_get_tcp_port(const struct Tox_Options *options); | |||
642 | 648 | ||
643 | void tox_options_set_tcp_port(struct Tox_Options *options, uint16_t tcp_port); | 649 | void tox_options_set_tcp_port(struct Tox_Options *options, uint16_t tcp_port); |
644 | 650 | ||
651 | bool tox_options_get_hole_punching_enabled(const struct Tox_Options *options); | ||
652 | |||
653 | void tox_options_set_hole_punching_enabled(struct Tox_Options *options, bool hole_punching_enabled); | ||
654 | |||
645 | TOX_SAVEDATA_TYPE tox_options_get_savedata_type(const struct Tox_Options *options); | 655 | TOX_SAVEDATA_TYPE tox_options_get_savedata_type(const struct Tox_Options *options); |
646 | 656 | ||
647 | void tox_options_set_savedata_type(struct Tox_Options *options, TOX_SAVEDATA_TYPE type); | 657 | void tox_options_set_savedata_type(struct Tox_Options *options, TOX_SAVEDATA_TYPE type); |