From 4d5dd554c5e715e7355c3672ef9985c67ee53667 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 28 Aug 2019 11:35:43 +0200 Subject: [PATCH] Add unpad function --- src/algo_thunder.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/algo_thunder.c b/src/algo_thunder.c index 9e7072c..20e854a 100644 --- a/src/algo_thunder.c +++ b/src/algo_thunder.c @@ -8,15 +8,16 @@ // A Tor cell size is 512 bytes but handle only 498 bytes of data #define TOR_CELL_SIZE 498 #define ALLOWED_JITTER_MS 200 +#define MAX_LINKS 64 struct thunder_ctx { uint16_t recv_id; uint16_t emit_id; uint8_t selected_link; uint8_t total_links; - uint8_t delta_t_per_link[64]; - uint64_t received_pkts_on_link[64]; - uint8_t blacklisted[64]; + uint8_t delta_t_per_link[MAX_LINKS]; + uint64_t received_pkts_on_link[MAX_LINKS]; + uint8_t blacklisted[MAX_LINKS]; size_t monit_pkt_size; struct timespec prev_link_time, prev_packet_time; }; @@ -193,8 +194,29 @@ void classify(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct b } } -void unpad() { +struct unpad_info { + union abstract_packet *ap_arr_pl[MAX_LINKS], *ap_arr_meta[MAX_LINKS]; + uint8_t ap_arr_vals; +}; +void unpad(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp, struct unpad_info *ui) { + struct algo_ctx* app_ctx = fdinfo->cat->app_ctx; + struct thunder_ctx* thunderc = app_ctx->misc; + + for (union abstract_packet* ap = buffer_first_ap (bp); ap != NULL; ap = ap_next(ap)) { + if (ap->fmt.headers.cmd != CMD_UDP_ENCAPSULATED) continue; + + union abstract_packet* ap_meta = ap_next(ap); + if (ap_meta == NULL || ap_meta->fmt.headers.cmd != CMD_UDP_METADATA_THUNDER) { + fprintf(stderr, "Unexpected packet, expecting udp metadata\n"); + } + + if (ap_meta->fmt.content.udp_metadata_thunder.id > thunderc->recv_id) { + ui->ap_arr_pl[ui->ap_arr_vals] = ap; + ui->ap_arr_meta[ui->ap_arr_vals] = ap_meta; + ui->ap_arr_vals++; + } + } } void adapt() { @@ -202,8 +224,10 @@ void adapt() { } int algo_thunder_on_stream(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) { + struct unpad_info ui = {0}; + classify(ctx, fdinfo, bp); - unpad(); + unpad(ctx, fdinfo, bp, &ui); adapt(); return 0; }