From a9e5267495ea0c8f15e2b88d47515930d7232da8 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 28 Aug 2019 16:33:43 +0200 Subject: [PATCH] WIP debug algo thunder --- src/algo_thunder.c | 31 ++++++++++++++++++++++++++++--- src/packet.c | 1 + 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/algo_thunder.c b/src/algo_thunder.c index 3e66176..d7c78c0 100644 --- a/src/algo_thunder.c +++ b/src/algo_thunder.c @@ -57,6 +57,7 @@ void prepare(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct bu .fmt.content.udp_metadata_thunder.id = thunderc->emit_id, }; buffer_append_ap (bp, &metadata); + if (ctx->verbose > 1) fprintf(stderr, " [algo_thunder] UDP metadata added\n"); } void pad(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) { @@ -79,14 +80,21 @@ void pad(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer struct buffer_packet *bp_iter = get_app_buffer (&app_ctx->br, (void *)add_ref); if (bp_iter == NULL) break; union abstract_packet *ap = buffer_first_ap (bp_iter); - if (ap->fmt.headers.cmd != CMD_UDP_ENCAPSULATED || ap->fmt.headers.flags & FLAG_READ_NEXT) { - fprintf(stderr, "Invalid buffer!\n"); + if (ap->fmt.headers.cmd != CMD_UDP_ENCAPSULATED) { + fprintf(stderr, "Invalid buffer payload!\n"); + exit(EXIT_FAILURE); + } + union abstract_packet *ap_meta = ap_next (ap); + if (ap_meta->fmt.headers.cmd != CMD_UDP_METADATA_THUNDER) { + fprintf(stderr, "Invalid buffer metadata!\n"); exit(EXIT_FAILURE); } - if (buffer_full_size (bp) + ap->fmt.headers.size > TOR_CELL_SIZE - thunderc->monit_pkt_size) break; + if (buffer_full_size (bp) + ap->fmt.headers.size + ap_meta->fmt.headers.size > TOR_CELL_SIZE - thunderc->monit_pkt_size) break; buffer_append_ap (bp, ap); + buffer_append_ap (bp, ap_meta); + if (ctx->verbose > 1) fprintf(stderr, " [algo_thunder] Pad packet (now %ld bytes)\n", buffer_full_size (bp)); } } @@ -98,6 +106,10 @@ int schedule(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct bu do { // 1. We choose the link + if (cat->socklist->len == 0) { + if (ctx->verbose > 1) fprintf(stderr, " [algo_thunder] No link available, packet will be dropped\n"); + break; + } thunderc->selected_link = (thunderc->selected_link + 1) % cat->socklist->len; // 2. We create the packet template @@ -181,7 +193,12 @@ void classify(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct b bi->i = i; bi->app_ctx = app_ctx; bi->missing = expected; set_timeout (ctx, timeout, &bi, on_block); + if (ctx->verbose > 1) { + fprintf(stderr, " [algo_thunder] Set timeout on link %d of %ld ms (packets expected: %ld, seen: %ld)\n", + i, timeout, expected, thunderc->received_pkts_on_link[i]); + } } + if (ctx->verbose > 1) fprintf(stderr, " [algo_thunder] Classify done\n"); } struct unpad_info { @@ -207,6 +224,7 @@ void unpad(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buff ui->ap_arr_vals++; } } + if (ctx->verbose > 1) fprintf(stderr, " [algo_thunder] Unpad done\n"); } void adapt(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp, struct unpad_info *ui) { @@ -232,6 +250,7 @@ void adapt(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buff } mv_buffer_rtof (&app_ctx->br, fdinfo); + if (ctx->verbose > 1) fprintf(stderr, " [algo_thunder] Adapt done\n"); } int algo_thunder_on_stream(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) { @@ -250,8 +269,14 @@ int algo_thunder_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo* f return 0; } +void algo_thunder_free(void* v) { + struct rr_ctx* rr = v; + free(rr); +} + void algo_thunder_init(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx, struct algo_params* ap) { app_ctx->misc = malloc(sizeof(struct thunder_ctx)); + app_ctx->free_misc = algo_thunder_free; if (app_ctx->misc == NULL) { perror("malloc failed in algo thunder init"); exit(EXIT_FAILURE); diff --git a/src/packet.c b/src/packet.c index 3422a5f..898a734 100644 --- a/src/packet.c +++ b/src/packet.c @@ -41,6 +41,7 @@ union abstract_packet* buffer_append_ap(struct buffer_packet* bp, union abstract union abstract_packet *new_ap = buffer_last_ap(bp); memcpy(new_ap, ap, ap->fmt.headers.size); bp->ap_count++; + new_ap->fmt.headers.flags &= ~FLAG_READ_NEXT; return new_ap; }