Removed tox_connect, initial connections are made on first tox_do

This commit is contained in:
saneki 2014-09-12 12:21:17 -05:00
parent 98a93c7880
commit 27369ac762
6 changed files with 22 additions and 41 deletions

View File

@ -2229,6 +2229,13 @@ DHT *new_DHT(Networking_Core *net)
void do_DHT(DHT *dht)
{
// Load friends/clients if first call to do_DHT
if(dht->has_loaded_friends_clients == 0)
{
dht->has_loaded_friends_clients = 1;
DHT_connect_after_load(dht);
}
unix_time_update();
if (dht->last_run == unix_time()) {

View File

@ -202,6 +202,7 @@ typedef struct {
// Used after loading of file (tox_load), but no longer needed after connect (tox_connect)
// Unsure if friends_list and num_friends could just be used instead?
int has_loaded_friends_clients; // Whether or not we have loaded on the first do_DHT
DHT_Friend *loaded_friends_list;
uint32_t loaded_num_friends;
Client_data *loaded_clients_list;

View File

@ -2408,6 +2408,17 @@ uint32_t messenger_run_interval(Messenger *m)
/* The main loop that needs to be run at least 20 times per second. */
void do_messenger(Messenger *m)
{
// Add the TCP relays, but only if this is the first time calling do_messenger
if(m->has_added_relays == 0)
{
m->has_added_relays = 1;
int i;
for (i = 0; i < NUM_SAVED_TCP_RELAYS; ++i) {
add_tcp_relay(m->net_crypto, m->loaded_relays[i].ip_port, m->loaded_relays[i].client_id);
}
}
unix_time_update();
if (!m->options.udp_disabled) {
@ -2554,7 +2565,6 @@ void do_messenger(Messenger *m)
#define MESSENGER_STATE_TYPE_PATH_NODE 11
#define SAVED_FRIEND_REQUEST_SIZE 1024
#define NUM_SAVED_TCP_RELAYS 8
#define NUM_SAVED_PATH_NODES 8
struct SAVED_FRIEND {
uint8_t status;
@ -2859,25 +2869,6 @@ int messenger_load(Messenger *m, const uint8_t *data, uint32_t length)
return -1;
}
/* Connect after loading messenger from file */
int messenger_connect(Messenger *m)
{
int i;
if(m == NULL)
return -1;
DHT *dht = m->dht;
if(DHT_connect_after_load(dht) == -1)
return -1;
for (i = 0; i < NUM_SAVED_TCP_RELAYS; ++i) {
add_tcp_relay(m->net_crypto, m->loaded_relays[i].ip_port, m->loaded_relays[i].client_id);
}
return 0;
}
/* Return the number of friends in the instance m.
* You should use this to determine how much memory to allocate
* for copy_friendlist. */

View File

@ -189,7 +189,7 @@ typedef struct {
} lossless_packethandlers[PACKET_ID_LOSSLESS_RANGE_SIZE];
} Friend;
#define NUM_SAVED_TCP_RELAYS 8
typedef struct Messenger {
Networking_Core *net;
@ -219,9 +219,8 @@ typedef struct Messenger {
uint64_t last_LANdiscovery;
// Relays loaded from config
// 8 should be NUM_SAVED_TCP_RELAYS but it is defined in c file
Node_format loaded_relays[8];
uint8_t has_added_relays; // If the first connection has occurred in do_messenger
Node_format loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config
void (*friend_message)(struct Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
void *friend_message_userdata;
@ -780,9 +779,6 @@ void messenger_save(const Messenger *m, uint8_t *data);
/* Load the messenger from data of size length. */
int messenger_load(Messenger *m, const uint8_t *data, uint32_t length);
/* Connect after loading messenger from file */
int messenger_connect(Messenger *m);
/* Return the number of friends in the instance m.
* You should use this to determine how much memory to allocate
* for copy_friendlist. */

View File

@ -928,10 +928,3 @@ int tox_load(Tox *tox, const uint8_t *data, uint32_t length)
Messenger *m = tox;
return messenger_load(m, data, length);
}
/* Connect after loading the messenger from file */
int tox_connect(Tox *tox)
{
Messenger *m = tox;
return messenger_connect(m);
}

View File

@ -723,13 +723,6 @@ void tox_save(const Tox *tox, uint8_t *data);
*/
int tox_load(Tox *tox, const uint8_t *data, uint32_t length);
/* Perform connections after messenger has been loaded from file.
*
* returns 0 on success
* returns -1 on failure
*/
int tox_connect(Tox *tox);
#ifdef __cplusplus
}
#endif