Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The git blame wall #1216

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
20 changes: 14 additions & 6 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BasedOnStyle: Google
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: 'true'
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: 'false'
AlignConsecutiveDeclarations: 'false'
AlignEscapedNewlinesLeft: 'true'
AlignOperands: 'false'
Expand All @@ -19,14 +19,22 @@ BreakBeforeTernaryOperators: 'true'
BreakConstructorInitializersBeforeComma: 'true'
Cpp11BracedListStyle: 'true'
KeepEmptyLinesAtTheStartOfBlocks: 'false'
Language: Cpp
NamespaceIndentation: All
PenaltyBreakString: '3'
SpaceBeforeParens: Never
SpacesInAngles: 'true'
SpaceBeforeParens: ControlStatements
SpacesInAngles: 'false'
SpacesInContainerLiterals: 'false'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
Standard: Cpp11
UseTab: Never
SortIncludes: false
SortIncludes: false
ColumnLimit: 100

# pointers and reference declaration are part of the type
DerivePointerAlignment: false
PointerAlignment: Left

# when wrapping function calls/declarations, force each parameter to have its own line
BinPackParameters: 'false'
BinPackArguments: 'false'
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
[submodule "external/date"]
path = external/date
url = https://github.com/HowardHinnant/date.git
[submodule "external/clang-format-hooks"]
path = external/clang-format-hooks
url = https://github.com/barisione/clang-format-hooks/
74 changes: 35 additions & 39 deletions daemon/lokinetctl.cpp
Original file line number Diff line number Diff line change
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,65 @@ 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 >())(
"c,config", "config file",
cxxopts::value< std::string >()->default_value(
llarp::GetDefaultConfigPath().string()))
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()))
#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