diff --git a/src/algo_naive.c b/src/algo_naive.c index 744aa35..b3f6dca 100644 --- a/src/algo_naive.c +++ b/src/algo_naive.c @@ -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)); diff --git a/src/algo_rr.c b/src/algo_rr.c index 216e430..4728a2a 100644 --- a/src/algo_rr.c +++ b/src/algo_rr.c @@ -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)); diff --git a/src/algo_skel.c b/src/algo_skel.c index b3fa20b..32cefff 100644 --- a/src/algo_skel.c +++ b/src/algo_skel.c @@ -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; } } diff --git a/src/algo_skel.h b/src/algo_skel.h index 40f140f..cd7c5fa 100644 --- a/src/algo_skel.h +++ b/src/algo_skel.h @@ -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; diff --git a/src/donar_client.c b/src/donar_client.c index 206976f..ee4e994 100644 --- a/src/donar_client.c +++ b/src/donar_client.c @@ -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)); diff --git a/src/donar_server.c b/src/donar_server.c index 4335f0b..310f2b5 100644 --- a/src/donar_server.c +++ b/src/donar_server.c @@ -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));