2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/config/config.hpp>
|
|
|
|
#include <llarp/router_contact.hpp>
|
|
|
|
#include <llarp/util/logging/logger.hpp>
|
|
|
|
#include <llarp/util/logging/ostream_logger.hpp>
|
2018-07-24 03:40:34 +00:00
|
|
|
|
2019-08-12 21:47:30 +00:00
|
|
|
#include <cxxopts.hpp>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2018-08-17 10:40:40 +00:00
|
|
|
|
2019-10-05 16:48:05 +00:00
|
|
|
namespace
|
2018-05-21 12:51:10 +00:00
|
|
|
{
|
2019-10-05 16:48:05 +00:00
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
dumpRc(const std::vector<std::string>& files)
|
2019-08-12 22:10:07 +00:00
|
|
|
{
|
2019-10-05 16:48:05 +00:00
|
|
|
nlohmann::json result;
|
2020-04-07 18:38:56 +00:00
|
|
|
for (const auto& file : files)
|
2019-08-12 22:10:07 +00:00
|
|
|
{
|
2019-10-05 16:48:05 +00:00
|
|
|
llarp::RouterContact rc;
|
|
|
|
const bool ret = rc.Read(file.c_str());
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
if (ret)
|
2019-08-12 22:10:07 +00:00
|
|
|
{
|
|
|
|
result[file] = rc.ToJson();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-05 16:48:05 +00:00
|
|
|
std::cerr << "file = " << file << " was not a valid rc file\n";
|
2019-08-12 22:10:07 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-05 16:48:05 +00:00
|
|
|
std::cout << result << "\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2018-09-19 12:22:34 +00:00
|
|
|
|
2019-08-12 21:47:30 +00:00
|
|
|
int
|
2019-08-12 22:10:07 +00:00
|
|
|
main(int argc, char* argv[])
|
2019-08-12 21:47:30 +00:00
|
|
|
{
|
2020-04-07 20:41:11 +00:00
|
|
|
cxxopts::Options options(
|
|
|
|
"lokinetctl",
|
|
|
|
"LokiNET is a free, open source, private, "
|
|
|
|
"decentralized, \"market based sybil resistant\" "
|
|
|
|
"and IP based onion routing network");
|
2020-03-27 16:38:50 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
options.add_options()("v,verbose", "Verbose", cxxopts::value<bool>())(
|
|
|
|
"h,help", "help", cxxopts::value<bool>())(
|
|
|
|
"c,config",
|
|
|
|
"config file",
|
|
|
|
cxxopts::value<std::string>()->default_value(llarp::GetDefaultConfigPath().string()))(
|
|
|
|
"dump", "dump rc file", cxxopts::value<std::vector<std::string>>(), "FILE");
|
2018-08-31 12:46:54 +00:00
|
|
|
|
2019-08-12 22:10:07 +00:00
|
|
|
try
|
|
|
|
{
|
2019-08-12 21:47:30 +00:00
|
|
|
const auto result = options.parse(argc, argv);
|
2018-08-24 16:07:17 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
if (result.count("verbose") > 0)
|
2019-08-12 21:47:30 +00:00
|
|
|
{
|
|
|
|
SetLogLevel(llarp::eLogDebug);
|
2019-08-12 22:10:07 +00:00
|
|
|
llarp::LogContext::Instance().logStream =
|
2020-04-07 18:38:56 +00:00
|
|
|
std::make_unique<llarp::OStreamLogStream>(true, std::cerr);
|
2019-08-12 21:47:30 +00:00
|
|
|
llarp::LogDebug("debug logging activated");
|
|
|
|
}
|
2019-10-05 16:48:05 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLogLevel(llarp::eLogError);
|
|
|
|
llarp::LogContext::Instance().logStream =
|
2020-04-07 18:38:56 +00:00
|
|
|
std::make_unique<llarp::OStreamLogStream>(true, std::cerr);
|
2019-10-05 16:48:05 +00:00
|
|
|
}
|
2018-08-24 16:07:17 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
if (result.count("help") > 0)
|
2018-08-31 12:46:54 +00:00
|
|
|
{
|
2019-08-12 21:47:30 +00:00
|
|
|
std::cout << options.help() << std::endl;
|
|
|
|
return 0;
|
2018-08-31 12:46:54 +00:00
|
|
|
}
|
2018-08-24 16:07:17 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
if (result.count("dump") > 0)
|
2018-08-24 16:07:17 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!dumpRc(result["dump"].as<std::vector<std::string>>()))
|
2018-08-31 12:46:54 +00:00
|
|
|
{
|
2019-08-12 22:10:07 +00:00
|
|
|
return 1;
|
2018-08-31 12:46:54 +00:00
|
|
|
}
|
2018-08-24 16:07:17 +00:00
|
|
|
}
|
2018-05-21 12:51:10 +00:00
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
catch (const cxxopts::OptionParseException& ex)
|
2018-09-27 18:08:42 +00:00
|
|
|
{
|
2019-08-12 21:47:30 +00:00
|
|
|
std::cerr << ex.what() << std::endl;
|
|
|
|
std::cout << options.help() << std::endl;
|
2018-09-27 18:08:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2018-08-02 23:30:34 +00:00
|
|
|
|
2019-08-12 21:47:30 +00:00
|
|
|
return 0;
|
2018-05-21 12:51:10 +00:00
|
|
|
}
|