WIP redundancy
This commit is contained in:
parent
c20117188c
commit
8fdcc452d4
1 changed files with 53 additions and 3 deletions
|
@ -113,6 +113,44 @@ void algo_lightning_init(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx, str
|
||||||
printf("explain = %s\n", lightc->explain ? "yes" : "no");
|
printf("explain = %s\n", lightc->explain ? "yes" : "no");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void algo_lightning_pad(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
|
||||||
|
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
||||||
|
struct light_ctx* lightc = app_ctx->misc;
|
||||||
|
uint64_t ref = lightc->pkt_sent_id;
|
||||||
|
|
||||||
|
// 0. Store current buffer to application
|
||||||
|
fprintf(stderr, " [algo_lightning] Store buffer with pointer %p\n", (void*) ref);
|
||||||
|
dup_buffer_toa (&app_ctx->br, bp, (void *)ref);
|
||||||
|
|
||||||
|
// 1. Clean old buffers (we keep only thunderc->total_links buffer, keeping more would be useless)
|
||||||
|
fprintf(stderr, " [algo_lightning] Clean queue\n");
|
||||||
|
if (ref > lightc->total_links && get_app_buffer (&app_ctx->br, (void *)(ref - lightc->total_links))) {
|
||||||
|
mv_buffer_atof (&app_ctx->br, (void *)(ref - lightc->total_links));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Append abstract packets stored in our buffers
|
||||||
|
uint64_t add_ref = ref;
|
||||||
|
while(1) {
|
||||||
|
fprintf(stderr, " [algo_lightning] Enter loop\n");
|
||||||
|
if (add_ref < 1) break;
|
||||||
|
add_ref--;
|
||||||
|
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) {
|
||||||
|
fprintf(stderr, "Invalid buffer payload!\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, " [algo_lightning] Start loop, currently %ld bytes, would be %ld\n", buffer_full_size (bp), buffer_full_size (bp) + ap->fmt.headers.size);
|
||||||
|
|
||||||
|
if (buffer_full_size (bp) + ap->fmt.headers.size > TOR_CELL_SIZE - lightc->monit_pkt_size) break;
|
||||||
|
|
||||||
|
buffer_append_ap (bp, ap);
|
||||||
|
/*if (ctx->verbose > 1)*/ fprintf(stderr, " [algo_lightning] Pad packet (now %ld bytes)\n", buffer_full_size (bp));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void monitoring(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
|
void monitoring(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
|
||||||
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
||||||
struct light_ctx* lightc = app_ctx->misc;
|
struct light_ctx* lightc = app_ctx->misc;
|
||||||
|
@ -313,7 +351,10 @@ int algo_lightning_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo*
|
||||||
struct light_ctx* lightc = app_ctx->misc;
|
struct light_ctx* lightc = app_ctx->misc;
|
||||||
union abstract_packet* ap = (union abstract_packet*) &bp->ip;
|
union abstract_packet* ap = (union abstract_packet*) &bp->ip;
|
||||||
|
|
||||||
// Last step, send packet
|
// Pad packet
|
||||||
|
algo_lightning_pad (ctx, fdinfo, bp);
|
||||||
|
|
||||||
|
// Compute stats
|
||||||
struct stat_entry stats[MAX_LINKS] = {0};
|
struct stat_entry stats[MAX_LINKS] = {0};
|
||||||
algo_lightning_update_stats(lightc, stats);
|
algo_lightning_update_stats(lightc, stats);
|
||||||
|
|
||||||
|
@ -325,6 +366,7 @@ int algo_lightning_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo*
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Init vars
|
||||||
struct timespec now, sel_link_last, temp_time;
|
struct timespec now, sel_link_last, temp_time;
|
||||||
set_now(&now);
|
set_now(&now);
|
||||||
uint64_t now_timestamp = timespec_get_unit(&now, MILISEC);
|
uint64_t now_timestamp = timespec_get_unit(&now, MILISEC);
|
||||||
|
@ -353,8 +395,16 @@ int algo_lightning_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo*
|
||||||
timespec_diff (&now, &sel_link_last, &temp_time);
|
timespec_diff (&now, &sel_link_last, &temp_time);
|
||||||
uint64_t elapsed = timespec_get_unit(&temp_time, MILISEC);
|
uint64_t elapsed = timespec_get_unit(&temp_time, MILISEC);
|
||||||
if (lightc->is_measlat) {
|
if (lightc->is_measlat) {
|
||||||
struct measure_packet *mp = (void*)&ap->fmt.content.udp_encapsulated.payload;
|
union abstract_packet* cur = ap;
|
||||||
mp->flag = 1;
|
while (cur != NULL) {
|
||||||
|
if (ap->fmt.headers.cmd != CMD_UDP_ENCAPSULATED) {
|
||||||
|
cur = ap_next(cur);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
struct measure_packet *mp = (void*)&cur->fmt.content.udp_encapsulated.payload;
|
||||||
|
mp->flag = 1;
|
||||||
|
cur = ap_next(cur);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (elapsed >= lightc->sleep_duration) {
|
if (elapsed >= lightc->sleep_duration) {
|
||||||
send_message (ctx, bp);
|
send_message (ctx, bp);
|
||||||
|
|
Loading…
Reference in a new issue