From 347ea4f6cd93561770be4c4b06e9522d9b2a49b5 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 28 Mar 2019 15:58:18 +0100 Subject: [PATCH] Inform users that circuit is up on naive --- src/algo_naive.c | 7 +++++++ src/algo_rr.c | 21 +++++++++------------ src/algo_skel.c | 1 - src/algo_skel.h | 10 +++++----- src/algo_utils.h | 5 ++++- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/algo_naive.c b/src/algo_naive.c index b3f6dca..8e4e22c 100644 --- a/src/algo_naive.c +++ b/src/algo_naive.c @@ -86,6 +86,11 @@ int on_tcp_write(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { struct algo_ctx* app_ctx = fdinfo->cat->app_ctx; int write_res = FDS_READY; + if (!app_ctx->is_rdy && strcmp(fdinfo->url, "tcp:write:127.0.0.1:7500") == 0) { + app_ctx->is_rdy = 1; + printf("=== Requested circuit is up ===\n"); + } + // 1. Get current write buffer OR a buffer from the waiting queue OR leave if ((bp = get_write_buffer(app_ctx, fdinfo)) == NULL) return 1; @@ -203,6 +208,8 @@ void algo_naive(struct evt_core_ctx* evt, struct algo_skel* as, struct algo_para ctx->application_waiting = g_hash_table_new (NULL, NULL); ctx->used_buffer = g_hash_table_new(g_int_hash, g_int_equal); ctx->write_waiting = g_hash_table_new_full (g_int_hash, g_int_equal, NULL, naive_free_simple); + ctx->ap = *ap; + ctx->is_rdy = 0; for (int i = 0; i < sizeof(ctx->bps) / sizeof(ctx->bps[0]); i++) { g_queue_push_tail(ctx->free_buffer, &(ctx->bps[i])); } diff --git a/src/algo_rr.c b/src/algo_rr.c index fad6a42..f6dd0de 100644 --- a/src/algo_rr.c +++ b/src/algo_rr.c @@ -18,8 +18,6 @@ struct deferred_pkt { }; struct rr_ctx { - uint8_t link_count; - uint8_t is_rdy; uint8_t my_links; uint16_t my_links_ver; uint8_t remote_links; @@ -28,7 +26,6 @@ struct rr_ctx { uint16_t recv_id_late; uint16_t sent_id; uint8_t current_link; - struct algo_params ap; struct timespec emit_time; struct deferred_pkt real[PACKET_BUFFER_SIZE]; struct waited_pkt wait[PACKET_BUFFER_SIZE]; @@ -370,8 +367,8 @@ int rr_on_udp_read(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { sprintf(url, "tcp:write:127.0.0.1:%d", 7500 + sel_link); //@FIXME Hardcoded to_fdinfo = evt_core_get_from_url (ctx, url); if (to_fdinfo == NULL) continue; // Missing link - if (rr->ap.is_waiting_bootstrap && !rr->is_rdy) goto not_ready; // Some links are down - if (!rr->ap.is_healing || rr->my_links & (1 << sel_link)) { + if (app_ctx->ap.is_waiting_bootstrap && !app_ctx->is_rdy) goto not_ready; // Some links are down + if (!app_ctx->ap.is_healing || rr->my_links & (1 << sel_link)) { rr->current_link = sel_link; mv_buffer_rtow (app_ctx, fdinfo, to_fdinfo); rr_on_tcp_write(ctx, to_fdinfo); @@ -400,10 +397,10 @@ int rr_on_tcp_write(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { int write_res = FDS_READY; // 0. Show some information about circuits - uint8_t is_rdy = fdinfo->cat->socklist->len >= rr->link_count ? 1 : 0; - if (!rr->is_rdy && is_rdy) printf("=== Our %d requested circuits are now up ===\n", rr->link_count); - else if (rr->is_rdy && !is_rdy) printf("=== Only %d/%d circuits are available, results could be biased ===\n", fdinfo->cat->socklist->len, rr->link_count); - rr->is_rdy = is_rdy; + 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 = is_rdy; // 1. Get current write buffer OR a buffer from the waiting queue OR leave if ((bp = get_write_buffer(app_ctx, fdinfo)) == NULL) return 1; @@ -497,6 +494,9 @@ void algo_rr(struct evt_core_ctx* evt, struct algo_skel* as, struct algo_params* ctx->application_waiting = g_hash_table_new (NULL, NULL); ctx->used_buffer = g_hash_table_new(g_int_hash, g_int_equal); ctx->write_waiting = g_hash_table_new_full (g_int_hash, g_int_equal, NULL, naive_free_simple); + ctx->link_count = 8; + ctx->is_rdy = 0; + ctx->ap = *ap; struct rr_ctx* rr = malloc(sizeof(struct rr_ctx)); if (rr == NULL) goto init_err; memset(rr, 0, sizeof(struct rr_ctx)); @@ -506,9 +506,6 @@ void algo_rr(struct evt_core_ctx* evt, struct algo_skel* as, struct algo_params* rr->sent_id = 1; rr->recv_id = 0; rr->recv_id_late = 0; - rr->link_count = 8; - rr->is_rdy = 0; - rr->ap = *ap; ctx->misc = rr; for (int i = 0; i < sizeof(ctx->bps) / sizeof(ctx->bps[0]); i++) { g_queue_push_tail(ctx->free_buffer, &(ctx->bps[i])); diff --git a/src/algo_skel.c b/src/algo_skel.c index 32cefff..5162f42 100644 --- a/src/algo_skel.c +++ b/src/algo_skel.c @@ -10,4 +10,3 @@ void init_algo(struct evt_core_ctx* ctx, struct algo_skel* as, char* name, struc fprintf(stderr, "Algorithm %s has not been found\n", name); exit(EXIT_FAILURE); } - diff --git a/src/algo_skel.h b/src/algo_skel.h index cd7c5fa..658cc10 100644 --- a/src/algo_skel.h +++ b/src/algo_skel.h @@ -8,6 +8,11 @@ #include "utils.h" #include "url.h" +struct algo_params { + uint8_t is_waiting_bootstrap; + uint8_t is_healing; +}; + struct algo_skel { struct evt_core_cat on_udp_read; struct evt_core_cat on_tcp_read; @@ -16,11 +21,6 @@ struct algo_skel { struct evt_core_cat on_tcp_co; }; -struct algo_params { - uint8_t is_waiting_bootstrap; - uint8_t is_healing; -}; - typedef void (*algo_init)(struct evt_core_ctx* ctx, struct algo_skel* as, struct algo_params* ap); void init_algo(struct evt_core_ctx* ctx, struct algo_skel* as, char* name, struct algo_params* ap); diff --git a/src/algo_utils.h b/src/algo_utils.h index 3fc55cc..755b004 100644 --- a/src/algo_utils.h +++ b/src/algo_utils.h @@ -1,13 +1,16 @@ #pragma once -#include "algo_skel.h" #include #include #include +#include "algo_skel.h" #define PACKET_BUFFER_SIZE 20 typedef void (*algo_ctx_free_misc)(void*); struct algo_ctx { + uint8_t link_count; + uint8_t is_rdy; + struct algo_params ap; int ref_count; struct buffer_packet bps[PACKET_BUFFER_SIZE]; GQueue* free_buffer; // Available buffers