From e543c446742e4a90faad34cbb490535170e3bc9a Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 20 Mar 2019 10:28:52 +0100 Subject: [PATCH] Show buffer states --- src/algo_rr.c | 10 ++++++---- src/algo_utils.c | 29 +++++++++++++++++++++++++---- src/algo_utils.h | 2 +- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/algo_rr.c b/src/algo_rr.c index 1994790..ae6dc8e 100644 --- a/src/algo_rr.c +++ b/src/algo_rr.c @@ -113,7 +113,7 @@ void rr_pkt_register(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct algo_ctx* app_ctx = fdinfo->cat->app_ctx; struct rr_ctx* rr = app_ctx->misc; - printf("Selected url %s for pkt %d to be queued for delivery\n", fdinfo->url, bp->ip.ap.str.id); + //printf("Selected url %s for pkt %d to be queued for delivery\n", fdinfo->url, bp->ip.ap.str.id); // 1. Update links I can use thanks to target feedback if (bp->ip.ap.str.id > rr->my_links_ver) { @@ -130,7 +130,7 @@ void rr_pkt_register(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, } // 3. If packet arrived too early, we register a timer - printf("%d < %d = %d\n", rr->recv_id, bp->ip.ap.str.id - 1, ring_lt(rr->recv_id, bp->ip.ap.str.id - 1)); + //printf("%d < %d = %d\n", rr->recv_id, bp->ip.ap.str.id - 1, ring_lt(rr->recv_id, bp->ip.ap.str.id - 1)); if (ring_lt(rr->recv_id, bp->ip.ap.str.id - 1)) { int64_t timeout = rr->mjit - (int64_t) bp->ip.ap.str.deltat; //printf("%ld - %ld = %ld\n", rr->mjit, (int64_t) bp->ip.ap.str.deltat, timeout); @@ -161,7 +161,7 @@ void rr_deliver(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct struct rr_ctx* rr = app_ctx->misc; char url[255]; - printf("Selected url %s for pkt %d to be delivered\n", fdinfo->url, bp->ip.ap.str.id); + //printf("Selected url %s for pkt %d to be delivered\n", fdinfo->url, bp->ip.ap.str.id); // 0. We update our cursor rr->recv_id = bp->ip.ap.str.id; @@ -313,7 +313,7 @@ int rr_on_udp_read(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { //printf("-- Trying %s\n", url); to_fdinfo = evt_core_get_from_url (ctx, url); if (to_fdinfo != NULL) { - printf("Selected url %s for pkt %d to be sent on Tor\n", url, bp->ip.ap.str.id); + //printf("Selected url %s for pkt %d to be sent on Tor\n", url, bp->ip.ap.str.id); break; } } @@ -376,7 +376,9 @@ int rr_on_timer(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { printf("Timer reached for packet %d\n", pkt->id); + // !BLACKLIST LINK //rr->remote_links &= 0xffff ^ 1 << pkt->link_num; + while (ring_lt(rr->recv_id, pkt->id)) { rr->recv_id++; rr_pkt_unroll (ctx, app_ctx); diff --git a/src/algo_utils.c b/src/algo_utils.c index 5e6542e..4f2b5d4 100644 --- a/src/algo_utils.c +++ b/src/algo_utils.c @@ -12,6 +12,15 @@ void free_naive(void* app_ctx) { free(ctx); } +void iterate(int* fd, GQueue* q, int* waiting_count) { + fprintf(stderr, "Queue for fd=%d has length=%d\n", *fd, q->length); + waiting_count += q->length; +} + +void iterate2(int* fd, struct buffer_packet *bp, gpointer user_data) { + fprintf(stderr, "fd=%d has a used_buffer entry\n", *fd); +} + /** * Returns a buffer if available, NULL otherwise */ @@ -25,6 +34,15 @@ struct buffer_packet* get_read_buffer(struct algo_ctx *app_ctx, struct evt_core_ // 2. Get a new buffer otherwise bp = g_queue_pop_head(app_ctx->free_buffer); if (bp == NULL) { + fprintf(stderr, "No more free buffer for fd=%d.\n", fdinfo->fd); + int waiting_count = 0; + g_hash_table_foreach(app_ctx->write_waiting, (GHFunc)iterate, &waiting_count); + g_hash_table_foreach(app_ctx->used_buffer, (GHFunc)iterate2, NULL); + fprintf(stderr, "total_buffers=%d, used_buffers=%d. free_buffer=%d, waiting_buffer=%d.\n", + PACKET_BUFFER_SIZE, + g_hash_table_size(app_ctx->used_buffer), + app_ctx->free_buffer->length, + waiting_count); // 2.1 If no buffer is available, we subscribe to be notified later g_queue_push_tail (app_ctx->read_waiting, &(fdinfo->fd)); return NULL; @@ -86,10 +104,13 @@ void mv_buffer_wtor(struct algo_ctx* app_ctx, struct evt_core_fdinfo* fdinfo, st void notify_read(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx) { struct evt_core_fdinfo* next_fdinfo = NULL; while (next_fdinfo == NULL) { - int fd = GPOINTER_TO_INT(g_queue_pop_head(app_ctx->read_waiting)); - if (fd == 0) break; - next_fdinfo = evt_core_get_from_fd (ctx, fd); - if (strcmp(next_fdinfo->cat->name, "tcp-read") == 0 || strcmp(next_fdinfo->cat->name, "udp-read") == 0) { + int* fd = g_queue_pop_head(app_ctx->read_waiting); + if (fd == NULL) break; + next_fdinfo = evt_core_get_from_fd (ctx, *fd); + if (next_fdinfo == NULL) { + fprintf(stderr, "Unable to find fdinfo for fd=%d\n", *fd); + exit(EXIT_FAILURE); + } else if (strcmp(next_fdinfo->cat->name, "tcp-read") == 0 || strcmp(next_fdinfo->cat->name, "udp-read") == 0) { next_fdinfo->cat->cb(ctx, next_fdinfo); } else { fprintf(stderr, "A fd from category %s can't be stored in read_waiting\n", next_fdinfo->cat->name); diff --git a/src/algo_utils.h b/src/algo_utils.h index 820dfef..f515190 100644 --- a/src/algo_utils.h +++ b/src/algo_utils.h @@ -3,7 +3,7 @@ #include #include #include -#define PACKET_BUFFER_SIZE 100 +#define PACKET_BUFFER_SIZE 20 typedef void (*algo_ctx_free_misc)(void*);