1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/daemon/rcutil.cpp

100 lines
2.1 KiB
C++
Raw Normal View History

2018-12-12 02:55:30 +01:00
#include <router_contact.hpp>
2019-08-13 00:09:44 +02:00
#include <util/logger.hpp>
#include <util/ostream_logger.hpp>
2018-07-24 05:40:34 +02:00
2019-08-13 02:26:25 +02:00
#include <absl/synchronization/mutex.h>
2019-08-12 23:47:30 +02:00
#include <cxxopts.hpp>
#include <string>
#include <vector>
2019-08-13 00:10:07 +02:00
bool
dumpRc(const std::vector< std::string >& files, bool json)
2018-05-21 14:51:10 +02:00
{
2019-08-13 00:10:07 +02:00
nlohmann::json result;
for(const auto& file : files)
{
llarp::RouterContact rc;
const bool ret = rc.Read(file.c_str());
2019-08-12 23:47:30 +02:00
2019-08-13 00:10:07 +02:00
if(ret)
{
if(json)
{
result[file] = rc.ToJson();
}
else
{
std::cout << "file = " << file << "\n";
std::cout << rc << "\n\n";
}
}
else
{
std::cerr << "file = " << file << " was not a valid rc file\n";
2018-05-21 14:51:10 +02:00
}
2019-08-13 00:10:07 +02:00
}
2019-08-13 00:10:07 +02:00
if(json)
std::cout << result << "\n";
2019-08-13 00:09:44 +02:00
2019-08-13 00:10:07 +02:00
return true;
2019-08-12 23:47:30 +02:00
}
2019-08-12 23:47:30 +02:00
int
2019-08-13 00:10:07 +02:00
main(int argc, char* argv[])
2019-08-12 23:47:30 +02:00
{
#ifdef LOKINET_DEBUG
absl::SetMutexDeadlockDetectionMode(absl::OnDeadlockCycle::kAbort);
#endif
2019-08-12 23:47:30 +02: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 23:47:30 +02:00
options.add_options()
("v,verbose", "Verbose", cxxopts::value<bool>())
("h,help", "help", cxxopts::value<bool>())
2019-08-13 00:09:44 +02:00
("j,json", "output in json", cxxopts::value<bool>())
2019-08-13 00:10:07 +02:00
("dump", "dump rc file", cxxopts::value<std::vector<std::string> >(), "FILE");
2019-08-12 23:47:30 +02:00
// clang-format on
2018-08-31 14:46:54 +02:00
2019-08-13 00:10:07 +02:00
try
{
2019-08-12 23:47:30 +02:00
const auto result = options.parse(argc, argv);
2019-08-13 00:10:07 +02:00
const bool json = result["json"].as< bool >();
2019-08-13 00:09:44 +02:00
2019-08-12 23:47:30 +02:00
if(result.count("verbose") > 0)
{
SetLogLevel(llarp::eLogDebug);
2019-08-13 00:10:07 +02:00
llarp::LogContext::Instance().logStream =
std::make_unique< llarp::OStreamLogStream >(std::cerr);
2019-08-12 23:47:30 +02:00
llarp::LogDebug("debug logging activated");
}
2019-08-12 23:47:30 +02:00
if(result.count("help") > 0)
2018-08-31 14:46:54 +02:00
{
2019-08-12 23:47:30 +02:00
std::cout << options.help() << std::endl;
return 0;
2018-08-31 14:46:54 +02:00
}
2019-08-12 23:47:30 +02:00
if(result.count("dump") > 0)
{
2019-08-13 00:10:07 +02:00
if(!dumpRc(result["dump"].as< std::vector< std::string > >(), json))
2018-08-31 14:46:54 +02:00
{
2019-08-13 00:10:07 +02:00
return 1;
2018-08-31 14:46:54 +02:00
}
}
2018-05-21 14:51:10 +02:00
}
2019-08-13 00:10:07 +02:00
catch(const cxxopts::OptionParseException& ex)
{
2019-08-12 23:47:30 +02:00
std::cerr << ex.what() << std::endl;
std::cout << options.help() << std::endl;
return 1;
}
2018-08-03 01:30:34 +02:00
2019-08-12 23:47:30 +02:00
return 0;
2018-05-21 14:51:10 +02:00
}