summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsaneki <fake.saneki@gmail.com>2014-09-12 12:21:17 -0500
committersaneki <fake.saneki@gmail.com>2014-09-12 12:21:17 -0500
commit27369ac76278aace29b52eb5523af80f3d9a1880 (patch)
treec74d4c0921088547fbbba9fae3ebade1de6ec88f
parent98a93c7880dfc4ce0e1466dae3d1757df580378b (diff)
Removed tox_connect, initial connections are made on first tox_do
-rw-r--r--toxcore/DHT.c7
-rw-r--r--toxcore/DHT.h1
-rw-r--r--toxcore/Messenger.c31
-rw-r--r--toxcore/Messenger.h10
-rw-r--r--toxcore/tox.c7
-rw-r--r--toxcore/tox.h7
6 files changed, 22 insertions, 41 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 5041cc4e..be675b26 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -2229,6 +2229,13 @@ DHT *new_DHT(Networking_Core *net)
2229 2229
2230void do_DHT(DHT *dht) 2230void do_DHT(DHT *dht)
2231{ 2231{
2232 // Load friends/clients if first call to do_DHT
2233 if(dht->has_loaded_friends_clients == 0)
2234 {
2235 dht->has_loaded_friends_clients = 1;
2236 DHT_connect_after_load(dht);
2237 }
2238
2232 unix_time_update(); 2239 unix_time_update();
2233 2240
2234 if (dht->last_run == unix_time()) { 2241 if (dht->last_run == unix_time()) {
diff --git a/toxcore/DHT.h b/toxcore/DHT.h
index bbba6209..4beda37e 100644
--- a/toxcore/DHT.h
+++ b/toxcore/DHT.h
@@ -202,6 +202,7 @@ typedef struct {
202 202
203 // Used after loading of file (tox_load), but no longer needed after connect (tox_connect) 203 // Used after loading of file (tox_load), but no longer needed after connect (tox_connect)
204 // Unsure if friends_list and num_friends could just be used instead? 204 // Unsure if friends_list and num_friends could just be used instead?
205 int has_loaded_friends_clients; // Whether or not we have loaded on the first do_DHT
205 DHT_Friend *loaded_friends_list; 206 DHT_Friend *loaded_friends_list;
206 uint32_t loaded_num_friends; 207 uint32_t loaded_num_friends;
207 Client_data *loaded_clients_list; 208 Client_data *loaded_clients_list;
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index a6bfbc8a..5dbed346 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -2408,6 +2408,17 @@ uint32_t messenger_run_interval(Messenger *m)
2408/* The main loop that needs to be run at least 20 times per second. */ 2408/* The main loop that needs to be run at least 20 times per second. */
2409void do_messenger(Messenger *m) 2409void do_messenger(Messenger *m)
2410{ 2410{
2411 // Add the TCP relays, but only if this is the first time calling do_messenger
2412 if(m->has_added_relays == 0)
2413 {
2414 m->has_added_relays = 1;
2415
2416 int i;
2417 for (i = 0; i < NUM_SAVED_TCP_RELAYS; ++i) {
2418 add_tcp_relay(m->net_crypto, m->loaded_relays[i].ip_port, m->loaded_relays[i].client_id);
2419 }
2420 }
2421
2411 unix_time_update(); 2422 unix_time_update();
2412 2423
2413 if (!m->options.udp_disabled) { 2424 if (!m->options.udp_disabled) {
@@ -2554,7 +2565,6 @@ void do_messenger(Messenger *m)
2554#define MESSENGER_STATE_TYPE_PATH_NODE 11 2565#define MESSENGER_STATE_TYPE_PATH_NODE 11
2555 2566
2556#define SAVED_FRIEND_REQUEST_SIZE 1024 2567#define SAVED_FRIEND_REQUEST_SIZE 1024
2557#define NUM_SAVED_TCP_RELAYS 8
2558#define NUM_SAVED_PATH_NODES 8 2568#define NUM_SAVED_PATH_NODES 8
2559struct SAVED_FRIEND { 2569struct SAVED_FRIEND {
2560 uint8_t status; 2570 uint8_t status;
@@ -2859,25 +2869,6 @@ int messenger_load(Messenger *m, const uint8_t *data, uint32_t length)
2859 return -1; 2869 return -1;
2860} 2870}
2861 2871
2862/* Connect after loading messenger from file */
2863int messenger_connect(Messenger *m)
2864{
2865 int i;
2866
2867 if(m == NULL)
2868 return -1;
2869
2870 DHT *dht = m->dht;
2871 if(DHT_connect_after_load(dht) == -1)
2872 return -1;
2873
2874 for (i = 0; i < NUM_SAVED_TCP_RELAYS; ++i) {
2875 add_tcp_relay(m->net_crypto, m->loaded_relays[i].ip_port, m->loaded_relays[i].client_id);
2876 }
2877
2878 return 0;
2879}
2880
2881/* Return the number of friends in the instance m. 2872/* Return the number of friends in the instance m.
2882 * You should use this to determine how much memory to allocate 2873 * You should use this to determine how much memory to allocate
2883 * for copy_friendlist. */ 2874 * for copy_friendlist. */
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index ee3c3fa5..c3ae686a 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -189,7 +189,7 @@ typedef struct {
189 } lossless_packethandlers[PACKET_ID_LOSSLESS_RANGE_SIZE]; 189 } lossless_packethandlers[PACKET_ID_LOSSLESS_RANGE_SIZE];
190} Friend; 190} Friend;
191 191
192 192#define NUM_SAVED_TCP_RELAYS 8
193typedef struct Messenger { 193typedef struct Messenger {
194 194
195 Networking_Core *net; 195 Networking_Core *net;
@@ -219,9 +219,8 @@ typedef struct Messenger {
219 219
220 uint64_t last_LANdiscovery; 220 uint64_t last_LANdiscovery;
221 221
222 // Relays loaded from config 222 uint8_t has_added_relays; // If the first connection has occurred in do_messenger
223 // 8 should be NUM_SAVED_TCP_RELAYS but it is defined in c file 223 Node_format loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config
224 Node_format loaded_relays[8];
225 224
226 void (*friend_message)(struct Messenger *m, int32_t, const uint8_t *, uint16_t, void *); 225 void (*friend_message)(struct Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
227 void *friend_message_userdata; 226 void *friend_message_userdata;
@@ -780,9 +779,6 @@ void messenger_save(const Messenger *m, uint8_t *data);
780/* Load the messenger from data of size length. */ 779/* Load the messenger from data of size length. */
781int messenger_load(Messenger *m, const uint8_t *data, uint32_t length); 780int messenger_load(Messenger *m, const uint8_t *data, uint32_t length);
782 781
783/* Connect after loading messenger from file */
784int messenger_connect(Messenger *m);
785
786/* Return the number of friends in the instance m. 782/* Return the number of friends in the instance m.
787 * You should use this to determine how much memory to allocate 783 * You should use this to determine how much memory to allocate
788 * for copy_friendlist. */ 784 * for copy_friendlist. */
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 73bbe1c6..b2aadd39 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -928,10 +928,3 @@ int tox_load(Tox *tox, const uint8_t *data, uint32_t length)
928 Messenger *m = tox; 928 Messenger *m = tox;
929 return messenger_load(m, data, length); 929 return messenger_load(m, data, length);
930} 930}
931
932/* Connect after loading the messenger from file */
933int tox_connect(Tox *tox)
934{
935 Messenger *m = tox;
936 return messenger_connect(m);
937}
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 8a564e6b..1f251085 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -723,13 +723,6 @@ void tox_save(const Tox *tox, uint8_t *data);
723 */ 723 */
724int tox_load(Tox *tox, const uint8_t *data, uint32_t length); 724int tox_load(Tox *tox, const uint8_t *data, uint32_t length);
725 725
726/* Perform connections after messenger has been loaded from file.
727 *
728 * returns 0 on success
729 * returns -1 on failure
730 */
731int tox_connect(Tox *tox);
732
733#ifdef __cplusplus 726#ifdef __cplusplus
734} 727}
735#endif 728#endif