tor_multipath_voip/src/donar.c

82 lines
2.1 KiB
C
Raw Normal View History

2019-02-08 13:28:39 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
2019-02-15 17:09:51 +00:00
#include <gmodule.h>
2019-02-11 21:40:00 +00:00
#include "algo_skel.h"
2019-02-11 09:23:38 +00:00
#include "donar_client.h"
#include "donar_server.h"
2019-02-08 13:28:39 +00:00
2019-02-15 17:09:51 +00:00
void free_port (void* ptr) {
free(ptr);
}
2019-02-08 13:28:39 +00:00
int main(int argc, char** argv) {
printf("~ Donar ~\n");
2019-02-11 09:23:38 +00:00
2019-02-13 14:32:38 +00:00
int opt, is_server, is_client, errored;
2019-02-15 17:09:51 +00:00
char *port, *onion_file, *algo;
2019-02-11 22:40:37 +00:00
onion_file = NULL;
2019-02-13 14:32:38 +00:00
algo = NULL;
2019-02-11 22:40:37 +00:00
is_server = 0;
is_client = 0;
2019-02-13 14:32:38 +00:00
errored = 0;
2019-02-15 17:09:51 +00:00
GPtrArray* ports = g_ptr_array_new_with_free_func (free_port);
2019-02-13 14:32:38 +00:00
while ((opt = getopt(argc, argv, "csh:p:o:a:")) != -1) {
2019-02-11 09:23:38 +00:00
switch(opt) {
case 's':
is_server = 1;
break;
2019-02-11 22:40:37 +00:00
case 'p':
port = strdup(optarg);
2019-02-15 17:09:51 +00:00
if (port == NULL) goto terminate;
g_ptr_array_add (ports, port);
2019-02-11 22:40:37 +00:00
break;
case 'o':
onion_file = strdup(optarg);
break;
2019-02-11 09:23:38 +00:00
case 'c':
is_client = 1;
break;
2019-02-13 14:32:38 +00:00
case 'a':
algo = strdup(optarg);
break;
2019-02-11 09:23:38 +00:00
default:
2019-02-13 14:32:38 +00:00
goto in_error;
2019-02-11 09:23:38 +00:00
}
}
2019-02-13 14:32:38 +00:00
if (!(is_server ^ is_client)) goto in_error;
if (algo == NULL) goto in_error;
2019-02-11 09:23:38 +00:00
2019-02-18 16:51:13 +00:00
struct algo_skel as = {0};
2019-02-13 14:32:38 +00:00
init_algo(&as, algo);
2019-02-11 15:23:20 +00:00
if (is_server) {
struct donar_server_ctx ctx;
2019-02-15 17:09:51 +00:00
if (ports->len < 1) goto in_error;
donar_server(&ctx, &as, ports);
2019-02-11 15:23:20 +00:00
} else if (is_client) {
struct donar_client_ctx ctx;
2019-02-15 17:09:51 +00:00
if (ports->len < 1 || onion_file == NULL) goto in_error;
donar_client(&ctx, &as, onion_file, ports);
2019-02-11 15:23:20 +00:00
}
2019-02-13 14:32:38 +00:00
goto terminate;
in_error:
errored = 1;
2019-02-15 17:09:51 +00:00
fprintf(stderr, "Usage as client : %s -c -a <algo> -p <udp port 1> -p <udp port 2> -o <onion service file>\n", argv[0]);
fprintf(stderr, "Usage as server : %s -s -a <algo> -p <udp port 1> -p <udp port 2>\n\n", argv[0]);
fprintf(stderr, "Passed parameters: client=%d, server=%d, algo=%s, registered_ports=%d, onion_file=%s\n",
is_client, is_server, algo, ports->len, onion_file);
2019-02-13 14:32:38 +00:00
terminate:
if (onion_file != NULL) free(onion_file);
if (algo != NULL) free(algo);
2019-02-18 20:55:53 +00:00
g_ptr_array_free(ports, TRUE);
2019-02-11 09:23:38 +00:00
2019-02-13 14:32:38 +00:00
return errored;
2019-02-08 13:28:39 +00:00
}