diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Lossless_UDP.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/toxcore/Lossless_UDP.c b/toxcore/Lossless_UDP.c index d6f01349..63f3bd16 100644 --- a/toxcore/Lossless_UDP.c +++ b/toxcore/Lossless_UDP.c | |||
@@ -713,15 +713,13 @@ Lossless_UDP *new_lossless_udp(Networking_Core *net) | |||
713 | */ | 713 | */ |
714 | static void do_new(Lossless_UDP *ludp) | 714 | static void do_new(Lossless_UDP *ludp) |
715 | { | 715 | { |
716 | uint32_t i; | ||
717 | uint64_t temp_time = current_time(); | 716 | uint64_t temp_time = current_time(); |
718 | 717 | ||
719 | tox_array_for_each(&ludp->connections, Connection, tmp) { | 718 | tox_array_for_each(&ludp->connections, Connection, tmp) { |
720 | if (tmp->status == 1) | 719 | if (tmp->status == 1 && (tmp->last_sent + (1000000UL / tmp->SYNC_rate)) <= temp_time) { |
721 | if ((tmp->last_sent + (1000000UL / tmp->SYNC_rate)) <= temp_time) { | 720 | send_handshake(ludp, tmp->ip_port, tmp->handshake_id1, 0); |
722 | send_handshake(ludp, tmp->ip_port, tmp->handshake_id1, 0); | 721 | tmp->last_sent = temp_time; |
723 | tmp->last_sent = temp_time; | 722 | } |
724 | } | ||
725 | 723 | ||
726 | /* kill all timed out connections */ | 724 | /* kill all timed out connections */ |
727 | if (tmp->status > 0 && (tmp->last_recvSYNC + tmp->timeout * 1000000UL) < temp_time && tmp->status != 4) { | 725 | if (tmp->status > 0 && (tmp->last_recvSYNC + tmp->timeout * 1000000UL) < temp_time && tmp->status != 4) { |
@@ -730,19 +728,18 @@ static void do_new(Lossless_UDP *ludp) | |||
730 | } | 728 | } |
731 | 729 | ||
732 | if (tmp->status > 0 && tmp->killat < temp_time) | 730 | if (tmp->status > 0 && tmp->killat < temp_time) |
733 | kill_connection(ludp, i); | 731 | kill_connection(ludp, tmp_i); |
734 | } | 732 | } |
735 | } | 733 | } |
736 | 734 | ||
737 | static void do_SYNC(Lossless_UDP *ludp) | 735 | static void do_SYNC(Lossless_UDP *ludp) |
738 | { | 736 | { |
739 | uint32_t i; | ||
740 | uint64_t temp_time = current_time(); | 737 | uint64_t temp_time = current_time(); |
741 | 738 | ||
742 | tox_array_for_each(&ludp->connections, Connection, tmp) { | 739 | tox_array_for_each(&ludp->connections, Connection, tmp) { |
743 | if (tmp->status == 2 || tmp->status == 3) | 740 | if (tmp->status == 2 || tmp->status == 3) |
744 | if ((tmp->last_SYNC + (1000000UL / tmp->SYNC_rate)) <= temp_time) { | 741 | if ((tmp->last_SYNC + (1000000UL / tmp->SYNC_rate)) <= temp_time) { |
745 | send_SYNC(ludp, i); | 742 | send_SYNC(ludp, tmp_i); |
746 | tmp->last_SYNC = temp_time; | 743 | tmp->last_SYNC = temp_time; |
747 | } | 744 | } |
748 | } | 745 | } |
@@ -750,16 +747,15 @@ static void do_SYNC(Lossless_UDP *ludp) | |||
750 | 747 | ||
751 | static void do_data(Lossless_UDP *ludp) | 748 | static void do_data(Lossless_UDP *ludp) |
752 | { | 749 | { |
753 | uint32_t i; | ||
754 | uint64_t j; | 750 | uint64_t j; |
755 | uint64_t temp_time = current_time(); | 751 | uint64_t temp_time = current_time(); |
756 | 752 | ||
757 | tox_array_for_each(&ludp->connections, Connection, tmp) { | 753 | tox_array_for_each(&ludp->connections, Connection, tmp) { |
758 | if (tmp->status == 3 && sendqueue(ludp, i) != 0 && | 754 | if (tmp->status == 3 && sendqueue(ludp, tmp_i) != 0 && |
759 | (tmp->last_sent + (1000000UL / tmp->data_rate)) <= temp_time) | 755 | (tmp->last_sent + (1000000UL / tmp->data_rate)) <= temp_time) |
760 | { | 756 | { |
761 | for (j = tmp->last_sent; j < temp_time; j += (1000000UL / tmp->data_rate)) | 757 | for (j = tmp->last_sent; j < temp_time; j += (1000000UL / tmp->data_rate)) |
762 | send_DATA(ludp, i); | 758 | send_DATA(ludp, tmp_i); |
763 | 759 | ||
764 | tmp->last_sent = temp_time; | 760 | tmp->last_sent = temp_time; |
765 | 761 | ||
@@ -776,7 +772,6 @@ static void do_data(Lossless_UDP *ludp) | |||
776 | */ | 772 | */ |
777 | static void adjust_rates(Lossless_UDP *ludp) | 773 | static void adjust_rates(Lossless_UDP *ludp) |
778 | { | 774 | { |
779 | uint32_t i; | ||
780 | uint64_t temp_time = current_time(); | 775 | uint64_t temp_time = current_time(); |
781 | 776 | ||
782 | tox_array_for_each(&ludp->connections, Connection, tmp) { | 777 | tox_array_for_each(&ludp->connections, Connection, tmp) { |
@@ -784,7 +779,7 @@ static void adjust_rates(Lossless_UDP *ludp) | |||
784 | tmp->SYNC_rate = MAX_SYNC_RATE; | 779 | tmp->SYNC_rate = MAX_SYNC_RATE; |
785 | 780 | ||
786 | if (tmp->status == 3) { | 781 | if (tmp->status == 3) { |
787 | if (sendqueue(ludp, i) != 0) { | 782 | if (sendqueue(ludp, tmp_i) != 0) { |
788 | tmp->data_rate = (BUFFER_PACKET_NUM - tmp->num_req_paquets) * MAX_SYNC_RATE; | 783 | tmp->data_rate = (BUFFER_PACKET_NUM - tmp->num_req_paquets) * MAX_SYNC_RATE; |
789 | tmp->SYNC_rate = MAX_SYNC_RATE; | 784 | tmp->SYNC_rate = MAX_SYNC_RATE; |
790 | } else if (tmp->last_recvdata + 1000000UL > temp_time) | 785 | } else if (tmp->last_recvdata + 1000000UL > temp_time) |