diff --git a/src/donar.c b/src/donar.c index c62aa2e..3f211a3 100644 --- a/src/donar.c +++ b/src/donar.c @@ -45,10 +45,11 @@ int main(int argc, char** argv) { exit(EXIT_FAILURE); } + struct algo_skel as; + algo_naive (&as); + if (is_server) { struct donar_server_ctx ctx; - struct algo_skel as; - algo_naive (&as); if (host == NULL || port == NULL) { fprintf(stderr, "You need to set a host -h and a port -p\n"); exit(EXIT_FAILURE); @@ -56,7 +57,12 @@ int main(int argc, char** argv) { printf("params: %s:%s\n", host, port); donar_server(&ctx, &as, host, port); } else if (is_client) { - donar_client(); + struct donar_client_ctx ctx; + if (port == NULL || onion_file == NULL) { + fprintf(stderr, "You need to set an onion_file -o and a port -p\n"); + exit(EXIT_FAILURE); + } + donar_client(&ctx, &as, onion_file, port); } free(onion_file); diff --git a/src/donar_client.c b/src/donar_client.c index 188c487..7f9483e 100644 --- a/src/donar_client.c +++ b/src/donar_client.c @@ -1 +1,34 @@ -void donar_client() {} +#include "donar_client.h" + +void load_onion_services(struct donar_client_ctx* ctx, char* onion_file, int ports_count) { + tor_os_create (&(ctx->tos), onion_file, NULL, ports_count); + tor_os_read (&(ctx->tos)); +} + +void init_tcp_clients(struct donar_client_ctx* ctx) { + +} + +void donar_client(struct donar_client_ctx* ctx, struct algo_skel* algo, char* onion_file, char* port) { + 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)); + printf("--- Categories created\n"); + + load_onion_services (ctx, onion_file, CLIENT_PORT_SIZE); + printf("--- Onion services loaded\n"); + + for (int i = 0; i < ctx->tos.filled; i++) { + printf("onion service: %s\n",ctx->tos.keys->pub); + } + + for (uint16_t i = 0; i < CLIENT_PORT_SIZE ; i++) { + ctx->ports[i] = 7500 + i; + } + + init_tcp_clients(ctx); + +} diff --git a/src/donar_client.h b/src/donar_client.h index 48f4823..43e8d6f 100644 --- a/src/donar_client.h +++ b/src/donar_client.h @@ -1,5 +1,15 @@ #pragma once #include #include +#include "algo_skel.h" +#include "tor_os.h" -void donar_client(); +#define CLIENT_PORT_SIZE 10 + +struct donar_client_ctx { + struct tor_os_str tos; + struct evt_core_ctx evts; + uint16_t ports[CLIENT_PORT_SIZE]; +}; + +void donar_client(struct donar_client_ctx* ctx, struct algo_skel* as, char* onion_file, char* port); diff --git a/src/tor_os.c b/src/tor_os.c index a782f10..1d56c76 100644 --- a/src/tor_os.c +++ b/src/tor_os.c @@ -3,6 +3,7 @@ void tor_os_create(struct tor_os_str* os, char* pub_file, char* priv_file, size_t size) { os->size = size; os->filled = 0; + os->priv_file = NULL; if (priv_file != NULL) { os->priv_file = malloc(sizeof(char) * (strlen(priv_file) + 1));