2019-08-09 15:01:28 +00:00
|
|
|
#include <sys/timerfd.h>
|
|
|
|
#include "algo_utils.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "url.h"
|
|
|
|
#include "proxy.h"
|
|
|
|
#include "timer.h"
|
|
|
|
|
2019-08-13 15:07:52 +00:00
|
|
|
struct thunder_ctx {
|
|
|
|
uint16_t recv_id;
|
|
|
|
uint16_t emit_id;
|
2019-08-26 10:08:31 +00:00
|
|
|
uint64_t lid_sent;
|
|
|
|
uint8_t selected_link;
|
|
|
|
uint8_t total_links;
|
|
|
|
uint64_t lid_sent_per_link[64];
|
|
|
|
uint8_t delta_t_per_link[64];
|
2019-08-13 15:07:52 +00:00
|
|
|
};
|
|
|
|
|
2019-08-09 15:01:28 +00:00
|
|
|
|
|
|
|
void prepare(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
|
2019-08-13 15:07:52 +00:00
|
|
|
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
|
|
|
struct thunder_ctx* thunderc = app_ctx->misc;
|
|
|
|
|
|
|
|
thunderc->emit_id++;
|
|
|
|
union abstract_packet metadata = {
|
|
|
|
.fmt.headers.cmd = CMD_UDP_METADATA_THUNDER,
|
|
|
|
.fmt.headers.size = sizeof(metadata.fmt.headers) + sizeof(metadata.fmt.content.udp_metadata_thunder),
|
|
|
|
.fmt.headers.flags = 0,
|
|
|
|
.fmt.content.udp_metadata_thunder.id = thunderc->emit_id,
|
2019-08-26 10:08:31 +00:00
|
|
|
.fmt.content.udp_metadata_thunder.deltat = 0 //@FIXME
|
2019-08-13 15:07:52 +00:00
|
|
|
};
|
2019-08-26 10:08:31 +00:00
|
|
|
buffer_append_ap (bp, &metadata);
|
|
|
|
|
2019-08-09 15:01:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pad(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int schedule(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
|
2019-08-26 10:08:31 +00:00
|
|
|
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
|
|
|
struct thunder_ctx* thunderc = app_ctx->misc;
|
|
|
|
struct evt_core_fdinfo *to_fdinfo = NULL;
|
|
|
|
struct evt_core_cat* cat = evt_core_get_from_cat (ctx, "tcp-write");
|
|
|
|
|
|
|
|
do {
|
|
|
|
thunderc->selected_link = thunderc->selected_link + 1 % cat->socklist->len;
|
|
|
|
|
|
|
|
if (thunderc->selected_link == 0) {
|
|
|
|
thunderc->lid_sent++;
|
|
|
|
|
|
|
|
}
|
2019-08-09 15:01:28 +00:00
|
|
|
|
2019-08-26 10:08:31 +00:00
|
|
|
union abstract_packet links = {
|
|
|
|
.fmt.headers.cmd = CMD_LINK_MONITORING_THUNDER,
|
|
|
|
.fmt.headers.size = sizeof(links.fmt.headers) + sizeof(links.fmt.content.link_monitoring_thunder),
|
|
|
|
.fmt.headers.flags = 0,
|
|
|
|
.fmt.content.link_monitoring_thunder.lid = thunderc->lid_sent,
|
|
|
|
.fmt.content.link_monitoring_thunder.links_status = NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
to_fdinfo = g_array_index(cat->socklist, struct evt_core_fdinfo*, thunderc->selected_link);
|
|
|
|
|
|
|
|
// We move the buffer and notify the target
|
|
|
|
struct buffer_packet* bp_dup = dup_buffer_tow (&app_ctx->br, bp, to_fdinfo);
|
|
|
|
buffer_append_ap (bp_dup, &links);
|
|
|
|
|
|
|
|
main_on_tcp_write(ctx, to_fdinfo);
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
if (ctx->verbose > 1) fprintf(stderr, " [algo_thunder] Packets sent\n");
|
|
|
|
|
|
|
|
// Release the buffer
|
|
|
|
mv_buffer_rtof (&app_ctx->br, fdinfo);
|
2019-08-09 15:01:28 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void algo_thunder_init(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx, struct algo_params* ap) {
|
2019-08-13 15:07:52 +00:00
|
|
|
app_ctx->misc = malloc(sizeof(struct thunder_ctx));
|
|
|
|
if (app_ctx->misc == NULL) {
|
|
|
|
perror("malloc failed in algo thunder init");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
memset(app_ctx->misc, 0, sizeof(struct thunder_ctx));
|
2019-08-26 10:08:31 +00:00
|
|
|
struct thunder_ctx* thunderc = app_ctx->misc;
|
2019-08-09 15:01:28 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int algo_thunder_on_stream(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int algo_thunder_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
|
|
|
|
prepare(ctx, fdinfo, bp);
|
|
|
|
pad(ctx, fdinfo, bp);
|
|
|
|
return schedule(ctx, fdinfo, bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int algo_thunder_on_err(struct evt_core_ctx *ctx, struct evt_core_fdinfo *fdinfo) {
|
|
|
|
if (strstr(fdinfo->cat->name, "udp") != NULL) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|