Fix init error

This commit is contained in:
Quentin Dufour 2019-03-19 17:09:42 +01:00
parent ef49d07dd9
commit 3293197860
6 changed files with 27 additions and 20 deletions

View file

@ -20,6 +20,7 @@ typedef void (*algo_init)(struct evt_core_ctx* ctx, struct algo_skel* as);
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);
struct algo_desc {
algo_init init;
@ -30,5 +31,9 @@ static struct algo_desc available_algo[] = {
{
.init = algo_naive,
.name = "naive"
},
{
.init = algo_rr,
.name = "rr"
}
};

View file

@ -58,18 +58,14 @@ int main(int argc, char** argv) {
if (!(is_server ^ is_client)) goto in_error;
if (algo == NULL) goto in_error;
struct algo_skel as = {0};
if (is_server) {
struct donar_server_ctx ctx;
init_algo(&ctx.evts, &as, algo);
if (exposed_ports->len < 1 && remote_ports->len < 1) goto in_error;
donar_server(&ctx, &as, exposed_ports, remote_ports);
donar_server(&ctx, algo, exposed_ports, remote_ports);
} else if (is_client) {
struct donar_client_ctx ctx;
init_algo(&ctx.evts, &as, algo);
if ((exposed_ports->len < 1 && remote_ports->len < 1) || onion_file == NULL) goto in_error;
donar_client(&ctx, &as, onion_file, exposed_ports, remote_ports);
donar_client(&ctx, algo, onion_file, exposed_ports, remote_ports);
}
goto terminate;

View file

@ -122,9 +122,12 @@ on_socks5_err:
return 1;
}
void donar_client(struct donar_client_ctx* ctx, struct algo_skel* algo,
void donar_client(struct donar_client_ctx* ctx, char* algoname,
char* onion_file, GPtrArray* exposed_ports, GPtrArray* remote_ports) {
struct algo_skel algo = {0};
evt_core_init (&(ctx->evts));
init_algo(&ctx->evts, &algo, algoname);
struct evt_core_cat init_socks5 = {
.app_ctx = ctx,
.free_app_ctx = NULL,
@ -135,11 +138,11 @@ void donar_client(struct donar_client_ctx* ctx, struct algo_skel* algo,
.socklist = NULL
};
evt_core_add_cat (&(ctx->evts), &init_socks5);
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));
evt_core_add_cat (&(ctx->evts), &(algo->on_udp_write));
evt_core_add_cat (&(ctx->evts), &(algo->on_tcp_write));
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));
evt_core_add_cat (&(ctx->evts), &(algo.on_udp_write));
evt_core_add_cat (&(ctx->evts), &(algo.on_tcp_write));
printf("--- Categories created\n");
load_onion_services (ctx, onion_file, CLIENT_PORT_SIZE);

View file

@ -19,5 +19,5 @@ struct donar_client_ctx {
} client_sock[CLIENT_PORT_SIZE];
};
void donar_client(struct donar_client_ctx* ctx, struct algo_skel* as,
void donar_client(struct donar_client_ctx* ctx, char* algoname,
char* onion_file, GPtrArray* exposed_ports, GPtrArray* remote_ports);

View file

@ -51,14 +51,17 @@ socket_create_err:
exit(EXIT_FAILURE);
}
void donar_server(struct donar_server_ctx* ctx, struct algo_skel* algo,
void donar_server(struct donar_server_ctx* ctx, char* algoname,
GPtrArray* exposed_ports, GPtrArray* remote_ports) {
struct algo_skel algo = {0};
evt_core_init (&(ctx->evts));
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));
evt_core_add_cat (&(ctx->evts), &(algo->on_udp_write));
evt_core_add_cat (&(ctx->evts), &(algo->on_tcp_write));
init_algo(&ctx->evts, &algo, algoname);
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));
evt_core_add_cat (&(ctx->evts), &(algo.on_udp_write));
evt_core_add_cat (&(ctx->evts), &(algo.on_tcp_write));
printf("--- Categories created\n");

View file

@ -20,5 +20,5 @@ struct donar_server_ctx {
uint16_t ports[PORT_SIZE];
};
void donar_server(struct donar_server_ctx* ctx, struct algo_skel* algo,
void donar_server(struct donar_server_ctx* ctx, char* algoname,
GPtrArray* exposed_ports, GPtrArray* remote_ports);