Some fixes

This commit is contained in:
Quentin 2019-10-08 10:10:59 +02:00
parent 11ece09158
commit 927123cb2e

View file

@ -200,7 +200,7 @@ int send_message(struct evt_core_ctx* ctx, struct buffer_packet* bp) {
union abstract_packet *ap_buf = buffer_append_ap (bp_dup, &monit); union abstract_packet *ap_buf = buffer_append_ap (bp_dup, &monit);
uint8_t *links = &ap_buf->fmt.content.link_monitoring_lightning.prev_links; uint8_t *links = &ap_buf->fmt.content.link_monitoring_lightning.prev_links;
for (int i = 0; i < lightc->sent_past_links; i++) { for (int i = 0; i < lightc->sent_past_links; i++) {
links[i] = lightc->prev_links[lightc->pkt_sent_id - (i + 1) % MAX_LINKS]; links[i] = lightc->prev_links[(lightc->pkt_sent_id - (i + 1)) % MAX_LINKS];
} }
lightc->prev_links[lightc->pkt_sent_id % MAX_LINKS] = lightc->selected_link; lightc->prev_links[lightc->pkt_sent_id % MAX_LINKS] = lightc->selected_link;
@ -224,27 +224,35 @@ int algo_lightning_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo*
int64_t stats[MAX_LINKS]; int64_t stats[MAX_LINKS];
algo_lightning_update_stats(lightc, stats); algo_lightning_update_stats(lightc, stats);
struct timespec now; struct timespec now, temp_time;
set_now(&now); set_now(&now);
while (1) { int protection = lightc->total_links;
while (protection-- > 0) {
lightc->selected_link = (lightc->selected_link + 1) % lightc->total_links; lightc->selected_link = (lightc->selected_link + 1) % lightc->total_links;
uint64_t cdelta = stats[lightc->selected_link]; int64_t cdelta = stats[lightc->selected_link];
// OK link // OK link
if (cdelta >= 0 && cdelta < lightc->max_ooo) { printf("cdelta=%ld\n", cdelta);
if (cdelta < lightc->max_ooo) {
send_message (ctx, bp); send_message (ctx, bp);
break; break;
} }
// Broken link that must be probed // Broken link that must be probed
if (elapsed_micros (&now, &lightc->last[lightc->selected_link]) >= lightc->sleep_duration) { timespec_diff (&now, &lightc->last[lightc->selected_link], &temp_time);
uint64_t elapsed = timespec_get_unit(&temp_time, MILISEC);
if (elapsed >= lightc->sleep_duration) {
send_message (ctx, bp); send_message (ctx, bp);
continue; continue;
} }
// Broken link probed recently // Broken link probed recently
} }
if (protection <= 0) {
fprintf(stderr, "Schedule error\n");
exit(EXIT_FAILURE);
}
mv_buffer_rtof (&app_ctx->br, fdinfo); mv_buffer_rtof (&app_ctx->br, fdinfo);
return 0; return 0;