Skip to content

Commit

Permalink
More robust connection algorithm
Browse files Browse the repository at this point in the history
Stolen from uTox
  • Loading branch information
gjedeer committed Dec 13, 2014
1 parent 9f66ecc commit 4f28d0b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,12 @@ int parse_lossless_packet(void *sender_uc, const uint8_t *data, uint32_t len)
return -1;
}

if(!data)
{
fprintf(stderr, "Got NULL pointer from toxcore - WTF?\n");
return -1;
}

if(data[0] != PROTOCOL_MAGIC_HIGH || data[1] != PROTOCOL_MAGIC_LOW)
{
fprintf(stderr, "Received data frame with invalid protocol magic number 0x%x%x\n", data[0], data[1]);
Expand Down Expand Up @@ -836,6 +842,19 @@ int main(int argc, char *argv[])
tox_options.proxy_enabled = 0;

tox = tox_new(&tox_options);
if(tox == NULL)
{
fprintf(stderr, "tox_new() failed - trying without proxy\n");
if(!tox_options.proxy_enabled || (tox_options.proxy_enabled = 0, (tox = tox_new(&tox_options)) == NULL))
{
fprintf(stderr, "tox_new() failed - trying without IPv6\n");
if(!tox_options.ipv6enabled || (tox_options.ipv6enabled = 0, (tox = tox_new(&tox_options)) == NULL))
{
fprintf(stderr, "tox_new() failed - exiting\n");
exit(1);
}
}
}

set_tox_username(tox);

Expand Down

0 comments on commit 4f28d0b

Please sign in to comment.