#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) { for (uint16_t i = 0; i < CLIENT_PORT_SIZE ; i++) { ctx->ports[i] = 7500 + i; } int sock1, sock2, err; char target_host[255]; for (int i = 0; i < CLIENT_PORT_SIZE; ) { sock1 = create_tcp_client("127.0.0.1", "9050"); err = socks5_handshake(sock1); if (err < 0) goto failed_socks5; if (strlen(ctx->tos.keys[i].pub) > 254) { fprintf(stderr, "Domain name is too long\n"); exit(EXIT_FAILURE); } sprintf(target_host, "%s.onion", ctx->tos.keys[i].pub); err = socks5_connect_dns(sock1, target_host, ctx->ports[i]); if (err < 0) goto failed_socks5; err = socks5_reply(sock1); if (err < 0) goto failed_socks5; sock2 = dup(sock1); if (sock2 < 0) goto failed_socks5; evt_core_add_fd (&(ctx->evts), "tcp-read", sock1); evt_core_add_fd (&(ctx->evts), "tcp-write", sock2); printf("Socket %d/%d %s:%d has been added to the pool\n", i+1, CLIENT_PORT_SIZE, target_host, ctx->ports[i]); i++; continue; failed_socks5: fprintf(stderr, "Failed connection for socket %d/%d. Sleeping 2 seconds...\n",i+1, CLIENT_PORT_SIZE); close(sock1); sleep(2); } } 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"); init_tcp_clients(ctx); printf("--- TCP Clients Connected\n"); // TODO: Debug that, listen UDP and launch loop }