WIP debug algo thunder
This commit is contained in:
parent
a1d58c1203
commit
a9e5267495
2 changed files with 29 additions and 3 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue