Fixed non initialized bug + WIP Donar Client

This commit is contained in:
Quentin 2019-02-12 20:33:12 +01:00
parent 3bfafabd44
commit d1bfdf520f
4 changed files with 55 additions and 5 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -1,5 +1,15 @@
#pragma once
#include <stdio.h>
#include <stdlib.h>
#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);

View File

@ -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));