Skip to content

Commit

Permalink
The Great Wall of Blame
Browse files Browse the repository at this point in the history
  • Loading branch information
notlesh committed Apr 7, 2020
1 parent 8ed4631 commit a19d4fb
Show file tree
Hide file tree
Showing 325 changed files with 8,630 additions and 9,800 deletions.
2 changes: 1 addition & 1 deletion .clang-format
@@ -1,5 +1,5 @@
BasedOnStyle: Google
AlignAfterOpenBracket: Align
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: 'false'
AlignConsecutiveDeclarations: 'false'
AlignEscapedNewlinesLeft: 'true'
Expand Down
71 changes: 33 additions & 38 deletions daemon/lokinetctl.cpp
Expand Up @@ -14,15 +14,15 @@
namespace
{
bool
dumpRc(const std::vector< std::string >& files)
dumpRc(const std::vector<std::string>& files)
{
nlohmann::json result;
for(const auto& file : files)
for (const auto& file : files)
{
llarp::RouterContact rc;
const bool ret = rc.Read(file.c_str());

if(ret)
if (ret)
{
result[file] = rc.ToJson();
}
Expand All @@ -40,10 +40,10 @@ namespace
size_t
curlCallback(void* contents, size_t size, size_t nmemb, void* userp) noexcept
{
auto* str = static_cast< std::string* >(userp);
auto* str = static_cast<std::string*>(userp);
size_t realsize = size * nmemb;

char* asChar = static_cast< char* >(contents);
char* asChar = static_cast<char*>(contents);

std::copy(asChar, asChar + realsize, std::back_inserter(*str));

Expand All @@ -57,32 +57,29 @@ namespace
curl_global_init(CURL_GLOBAL_ALL);

llarp::Config config;
if(!config.Load(configFile.c_str()))
if (!config.Load(configFile.c_str()))
{
llarp::LogError("Failed to load from config file: ", configFile);
return false;
}

if(!config.api.enableRPCServer())
if (!config.api.enableRPCServer())
{
llarp::LogError("Config does not have RPC enabled");
return false;
}

std::string address = config.api.rpcBindAddr() + "/jsonrpc";

const nlohmann::json request{{"method", command},
{"params", nlohmann::json::object()},
{"id", "foo"}};
const nlohmann::json request{
{"method", command}, {"params", nlohmann::json::object()}, {"id", "foo"}};

const std::string requestStr = request.dump();

std::unique_ptr< curl_slist, void (*)(curl_slist*) > chunk(
curl_slist_append(nullptr, "content-type: application/json"),
&curl_slist_free_all);
std::unique_ptr<curl_slist, void (*)(curl_slist*)> chunk(
curl_slist_append(nullptr, "content-type: application/json"), &curl_slist_free_all);

std::unique_ptr< CURL, void (*)(CURL*) > curl(curl_easy_init(),
&curl_easy_cleanup);
std::unique_ptr<CURL, void (*)(CURL*)> curl(curl_easy_init(), &curl_easy_cleanup);
curl_easy_setopt(curl.get(), CURLOPT_URL, address.c_str());
curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDS, requestStr.c_str());
curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDSIZE, requestStr.size());
Expand All @@ -93,7 +90,7 @@ namespace
curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, &result);

auto res = curl_easy_perform(curl.get());
if(res != CURLE_OK)
if (res != CURLE_OK)
{
llarp::LogError("Failed to curl endpoint, ", curl_easy_strerror(res));
return false;
Expand All @@ -109,66 +106,64 @@ namespace
int
main(int argc, char* argv[])
{
cxxopts::Options options("lokinetctl",
"LokiNET is a free, open source, private, "
"decentralized, \"market based sybil resistant\" "
"and IP based onion routing network");

options.add_options()("v,verbose", "Verbose", cxxopts::value< bool >())(
"h,help", "help", cxxopts::value< bool >())(
cxxopts::Options options(
"lokinetctl",
"LokiNET is a free, open source, private, "
"decentralized, \"market based sybil resistant\" "
"and IP based onion routing network");

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()))
cxxopts::value<std::string>()->default_value(llarp::GetDefaultConfigPath().string()))
#ifdef WITH_CURL
("j,jsonrpc", "hit json rpc endpoint", cxxopts::value< std::string >())
("j,jsonrpc", "hit json rpc endpoint", cxxopts::value<std::string>())
#endif
("dump", "dump rc file",
cxxopts::value< std::vector< std::string > >(), "FILE");
("dump", "dump rc file", cxxopts::value<std::vector<std::string>>(), "FILE");

try
{
const auto result = options.parse(argc, argv);

if(result.count("verbose") > 0)
if (result.count("verbose") > 0)
{
SetLogLevel(llarp::eLogDebug);
llarp::LogContext::Instance().logStream =
std::make_unique< llarp::OStreamLogStream >(true, std::cerr);
std::make_unique<llarp::OStreamLogStream>(true, std::cerr);
llarp::LogDebug("debug logging activated");
}
else
{
SetLogLevel(llarp::eLogError);
llarp::LogContext::Instance().logStream =
std::make_unique< llarp::OStreamLogStream >(true, std::cerr);
std::make_unique<llarp::OStreamLogStream>(true, std::cerr);
}

if(result.count("help") > 0)
if (result.count("help") > 0)
{
std::cout << options.help() << std::endl;
return 0;
}

if(result.count("dump") > 0)
if (result.count("dump") > 0)
{
if(!dumpRc(result["dump"].as< std::vector< std::string > >()))
if (!dumpRc(result["dump"].as<std::vector<std::string>>()))
{
return 1;
}
}

#ifdef WITH_CURL
if(result.count("jsonrpc") > 0)
if (result.count("jsonrpc") > 0)
{
if(!executeJsonRpc(result["jsonrpc"].as< std::string >(),
result["config"].as< std::string >()))
if (!executeJsonRpc(result["jsonrpc"].as<std::string>(), result["config"].as<std::string>()))
{
return 1;
}
}
#endif
}
catch(const cxxopts::OptionParseException& ex)
catch (const cxxopts::OptionParseException& ex)
{
std::cerr << ex.what() << std::endl;
std::cout << options.help() << std::endl;
Expand Down

0 comments on commit a19d4fb

Please sign in to comment.