lokinet/daemon/rcutil.cpp

79 lines
1.7 KiB
C++
Raw Normal View History

2018-12-12 01:55:30 +00:00
#include <router_contact.hpp>
2018-07-24 03:40:34 +00:00
2019-08-12 21:47:30 +00:00
#include <cxxopts.hpp>
#include <string>
#include <vector>
2019-08-12 21:47:30 +00:00
bool dumpRc(const std::vector<std::string>& files)
2018-05-21 12:51:10 +00:00
{
2019-08-12 21:47:30 +00:00
for(const auto& file : files)
{
2019-08-12 21:47:30 +00:00
llarp::RouterContact rc;
const bool ret = rc.Read(file.c_str());
if (ret)
{
2019-08-12 21:47:30 +00:00
std::cout << "file = " << file << "\n";
std::cout << rc << "\n\n";
}
2019-08-12 21:47:30 +00:00
else
{
2019-08-12 21:47:30 +00:00
std::cerr << "file = " << file << " was not a valid rc file\n";
}
2018-05-21 12:51:10 +00:00
}
2019-08-12 21:47:30 +00:00
return true;
}
2019-08-12 21:47:30 +00:00
int
main(int argc, char *argv[])
{
#ifdef LOKINET_DEBUG
absl::SetMutexDeadlockDetectionMode(absl::OnDeadlockCycle::kAbort);
#endif
2019-08-12 21:47:30 +00:00
// clang-format off
cxxopts::Options options(
"lokinet-rcutil",
"LokiNET is a free, open source, private, decentralized, \"market based sybil resistant\" and IP based onion routing network"
);
2019-08-12 21:47:30 +00:00
options.add_options()
("v,verbose", "Verbose", cxxopts::value<bool>())
("h,help", "help", cxxopts::value<bool>())
("dump", "dump rc file", cxxopts::value<std::vector<std::string>>(), "FILE");
// clang-format on
2018-08-31 12:46:54 +00:00
2019-08-12 21:47:30 +00:00
try {
const auto result = options.parse(argc, argv);
2019-08-12 21:47:30 +00:00
if(result.count("verbose") > 0)
{
SetLogLevel(llarp::eLogDebug);
llarp::LogDebug("debug logging activated");
}
2019-08-12 21:47:30 +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
}
2019-08-12 21:47:30 +00:00
if(result.count("dump") > 0)
{
2019-08-12 21:47:30 +00:00
if (!dumpRc(result["dump"].as<std::vector<std::string>>()))
2018-08-31 12:46:54 +00:00
{
2019-08-12 21:47:30 +00:00
return 1;
2018-08-31 12:46:54 +00:00
}
}
2018-05-21 12:51:10 +00:00
}
2019-08-12 21:47:30 +00:00
catch(const cxxopts::OptionParseException &ex)
{
2019-08-12 21:47:30 +00:00
std::cerr << ex.what() << std::endl;
std::cout << options.help() << std::endl;
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
}