diff --git a/src/algo_lightning.c b/src/algo_lightning.c index e87146a..851bedb 100644 --- a/src/algo_lightning.c +++ b/src/algo_lightning.c @@ -319,22 +319,20 @@ void algo_lightning_update_stats (struct light_ctx *lightc) { int64_t delta = 0; switch (lightc->historic[i].state) { case IN_ORDER: - lightc->stats[l].ooo += delta; - lightc->stats[l].meas_occ += 1; + delta = 0; break; case OOO_ONGOING: timespec_diff(&now, &lightc->historic[i].detected_at, &temp_time); delta = timespec_get_unit (&temp_time, MILISEC); - lightc->stats[l].ooo += delta; - lightc->stats[l].meas_occ += 1; + delta *= 2; break; case OOO_DONE: timespec_diff(&lightc->historic[i].finished_at, &lightc->historic[i].detected_at, &temp_time); delta = timespec_get_unit (&temp_time, MILISEC); - lightc->stats[l].ooo += delta; - lightc->stats[l].meas_occ += 1; break; } + lightc->stats[l].ooo += delta; + lightc->stats[l].meas_occ += 1; if (lightc->explain) printf("(stats.compute) packet=%ld, link=%d, status=%s, delta=%ld\n", lightc->historic[i].pkt_id, l, ooo_state_str[lightc->historic[i].state], delta); lightc->stats[l].link_id = l; @@ -384,12 +382,18 @@ int send_message(struct evt_core_ctx* ctx, struct buffer_packet* bp) { struct algo_ctx* app_ctx = cat->app_ctx; struct light_ctx* lightc = app_ctx->misc; - if (lightc->selected_link >= lightc->total_links) return 0; + if (lightc->selected_link >= lightc->total_links) { + fprintf(stderr, "[algo_lightning] PACKET DROPPED! Selected link id %d is greater than the total number of links %d\n", lightc->selected_link, lightc->total_links); + return 0; + } set_now(&lightc->status[lightc->selected_link].last); sprintf(url, "tcp:write:127.0.0.1:%d", 7500 + lightc->selected_link); struct evt_core_fdinfo *to_fdinfo = evt_core_get_from_url (ctx, url); - if (to_fdinfo == NULL) return 0; + if (to_fdinfo == NULL) { + fprintf(stderr, "[algo_lightning] PACKET DROPPED! We don't have any entry for %s currently\n", url); + return 0; + } struct buffer_packet* bp_dup = dup_buffer_tow (&app_ctx->br, bp, to_fdinfo); diff --git a/src/proxy.c b/src/proxy.c index 1f8e3be..c569047 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -103,7 +103,7 @@ int main_on_tcp_write(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) uint8_t is_rdy = fdinfo->cat->socklist->len >= app_ctx->link_count ? 1 : 0; if (!app_ctx->is_rdy && is_rdy) printf("=== Our %d requested circuits are now up ===\n", app_ctx->link_count); else if (app_ctx->is_rdy && !is_rdy) printf("=== Only %d/%d circuits are available, results could be biased ===\n", fdinfo->cat->socklist->len, app_ctx->link_count); - app_ctx->is_rdy = app_ctx->is_rdy || is_rdy; // @FIXME prevent deactivation for our tests + app_ctx->is_rdy = app_ctx->is_rdy || is_rdy; // @FIXME we don't want deactivation finally // 1. Get current write buffer OR a buffer from the waiting queue OR leave if ((bp = get_write_buffer(&app_ctx->br, fdinfo)) == NULL) return 1; @@ -117,6 +117,7 @@ int main_on_tcp_write(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) if (write_res == FDS_ERR) goto co_error; if (write_res == FDS_AGAIN) return 1; } + app_ctx->cell_sent++; free_buffer: @@ -218,7 +219,7 @@ void algo_main_init(struct evt_core_ctx* evt, struct algo_params* ap) { struct evt_core_cat tcp_read = { .name = "tcp-read", - .flags = EPOLLIN | EPOLLET | EPOLLHUP, + .flags = EPOLLIN | EPOLLET | EPOLLHUP | EPOLLRDHUP, .app_ctx = ctx, .free_app_ctx = algo_main_destroy, .cb = main_on_tcp_read, @@ -240,7 +241,7 @@ void algo_main_init(struct evt_core_ctx* evt, struct algo_params* ap) { struct evt_core_cat tcp_write = { .name = "tcp-write", - .flags = EPOLLOUT | EPOLLET | EPOLLHUP, + .flags = EPOLLOUT | EPOLLET | EPOLLHUP | EPOLLRDHUP, .app_ctx = ctx, .free_app_ctx = algo_main_destroy, .cb = main_on_tcp_write,