1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-27 01:53:27 +01:00

Merge branch 'master' into new_groupchats

This commit is contained in:
Jfreegman 2015-05-24 18:13:15 -04:00
commit 3826fd793d
2 changed files with 40 additions and 7 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_ERR_BOOTSTRAP err;
tox_bootstrap(m, ip, atoi(port), (uint8_t *) binary_string, &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); free(binary_string);
switch (err) { switch (err) {

View File

@ -306,14 +306,34 @@ static int load_nodelist(const char *filename)
return 0; 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) 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 /* Connects to a random DHT node listed in the DHTnodes file
* *
* return codes: * return codes:
* 0: success
* 1: failed to open node file * 1: failed to open node file
* 2: no line of sufficient length in node file * 2: no line of sufficient length in node file
* 3: failed to resolve name to IP * 3: failed to resolve name to IP
@ -325,8 +345,10 @@ static bool srvlist_loaded = false;
int init_connection(Tox *m) int init_connection(Tox *m)
{ {
if (toxNodes.lines > 0) /* already loaded nodelist */ if (toxNodes.lines > 0) { /* already loaded nodelist */
return init_connection_helper(m, rand() % toxNodes.lines) ? 0 : 3; init_connection_helper(m, rand() % toxNodes.lines);
return 0;
}
/* only once: /* only once:
* - load the nodelist * - load the nodelist
@ -349,7 +371,7 @@ int init_connection(Tox *m)
int n = MIN(NUM_INIT_NODES, toxNodes.lines); int n = MIN(NUM_INIT_NODES, toxNodes.lines);
for (i = 0; i < n; ++i) { 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; res = 0;
} }
@ -659,7 +681,11 @@ static Tox *load_tox(char *data_path, struct Tox_Options *tox_opts, TOX_ERR_NEW
(uint8_t *) plain, &pwerr); (uint8_t *) plain, &pwerr);
if (pwerr == TOX_ERR_DECRYPTION_OK) { if (pwerr == TOX_ERR_DECRYPTION_OK) {
m = tox_new(tox_opts, (uint8_t *) plain, plain_len, new_err); tox_opts->savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE;
tox_opts->savedata_data = (uint8_t *) plain;
tox_opts->savedata_length = plain_len;
m = tox_new(tox_opts, new_err);
if (m == NULL) { if (m == NULL) {
fclose(fp); fclose(fp);
@ -677,7 +703,11 @@ static Tox *load_tox(char *data_path, struct Tox_Options *tox_opts, TOX_ERR_NEW
} }
} }
} else { /* data is not encrypted */ } else { /* data is not encrypted */
m = tox_new(tox_opts, (uint8_t *) data, len, new_err); tox_opts->savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE;
tox_opts->savedata_data = (uint8_t *) data;
tox_opts->savedata_length = len;
m = tox_new(tox_opts, new_err);
if (m == NULL) { if (m == NULL) {
fclose(fp); fclose(fp);
@ -690,7 +720,9 @@ static Tox *load_tox(char *data_path, struct Tox_Options *tox_opts, TOX_ERR_NEW
if (file_exists(data_path)) if (file_exists(data_path))
exit_toxic_err("failed in load_toxic", FATALERR_FILEOP); exit_toxic_err("failed in load_toxic", FATALERR_FILEOP);
m = tox_new(tox_opts, NULL, 0, new_err); tox_opts->savedata_type = TOX_SAVEDATA_TYPE_NONE;
m = tox_new(tox_opts, new_err);
if (m == NULL) if (m == NULL)
return NULL; return NULL;