2018-05-27 20:03:10 +02:00
|
|
|
#include <llarp.h>
|
2018-05-18 20:27:13 +02:00
|
|
|
#include <signal.h>
|
2018-07-11 13:04:15 +02:00
|
|
|
#include <llarp/logger.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <sys/param.h> // for MIN
|
2018-05-20 18:15:16 +02:00
|
|
|
|
2018-05-27 20:03:10 +02:00
|
|
|
struct llarp_main *ctx = 0;
|
2018-04-30 18:14:20 +02:00
|
|
|
|
2018-05-22 17:54:19 +02:00
|
|
|
void
|
|
|
|
handle_signal(int sig)
|
2018-05-18 19:50:21 +02:00
|
|
|
{
|
2018-05-27 19:44:01 +02:00
|
|
|
if(ctx)
|
2018-05-27 20:03:10 +02:00
|
|
|
llarp_main_signal(ctx, sig);
|
2018-05-18 19:50:21 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 14:59:15 +02:00
|
|
|
#ifndef TESTNET
|
2018-06-06 23:23:57 +02:00
|
|
|
#define TESTNET 0
|
2018-06-06 14:59:15 +02:00
|
|
|
#endif
|
|
|
|
|
2018-05-22 17:54:19 +02:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2018-01-29 15:27:24 +01:00
|
|
|
const char *conffname = "daemon.ini";
|
2018-07-11 13:04:15 +02:00
|
|
|
int c;
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"config", required_argument, 0, 'c'},
|
|
|
|
{"logLevel", required_argument, 0, 'o'},
|
|
|
|
{0, 0, 0, 0}};
|
|
|
|
int option_index = 0;
|
|
|
|
c = getopt_long(argc, argv, "c:o:", long_options, &option_index);
|
|
|
|
if(c == -1)
|
|
|
|
break;
|
|
|
|
switch(c)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
conffname = optarg;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
if (strncmp(optarg, "debug", MIN(strlen(optarg), (unsigned long)5))==0)
|
|
|
|
{
|
|
|
|
cSetLogLevel(eLogDebug);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (strncmp(optarg, "info", MIN(strlen(optarg), (unsigned long)4))==0)
|
|
|
|
{
|
|
|
|
cSetLogLevel(eLogInfo);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (strncmp(optarg, "warn", MIN(strlen(optarg), (unsigned long)4))==0)
|
|
|
|
{
|
|
|
|
cSetLogLevel(eLogWarn);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (strncmp(optarg, "error", MIN(strlen(optarg), (unsigned long)5))==0)
|
|
|
|
{
|
|
|
|
cSetLogLevel(eLogError);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-06 14:59:15 +02:00
|
|
|
ctx = llarp_main_init(conffname, !TESTNET);
|
2018-05-27 21:13:25 +02:00
|
|
|
int code = 1;
|
|
|
|
if(ctx)
|
2018-05-27 20:03:10 +02:00
|
|
|
{
|
|
|
|
signal(SIGINT, handle_signal);
|
2018-05-27 21:13:25 +02:00
|
|
|
code = llarp_main_run(ctx);
|
2018-07-11 13:04:15 +02:00
|
|
|
//llarp_main_free(ctx);
|
2018-05-27 20:03:10 +02:00
|
|
|
}
|
2018-05-27 21:13:25 +02:00
|
|
|
return code;
|
2017-09-28 19:02:05 +02:00
|
|
|
}
|