1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-06-29 15:47:46 +02:00

separate bootstrapping and adding TCP relays per toxcore API changes

This commit is contained in:
Jfreegman 2015-05-24 17:56:30 -04:00 committed by cnhenry
parent ef1068b6aa
commit ca1fca5aa5
2 changed files with 27 additions and 4 deletions

View File

@ -260,6 +260,7 @@ void cmd_connect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)
TOX_ERR_BOOTSTRAP err;
tox_bootstrap(m, ip, atoi(port), (uint8_t *) binary_string, &err);
tox_add_tcp_relay(m, ip, atoi(port), (uint8_t *) binary_string, &err);
free(binary_string);
switch (err) {

View File

@ -305,14 +305,34 @@ static int load_nodelist(const char *filename)
return 0;
}
/* Bootstraps and adds as TCP relay.
* Returns 0 if both actions are successful.
* Returns -1 otherwise.
*/
int init_connection_helper(Tox *m, int line)
{
return tox_bootstrap(m, toxNodes.nodes[line], toxNodes.ports[line], (uint8_t *) toxNodes.keys[line], NULL);
TOX_ERR_BOOTSTRAP err;
tox_bootstrap(m, toxNodes.nodes[line], toxNodes.ports[line], (uint8_t *) toxNodes.keys[line], &err);
if (err != TOX_ERR_BOOTSTRAP_OK) {
fprintf(stderr, "Failed to bootstrap %s:%d\n", toxNodes.nodes[line], toxNodes.ports[line]);
return -1;
}
tox_add_tcp_relay(m, toxNodes.nodes[line], toxNodes.ports[line], (uint8_t *) toxNodes.keys[line], &err);
if (err != TOX_ERR_BOOTSTRAP_OK) {
fprintf(stderr, "Failed to add TCP relay %s:%d\n", toxNodes.nodes[line], toxNodes.ports[line]);
return -1;
}
return 0;
}
/* Connects to a random DHT node listed in the DHTnodes file
*
* return codes:
* 0: success
* 1: failed to open node file
* 2: no line of sufficient length in node file
* 3: failed to resolve name to IP
@ -324,8 +344,10 @@ static bool srvlist_loaded = false;
int init_connection(Tox *m)
{
if (toxNodes.lines > 0) /* already loaded nodelist */
return init_connection_helper(m, rand() % toxNodes.lines) ? 0 : 3;
if (toxNodes.lines > 0) { /* already loaded nodelist */
init_connection_helper(m, rand() % toxNodes.lines);
return 0;
}
/* only once:
* - load the nodelist
@ -348,7 +370,7 @@ int init_connection(Tox *m)
int n = MIN(NUM_INIT_NODES, toxNodes.lines);
for (i = 0; i < n; ++i) {
if (init_connection_helper(m, rand() % toxNodes.lines))
if (init_connection_helper(m, rand() % toxNodes.lines) == 0)
res = 0;
}