From 2610239d62d744294e55d44e46937bd6dea87559 Mon Sep 17 00:00:00 2001 From: tiptorrent development team Date: Tue, 17 Aug 2021 00:05:31 +0200 Subject: initial commit --- src/main.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/main.c (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..fd543a2 --- /dev/null +++ b/src/main.c @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2020-2021 Soleta Networks + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + */ + +#include "core.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int max_clients = DEFAULT_MAX_CLIENTS; +const char *root = "."; +bool redirect; + +static struct option tip_repo_opts[] = { + { "max-clients", 1, 0, 'n' }, + { "redirect", 0, 0, 'r' }, + { "root", 1, 0, 't' }, + { NULL }, +}; + +struct ev_io ev_io_server_rest; + +int main(int argc, char *argv[]) +{ + int socket_rest, val; + + openlog("tiptorrent", LOG_PID, LOG_DAEMON); + + tip_main_loop = ev_default_loop(0); + + if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) + exit(EXIT_FAILURE); + + while (1) { + val = getopt_long(argc, argv, "n:r", tip_repo_opts, NULL); + if (val < 0) + break; + + switch (val) { + case 'n': + max_clients = atoi(optarg); + if (max_clients <= 0) { + syslog(LOG_ERR, "Invalid number for max_clients"); + return EXIT_FAILURE; + } + break; + case 'r': + redirect = true; + break; + case 't': + root = strdup(optarg); + break; + case '?': + return EXIT_FAILURE; + default: + break; + } + } + + socket_rest = tip_socket_server_init("9999"); + if (socket_rest < 0) { + syslog(LOG_ERR, "Cannot open tiptorrent server socket\n"); + exit(EXIT_FAILURE); + } + + ev_io_init(&ev_io_server_rest, tip_server_accept_cb, socket_rest, EV_READ); + ev_io_start(tip_main_loop, &ev_io_server_rest); + + syslog(LOG_INFO, "Waiting for connections\n"); + + while (1) + ev_loop(tip_main_loop, 0); + + exit(EXIT_SUCCESS); +} -- cgit v1.2.3-18-g5258