summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto_tests/assoc_test.c1
-rw-r--r--auto_tests/crypto_test.c1
-rw-r--r--auto_tests/dht_test.c10
-rw-r--r--auto_tests/tox_test.c45
-rw-r--r--auto_tests/toxav_basic_test.c1
-rw-r--r--testing/DHT_test.c1
-rw-r--r--testing/Messenger_test.c1
-rw-r--r--testing/av_test.c1
-rw-r--r--testing/nTox.c78
-rw-r--r--testing/tox_sync.c2
-rw-r--r--toxav/audio.c12
-rw-r--r--toxav/group.c1
-rw-r--r--toxav/msi.c9
-rw-r--r--toxav/rtp.c164
-rw-r--r--toxav/toxav.c2
-rw-r--r--toxcore/DHT.c68
-rw-r--r--toxcore/LAN_discovery.c1
-rw-r--r--toxcore/Messenger.c55
-rw-r--r--toxcore/TCP_client.c6
-rw-r--r--toxcore/TCP_connection.c97
-rw-r--r--toxcore/TCP_server.c21
-rw-r--r--toxcore/assoc.c18
-rw-r--r--toxcore/friend_connection.c27
-rw-r--r--toxcore/group.c41
-rw-r--r--toxcore/list.c8
-rw-r--r--toxcore/net_crypto.c56
-rw-r--r--toxcore/network.c12
-rw-r--r--toxcore/onion.c6
-rw-r--r--toxcore/onion_client.c20
-rw-r--r--toxcore/tox.c51
-rw-r--r--toxencryptsave/toxencryptsave.c4
31 files changed, 411 insertions, 409 deletions
diff --git a/auto_tests/assoc_test.c b/auto_tests/assoc_test.c
index e9f5207f..79a97fd5 100644
--- a/auto_tests/assoc_test.c
+++ b/auto_tests/assoc_test.c
@@ -101,7 +101,6 @@ START_TEST(test_fillup)
101 if (j % 16 == 0) { 101 if (j % 16 == 0) {
102 memcpy(entries[j].id, id, crypto_box_PUBLICKEYBYTES - 30); 102 memcpy(entries[j].id, id, crypto_box_PUBLICKEYBYTES - 30);
103 memcpy(&closest[j / 16], &entries[j], sizeof(struct entry)); 103 memcpy(&closest[j / 16], &entries[j], sizeof(struct entry));
104
105 } 104 }
106 105
107 uint8_t res = Assoc_add_entry(assoc, entries[j].id, &entries[j].ippts_send, &entries[j].ipp_recv, 1); 106 uint8_t res = Assoc_add_entry(assoc, entries[j].id, &entries[j].ippts_send, &entries[j].ipp_recv, 1);
diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c
index eeb99567..30cc2178 100644
--- a/auto_tests/crypto_test.c
+++ b/auto_tests/crypto_test.c
@@ -131,7 +131,6 @@ START_TEST(test_fast_known)
131 131
132 ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector"); 132 ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector");
133 ck_assert_msg(mlen == sizeof(m) / sizeof(unsigned char), "wrong plaintext length"); 133 ck_assert_msg(mlen == sizeof(m) / sizeof(unsigned char), "wrong plaintext length");
134
135} 134}
136END_TEST 135END_TEST
137 136
diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c
index 92209e7a..7aab9573 100644
--- a/auto_tests/dht_test.c
+++ b/auto_tests/dht_test.c
@@ -404,10 +404,10 @@ void test_add_to_list(uint8_t cmp_list[][crypto_box_PUBLICKEYBYTES + 1], unsigne
404 memcpy(cmp_list[i], pk, crypto_box_PUBLICKEYBYTES); 404 memcpy(cmp_list[i], pk, crypto_box_PUBLICKEYBYTES);
405 cmp_list[i][crypto_box_PUBLICKEYBYTES] = 1; 405 cmp_list[i][crypto_box_PUBLICKEYBYTES] = 1;
406 return; 406 return;
407 } else { 407 }
408 if (memcmp(cmp_list[i], pk, crypto_box_PUBLICKEYBYTES) == 0) { 408
409 return; 409 if (memcmp(cmp_list[i], pk, crypto_box_PUBLICKEYBYTES) == 0) {
410 } 410 return;
411 } 411 }
412 } 412 }
413 413
@@ -557,8 +557,6 @@ END_TEST
557 557
558void ip_callback(void *data, int32_t number, IP_Port ip_port) 558void ip_callback(void *data, int32_t number, IP_Port ip_port)
559{ 559{
560
561
562} 560}
563 561
564 562
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index b2dc0c17..9af7ee41 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -614,13 +614,12 @@ START_TEST(test_few_clients)
614 tox_iterate(tox2, &to_compare); 614 tox_iterate(tox2, &to_compare);
615 tox_iterate(tox3, &to_compare); 615 tox_iterate(tox3, &to_compare);
616 616
617
618 if (typing_changes == 2) { 617 if (typing_changes == 2) {
619 break; 618 break;
620 } else {
621 ck_assert_msg(typing_changes == 0, "Typing fail");
622 } 619 }
623 620
621 ck_assert_msg(typing_changes == 0, "Typing fail");
622
624 c_sleep(50); 623 c_sleep(50);
625 } 624 }
626 625
@@ -635,10 +634,10 @@ START_TEST(test_few_clients)
635 634
636 if (typing_changes == 1) { 635 if (typing_changes == 1) {
637 break; 636 break;
638 } else {
639 ck_assert_msg(typing_changes == 0, "Typing fail");
640 } 637 }
641 638
639 ck_assert_msg(typing_changes == 0, "Typing fail");
640
642 c_sleep(50); 641 c_sleep(50);
643 } 642 }
644 643
@@ -663,10 +662,10 @@ START_TEST(test_few_clients)
663 662
664 if (custom_packet == 1) { 663 if (custom_packet == 1) {
665 break; 664 break;
666 } else {
667 ck_assert_msg(custom_packet == 0, "Lossless packet fail");
668 } 665 }
669 666
667 ck_assert_msg(custom_packet == 0, "Lossless packet fail");
668
670 c_sleep(50); 669 c_sleep(50);
671 } 670 }
672 671
@@ -686,10 +685,10 @@ START_TEST(test_few_clients)
686 685
687 if (custom_packet == 1) { 686 if (custom_packet == 1) {
688 break; 687 break;
689 } else {
690 ck_assert_msg(custom_packet == 0, "lossy packet fail");
691 } 688 }
692 689
690 ck_assert_msg(custom_packet == 0, "lossy packet fail");
691
693 c_sleep(50); 692 c_sleep(50);
694 } 693 }
695 694
@@ -725,11 +724,11 @@ START_TEST(test_few_clients)
725 if (sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv 724 if (sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv
726 && file_accepted == 1) { 725 && file_accepted == 1) {
727 break; 726 break;
728 } else {
729 ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %llu %llu %llu", sendf_ok, file_recv,
730 totalf_size == file_size, size_recv == file_size, sending_pos == size_recv, file_accepted == 1, totalf_size, size_recv,
731 sending_pos);
732 } 727 }
728
729 ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %llu %llu %llu", sendf_ok, file_recv,
730 totalf_size == file_size, size_recv == file_size, sending_pos == size_recv, file_accepted == 1, totalf_size, size_recv,
731 sending_pos);
733 } 732 }
734 733
735 uint32_t tox1_interval = tox_iteration_interval(tox1); 734 uint32_t tox1_interval = tox_iteration_interval(tox1);
@@ -772,12 +771,12 @@ START_TEST(test_few_clients)
772 if (sendf_ok && file_recv && m_send_reached && totalf_size == file_size && size_recv == max_sending 771 if (sendf_ok && file_recv && m_send_reached && totalf_size == file_size && size_recv == max_sending
773 && sending_pos == size_recv && file_accepted == 1) { 772 && sending_pos == size_recv && file_accepted == 1) {
774 break; 773 break;
775 } else {
776 ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %u %llu %llu %llu %llu", sendf_ok, file_recv,
777 m_send_reached, totalf_size == file_size, size_recv == max_sending, sending_pos == size_recv, file_accepted == 1,
778 totalf_size, file_size,
779 size_recv, sending_pos);
780 } 774 }
775
776 ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %u %llu %llu %llu %llu", sendf_ok, file_recv,
777 m_send_reached, totalf_size == file_size, size_recv == max_sending, sending_pos == size_recv, file_accepted == 1,
778 totalf_size, file_size,
779 size_recv, sending_pos);
781 } 780 }
782 781
783 uint32_t tox1_interval = tox_iteration_interval(tox1); 782 uint32_t tox1_interval = tox_iteration_interval(tox1);
@@ -806,7 +805,6 @@ START_TEST(test_few_clients)
806 ck_assert_msg(tox_file_get_file_id(tox2, 0, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id failed"); 805 ck_assert_msg(tox_file_get_file_id(tox2, 0, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id failed");
807 ck_assert_msg(gfierr == TOX_ERR_FILE_GET_OK, "wrong error"); 806 ck_assert_msg(gfierr == TOX_ERR_FILE_GET_OK, "wrong error");
808 807
809
810 while (1) { 808 while (1) {
811 tox_iterate(tox1, &to_compare); 809 tox_iterate(tox1, &to_compare);
812 tox_iterate(tox2, &to_compare); 810 tox_iterate(tox2, &to_compare);
@@ -816,11 +814,11 @@ START_TEST(test_few_clients)
816 if (sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv 814 if (sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv
817 && file_accepted == 1) { 815 && file_accepted == 1) {
818 break; 816 break;
819 } else {
820 ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %llu %llu %llu", sendf_ok, file_recv,
821 totalf_size == file_size, size_recv == file_size, sending_pos == size_recv, file_accepted == 1, totalf_size, size_recv,
822 sending_pos);
823 } 817 }
818
819 ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %llu %llu %llu", sendf_ok, file_recv,
820 totalf_size == file_size, size_recv == file_size, sending_pos == size_recv, file_accepted == 1, totalf_size, size_recv,
821 sending_pos);
824 } 822 }
825 823
826 uint32_t tox1_interval = tox_iteration_interval(tox1); 824 uint32_t tox1_interval = tox_iteration_interval(tox1);
@@ -1013,7 +1011,6 @@ loop_top:
1013 ++counter; 1011 ++counter;
1014 } 1012 }
1015 } 1013 }
1016
1017 } 1014 }
1018 1015
1019 if (counter == NUM_FRIENDS * 2) { 1016 if (counter == NUM_FRIENDS * 2) {
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c
index 971c1d83..747c3aa1 100644
--- a/auto_tests/toxav_basic_test.c
+++ b/auto_tests/toxav_basic_test.c
@@ -49,7 +49,6 @@
49typedef struct { 49typedef struct {
50 bool incoming; 50 bool incoming;
51 uint32_t state; 51 uint32_t state;
52
53} CallControl; 52} CallControl;
54 53
55 54
diff --git a/testing/DHT_test.c b/testing/DHT_test.c
index e782d765..f6a2c4bc 100644
--- a/testing/DHT_test.c
+++ b/testing/DHT_test.c
@@ -98,7 +98,6 @@ void print_assoc(IPPTsPng *assoc, uint8_t ours)
98 98
99 printf("Timestamp: %llu\n", (long long unsigned int) assoc->ret_timestamp); 99 printf("Timestamp: %llu\n", (long long unsigned int) assoc->ret_timestamp);
100 print_hardening(&assoc->hardening); 100 print_hardening(&assoc->hardening);
101
102} 101}
103 102
104void print_clientlist(DHT *dht) 103void print_clientlist(DHT *dht)
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index 790439e7..edfe4fb1 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -146,7 +146,6 @@ int main(int argc, char *argv[])
146 read = fread(buffer, 1, 128000, file); 146 read = fread(buffer, 1, 128000, file);
147 printf("Messenger loaded: %i\n", messenger_load(m, buffer, read)); 147 printf("Messenger loaded: %i\n", messenger_load(m, buffer, read));
148 fclose(file); 148 fclose(file);
149
150 } 149 }
151 150
152 m_callback_friendrequest(m, print_request, NULL); 151 m_callback_friendrequest(m, print_request, NULL);
diff --git a/testing/av_test.c b/testing/av_test.c
index 2c8281f4..cac5abd5 100644
--- a/testing/av_test.c
+++ b/testing/av_test.c
@@ -76,7 +76,6 @@ typedef struct {
76 uint32_t state; 76 uint32_t state;
77 pthread_mutex_t arb_mutex[1]; 77 pthread_mutex_t arb_mutex[1];
78 RingBuffer *arb; /* Audio ring buffer */ 78 RingBuffer *arb; /* Audio ring buffer */
79
80} CallControl; 79} CallControl;
81 80
82struct toxav_thread_data { 81struct toxav_thread_data {
diff --git a/testing/nTox.c b/testing/nTox.c
index d55d7653..689d2002 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -510,7 +510,9 @@ void line_eval(Tox *m, char *line)
510 new_lines_mark(help_friend1, 1); 510 new_lines_mark(help_friend1, 1);
511 new_lines_mark(help_friend2, 1); 511 new_lines_mark(help_friend2, 1);
512 return; 512 return;
513 } else if (line[3] == 'g') { 513 }
514
515 if (line[3] == 'g') {
514 new_lines_mark(help_group, 1); 516 new_lines_mark(help_group, 1);
515 return; 517 return;
516 } 518 }
@@ -779,56 +781,56 @@ void wrap_bars(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], si
779 } 781 }
780 782
781 continue; 783 continue;
782 } else { 784 }
783 /* at the limit */
784 if (bar_avail > nl_got) {
785 /* overwrite */
786 memcpy(output + bar_avail - 1, wrap_cont_str, wrap_cont_len);
787 nl_got = bar_avail;
788
789 ipos--;
790 continue;
791 }
792 785
793 if (space_avail > nl_got) { 786 /* at the limit */
794 if (opos + wrap_cont_len - 1 >= STRING_LENGTH_WRAPPED) { 787 if (bar_avail > nl_got) {
795 opos = STRING_LENGTH_WRAPPED - 1; 788 /* overwrite */
796 break; 789 memcpy(output + bar_avail - 1, wrap_cont_str, wrap_cont_len);
797 } 790 nl_got = bar_avail;
798 791
799 /* move forward by 2 characters */ 792 ipos--;
800 memmove(output + space_avail + 3, output + space_avail + 1, opos - (space_avail + 1)); 793 continue;
801 memcpy(output + space_avail, wrap_cont_str, wrap_cont_len); 794 }
802 nl_got = space_avail + 1;
803 795
804 opos += 2; 796 if (space_avail > nl_got) {
805 ipos--; 797 if (opos + wrap_cont_len - 1 >= STRING_LENGTH_WRAPPED) {
806 continue; 798 opos = STRING_LENGTH_WRAPPED - 1;
799 break;
807 } 800 }
808 801
809 char c = input[ipos]; 802 /* move forward by 2 characters */
803 memmove(output + space_avail + 3, output + space_avail + 1, opos - (space_avail + 1));
804 memcpy(output + space_avail, wrap_cont_str, wrap_cont_len);
805 nl_got = space_avail + 1;
810 806
811 if ((c == '|') || (c == ' ') || (c == '\n')) { 807 opos += 2;
812 if (opos + wrap_cont_len >= STRING_LENGTH_WRAPPED) { 808 ipos--;
813 opos = STRING_LENGTH_WRAPPED - 1; 809 continue;
814 break; 810 }
815 }
816
817 memcpy(output + opos, wrap_cont_str, wrap_cont_len);
818
819 nl_got = opos;
820 opos += wrap_cont_len;
821 }
822 811
823 output[opos++] = input[ipos]; 812 char c = input[ipos];
824 813
825 if (opos >= STRING_LENGTH_WRAPPED) { 814 if ((c == '|') || (c == ' ') || (c == '\n')) {
815 if (opos + wrap_cont_len >= STRING_LENGTH_WRAPPED) {
826 opos = STRING_LENGTH_WRAPPED - 1; 816 opos = STRING_LENGTH_WRAPPED - 1;
827 break; 817 break;
828 } 818 }
829 819
830 continue; 820 memcpy(output + opos, wrap_cont_str, wrap_cont_len);
821
822 nl_got = opos;
823 opos += wrap_cont_len;
831 } 824 }
825
826 output[opos++] = input[ipos];
827
828 if (opos >= STRING_LENGTH_WRAPPED) {
829 opos = STRING_LENGTH_WRAPPED - 1;
830 break;
831 }
832
833 continue;
832 } 834 }
833 835
834 if (opos >= STRING_LENGTH_WRAPPED) { 836 if (opos >= STRING_LENGTH_WRAPPED) {
diff --git a/testing/tox_sync.c b/testing/tox_sync.c
index 8fa11625..f30ce059 100644
--- a/testing/tox_sync.c
+++ b/testing/tox_sync.c
@@ -173,7 +173,6 @@ void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number,
173 if (tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, 0)) { 173 if (tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, 0)) {
174 printf("Accepted file transfer. (file: %s)\n", fullpath); 174 printf("Accepted file transfer. (file: %s)\n", fullpath);
175 } 175 }
176
177} 176}
178 177
179void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, 178void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control,
@@ -323,7 +322,6 @@ int main(int argc, char *argv[])
323 } 322 }
324 323
325 closedir(d); 324 closedir(d);
326
327 } else { 325 } else {
328 printf("\nFailed to open directory.\n"); 326 printf("\nFailed to open directory.\n");
329 return 1; 327 return 1;
diff --git a/toxav/audio.c b/toxav/audio.c
index eaa1f6d0..c0bfa608 100644
--- a/toxav/audio.c
+++ b/toxav/audio.c
@@ -413,13 +413,13 @@ bool reconfigure_audio_encoder(Logger *log, OpusEncoder **e, int32_t new_br, int
413 *e = new_encoder; 413 *e = new_encoder;
414 } else if (*old_br == new_br) { 414 } else if (*old_br == new_br) {
415 return true; /* Nothing changed */ 415 return true; /* Nothing changed */
416 } else { 416 }
417 int status = opus_encoder_ctl(*e, OPUS_SET_BITRATE(new_br));
418 417
419 if (status != OPUS_OK) { 418 int status = opus_encoder_ctl(*e, OPUS_SET_BITRATE(new_br));
420 LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status)); 419
421 return false; 420 if (status != OPUS_OK) {
422 } 421 LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status));
422 return false;
423 } 423 }
424 424
425 *old_br = new_br; 425 *old_br = new_br;
diff --git a/toxav/group.c b/toxav/group.c
index dea10af7..969250f8 100644
--- a/toxav/group.c
+++ b/toxav/group.c
@@ -370,7 +370,6 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, int g
370 if (out_audio_samples <= 0) { 370 if (out_audio_samples <= 0) {
371 return -1; 371 return -1;
372 } 372 }
373
374 } 373 }
375 374
376 if (out_audio) { 375 if (out_audio) {
diff --git a/toxav/msi.c b/toxav/msi.c
index 3becac7e..a62bdb35 100644
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -46,7 +46,6 @@ typedef enum {
46 IDRequest = 1, 46 IDRequest = 1,
47 IDError, 47 IDError,
48 IDCapabilities, 48 IDCapabilities,
49
50} MSIHeaderID; 49} MSIHeaderID;
51 50
52 51
@@ -538,7 +537,6 @@ MSICall *new_call (MSISession *session, uint32_t friend_number)
538 } 537 }
539 538
540 session->calls_tail = session->calls_head = friend_number; 539 session->calls_tail = session->calls_head = friend_number;
541
542 } else if (session->calls_tail < friend_number) { /* Appending */ 540 } else if (session->calls_tail < friend_number) { /* Appending */
543 void *tmp = realloc(session->calls, sizeof(MSICall *) * (friend_number + 1)); 541 void *tmp = realloc(session->calls, sizeof(MSICall *) * (friend_number + 1));
544 542
@@ -560,7 +558,6 @@ MSICall *new_call (MSISession *session, uint32_t friend_number)
560 session->calls[session->calls_tail]->next = rc; 558 session->calls[session->calls_tail]->next = rc;
561 559
562 session->calls_tail = friend_number; 560 session->calls_tail = friend_number;
563
564 } else if (session->calls_head > friend_number) { /* Inserting at front */ 561 } else if (session->calls_head > friend_number) { /* Inserting at front */
565 rc->next = session->calls[session->calls_head]; 562 rc->next = session->calls[session->calls_head];
566 session->calls[session->calls_head]->prev = rc; 563 session->calls[session->calls_head]->prev = rc;
@@ -736,7 +733,6 @@ void handle_push (MSICall *call, const MSIMessage *msg)
736 if (invoke_callback(call, msi_OnStart) == -1) { 733 if (invoke_callback(call, msi_OnStart) == -1) {
737 goto FAILURE; 734 goto FAILURE;
738 } 735 }
739
740 } 736 }
741 break; 737 break;
742 738
@@ -767,7 +763,6 @@ void handle_pop (MSICall *call, const MSIMessage *msg)
767 LOGGER_WARNING(call->session->messenger->log, "Friend detected an error: %d", msg->error.value); 763 LOGGER_WARNING(call->session->messenger->log, "Friend detected an error: %d", msg->error.value);
768 call->error = msg->error.value; 764 call->error = msg->error.value;
769 invoke_callback(call, msi_OnError); 765 invoke_callback(call, msi_OnError);
770
771 } else { 766 } else {
772 switch (call->state) { 767 switch (call->state) {
773 case msi_CallInactive: { 768 case msi_CallInactive: {
@@ -812,10 +807,10 @@ void handle_msi_packet (Messenger *m, uint32_t friend_number, const uint8_t *dat
812 LOGGER_WARNING(m->log, "Error parsing message"); 807 LOGGER_WARNING(m->log, "Error parsing message");
813 send_error(m, friend_number, msi_EInvalidMessage); 808 send_error(m, friend_number, msi_EInvalidMessage);
814 return; 809 return;
815 } else {
816 LOGGER_DEBUG(m->log, "Successfully parsed message");
817 } 810 }
818 811
812 LOGGER_DEBUG(m->log, "Successfully parsed message");
813
819 pthread_mutex_lock(session->mutex); 814 pthread_mutex_lock(session->mutex);
820 MSICall *call = get_call(session, friend_number); 815 MSICall *call = get_call(session, friend_number);
821 816
diff --git a/toxav/rtp.c b/toxav/rtp.c
index 1556d23d..38e64dd7 100644
--- a/toxav/rtp.c
+++ b/toxav/rtp.c
@@ -268,12 +268,12 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data,
268 */ 268 */
269 if (chloss(session, header)) { 269 if (chloss(session, header)) {
270 return 0; 270 return 0;
271 } else {
272 /* Message is not late; pick up the latest parameters */
273 session->rsequnum = ntohs(header->sequnum);
274 session->rtimestamp = ntohl(header->timestamp);
275 } 271 }
276 272
273 /* Message is not late; pick up the latest parameters */
274 session->rsequnum = ntohs(header->sequnum);
275 session->rtimestamp = ntohl(header->timestamp);
276
277 bwc_add_recv(session->bwc, length); 277 bwc_add_recv(session->bwc, length);
278 278
279 /* Invoke processing of active multiparted message */ 279 /* Invoke processing of active multiparted message */
@@ -296,69 +296,43 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data,
296 } 296 }
297 297
298 return session->mcb (session->cs, new_message(length, data, length)); 298 return session->mcb (session->cs, new_message(length, data, length));
299 } else { 299 }
300 /* The message is sent in multiple parts */
301
302 if (session->mp) {
303 /* There are 2 possible situations in this case:
304 * 1) being that we got the part of already processing message.
305 * 2) being that we got the part of a new/old message.
306 *
307 * We handle them differently as we only allow a single multiparted
308 * processing message
309 */
310
311 if (session->mp->header.sequnum == ntohs(header->sequnum) &&
312 session->mp->header.timestamp == ntohl(header->timestamp)) {
313 /* First case */
314
315 /* Make sure we have enough allocated memory */
316 if (session->mp->header.tlen - session->mp->len < length - sizeof(struct RTPHeader) ||
317 session->mp->header.tlen <= ntohs(header->cpart)) {
318 /* There happened to be some corruption on the stream;
319 * continue wihtout this part
320 */
321 return 0;
322 }
323
324 memcpy(session->mp->data + ntohs(header->cpart), data + sizeof(struct RTPHeader),
325 length - sizeof(struct RTPHeader));
326 300
327 session->mp->len += length - sizeof(struct RTPHeader); 301 /* The message is sent in multiple parts */
328 302
329 bwc_add_recv(session->bwc, length); 303 if (session->mp) {
304 /* There are 2 possible situations in this case:
305 * 1) being that we got the part of already processing message.
306 * 2) being that we got the part of a new/old message.
307 *
308 * We handle them differently as we only allow a single multiparted
309 * processing message
310 */
330 311
331 if (session->mp->len == session->mp->header.tlen) { 312 if (session->mp->header.sequnum == ntohs(header->sequnum) &&
332 /* Received a full message; now push it for the further 313 session->mp->header.timestamp == ntohl(header->timestamp)) {
333 * processing. 314 /* First case */
334 */
335 if (session->mcb) {
336 session->mcb (session->cs, session->mp);
337 } else {
338 free(session->mp);
339 }
340 315
341 session->mp = NULL; 316 /* Make sure we have enough allocated memory */
342 } 317 if (session->mp->header.tlen - session->mp->len < length - sizeof(struct RTPHeader) ||
343 } else { 318 session->mp->header.tlen <= ntohs(header->cpart)) {
344 /* Second case */ 319 /* There happened to be some corruption on the stream;
320 * continue wihtout this part
321 */
322 return 0;
323 }
345 324
346 if (session->mp->header.timestamp > ntohl(header->timestamp)) { 325 memcpy(session->mp->data + ntohs(header->cpart), data + sizeof(struct RTPHeader),
347 /* The received message part is from the old message; 326 length - sizeof(struct RTPHeader));
348 * discard it.
349 */
350 return 0;
351 }
352 327
353 /* Measure missing parts of the old message */ 328 session->mp->len += length - sizeof(struct RTPHeader);
354 bwc_add_lost(session->bwc,
355 (session->mp->header.tlen - session->mp->len) +
356 329
357 /* Must account sizes of rtp headers too */ 330 bwc_add_recv(session->bwc, length);
358 ((session->mp->header.tlen - session->mp->len) /
359 MAX_CRYPTO_DATA_SIZE) * sizeof(struct RTPHeader) );
360 331
361 /* Push the previous message for processing */ 332 if (session->mp->len == session->mp->header.tlen) {
333 /* Received a full message; now push it for the further
334 * processing.
335 */
362 if (session->mcb) { 336 if (session->mcb) {
363 session->mcb (session->cs, session->mp); 337 session->mcb (session->cs, session->mp);
364 } else { 338 } else {
@@ -366,40 +340,66 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data,
366 } 340 }
367 341
368 session->mp = NULL; 342 session->mp = NULL;
369 goto NEW_MULTIPARTED;
370 } 343 }
371 } else { 344 } else {
372 /* In this case threat the message as if it was received in order 345 /* Second case */
373 */
374
375 /* This is also a point for new multiparted messages */
376NEW_MULTIPARTED:
377 346
378 /* Only allow messages which have arrived in order; 347 if (session->mp->header.timestamp > ntohl(header->timestamp)) {
379 * drop late messages 348 /* The received message part is from the old message;
380 */ 349 * discard it.
381 if (chloss(session, header)) { 350 */
382 return 0; 351 return 0;
383 } else {
384 /* Message is not late; pick up the latest parameters */
385 session->rsequnum = ntohs(header->sequnum);
386 session->rtimestamp = ntohl(header->timestamp);
387 } 352 }
388 353
389 bwc_add_recv(session->bwc, length); 354 /* Measure missing parts of the old message */
355 bwc_add_lost(session->bwc,
356 (session->mp->header.tlen - session->mp->len) +
357
358 /* Must account sizes of rtp headers too */
359 ((session->mp->header.tlen - session->mp->len) /
360 MAX_CRYPTO_DATA_SIZE) * sizeof(struct RTPHeader) );
390 361
391 /* Again, only store message if handler is present 362 /* Push the previous message for processing */
392 */
393 if (session->mcb) { 363 if (session->mcb) {
394 session->mp = new_message(ntohs(header->tlen) + sizeof(struct RTPHeader), data, length); 364 session->mcb (session->cs, session->mp);
365 } else {
366 free(session->mp);
367 }
395 368
396 /* Reposition data if necessary */ 369 session->mp = NULL;
397 if (ntohs(header->cpart)) { 370 goto NEW_MULTIPARTED;
398 ; 371 }
399 } 372 } else {
373 /* In this case threat the message as if it was received in order
374 */
375
376 /* This is also a point for new multiparted messages */
377NEW_MULTIPARTED:
378
379 /* Only allow messages which have arrived in order;
380 * drop late messages
381 */
382 if (chloss(session, header)) {
383 return 0;
384 }
385
386 /* Message is not late; pick up the latest parameters */
387 session->rsequnum = ntohs(header->sequnum);
388 session->rtimestamp = ntohl(header->timestamp);
400 389
401 memmove(session->mp->data + ntohs(header->cpart), session->mp->data, session->mp->len); 390 bwc_add_recv(session->bwc, length);
391
392 /* Again, only store message if handler is present
393 */
394 if (session->mcb) {
395 session->mp = new_message(ntohs(header->tlen) + sizeof(struct RTPHeader), data, length);
396
397 /* Reposition data if necessary */
398 if (ntohs(header->cpart)) {
399 ;
402 } 400 }
401
402 memmove(session->mp->data + ntohs(header->cpart), session->mp->data, session->mp->len);
403 } 403 }
404 } 404 }
405 405
diff --git a/toxav/toxav.c b/toxav/toxav.c
index 126e29a7..749519a2 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -1087,7 +1087,6 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
1087 } 1087 }
1088 1088
1089 av->calls_tail = av->calls_head = friend_number; 1089 av->calls_tail = av->calls_head = friend_number;
1090
1091 } else if (av->calls_tail < friend_number) { /* Appending */ 1090 } else if (av->calls_tail < friend_number) { /* Appending */
1092 void *tmp = realloc(av->calls, sizeof(ToxAVCall *) * (friend_number + 1)); 1091 void *tmp = realloc(av->calls, sizeof(ToxAVCall *) * (friend_number + 1));
1093 1092
@@ -1111,7 +1110,6 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
1111 av->calls[av->calls_tail]->next = call; 1110 av->calls[av->calls_tail]->next = call;
1112 1111
1113 av->calls_tail = friend_number; 1112 av->calls_tail = friend_number;
1114
1115 } else if (av->calls_head > friend_number) { /* Inserting at front */ 1113 } else if (av->calls_head > friend_number) { /* Inserting at front */
1116 call->next = av->calls[av->calls_head]; 1114 call->next = av->calls[av->calls_head];
1117 av->calls[av->calls_head]->prev = call; 1115 av->calls[av->calls_head]->prev = call;
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index c9fa9939..2fd18c49 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -195,12 +195,14 @@ int to_host_family(IP *ip)
195 if (ip->family == TOX_AF_INET) { 195 if (ip->family == TOX_AF_INET) {
196 ip->family = AF_INET; 196 ip->family = AF_INET;
197 return 0; 197 return 0;
198 } else if (ip->family == TOX_AF_INET6) { 198 }
199
200 if (ip->family == TOX_AF_INET6) {
199 ip->family = AF_INET6; 201 ip->family = AF_INET6;
200 return 0; 202 return 0;
201 } else {
202 return -1;
203 } 203 }
204
205 return -1;
204} 206}
205 207
206#define PACKED_NODE_SIZE_IP4 (1 + SIZE_IP4 + sizeof(uint16_t) + crypto_box_PUBLICKEYBYTES) 208#define PACKED_NODE_SIZE_IP4 (1 + SIZE_IP4 + sizeof(uint16_t) + crypto_box_PUBLICKEYBYTES)
@@ -213,15 +215,21 @@ int packed_node_size(uint8_t ip_family)
213{ 215{
214 if (ip_family == AF_INET) { 216 if (ip_family == AF_INET) {
215 return PACKED_NODE_SIZE_IP4; 217 return PACKED_NODE_SIZE_IP4;
216 } else if (ip_family == TCP_INET) { 218 }
219
220 if (ip_family == TCP_INET) {
217 return PACKED_NODE_SIZE_IP4; 221 return PACKED_NODE_SIZE_IP4;
218 } else if (ip_family == AF_INET6) { 222 }
223
224 if (ip_family == AF_INET6) {
219 return PACKED_NODE_SIZE_IP6; 225 return PACKED_NODE_SIZE_IP6;
220 } else if (ip_family == TCP_INET6) { 226 }
227
228 if (ip_family == TCP_INET6) {
221 return PACKED_NODE_SIZE_IP6; 229 return PACKED_NODE_SIZE_IP6;
222 } else {
223 return -1;
224 } 230 }
231
232 return -1;
225} 233}
226 234
227 235
@@ -434,7 +442,9 @@ static int client_or_ip_port_in_list(Logger *log, Client_data *list, uint16_t le
434 /* kill the other address, if it was set */ 442 /* kill the other address, if it was set */
435 memset(&list[i].assoc6, 0, sizeof(list[i].assoc6)); 443 memset(&list[i].assoc6, 0, sizeof(list[i].assoc6));
436 return 1; 444 return 1;
437 } else if ((ip_port.ip.family == AF_INET6) && ipport_equal(&list[i].assoc6.ip_port, &ip_port)) { 445 }
446
447 if ((ip_port.ip.family == AF_INET6) && ipport_equal(&list[i].assoc6.ip_port, &ip_port)) {
438 /* Initialize client timestamp. */ 448 /* Initialize client timestamp. */
439 list[i].assoc6.timestamp = temp_time; 449 list[i].assoc6.timestamp = temp_time;
440 memcpy(list[i].public_key, public_key, crypto_box_PUBLICKEYBYTES); 450 memcpy(list[i].public_key, public_key, crypto_box_PUBLICKEYBYTES);
@@ -739,9 +749,9 @@ static unsigned int store_node_ok(const Client_data *client, const uint8_t *publ
739 if ((is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT) && is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT)) 749 if ((is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT) && is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT))
740 || (id_closest(comp_public_key, client->public_key, public_key) == 2)) { 750 || (id_closest(comp_public_key, client->public_key, public_key) == 2)) {
741 return 1; 751 return 1;
742 } else {
743 return 0;
744 } 752 }
753
754 return 0;
745} 755}
746 756
747static void sort_client_list(Client_data *list, unsigned int length, const uint8_t *comp_public_key) 757static void sort_client_list(Client_data *list, unsigned int length, const uint8_t *comp_public_key)
@@ -1677,9 +1687,9 @@ int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enable
1677 } 1687 }
1678 1688
1679 return 1; 1689 return 1;
1680 } else {
1681 return 0;
1682 } 1690 }
1691
1692 return 0;
1683} 1693}
1684 1694
1685/* Send the given packet to node with public_key 1695/* Send the given packet to node with public_key
@@ -1696,11 +1706,13 @@ int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packe
1696 1706
1697 if (ip_isset(&client->assoc6.ip_port.ip)) { 1707 if (ip_isset(&client->assoc6.ip_port.ip)) {
1698 return sendpacket(dht->net, client->assoc6.ip_port, packet, length); 1708 return sendpacket(dht->net, client->assoc6.ip_port, packet, length);
1699 } else if (ip_isset(&client->assoc4.ip_port.ip)) { 1709 }
1710
1711 if (ip_isset(&client->assoc4.ip_port.ip)) {
1700 return sendpacket(dht->net, client->assoc4.ip_port, packet, length); 1712 return sendpacket(dht->net, client->assoc4.ip_port, packet, length);
1701 } else {
1702 break;
1703 } 1713 }
1714
1715 break;
1704 } 1716 }
1705 } 1717 }
1706 1718
@@ -1955,7 +1967,9 @@ static int handle_NATping(void *object, IP_Port source, const uint8_t *source_pu
1955 send_NATping(dht, source_pubkey, ping_id, NAT_PING_RESPONSE); 1967 send_NATping(dht, source_pubkey, ping_id, NAT_PING_RESPONSE);
1956 friend->nat.recvNATping_timestamp = unix_time(); 1968 friend->nat.recvNATping_timestamp = unix_time();
1957 return 0; 1969 return 0;
1958 } else if (packet[0] == NAT_PING_RESPONSE) { 1970 }
1971
1972 if (packet[0] == NAT_PING_RESPONSE) {
1959 if (friend->nat.NATping_id == ping_id) { 1973 if (friend->nat.NATping_id == ping_id) {
1960 friend->nat.NATping_id = random_64b(); 1974 friend->nat.NATping_id = random_64b();
1961 friend->nat.hole_punching = 1; 1975 friend->nat.hole_punching = 1;
@@ -2186,7 +2200,9 @@ static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *public_key, sa_
2186 2200
2187 if (sa_family == AF_INET) { 2201 if (sa_family == AF_INET) {
2188 return &dht->close_clientlist[i].assoc4; 2202 return &dht->close_clientlist[i].assoc4;
2189 } else if (sa_family == AF_INET6) { 2203 }
2204
2205 if (sa_family == AF_INET6) {
2190 return &dht->close_clientlist[i].assoc6; 2206 return &dht->close_clientlist[i].assoc6;
2191 } 2207 }
2192 } 2208 }
@@ -2319,9 +2335,9 @@ Node_format random_node(DHT *dht, sa_family_t sa_family)
2319 2335
2320 if (num_nodes == 0) { 2336 if (num_nodes == 0) {
2321 return nodes_list[0]; 2337 return nodes_list[0];
2322 } else {
2323 return nodes_list[rand() % num_nodes];
2324 } 2338 }
2339
2340 return nodes_list[rand() % num_nodes];
2325} 2341}
2326 2342
2327/* Put up to max_num nodes in nodes from the closelist. 2343/* Put up to max_num nodes in nodes from the closelist.
@@ -2488,13 +2504,13 @@ static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *pack
2488 2504
2489 return dht->cryptopackethandlers[number].function(dht->cryptopackethandlers[number].object, source, public_key, 2505 return dht->cryptopackethandlers[number].function(dht->cryptopackethandlers[number].object, source, public_key,
2490 data, len); 2506 data, len);
2507 }
2491 2508
2492 } else { /* If request is not for us, try routing it. */ 2509 /* If request is not for us, try routing it. */
2493 int retval = route_packet(dht, packet + 1, packet, length); 2510 int retval = route_packet(dht, packet + 1, packet, length);
2494 2511
2495 if ((unsigned int)retval == length) { 2512 if ((unsigned int)retval == length) {
2496 return 0; 2513 return 0;
2497 }
2498 } 2514 }
2499 } 2515 }
2500 2516
@@ -2747,7 +2763,6 @@ static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t le
2747 } else { 2763 } else {
2748 dht->loaded_num_nodes = 0; 2764 dht->loaded_num_nodes = 0;
2749 } 2765 }
2750
2751 } /* localize declarations */ 2766 } /* localize declarations */
2752 2767
2753 break; 2768 break;
@@ -2824,7 +2839,6 @@ int DHT_non_lan_connected(const DHT *dht)
2824 if (!is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT) && LAN_ip(client->assoc6.ip_port.ip) == -1) { 2839 if (!is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT) && LAN_ip(client->assoc6.ip_port.ip) == -1) {
2825 return 1; 2840 return 1;
2826 } 2841 }
2827
2828 } 2842 }
2829 2843
2830 return 0; 2844 return 0;
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c
index ab28f612..4edc960a 100644
--- a/toxcore/LAN_discovery.c
+++ b/toxcore/LAN_discovery.c
@@ -299,7 +299,6 @@ int LAN_ip(IP ip)
299 if ((ip4.uint8[0] == 100) && ((ip4.uint8[1] & 0xC0) == 0x40)) { 299 if ((ip4.uint8[0] == 100) && ((ip4.uint8[1] & 0xC0) == 0x40)) {
300 return 0; 300 return 0;
301 } 301 }
302
303 } else if (ip.family == AF_INET6) { 302 } else if (ip.family == AF_INET6) {
304 303
305 /* autogenerated for each interface: FE80::* (up to FEBF::*) 304 /* autogenerated for each interface: FE80::* (up to FEBF::*)
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 81e17b7b..99281c73 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -455,16 +455,16 @@ int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber)
455 455
456 if (direct_connected) { 456 if (direct_connected) {
457 return CONNECTION_UDP; 457 return CONNECTION_UDP;
458 } else {
459 if (num_online_relays) {
460 return CONNECTION_TCP;
461 } else {
462 return CONNECTION_UNKNOWN;
463 }
464 } 458 }
465 } else { 459
466 return CONNECTION_NONE; 460 if (num_online_relays) {
461 return CONNECTION_TCP;
462 }
463
464 return CONNECTION_UNKNOWN;
467 } 465 }
466
467 return CONNECTION_NONE;
468} 468}
469 469
470int m_friend_exists(const Messenger *m, int32_t friendnumber) 470int m_friend_exists(const Messenger *m, int32_t friendnumber)
@@ -906,9 +906,9 @@ static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber)
906 if (ret == CONNECTION_UNKNOWN) { 906 if (ret == CONNECTION_UNKNOWN) {
907 if (last_connection_udp_tcp == CONNECTION_UDP) { 907 if (last_connection_udp_tcp == CONNECTION_UDP) {
908 return; 908 return;
909 } else {
910 ret = CONNECTION_TCP;
911 } 909 }
910
911 ret = CONNECTION_TCP;
912 } 912 }
913 913
914 if (last_connection_udp_tcp != ret) { 914 if (last_connection_udp_tcp != ret) {
@@ -1276,9 +1276,9 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber,
1276 if (!(ft->paused & FILE_PAUSE_US)) { 1276 if (!(ft->paused & FILE_PAUSE_US)) {
1277 if (ft->paused & FILE_PAUSE_OTHER) { 1277 if (ft->paused & FILE_PAUSE_OTHER) {
1278 return -6; 1278 return -6;
1279 } else {
1280 return -7;
1281 } 1279 }
1280
1281 return -7;
1282 } 1282 }
1283 } else { 1283 } else {
1284 if (ft->status != FILESTATUS_NOT_ACCEPTED) { 1284 if (ft->status != FILESTATUS_NOT_ACCEPTED) {
@@ -1481,7 +1481,6 @@ int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
1481 } 1481 }
1482 1482
1483 return -6; 1483 return -6;
1484
1485} 1484}
1486 1485
1487/* Give the number of bytes left to be sent/received. 1486/* Give the number of bytes left to be sent/received.
@@ -1504,14 +1503,14 @@ uint64_t file_dataremaining(const Messenger *m, int32_t friendnumber, uint8_t fi
1504 1503
1505 return m->friendlist[friendnumber].file_sending[filenumber].size - 1504 return m->friendlist[friendnumber].file_sending[filenumber].size -
1506 m->friendlist[friendnumber].file_sending[filenumber].transferred; 1505 m->friendlist[friendnumber].file_sending[filenumber].transferred;
1507 } else { 1506 }
1508 if (m->friendlist[friendnumber].file_receiving[filenumber].status == FILESTATUS_NONE) {
1509 return 0;
1510 }
1511 1507
1512 return m->friendlist[friendnumber].file_receiving[filenumber].size - 1508 if (m->friendlist[friendnumber].file_receiving[filenumber].status == FILESTATUS_NONE) {
1513 m->friendlist[friendnumber].file_receiving[filenumber].transferred; 1509 return 0;
1514 } 1510 }
1511
1512 return m->friendlist[friendnumber].file_receiving[filenumber].size -
1513 m->friendlist[friendnumber].file_receiving[filenumber].transferred;
1515} 1514}
1516 1515
1517static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber) 1516static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber)
@@ -1593,7 +1592,6 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber)
1593 } 1592 }
1594 1593
1595 --free_slots; 1594 --free_slots;
1596
1597 } 1595 }
1598 1596
1599 if (num == 0) { 1597 if (num == 0) {
@@ -1686,7 +1684,6 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receiv
1686 if (receive_send) { 1684 if (receive_send) {
1687 --m->friendlist[friendnumber].num_sending_files; 1685 --m->friendlist[friendnumber].num_sending_files;
1688 } 1686 }
1689
1690 } else if (control_type == FILECONTROL_SEEK) { 1687 } else if (control_type == FILECONTROL_SEEK) {
1691 uint64_t position; 1688 uint64_t position;
1692 1689
@@ -1816,9 +1813,9 @@ int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uin
1816 if (send_lossy_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, 1813 if (send_lossy_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
1817 m->friendlist[friendnumber].friendcon_id), data, length) == -1) { 1814 m->friendlist[friendnumber].friendcon_id), data, length) == -1) {
1818 return -5; 1815 return -5;
1819 } else {
1820 return 0;
1821 } 1816 }
1817
1818 return 0;
1822} 1819}
1823 1820
1824static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length) 1821static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length)
@@ -1876,9 +1873,9 @@ int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const
1876 if (write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, 1873 if (write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
1877 m->friendlist[friendnumber].friendcon_id), data, length, 1) == -1) { 1874 m->friendlist[friendnumber].friendcon_id), data, length, 1) == -1) {
1878 return -5; 1875 return -5;
1879 } else {
1880 return 0;
1881 } 1876 }
1877
1878 return 0;
1882} 1879}
1883 1880
1884/* Function to filter out some friend requests*/ 1881/* Function to filter out some friend requests*/
@@ -2462,9 +2459,9 @@ uint32_t messenger_run_interval(const Messenger *m)
2462 2459
2463 if (crypto_interval > MIN_RUN_INTERVAL) { 2460 if (crypto_interval > MIN_RUN_INTERVAL) {
2464 return MIN_RUN_INTERVAL; 2461 return MIN_RUN_INTERVAL;
2465 } else {
2466 return crypto_interval;
2467 } 2462 }
2463
2464 return crypto_interval;
2468} 2465}
2469 2466
2470/* The main loop that needs to be run at least 20 times per second. */ 2467/* The main loop that needs to be run at least 20 times per second. */
@@ -2954,9 +2951,9 @@ int messenger_load(Messenger *m, const uint8_t *data, uint32_t length)
2954 if (!data32[0] && (data32[1] == MESSENGER_STATE_COOKIE_GLOBAL)) { 2951 if (!data32[0] && (data32[1] == MESSENGER_STATE_COOKIE_GLOBAL)) {
2955 return load_state(messenger_load_state_callback, m, data + cookie_len, 2952 return load_state(messenger_load_state_callback, m, data + cookie_len,
2956 length - cookie_len, MESSENGER_STATE_COOKIE_TYPE); 2953 length - cookie_len, MESSENGER_STATE_COOKIE_TYPE);
2957 } else {
2958 return -1;
2959 } 2954 }
2955
2956 return -1;
2960} 2957}
2961 2958
2962/* Return the number of friends in the instance m. 2959/* Return the number of friends in the instance m.
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c
index 641760ae..15e26107 100644
--- a/toxcore/TCP_client.c
+++ b/toxcore/TCP_client.c
@@ -202,7 +202,6 @@ static int proxy_socks5_read_connection_response(TCP_Client_Connection *TCP_conn
202 if (data[0] == 5 && data[1] == 0) { 202 if (data[0] == 5 && data[1] == 0) {
203 return 1; 203 return 1;
204 } 204 }
205
206 } else { 205 } else {
207 uint8_t data[4 + sizeof(IP6) + sizeof(uint16_t)]; 206 uint8_t data[4 + sizeof(IP6) + sizeof(uint16_t)];
208 int ret = read_TCP_packet(TCP_conn->sock, data, sizeof(data)); 207 int ret = read_TCP_packet(TCP_conn->sock, data, sizeof(data));
@@ -364,7 +363,6 @@ static void wipe_priority_list(TCP_Client_Connection *con)
364 p = p->next; 363 p = p->next;
365 free(pp); 364 free(pp);
366 } 365 }
367
368} 366}
369 367
370/* return 1 on success. 368/* return 1 on success.
@@ -828,9 +826,9 @@ static int handle_TCP_packet(TCP_Client_Connection *conn, const uint8_t *data, u
828 } 826 }
829 827
830 return 0; 828 return 0;
831 } else {
832 return -1;
833 } 829 }
830
831 return -1;
834 } 832 }
835 833
836 case TCP_PACKET_OOB_RECV: { 834 case TCP_PACKET_OOB_RECV: {
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c
index 786cb164..922bf0df 100644
--- a/toxcore/TCP_connection.c
+++ b/toxcore/TCP_connection.c
@@ -256,7 +256,9 @@ int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, c
256 256
257 if (ret == 1) { 257 if (ret == 1) {
258 return 0; 258 return 0;
259 } else if (!limit_reached) { 259 }
260
261 if (!limit_reached) {
260 ret = 0; 262 ret = 0;
261 263
262 /* Send oob packets to all relays tied to the connection. */ 264 /* Send oob packets to all relays tied to the connection. */
@@ -280,12 +282,12 @@ int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, c
280 282
281 if (ret >= 1) { 283 if (ret >= 1) {
282 return 0; 284 return 0;
283 } else {
284 return -1;
285 } 285 }
286 } else { 286
287 return -1; 287 return -1;
288 } 288 }
289
290 return -1;
289} 291}
290 292
291/* Return a random TCP connection number for use in send_tcp_onion_request. 293/* Return a random TCP connection number for use in send_tcp_onion_request.
@@ -527,7 +529,7 @@ int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number,
527 } 529 }
528 530
529 if (status) { 531 if (status) {
530 /* Conection is unsleeping. */ 532 /* Connection is unsleeping. */
531 if (con_to->status != TCP_CONN_SLEEPING) { 533 if (con_to->status != TCP_CONN_SLEEPING) {
532 return -1; 534 return -1;
533 } 535 }
@@ -551,32 +553,32 @@ int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number,
551 553
552 con_to->status = TCP_CONN_VALID; 554 con_to->status = TCP_CONN_VALID;
553 return 0; 555 return 0;
554 } else { 556 }
555 /* Conection is going to sleep. */
556 if (con_to->status != TCP_CONN_VALID) {
557 return -1;
558 }
559 557
560 unsigned int i; 558 /* Connection is going to sleep. */
559 if (con_to->status != TCP_CONN_VALID) {
560 return -1;
561 }
561 562
562 for (i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { 563 unsigned int i;
563 if (con_to->connections[i].tcp_connection) {
564 unsigned int tcp_connections_number = con_to->connections[i].tcp_connection - 1;
565 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
566 564
567 if (!tcp_con) { 565 for (i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) {
568 continue; 566 if (con_to->connections[i].tcp_connection) {
569 } 567 unsigned int tcp_connections_number = con_to->connections[i].tcp_connection - 1;
568 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
570 569
571 if (con_to->connections[i].status == TCP_CONNECTIONS_STATUS_ONLINE) { 570 if (!tcp_con) {
572 ++tcp_con->sleep_count; 571 continue;
573 }
574 } 572 }
575 }
576 573
577 con_to->status = TCP_CONN_SLEEPING; 574 if (con_to->connections[i].status == TCP_CONNECTIONS_STATUS_ONLINE) {
578 return 0; 575 ++tcp_con->sleep_count;
576 }
577 }
579 } 578 }
579
580 con_to->status = TCP_CONN_SLEEPING;
581 return 0;
580} 582}
581 583
582static _Bool tcp_connection_in_conn(TCP_Connection_to *con_to, unsigned int tcp_connections_number) 584static _Bool tcp_connection_in_conn(TCP_Connection_to *con_to, unsigned int tcp_connections_number)
@@ -980,10 +982,10 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8
980 982
981 if (con_to && tcp_connection_in_conn(con_to, tcp_connections_number)) { 983 if (con_to && tcp_connection_in_conn(con_to, tcp_connections_number)) {
982 return tcp_data_callback(object, connections_number, 0, data, length, userdata); 984 return tcp_data_callback(object, connections_number, 0, data, length, userdata);
983 } else { 985 }
984 if (tcp_c->tcp_oob_callback) { 986
985 tcp_c->tcp_oob_callback(tcp_c->tcp_oob_callback_object, public_key, tcp_connections_number, data, length); 987 if (tcp_c->tcp_oob_callback) {
986 } 988 tcp_c->tcp_oob_callback(tcp_c->tcp_oob_callback_object, public_key, tcp_connections_number, data, length);
987 } 989 }
988 990
989 return 0; 991 return 0;
@@ -1086,7 +1088,6 @@ static int add_tcp_relay_instance(TCP_Connections *tcp_c, IP_Port ip_port, const
1086 1088
1087 TCP_con *tcp_con = &tcp_c->tcp_connections[tcp_connections_number]; 1089 TCP_con *tcp_con = &tcp_c->tcp_connections[tcp_connections_number];
1088 1090
1089
1090 tcp_con->connection = new_TCP_connection(ip_port, relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, 1091 tcp_con->connection = new_TCP_connection(ip_port, relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key,
1091 &tcp_c->proxy_info); 1092 &tcp_c->proxy_info);
1092 1093
@@ -1174,25 +1175,25 @@ int add_tcp_relay_connection(TCP_Connections *tcp_c, int connections_number, IP_
1174 1175
1175 if (tcp_connections_number != -1) { 1176 if (tcp_connections_number != -1) {
1176 return add_tcp_number_relay_connection(tcp_c, connections_number, tcp_connections_number); 1177 return add_tcp_number_relay_connection(tcp_c, connections_number, tcp_connections_number);
1177 } else { 1178 }
1178 if (online_tcp_connection_from_conn(con_to) >= RECOMMENDED_FRIEND_TCP_CONNECTIONS) {
1179 return -1;
1180 }
1181 1179
1182 int tcp_connections_number = add_tcp_relay_instance(tcp_c, ip_port, relay_pk); 1180 if (online_tcp_connection_from_conn(con_to) >= RECOMMENDED_FRIEND_TCP_CONNECTIONS) {
1181 return -1;
1182 }
1183 1183
1184 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); 1184 tcp_connections_number = add_tcp_relay_instance(tcp_c, ip_port, relay_pk);
1185 1185
1186 if (!tcp_con) { 1186 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
1187 return -1;
1188 }
1189 1187
1190 if (add_tcp_connection_to_conn(con_to, tcp_connections_number) == -1) { 1188 if (!tcp_con) {
1191 return -1; 1189 return -1;
1192 } 1190 }
1193 1191
1194 return 0; 1192 if (add_tcp_connection_to_conn(con_to, tcp_connections_number) == -1) {
1193 return -1;
1195 } 1194 }
1195
1196 return 0;
1196} 1197}
1197 1198
1198/* return number of online tcp relays tied to the connection on success. 1199/* return number of online tcp relays tied to the connection on success.
@@ -1406,12 +1407,12 @@ static void kill_nonused_tcp(TCP_Connections *tcp_c)
1406 1407
1407 if (num_online <= RECOMMENDED_FRIEND_TCP_CONNECTIONS) { 1408 if (num_online <= RECOMMENDED_FRIEND_TCP_CONNECTIONS) {
1408 return; 1409 return;
1409 } else { 1410 }
1410 unsigned int n = num_online - RECOMMENDED_FRIEND_TCP_CONNECTIONS;
1411 1411
1412 if (n < num_kill) { 1412 unsigned int n = num_online - RECOMMENDED_FRIEND_TCP_CONNECTIONS;
1413 num_kill = n; 1413
1414 } 1414 if (n < num_kill) {
1415 num_kill = n;
1415 } 1416 }
1416 1417
1417 for (i = 0; i < num_kill; ++i) { 1418 for (i = 0; i < num_kill; ++i) {
@@ -1437,5 +1438,3 @@ void kill_tcp_connections(TCP_Connections *tcp_c)
1437 free(tcp_c->connections); 1438 free(tcp_c->connections);
1438 free(tcp_c); 1439 free(tcp_c);
1439} 1440}
1440
1441
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c
index d689e817..81f884d8 100644
--- a/toxcore/TCP_server.c
+++ b/toxcore/TCP_server.c
@@ -325,7 +325,6 @@ static int send_pending_data_nonpriority(TCP_Secure_Connection *con)
325 325
326 con->last_packet_sent += len; 326 con->last_packet_sent += len;
327 return -1; 327 return -1;
328
329} 328}
330 329
331/* return 0 if pending data was sent completely 330/* return 0 if pending data was sent completely
@@ -620,9 +619,9 @@ static int handle_TCP_routing_req(TCP_Server *TCP_server, uint32_t con_id, const
620 if (public_key_cmp(public_key, con->connections[i].public_key) == 0) { 619 if (public_key_cmp(public_key, con->connections[i].public_key) == 0) {
621 if (send_routing_response(con, i + NUM_RESERVED_PORTS, public_key) == -1) { 620 if (send_routing_response(con, i + NUM_RESERVED_PORTS, public_key) == -1) {
622 return -1; 621 return -1;
623 } else {
624 return 0;
625 } 622 }
623
624 return 0;
626 } 625 }
627 } else if (index == (uint32_t)~0) { 626 } else if (index == (uint32_t)~0) {
628 index = i; 627 index = i;
@@ -737,9 +736,9 @@ static int rm_connection_index(TCP_Server *TCP_server, TCP_Secure_Connection *co
737 con->connections[con_number].other_id = 0; 736 con->connections[con_number].other_id = 0;
738 con->connections[con_number].status = 0; 737 con->connections[con_number].status = 0;
739 return 0; 738 return 0;
740 } else {
741 return -1;
742 } 739 }
740
741 return -1;
743} 742}
744 743
745static int handle_onion_recv_1(void *object, IP_Port dest, const uint8_t *data, uint16_t length) 744static int handle_onion_recv_1(void *object, IP_Port dest, const uint8_t *data, uint16_t length)
@@ -830,9 +829,9 @@ static int handle_TCP_packet(TCP_Server *TCP_server, uint32_t con_id, const uint
830 } 829 }
831 830
832 return 0; 831 return 0;
833 } else {
834 return -1;
835 } 832 }
833
834 return -1;
836 } 835 }
837 836
838 case TCP_PACKET_OOB_SEND: { 837 case TCP_PACKET_OOB_SEND: {
@@ -1132,12 +1131,14 @@ static int do_unconfirmed(TCP_Server *TCP_server, uint32_t i)
1132 1131
1133 if (len == 0) { 1132 if (len == 0) {
1134 return -1; 1133 return -1;
1135 } else if (len == -1) { 1134 }
1135
1136 if (len == -1) {
1136 kill_TCP_connection(conn); 1137 kill_TCP_connection(conn);
1137 return -1; 1138 return -1;
1138 } else {
1139 return confirm_TCP_connection(TCP_server, conn, packet, len);
1140 } 1139 }
1140
1141 return confirm_TCP_connection(TCP_server, conn, packet, len);
1141} 1142}
1142 1143
1143static void do_confirmed_recv(TCP_Server *TCP_server, uint32_t i) 1144static void do_confirmed_recv(TCP_Server *TCP_server, uint32_t i)
diff --git a/toxcore/assoc.c b/toxcore/assoc.c
index ced1f65a..9060c3d4 100644
--- a/toxcore/assoc.c
+++ b/toxcore/assoc.c
@@ -272,11 +272,13 @@ static IP_Port *entry_heard_get(Client_entry *entry, const IP_Port *ipp)
272{ 272{
273 if (ipp->ip.family == AF_INET) { 273 if (ipp->ip.family == AF_INET) {
274 return &entry->assoc_heard4; 274 return &entry->assoc_heard4;
275 } else if (ipp->ip.family == AF_INET6) { 275 }
276
277 if (ipp->ip.family == AF_INET6) {
276 return &entry->assoc_heard6; 278 return &entry->assoc_heard6;
277 } else {
278 return NULL;
279 } 279 }
280
281 return NULL;
280} 282}
281 283
282/* store a "heard" entry 284/* store a "heard" entry
@@ -629,13 +631,13 @@ uint8_t Assoc_add_entry(Assoc *assoc, const uint8_t *id, const IPPTs *ippts_send
629 if (!candidates_search(assoc, id, hash, &cnd_entry)) { 631 if (!candidates_search(assoc, id, hash, &cnd_entry)) {
630 if (candidates_create_new(assoc, hash, id, used, ippts_send, ipp_recv)) { 632 if (candidates_create_new(assoc, hash, id, used, ippts_send, ipp_recv)) {
631 return 1; 633 return 1;
632 } else {
633 return 0;
634 } 634 }
635 } else { 635
636 candidates_update_assoc(assoc, cnd_entry, used, ippts_send, ipp_recv); 636 return 0;
637 return 2;
638 } 637 }
638
639 candidates_update_assoc(assoc, cnd_entry, used, ippts_send, ipp_recv);
640 return 2;
639} 641}
640 642
641/*****************************************************************************/ 643/*****************************************************************************/
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c
index 31a7d187..0779fb20 100644
--- a/toxcore/friend_connection.c
+++ b/toxcore/friend_connection.c
@@ -269,9 +269,9 @@ static int tcp_relay_node_callback(void *object, uint32_t number, IP_Port ip_por
269 269
270 if (friend_con->crypt_connection_id != -1) { 270 if (friend_con->crypt_connection_id != -1) {
271 return friend_add_tcp_relay(fr_c, number, ip_port, public_key); 271 return friend_add_tcp_relay(fr_c, number, ip_port, public_key);
272 } else {
273 return add_tcp_relay(fr_c->net_crypto, ip_port, public_key);
274 } 272 }
273
274 return add_tcp_relay(fr_c->net_crypto, ip_port, public_key);
275} 275}
276 276
277static int friend_new_connection(Friend_Connections *fr_c, int friendcon_id); 277static int friend_new_connection(Friend_Connections *fr_c, int friendcon_id);
@@ -411,10 +411,14 @@ static int handle_packet(void *object, int number, uint8_t *data, uint16_t lengt
411 } 411 }
412 412
413 return 0; 413 return 0;
414 } else if (data[0] == PACKET_ID_ALIVE) { 414 }
415
416 if (data[0] == PACKET_ID_ALIVE) {
415 friend_con->ping_lastrecv = unix_time(); 417 friend_con->ping_lastrecv = unix_time();
416 return 0; 418 return 0;
417 } else if (data[0] == PACKET_ID_SHARE_RELAYS) { 419 }
420
421 if (data[0] == PACKET_ID_SHARE_RELAYS) {
418 Node_format nodes[MAX_SHARED_RELAYS]; 422 Node_format nodes[MAX_SHARED_RELAYS];
419 int n; 423 int n;
420 424
@@ -795,16 +799,16 @@ int send_friend_request_packet(Friend_Connections *fr_c, int friendcon_id, uint3
795 if (friend_con->status == FRIENDCONN_STATUS_CONNECTED) { 799 if (friend_con->status == FRIENDCONN_STATUS_CONNECTED) {
796 packet[0] = PACKET_ID_FRIEND_REQUESTS; 800 packet[0] = PACKET_ID_FRIEND_REQUESTS;
797 return write_cryptpacket(fr_c->net_crypto, friend_con->crypt_connection_id, packet, sizeof(packet), 0) != -1; 801 return write_cryptpacket(fr_c->net_crypto, friend_con->crypt_connection_id, packet, sizeof(packet), 0) != -1;
798 } else { 802 }
799 packet[0] = CRYPTO_PACKET_FRIEND_REQ;
800 int num = send_onion_data(fr_c->onion_c, friend_con->onion_friendnum, packet, sizeof(packet));
801 803
802 if (num <= 0) { 804 packet[0] = CRYPTO_PACKET_FRIEND_REQ;
803 return -1; 805 int num = send_onion_data(fr_c->onion_c, friend_con->onion_friendnum, packet, sizeof(packet));
804 }
805 806
806 return num; 807 if (num <= 0) {
808 return -1;
807 } 809 }
810
811 return num;
808} 812}
809 813
810/* Create new friend_connections instance. */ 814/* Create new friend_connections instance. */
@@ -867,7 +871,6 @@ void do_friend_connections(Friend_Connections *fr_c)
867 connect_to_saved_tcp_relays(fr_c, i, (MAX_FRIEND_TCP_CONNECTIONS / 2)); /* Only fill it half up. */ 871 connect_to_saved_tcp_relays(fr_c, i, (MAX_FRIEND_TCP_CONNECTIONS / 2)); /* Only fill it half up. */
868 } 872 }
869 } 873 }
870
871 } else if (friend_con->status == FRIENDCONN_STATUS_CONNECTED) { 874 } else if (friend_con->status == FRIENDCONN_STATUS_CONNECTED) {
872 if (friend_con->ping_lastsent + FRIEND_PING_INTERVAL < temp_time) { 875 if (friend_con->ping_lastsent + FRIEND_PING_INTERVAL < temp_time) {
873 send_ping(fr_c, i); 876 send_ping(fr_c, i);
diff --git a/toxcore/group.c b/toxcore/group.c
index 6d5c6ad4..db114529 100644
--- a/toxcore/group.c
+++ b/toxcore/group.c
@@ -320,7 +320,6 @@ static unsigned int pk_in_closest_peers(Group_c *g, uint8_t *real_pk)
320 if (public_key_cmp(g->closest_peers[i].real_pk, real_pk) == 0) { 320 if (public_key_cmp(g->closest_peers[i].real_pk, real_pk) == 0) {
321 return 1; 321 return 1;
322 } 322 }
323
324 } 323 }
325 324
326 return 0; 325 return 0;
@@ -983,10 +982,10 @@ int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber)
983 982
984 if (send_group_invite_packet(g_c->m, friendnumber, invite, sizeof(invite))) { 983 if (send_group_invite_packet(g_c->m, friendnumber, invite, sizeof(invite))) {
985 return 0; 984 return 0;
986 } else {
987 wipe_group_chat(g_c, groupnumber);
988 return -1;
989 } 985 }
986
987 wipe_group_chat(g_c, groupnumber);
988 return -1;
990} 989}
991 990
992static unsigned int send_peer_query(Group_Chats *g_c, int friendcon_id, uint16_t group_num); 991static unsigned int send_peer_query(Group_Chats *g_c, int friendcon_id, uint16_t group_num);
@@ -1051,10 +1050,10 @@ int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type
1051 1050
1052 send_peer_query(g_c, friendcon_id, other_groupnum); 1051 send_peer_query(g_c, friendcon_id, other_groupnum);
1053 return groupnumber; 1052 return groupnumber;
1054 } else {
1055 g->status = GROUPCHAT_STATUS_NONE;
1056 return -1;
1057 } 1053 }
1054
1055 g->status = GROUPCHAT_STATUS_NONE;
1056 return -1;
1058} 1057}
1059 1058
1060/* Set the callback for group invites. 1059/* Set the callback for group invites.
@@ -1193,9 +1192,9 @@ int group_ping_send(const Group_Chats *g_c, int groupnumber)
1193{ 1192{
1194 if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, 0, 0)) { 1193 if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, 0, 0)) {
1195 return 0; 1194 return 0;
1196 } else {
1197 return -1;
1198 } 1195 }
1196
1197 return -1;
1199} 1198}
1200 1199
1201#define GROUP_MESSAGE_NEW_PEER_ID 16 1200#define GROUP_MESSAGE_NEW_PEER_ID 16
@@ -1216,9 +1215,9 @@ int group_new_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_n
1216 1215
1217 if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_NEW_PEER_ID, packet, sizeof(packet))) { 1216 if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_NEW_PEER_ID, packet, sizeof(packet))) {
1218 return 0; 1217 return 0;
1219 } else {
1220 return -1;
1221 } 1218 }
1219
1220 return -1;
1222} 1221}
1223 1222
1224#define GROUP_MESSAGE_KILL_PEER_ID 17 1223#define GROUP_MESSAGE_KILL_PEER_ID 17
@@ -1237,9 +1236,9 @@ static int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_
1237 1236
1238 if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_KILL_PEER_ID, packet, sizeof(packet))) { 1237 if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_KILL_PEER_ID, packet, sizeof(packet))) {
1239 return 0; 1238 return 0;
1240 } else {
1241 return -1;
1242 } 1239 }
1240
1241 return -1;
1243} 1242}
1244 1243
1245#define GROUP_MESSAGE_NAME_ID 48 1244#define GROUP_MESSAGE_NAME_ID 48
@@ -1256,9 +1255,9 @@ static int group_name_send(const Group_Chats *g_c, int groupnumber, const uint8_
1256 1255
1257 if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_NAME_ID, nick, nick_len)) { 1256 if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_NAME_ID, nick, nick_len)) {
1258 return 0; 1257 return 0;
1259 } else {
1260 return -1;
1261 } 1258 }
1259
1260 return -1;
1262} 1261}
1263 1262
1264#define GROUP_MESSAGE_TITLE_ID 49 1263#define GROUP_MESSAGE_TITLE_ID 49
@@ -1293,9 +1292,9 @@ int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *tit
1293 1292
1294 if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_TITLE_ID, title, title_len)) { 1293 if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_TITLE_ID, title, title_len)) {
1295 return 0; 1294 return 0;
1296 } else {
1297 return -1;
1298 } 1295 }
1296
1297 return -1;
1299} 1298}
1300 1299
1301/* Get group title from groupnumber and put it in title. 1300/* Get group title from groupnumber and put it in title.
@@ -1878,9 +1877,9 @@ int group_message_send(const Group_Chats *g_c, int groupnumber, const uint8_t *m
1878{ 1877{
1879 if (send_message_group(g_c, groupnumber, PACKET_ID_MESSAGE, message, length)) { 1878 if (send_message_group(g_c, groupnumber, PACKET_ID_MESSAGE, message, length)) {
1880 return 0; 1879 return 0;
1881 } else {
1882 return -1;
1883 } 1880 }
1881
1882 return -1;
1884} 1883}
1885 1884
1886/* send a group action 1885/* send a group action
@@ -1891,9 +1890,9 @@ int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *ac
1891{ 1890{
1892 if (send_message_group(g_c, groupnumber, PACKET_ID_ACTION, action, length)) { 1891 if (send_message_group(g_c, groupnumber, PACKET_ID_ACTION, action, length)) {
1893 return 0; 1892 return 0;
1894 } else {
1895 return -1;
1896 } 1893 }
1894
1895 return -1;
1897} 1896}
1898 1897
1899/* High level function to send custom lossy packets. 1898/* High level function to send custom lossy packets.
diff --git a/toxcore/list.c b/toxcore/list.c
index b97727f8..305e563c 100644
--- a/toxcore/list.c
+++ b/toxcore/list.c
@@ -119,18 +119,18 @@ static int resize(BS_LIST *list, uint32_t new_size)
119 119
120 if (!p) { 120 if (!p) {
121 return 0; 121 return 0;
122 } else {
123 list->data = p;
124 } 122 }
125 123
124 list->data = p;
125
126 p = realloc(list->ids, sizeof(int) * new_size); 126 p = realloc(list->ids, sizeof(int) * new_size);
127 127
128 if (!p) { 128 if (!p) {
129 return 0; 129 return 0;
130 } else {
131 list->ids = p;
132 } 130 }
133 131
132 list->ids = p;
133
134 return 1; 134 return 1;
135} 135}
136 136
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 63043494..e2d7e494 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -482,13 +482,17 @@ IP_Port return_ip_port_connection(Net_Crypto *c, int crypt_connection_id)
482 482
483 if (v4 && LAN_ip(conn->ip_portv4.ip) == 0) { 483 if (v4 && LAN_ip(conn->ip_portv4.ip) == 0) {
484 return conn->ip_portv4; 484 return conn->ip_portv4;
485 } else if (v6 && conn->ip_portv6.ip.family == AF_INET6) { 485 }
486
487 if (v6 && conn->ip_portv6.ip.family == AF_INET6) {
486 return conn->ip_portv6; 488 return conn->ip_portv6;
487 } else if (conn->ip_portv4.ip.family == AF_INET) { 489 }
490
491 if (conn->ip_portv4.ip.family == AF_INET) {
488 return conn->ip_portv4; 492 return conn->ip_portv4;
489 } else {
490 return empty;
491 } 493 }
494
495 return empty;
492} 496}
493 497
494/* Sends a packet to the peer using the fastest route. 498/* Sends a packet to the peer using the fastest route.
@@ -519,10 +523,10 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t
519 if ((uint32_t)sendpacket(c->dht->net, ip_port, data, length) == length) { 523 if ((uint32_t)sendpacket(c->dht->net, ip_port, data, length) == length) {
520 pthread_mutex_unlock(&conn->mutex); 524 pthread_mutex_unlock(&conn->mutex);
521 return 0; 525 return 0;
522 } else {
523 pthread_mutex_unlock(&conn->mutex);
524 return -1;
525 } 526 }
527
528 pthread_mutex_unlock(&conn->mutex);
529 return -1;
526 } 530 }
527 531
528 //TODO: a better way of sending packets directly to confirm the others ip. 532 //TODO: a better way of sending packets directly to confirm the others ip.
@@ -775,7 +779,6 @@ static int generate_request_packet(uint8_t *data, uint16_t length, const Packets
775 if (length <= cur_len) { 779 if (length <= cur_len) {
776 return cur_len; 780 return cur_len;
777 } 781 }
778
779 } else if (n == 255) { 782 } else if (n == 255) {
780 data[cur_len] = 0; 783 data[cur_len] = 0;
781 n = 0; 784 n = 0;
@@ -1135,7 +1138,9 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32
1135 1138
1136 if (ret == -1) { 1139 if (ret == -1) {
1137 return -1; 1140 return -1;
1138 } else if (ret == 0) { 1141 }
1142
1143 if (ret == 0) {
1139 continue; 1144 continue;
1140 } 1145 }
1141 1146
@@ -1391,10 +1396,10 @@ static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, con
1391 1396
1392 if (requested == -1) { 1397 if (requested == -1) {
1393 return -1; 1398 return -1;
1394 } else {
1395 //TODO?
1396 } 1399 }
1397 1400
1401 // else { /* TODO? */ }
1402
1398 set_buffer_end(&conn->recv_array, num); 1403 set_buffer_end(&conn->recv_array, num);
1399 } else if (real_data[0] >= CRYPTO_RESERVED_PACKETS && real_data[0] < PACKET_ID_LOSSY_RANGE_START) { 1404 } else if (real_data[0] >= CRYPTO_RESERVED_PACKETS && real_data[0] < PACKET_ID_LOSSY_RANGE_START) {
1400 Packet_Data dt; 1405 Packet_Data dt;
@@ -1405,7 +1410,6 @@ static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, con
1405 return -1; 1410 return -1;
1406 } 1411 }
1407 1412
1408
1409 while (1) { 1413 while (1) {
1410 pthread_mutex_lock(&conn->mutex); 1414 pthread_mutex_lock(&conn->mutex);
1411 int ret = read_data_beg_buffer(&conn->recv_array, &dt); 1415 int ret = read_data_beg_buffer(&conn->recv_array, &dt);
@@ -1439,7 +1443,6 @@ static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, con
1439 conn->connection_lossy_data_callback(conn->connection_lossy_data_callback_object, 1443 conn->connection_lossy_data_callback(conn->connection_lossy_data_callback_object,
1440 conn->connection_lossy_data_callback_id, real_data, real_length); 1444 conn->connection_lossy_data_callback_id, real_data, real_length);
1441 } 1445 }
1442
1443 } else { 1446 } else {
1444 return -1; 1447 return -1;
1445 } 1448 }
@@ -1525,7 +1528,6 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons
1525 conn->dht_pk_callback(conn->dht_pk_callback_object, conn->dht_pk_callback_number, dht_public_key); 1528 conn->dht_pk_callback(conn->dht_pk_callback_object, conn->dht_pk_callback_number, dht_public_key);
1526 } 1529 }
1527 } 1530 }
1528
1529 } else { 1531 } else {
1530 return -1; 1532 return -1;
1531 } 1533 }
@@ -1536,11 +1538,9 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons
1536 case NET_PACKET_CRYPTO_DATA: { 1538 case NET_PACKET_CRYPTO_DATA: {
1537 if (conn->status == CRYPTO_CONN_NOT_CONFIRMED || conn->status == CRYPTO_CONN_ESTABLISHED) { 1539 if (conn->status == CRYPTO_CONN_NOT_CONFIRMED || conn->status == CRYPTO_CONN_ESTABLISHED) {
1538 return handle_data_packet_helper(c, crypt_connection_id, packet, length, udp, userdata); 1540 return handle_data_packet_helper(c, crypt_connection_id, packet, length, udp, userdata);
1539 } else {
1540 return -1;
1541 } 1541 }
1542 1542
1543 return 0; 1543 return -1;
1544 } 1544 }
1545 1545
1546 default: { 1546 default: {
@@ -1698,7 +1698,9 @@ static int crypto_connection_add_source(Net_Crypto *c, int crypt_connection_id,
1698 } 1698 }
1699 1699
1700 return 0; 1700 return 0;
1701 } else if (source.ip.family == TCP_FAMILY) { 1701 }
1702
1703 if (source.ip.family == TCP_FAMILY) {
1702 if (add_tcp_number_relay_connection(c->tcp_c, conn->connection_number_tcp, source.ip.ip6.uint32[0]) == 0) { 1704 if (add_tcp_number_relay_connection(c->tcp_c, conn->connection_number_tcp, source.ip.ip6.uint32[0]) == 0) {
1703 return 1; 1705 return 1;
1704 } 1706 }
@@ -1974,7 +1976,9 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, unsigned in
1974 1976
1975 if (data[0] == NET_PACKET_COOKIE_REQUEST) { 1977 if (data[0] == NET_PACKET_COOKIE_REQUEST) {
1976 return tcp_oob_handle_cookie_request(c, tcp_connections_number, public_key, data, length); 1978 return tcp_oob_handle_cookie_request(c, tcp_connections_number, public_key, data, length);
1977 } else if (data[0] == NET_PACKET_CRYPTO_HS) { 1979 }
1980
1981 if (data[0] == NET_PACKET_CRYPTO_HS) {
1978 IP_Port source; 1982 IP_Port source;
1979 source.port = 0; 1983 source.port = 0;
1980 source.ip.family = TCP_FAMILY; 1984 source.ip.family = TCP_FAMILY;
@@ -1985,9 +1989,9 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, unsigned in
1985 } 1989 }
1986 1990
1987 return 0; 1991 return 0;
1988 } else {
1989 return -1;
1990 } 1992 }
1993
1994 return -1;
1991} 1995}
1992 1996
1993/* Add a tcp relay, associating it to a crypt_connection_id. 1997/* Add a tcp relay, associating it to a crypt_connection_id.
@@ -2305,7 +2309,6 @@ static void send_crypto_packets(Net_Crypto *c)
2305 if (send_request_packet(c, i) == 0) { 2309 if (send_request_packet(c, i) == 0) {
2306 conn->last_request_packet_sent = temp_time; 2310 conn->last_request_packet_sent = temp_time;
2307 } 2311 }
2308
2309 } 2312 }
2310 2313
2311 if (conn->status == CRYPTO_CONN_ESTABLISHED) { 2314 if (conn->status == CRYPTO_CONN_ESTABLISHED) {
@@ -2433,7 +2436,6 @@ static void send_crypto_packets(Net_Crypto *c)
2433 conn->packet_send_rate_requested = conn->packet_send_rate; 2436 conn->packet_send_rate_requested = conn->packet_send_rate;
2434 } 2437 }
2435 } 2438 }
2436
2437 } 2439 }
2438 2440
2439 if (conn->last_packets_left_set == 0 || conn->last_packets_left_requested_set == 0) { 2441 if (conn->last_packets_left_set == 0 || conn->last_packets_left_requested_set == 0) {
@@ -2541,9 +2543,9 @@ uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connecti
2541 2543
2542 if (conn->packets_left < max_packets) { 2544 if (conn->packets_left < max_packets) {
2543 return conn->packets_left; 2545 return conn->packets_left;
2544 } else {
2545 return max_packets;
2546 } 2546 }
2547
2548 return max_packets;
2547} 2549}
2548 2550
2549/* Sends a lossless cryptopacket. 2551/* Sends a lossless cryptopacket.
@@ -2617,9 +2619,9 @@ int cryptpacket_received(Net_Crypto *c, int crypt_connection_id, uint32_t packet
2617 2619
2618 if (num < num1) { 2620 if (num < num1) {
2619 return 0; 2621 return 0;
2620 } else {
2621 return -1;
2622 } 2622 }
2623
2624 return -1;
2623} 2625}
2624 2626
2625/* return -1 on failure. 2627/* return -1 on failure.
diff --git a/toxcore/network.c b/toxcore/network.c
index fb491f4b..05867adc 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -753,11 +753,13 @@ int ip_equal(const IP *a, const IP *b)
753 if (a->family == b->family) { 753 if (a->family == b->family) {
754 if (a->family == AF_INET) { 754 if (a->family == AF_INET) {
755 return (a->ip4.in_addr.s_addr == b->ip4.in_addr.s_addr); 755 return (a->ip4.in_addr.s_addr == b->ip4.in_addr.s_addr);
756 } else if (a->family == AF_INET6) { 756 }
757
758 if (a->family == AF_INET6) {
757 return a->ip6.uint64[0] == b->ip6.uint64[0] && a->ip6.uint64[1] == b->ip6.uint64[1]; 759 return a->ip6.uint64[0] == b->ip6.uint64[0] && a->ip6.uint64[1] == b->ip6.uint64[1];
758 } else {
759 return 0;
760 } 760 }
761
762 return 0;
761 } 763 }
762 764
763 /* different family: check on the IPv6 one if it is the IPv4 one embedded */ 765 /* different family: check on the IPv6 one if it is the IPv4 one embedded */
@@ -921,7 +923,9 @@ int ip_parse_addr(const IP *ip, char *address, size_t length)
921 if (ip->family == AF_INET) { 923 if (ip->family == AF_INET) {
922 struct in_addr *addr = (struct in_addr *)&ip->ip4; 924 struct in_addr *addr = (struct in_addr *)&ip->ip4;
923 return inet_ntop(ip->family, addr, address, length) != NULL; 925 return inet_ntop(ip->family, addr, address, length) != NULL;
924 } else if (ip->family == AF_INET6) { 926 }
927
928 if (ip->family == AF_INET6) {
925 struct in6_addr *addr = (struct in6_addr *)&ip->ip6; 929 struct in6_addr *addr = (struct in6_addr *)&ip->ip6;
926 return inet_ntop(ip->family, addr, address, length) != NULL; 930 return inet_ntop(ip->family, addr, address, length) != NULL;
927 } 931 }
diff --git a/toxcore/onion.c b/toxcore/onion.c
index d3512780..0f0abf26 100644
--- a/toxcore/onion.c
+++ b/toxcore/onion.c
@@ -77,10 +77,10 @@ static int ip_unpack(IP *target, const uint8_t *data, unsigned int data_size, _B
77 77
78 if (!disable_family_check) { 78 if (!disable_family_check) {
79 return to_host_family(target); 79 return to_host_family(target);
80 } else {
81 to_host_family(target);
82 return 0;
83 } 80 }
81
82 to_host_family(target);
83 return 0;
84} 84}
85 85
86static void ipport_pack(uint8_t *data, const IP_Port *source) 86static void ipport_pack(uint8_t *data, const IP_Port *source)
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index 9d573240..851a0ee1 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -341,7 +341,9 @@ static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, const Onion_Pa
341 } 341 }
342 342
343 return 0; 343 return 0;
344 } else if (path->ip_port1.ip.family == TCP_FAMILY) { 344 }
345
346 if (path->ip_port1.ip.family == TCP_FAMILY) {
345 uint8_t packet[ONION_MAX_PACKET_SIZE]; 347 uint8_t packet[ONION_MAX_PACKET_SIZE];
346 int len = create_onion_packet_tcp(packet, sizeof(packet), path, dest, data, length); 348 int len = create_onion_packet_tcp(packet, sizeof(packet), path, dest, data, length);
347 349
@@ -350,9 +352,9 @@ static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, const Onion_Pa
350 } 352 }
351 353
352 return send_tcp_onion_request(onion_c->c, path->ip_port1.ip.ip4.uint32, packet, len); 354 return send_tcp_onion_request(onion_c->c, path->ip_port1.ip.ip4.uint32, packet, len);
353 } else {
354 return -1;
355 } 355 }
356
357 return -1;
356} 358}
357 359
358/* Creates a sendback for use in an announce request. 360/* Creates a sendback for use in an announce request.
@@ -453,7 +455,6 @@ static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, IP_
453 if (num == 0) { 455 if (num == 0) {
454 len = create_announce_request(request, sizeof(request), dest_pubkey, onion_c->c->self_public_key, 456 len = create_announce_request(request, sizeof(request), dest_pubkey, onion_c->c->self_public_key,
455 onion_c->c->self_secret_key, ping_id, onion_c->c->self_public_key, onion_c->temp_public_key, sendback); 457 onion_c->c->self_secret_key, ping_id, onion_c->c->self_public_key, onion_c->temp_public_key, sendback);
456
457 } else { 458 } else {
458 len = create_announce_request(request, sizeof(request), dest_pubkey, onion_c->friends_list[num - 1].temp_public_key, 459 len = create_announce_request(request, sizeof(request), dest_pubkey, onion_c->friends_list[num - 1].temp_public_key,
459 onion_c->friends_list[num - 1].temp_secret_key, ping_id, onion_c->friends_list[num - 1].real_public_key, zero_ping_id, 460 onion_c->friends_list[num - 1].temp_secret_key, ping_id, onion_c->friends_list[num - 1].real_public_key, zero_ping_id,
@@ -520,7 +521,6 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t
520 if (is_stored == 1 && public_key_cmp(pingid_or_key, onion_c->temp_public_key) != 0) { 521 if (is_stored == 1 && public_key_cmp(pingid_or_key, onion_c->temp_public_key) != 0) {
521 is_stored = 0; 522 is_stored = 0;
522 } 523 }
523
524 } else { 524 } else {
525 if (is_stored >= 2) { 525 if (is_stored >= 2) {
526 return -1; 526 return -1;
@@ -841,7 +841,9 @@ static int handle_tcp_onion(void *object, const uint8_t *data, uint16_t length,
841 841
842 if (data[0] == NET_PACKET_ANNOUNCE_RESPONSE) { 842 if (data[0] == NET_PACKET_ANNOUNCE_RESPONSE) {
843 return handle_announce_response(object, ip_port, data, length, userdata); 843 return handle_announce_response(object, ip_port, data, length, userdata);
844 } else if (data[0] == NET_PACKET_ONION_DATA_RESPONSE) { 844 }
845
846 if (data[0] == NET_PACKET_ONION_DATA_RESPONSE) {
845 return handle_data_response(object, ip_port, data, length, userdata); 847 return handle_data_response(object, ip_port, data, length, userdata);
846 } 848 }
847 849
@@ -1418,7 +1420,6 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
1418 onion_c->friends_list[friendnum].last_dht_pk_dht_sent = unix_time(); 1420 onion_c->friends_list[friendnum].last_dht_pk_dht_sent = unix_time();
1419 } 1421 }
1420 } 1422 }
1421
1422 } 1423 }
1423} 1424}
1424 1425
@@ -1541,9 +1542,9 @@ unsigned int onion_connection_status(const Onion_Client *onion_c)
1541 if (onion_c->onion_connected >= ONION_CONNECTION_SECONDS) { 1542 if (onion_c->onion_connected >= ONION_CONNECTION_SECONDS) {
1542 if (onion_c->UDP_connected) { 1543 if (onion_c->UDP_connected) {
1543 return 2; 1544 return 2;
1544 } else {
1545 return 1;
1546 } 1545 }
1546
1547 return 1;
1547 } 1548 }
1548 1549
1549 return 0; 1550 return 0;
@@ -1566,7 +1567,6 @@ void do_onion_client(Onion_Client *onion_c)
1566 if (onion_c->onion_connected < ONION_CONNECTION_SECONDS * 2) { 1567 if (onion_c->onion_connected < ONION_CONNECTION_SECONDS * 2) {
1567 ++onion_c->onion_connected; 1568 ++onion_c->onion_connected;
1568 } 1569 }
1569
1570 } else { 1570 } else {
1571 populate_path_nodes_tcp(onion_c); 1571 populate_path_nodes_tcp(onion_c);
1572 1572
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 94cb7261..40bfaf70 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -379,10 +379,10 @@ bool tox_bootstrap(Tox *tox, const char *address, uint16_t port, const uint8_t *
379 if (count) { 379 if (count) {
380 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_OK); 380 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_OK);
381 return 1; 381 return 1;
382 } else {
383 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_BAD_HOST);
384 return 0;
385 } 382 }
383
384 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_BAD_HOST);
385 return 0;
386} 386}
387 387
388bool tox_add_tcp_relay(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key, 388bool tox_add_tcp_relay(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key,
@@ -436,10 +436,10 @@ bool tox_add_tcp_relay(Tox *tox, const char *address, uint16_t port, const uint8
436 if (count) { 436 if (count) {
437 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_OK); 437 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_OK);
438 return 1; 438 return 1;
439 } else {
440 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_BAD_HOST);
441 return 0;
442 } 439 }
440
441 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_BAD_HOST);
442 return 0;
443} 443}
444 444
445TOX_CONNECTION tox_self_get_connection_status(const Tox *tox) 445TOX_CONNECTION tox_self_get_connection_status(const Tox *tox)
@@ -450,11 +450,13 @@ TOX_CONNECTION tox_self_get_connection_status(const Tox *tox)
450 450
451 if (ret == 2) { 451 if (ret == 2) {
452 return TOX_CONNECTION_UDP; 452 return TOX_CONNECTION_UDP;
453 } else if (ret == 1) { 453 }
454
455 if (ret == 1) {
454 return TOX_CONNECTION_TCP; 456 return TOX_CONNECTION_TCP;
455 } else {
456 return TOX_CONNECTION_NONE;
457 } 457 }
458
459 return TOX_CONNECTION_NONE;
458} 460}
459 461
460 462
@@ -529,10 +531,10 @@ bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, TOX_ERR_SET
529 send_name_all_groups(m->group_chat_object); 531 send_name_all_groups(m->group_chat_object);
530 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_OK); 532 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_OK);
531 return 1; 533 return 1;
532 } else {
533 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_TOO_LONG);
534 return 0;
535 } 534 }
535
536 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_TOO_LONG);
537 return 0;
536} 538}
537 539
538size_t tox_self_get_name_size(const Tox *tox) 540size_t tox_self_get_name_size(const Tox *tox)
@@ -561,10 +563,10 @@ bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t
561 if (m_set_statusmessage(m, status_message, length) == 0) { 563 if (m_set_statusmessage(m, status_message, length) == 0) {
562 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_OK); 564 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_OK);
563 return 1; 565 return 1;
564 } else {
565 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_TOO_LONG);
566 return 0;
567 } 566 }
567
568 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_TOO_LONG);
569 return 0;
568} 570}
569 571
570size_t tox_self_get_status_message_size(const Tox *tox) 572size_t tox_self_get_status_message_size(const Tox *tox)
@@ -623,7 +625,6 @@ static void set_friend_error(int32_t ret, TOX_ERR_FRIEND_ADD *error)
623 case FAERR_NOMEM: 625 case FAERR_NOMEM:
624 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_MALLOC); 626 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_MALLOC);
625 break; 627 break;
626
627 } 628 }
628} 629}
629 630
@@ -1095,7 +1096,9 @@ bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_
1095 if (ret == 0) { 1096 if (ret == 0) {
1096 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_OK); 1097 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_OK);
1097 return 1; 1098 return 1;
1098 } else if (ret == -1) { 1099 }
1100
1101 if (ret == -1) {
1099 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_FRIEND_NOT_FOUND); 1102 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_FRIEND_NOT_FOUND);
1100 } else { 1103 } else {
1101 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_NOT_FOUND); 1104 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_NOT_FOUND);
@@ -1268,9 +1271,9 @@ bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_
1268 1271
1269 if (ret == 0) { 1272 if (ret == 0) {
1270 return 1; 1273 return 1;
1271 } else {
1272 return 0;
1273 } 1274 }
1275
1276 return 0;
1274} 1277}
1275 1278
1276void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback, void *user_data) 1279void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback, void *user_data)
@@ -1300,9 +1303,9 @@ bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uin
1300 1303
1301 if (ret == 0) { 1304 if (ret == 0) {
1302 return 1; 1305 return 1;
1303 } else {
1304 return 0;
1305 } 1306 }
1307
1308 return 0;
1306} 1309}
1307 1310
1308void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback, void *user_data) 1311void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback, void *user_data)
@@ -1340,8 +1343,8 @@ uint16_t tox_self_get_tcp_port(const Tox *tox, TOX_ERR_GET_PORT *error)
1340 if (m->tcp_server) { 1343 if (m->tcp_server) {
1341 SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_OK); 1344 SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_OK);
1342 return m->options.tcp_server_port; 1345 return m->options.tcp_server_port;
1343 } else {
1344 SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_NOT_BOUND);
1345 return 0;
1346 } 1346 }
1347
1348 SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_NOT_BOUND);
1349 return 0;
1347} 1350}
diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c
index bcbe9518..69e5c0f3 100644
--- a/toxencryptsave/toxencryptsave.c
+++ b/toxencryptsave/toxencryptsave.c
@@ -315,7 +315,7 @@ bool tox_is_data_encrypted(const uint8_t *data)
315{ 315{
316 if (memcmp(data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) == 0) { 316 if (memcmp(data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) == 0) {
317 return 1; 317 return 1;
318 } else {
319 return 0;
320 } 318 }
319
320 return 0;
321} 321}