From 192f355121454f60f247cd00258b2705b4c22198 Mon Sep 17 00:00:00 2001 From: Quentin Date: Tue, 8 Oct 2019 10:54:27 +0200 Subject: [PATCH] Fix some errors --- src/algo_lightning.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/algo_lightning.c b/src/algo_lightning.c index 898af49..dc5930b 100644 --- a/src/algo_lightning.c +++ b/src/algo_lightning.c @@ -71,6 +71,9 @@ void algo_lightning_init(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx, str } } + for (int i = 0; i < lightc->sent_past_links; i++) + lightc->prev_links[i] = UINT8_MAX; + union abstract_packet m; lightc->monit_pkt_size = sizeof(m.fmt.headers) + sizeof(m.fmt.content.link_monitoring_lightning) + sizeof(uint8_t) * (lightc->sent_past_links - 1); timespec_set_unit (&lightc->window, window, MILISEC); @@ -155,6 +158,8 @@ void algo_lightning_update_stats (struct light_ctx *lightc, int64_t *stats) { for (int i = 0; i < HISTORIC_SIZE; i++) { if (timespec_lt(&lightc->historic[i].finished_at, ¬_before)) continue; + uint8_t l = lightc->historic[i].link_id; + if (l >= lightc->total_links) continue; int64_t delta = 0; switch (lightc->historic[i].state) { case IN_ORDER: @@ -168,7 +173,7 @@ void algo_lightning_update_stats (struct light_ctx *lightc, int64_t *stats) { delta = timespec_get_unit (&temp_time, MILISEC); break; } - uint8_t l = lightc->historic[i].link_id; + stats[l] = delta > stats[l] ? delta : stats[l]; } } @@ -191,6 +196,7 @@ int send_message(struct evt_core_ctx* ctx, struct buffer_packet* bp) { struct buffer_packet* bp_dup = dup_buffer_tow (&app_ctx->br, bp, to_fdinfo); + lightc->pkt_sent_id++; union abstract_packet monit = { .fmt.headers.cmd = CMD_LINK_MONITORING_LIGHTNING, .fmt.headers.size = lightc->monit_pkt_size, @@ -204,7 +210,6 @@ int send_message(struct evt_core_ctx* ctx, struct buffer_packet* bp) { } lightc->prev_links[lightc->pkt_sent_id % MAX_LINKS] = lightc->selected_link; - lightc->pkt_sent_id++; if (ctx->verbose > 1) { dump_buffer_packet(bp_dup); @@ -239,7 +244,6 @@ int algo_lightning_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo* int64_t cdelta = stats[lightc->selected_link]; // OK link - printf("cdelta=%ld\n", cdelta); if (cdelta < lightc->max_ooo) { send_message (ctx, bp); break;