diff options
Diffstat (limited to 'toxav/bwcontroller.c')
-rw-r--r-- | toxav/bwcontroller.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c index 2af8eee8..a9018162 100644 --- a/toxav/bwcontroller.c +++ b/toxav/bwcontroller.c | |||
@@ -50,6 +50,7 @@ struct BWController_s { | |||
50 | BWCRcvPkt rcvpkt; /* To calculate average received packet (this means split parts, not the full message!) */ | 50 | BWCRcvPkt rcvpkt; /* To calculate average received packet (this means split parts, not the full message!) */ |
51 | 51 | ||
52 | uint32_t packet_loss_counted_cycles; | 52 | uint32_t packet_loss_counted_cycles; |
53 | Mono_Time *bwc_mono_time; | ||
53 | }; | 54 | }; |
54 | 55 | ||
55 | struct BWCMessage { | 56 | struct BWCMessage { |
@@ -60,7 +61,8 @@ struct BWCMessage { | |||
60 | static int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object); | 61 | static int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object); |
61 | static void send_update(BWController *bwc); | 62 | static void send_update(BWController *bwc); |
62 | 63 | ||
63 | BWController *bwc_new(Messenger *m, uint32_t friendnumber, m_cb *mcb, void *mcb_user_data) | 64 | BWController *bwc_new(Messenger *m, uint32_t friendnumber, m_cb *mcb, void *mcb_user_data, |
65 | Mono_Time *bwc_mono_time) | ||
64 | { | 66 | { |
65 | BWController *retu = (BWController *)calloc(sizeof(struct BWController_s), 1); | 67 | BWController *retu = (BWController *)calloc(sizeof(struct BWController_s), 1); |
66 | LOGGER_DEBUG(m->log, "Creating bandwidth controller"); | 68 | LOGGER_DEBUG(m->log, "Creating bandwidth controller"); |
@@ -68,7 +70,8 @@ BWController *bwc_new(Messenger *m, uint32_t friendnumber, m_cb *mcb, void *mcb_ | |||
68 | retu->mcb_user_data = mcb_user_data; | 70 | retu->mcb_user_data = mcb_user_data; |
69 | retu->m = m; | 71 | retu->m = m; |
70 | retu->friend_number = friendnumber; | 72 | retu->friend_number = friendnumber; |
71 | uint64_t now = current_time_monotonic(m->mono_time); | 73 | retu->bwc_mono_time = bwc_mono_time; |
74 | uint64_t now = current_time_monotonic(bwc_mono_time); | ||
72 | retu->cycle.last_sent_timestamp = now; | 75 | retu->cycle.last_sent_timestamp = now; |
73 | retu->cycle.last_refresh_timestamp = now; | 76 | retu->cycle.last_refresh_timestamp = now; |
74 | retu->rcvpkt.rb = rb_new(BWC_AVG_PKT_COUNT); | 77 | retu->rcvpkt.rb = rb_new(BWC_AVG_PKT_COUNT); |
@@ -123,7 +126,7 @@ void bwc_add_recv(BWController *bwc, uint32_t recv_bytes) | |||
123 | static void send_update(BWController *bwc) | 126 | static void send_update(BWController *bwc) |
124 | { | 127 | { |
125 | if (bwc->packet_loss_counted_cycles > BWC_AVG_LOSS_OVER_CYCLES_COUNT && | 128 | if (bwc->packet_loss_counted_cycles > BWC_AVG_LOSS_OVER_CYCLES_COUNT && |
126 | current_time_monotonic(bwc->m->mono_time) - bwc->cycle.last_sent_timestamp > BWC_SEND_INTERVAL_MS) { | 129 | current_time_monotonic(bwc->bwc_mono_time) - bwc->cycle.last_sent_timestamp > BWC_SEND_INTERVAL_MS) { |
127 | bwc->packet_loss_counted_cycles = 0; | 130 | bwc->packet_loss_counted_cycles = 0; |
128 | 131 | ||
129 | if (bwc->cycle.lost) { | 132 | if (bwc->cycle.lost) { |
@@ -148,7 +151,7 @@ static void send_update(BWController *bwc) | |||
148 | } | 151 | } |
149 | } | 152 | } |
150 | 153 | ||
151 | bwc->cycle.last_sent_timestamp = current_time_monotonic(bwc->m->mono_time); | 154 | bwc->cycle.last_sent_timestamp = current_time_monotonic(bwc->bwc_mono_time); |
152 | bwc->cycle.lost = 0; | 155 | bwc->cycle.lost = 0; |
153 | bwc->cycle.recv = 0; | 156 | bwc->cycle.recv = 0; |
154 | } | 157 | } |
@@ -159,12 +162,12 @@ static int on_update(BWController *bwc, const struct BWCMessage *msg) | |||
159 | LOGGER_DEBUG(bwc->m->log, "%p Got update from peer", (void *)bwc); | 162 | LOGGER_DEBUG(bwc->m->log, "%p Got update from peer", (void *)bwc); |
160 | 163 | ||
161 | /* Peers sent update too soon */ | 164 | /* Peers sent update too soon */ |
162 | if (bwc->cycle.last_recv_timestamp + BWC_SEND_INTERVAL_MS > current_time_monotonic(bwc->m->mono_time)) { | 165 | if (bwc->cycle.last_recv_timestamp + BWC_SEND_INTERVAL_MS > current_time_monotonic(bwc->bwc_mono_time)) { |
163 | LOGGER_INFO(bwc->m->log, "%p Rejecting extra update", (void *)bwc); | 166 | LOGGER_INFO(bwc->m->log, "%p Rejecting extra update", (void *)bwc); |
164 | return -1; | 167 | return -1; |
165 | } | 168 | } |
166 | 169 | ||
167 | bwc->cycle.last_recv_timestamp = current_time_monotonic(bwc->m->mono_time); | 170 | bwc->cycle.last_recv_timestamp = current_time_monotonic(bwc->bwc_mono_time); |
168 | 171 | ||
169 | const uint32_t recv = msg->recv; | 172 | const uint32_t recv = msg->recv; |
170 | const uint32_t lost = msg->lost; | 173 | const uint32_t lost = msg->lost; |