summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorGDR! <gdr@gdr.name>2014-12-13 17:24:39 +0000
committerGDR! <gdr@gdr.name>2014-12-13 17:24:39 +0000
commit4f28d0b194fdd9607955f2e32de44f8fbf5d7d31 (patch)
treeec83f25bc02c95d6022cb59b3aaf37502870ffcd /main.c
parent9f66ecc193b1bca4eac19f178123215340c9cb14 (diff)
More robust connection algorithm
Stolen from uTox
Diffstat (limited to 'main.c')
-rw-r--r--main.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/main.c b/main.c
index 73ad1d0..2694ce4 100644
--- a/main.c
+++ b/main.c
@@ -494,6 +494,12 @@ int parse_lossless_packet(void *sender_uc, const uint8_t *data, uint32_t len)
494 return -1; 494 return -1;
495 } 495 }
496 496
497 if(!data)
498 {
499 fprintf(stderr, "Got NULL pointer from toxcore - WTF?\n");
500 return -1;
501 }
502
497 if(data[0] != PROTOCOL_MAGIC_HIGH || data[1] != PROTOCOL_MAGIC_LOW) 503 if(data[0] != PROTOCOL_MAGIC_HIGH || data[1] != PROTOCOL_MAGIC_LOW)
498 { 504 {
499 fprintf(stderr, "Received data frame with invalid protocol magic number 0x%x%x\n", data[0], data[1]); 505 fprintf(stderr, "Received data frame with invalid protocol magic number 0x%x%x\n", data[0], data[1]);
@@ -836,6 +842,19 @@ int main(int argc, char *argv[])
836 tox_options.proxy_enabled = 0; 842 tox_options.proxy_enabled = 0;
837 843
838 tox = tox_new(&tox_options); 844 tox = tox_new(&tox_options);
845 if(tox == NULL)
846 {
847 fprintf(stderr, "tox_new() failed - trying without proxy\n");
848 if(!tox_options.proxy_enabled || (tox_options.proxy_enabled = 0, (tox = tox_new(&tox_options)) == NULL))
849 {
850 fprintf(stderr, "tox_new() failed - trying without IPv6\n");
851 if(!tox_options.ipv6enabled || (tox_options.ipv6enabled = 0, (tox = tox_new(&tox_options)) == NULL))
852 {
853 fprintf(stderr, "tox_new() failed - exiting\n");
854 exit(1);
855 }
856 }
857 }
839 858
840 set_tox_username(tox); 859 set_tox_username(tox);
841 860