Update algo structure to support parameters

This commit is contained in:
Quentin Dufour 2019-03-28 11:54:01 +01:00
parent c12715e39e
commit b9d7ec48a2
6 changed files with 23 additions and 10 deletions

View file

@ -194,7 +194,7 @@ int on_err(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
return 0;
}
void algo_naive(struct evt_core_ctx* evt, struct algo_skel* as) {
void algo_naive(struct evt_core_ctx* evt, struct algo_skel* as, struct algo_params* ap) {
struct algo_ctx* ctx = malloc(sizeof(struct algo_ctx));
if (ctx == NULL) goto init_err;
memset(ctx, 0, sizeof(struct algo_ctx));

View file

@ -476,7 +476,7 @@ int rr_on_err(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
return 0;
}
void algo_rr(struct evt_core_ctx* evt, struct algo_skel* as) {
void algo_rr(struct evt_core_ctx* evt, struct algo_skel* as, struct algo_params* ap) {
struct algo_ctx* ctx = malloc(sizeof(struct algo_ctx));
if (ctx == NULL) goto init_err;
memset(ctx, 0, sizeof(struct algo_ctx));

View file

@ -1,9 +1,9 @@
#include "algo_skel.h"
void init_algo(struct evt_core_ctx* ctx, struct algo_skel* as, char* name) {
void init_algo(struct evt_core_ctx* ctx, struct algo_skel* as, char* name, struct algo_params* ap) {
for (int i = 0; i < sizeof(available_algo) / sizeof(available_algo[0]); i++) {
if (strcmp(available_algo[i].name, name) == 0) {
available_algo[i].init(ctx, as);
available_algo[i].init(ctx, as, ap);
return;
}
}

View file

@ -16,11 +16,16 @@ struct algo_skel {
struct evt_core_cat on_tcp_co;
};
typedef void (*algo_init)(struct evt_core_ctx* ctx, struct algo_skel* as);
struct algo_params {
uint8_t is_waiting_bootstrap;
uint8_t is_healing;
};
void init_algo(struct evt_core_ctx* ctx, struct algo_skel* as, char* name);
void algo_naive(struct evt_core_ctx* ctx, struct algo_skel* as);
void algo_rr(struct evt_core_ctx* ctx, struct algo_skel* as);
typedef void (*algo_init)(struct evt_core_ctx* ctx, struct algo_skel* as, struct algo_params* ap);
void init_algo(struct evt_core_ctx* ctx, struct algo_skel* as, char* name, struct algo_params* ap);
void algo_naive(struct evt_core_ctx* ctx, struct algo_skel* as, struct algo_params* ap);
void algo_rr(struct evt_core_ctx* ctx, struct algo_skel* as, struct algo_params* ap);
struct algo_desc {
algo_init init;

View file

@ -71,9 +71,13 @@ void init_socks5_sinks(struct donar_client_ctx* app_ctx) {
void donar_client(struct donar_client_ctx* ctx, struct donar_params* dp) {
struct algo_skel algo = {0};
struct algo_params ap = {
.is_waiting_bootstrap = dp->is_waiting_bootstrap,
.is_healing = dp->is_healing
};
evt_core_init (&(ctx->evts));
init_algo(&ctx->evts, &algo, dp->algo);
init_algo(&ctx->evts, &algo, dp->algo, &ap);
socks5_init (&ctx->evts);
init_socks5_sinks(ctx);
evt_core_add_cat (&(ctx->evts), &(algo.on_tcp_co));

View file

@ -53,9 +53,13 @@ socket_create_err:
void donar_server(struct donar_server_ctx* ctx, struct donar_params* dp) {
struct algo_skel algo = {0};
struct algo_params ap = {
.is_waiting_bootstrap = dp->is_waiting_bootstrap,
.is_healing = dp->is_healing
};
evt_core_init (&(ctx->evts));
init_algo(&ctx->evts, &algo, dp->algo);
init_algo(&ctx->evts, &algo, dp->algo, &ap);
evt_core_add_cat (&(ctx->evts), &(algo.on_tcp_co));
evt_core_add_cat (&(ctx->evts), &(algo.on_udp_read));
evt_core_add_cat (&(ctx->evts), &(algo.on_tcp_read));