Dump config

This commit is contained in:
Quentin 2020-01-20 23:35:02 +01:00
parent e2426741aa
commit 451fb9cdd6
6 changed files with 62 additions and 2 deletions

View file

@ -51,11 +51,31 @@ socket_create_err:
exit(EXIT_FAILURE);
}
struct tor_ctl* ugly_global_tctl;
int donar_server_stream_repair(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fd) {
fprintf(stderr, "I am a server, I do nothing with broken streams...\n");
tor_ctl_list_onions(ugly_global_tctl);
return 1;
}
struct donar_server_os_republish_params {
struct donar_server_ctx* dctx;
struct donar_params* dp;
};
void republish_tor_os(struct evt_core_ctx* ctx, void* user_data) {
struct donar_server_os_republish_params* dsorp = user_data;
int err = 0;
printf("Republish Tor OS\n");
err = tor_ctl_add_onion (&dsorp->dctx->tctl, &dsorp->dctx->tos, dsorp->dctx->ports, dsorp->dp->tof);
if (err != 0) {
fprintf(stderr, "Unable to create Onion Services (error: %d)\n", err);
exit(EXIT_FAILURE);
}
printf("Republish Tor OS\n");
}
void donar_server(struct donar_server_ctx* ctx, struct donar_params* dp) {
struct algo_params ap = {
.is_waiting_bootstrap = dp->is_waiting_bootstrap,
@ -80,6 +100,10 @@ void donar_server(struct donar_server_ctx* ctx, struct donar_params* dp) {
ctx->ports[i] = 7500 + i;
}
create_onion_services (&(ctx->tos), &(ctx->tctl), ctx->ports, dp->links, dp->tof);
ugly_global_tctl = &(ctx->tctl);
/*struct donar_server_os_republish_params dsorp = { .dctx = ctx, dp = dp};
init_timer(&(ctx->evts));
set_timeout(&(ctx->evts), 1000, &dsorp, republish_tor_os); */
printf("--- Onion services created\n");
init_tcp_servers(ctx, dp->links);
@ -95,5 +119,6 @@ void donar_server(struct donar_server_ctx* ctx, struct donar_params* dp) {
evt_core_loop (&(ctx->evts));
//stop_timer(&(ctx->evts));
destroy_resources (&(ctx->tos), &(ctx->tctl));
}

View file

@ -10,6 +10,7 @@
#include "evt_core.h"
#include "donar_init.h"
#include "proxy.h"
#include "timer.h"
#define PORT_SIZE 64

View file

@ -90,3 +90,14 @@ int set_timeout(struct evt_core_ctx* evts, uint64_t milli_sec, void* ctx, timer_
return fdinfo.fd;
}
void stop_timer(struct evt_core_ctx* evts) {
struct evt_core_cat* cat = evt_core_get_from_cat (evts, "set_timeout");
if (cat == NULL) {
fprintf(stderr, "timeout category does not exist\n");
return;
}
while (cat->socklist->len > 0) {
evt_core_rm_fd (evts, g_array_index (cat->socklist, struct evt_core_fdinfo*, 0)->fd);
}
}

View file

@ -5,3 +5,4 @@
typedef void (*timer_cb)(struct evt_core_ctx* ctx, void* user_data);
void init_timer(struct evt_core_ctx* evts);
int set_timeout(struct evt_core_ctx* evts, uint64_t milli_sec, void* ctx, timer_cb cb);
void stop_timer(struct evt_core_ctx* evts);

View file

@ -30,6 +30,27 @@ int tor_ctl_connect(struct tor_ctl* ctx, char* addr, char* service) {
return 0;
}
void tor_ctl_list_onions(struct tor_ctl* ctx) {
fprintf(ctx->wsock, "getinfo onions/current\n");
char delimiter, buffer[1024] = {0};
fscanf(ctx->rsock, " 250%c", &delimiter);
if (delimiter == '-') {
fscanf(ctx->rsock, "onions/current=%s", buffer);
if (strlen(buffer) > 0) printf("key: %s\n", buffer);
} else if (delimiter == '+') {
fscanf(ctx->rsock, "onions/current= ");
while (1) {
fgets(buffer, 1024, ctx->rsock);
if (strcmp(buffer, "250 OK\r\n") == 0) break;
if (strcmp(buffer, ".\r\n") == 0) continue;
printf("line: %s", buffer);
}
} else {
printf("deli:%c\n", delimiter);
}
}
int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, uint16_t* port, enum TOR_ONION_FLAGS flags) {
int err = 0;
char buffer1[1024] = {0};
@ -60,9 +81,9 @@ int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, uint16_t* por
/* Complete by creating new onion services */
for (int i = tos->filled; i < tos->size; i++) {
if (flags == TOR_ONION_FLAG_NONE)
fprintf(ctx->wsock, "add_onion NEW:RSA1024 Port=%d\n", port[i]);
fprintf(ctx->wsock, "add_onion NEW:ED25519-V3 Port=%d\n", port[i]);
else {
fprintf(ctx->wsock, "add_onion NEW:RSA1024 Port=%d Flags=", port[i]);
fprintf(ctx->wsock, "add_onion NEW:ED25519-V3 Port=%d Flags=", port[i]);
if (flags & TOR_ONION_FLAG_NON_ANONYMOUS)
fprintf(ctx->wsock, "NonAnonymous,");
fprintf(ctx->wsock, "\n");

View file

@ -21,4 +21,5 @@ enum TOR_ONION_FLAGS {
int tor_ctl_connect(struct tor_ctl* ctx, char* addr, char* service);
int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, uint16_t* port, enum TOR_ONION_FLAGS flags);
void tor_ctl_list_onions(struct tor_ctl* ctx);
void tor_ctl_close(struct tor_ctl* ctx);