From ae76b6b376f0f75d69acc636965aa770a2136369 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 1 Feb 2018 08:21:00 -0500 Subject: [PATCH] google format --- .clang-format | 108 ----------------------------------- Makefile | 4 +- daemon/main.c | 6 +- include/llarp/crypto.h | 6 +- include/llarp/crypto_async.h | 50 +++++++++------- include/llarp/ev.h | 20 +++---- include/llarp/router.h | 4 +- include/llarp/threadpool.h | 9 ++- include/llarp/version.h | 6 +- llarp/address_info.cpp | 7 +-- llarp/address_info.hpp | 2 +- llarp/bencode.hpp | 10 ++-- llarp/config.cpp | 13 ++--- llarp/config.hpp | 2 +- llarp/crypto_async.c | 68 +++++++++++----------- llarp/crypto_libsodium.cpp | 44 +++++++------- llarp/ev.cpp | 82 ++++++++++---------------- llarp/exit_info.cpp | 2 +- llarp/exit_info.hpp | 5 +- llarp/ini.hpp | 60 +++++++------------ llarp/link.cpp | 5 +- llarp/link.hpp | 6 +- llarp/mem.hpp | 17 +++--- llarp/mem_jemalloc.cpp | 5 +- llarp/mem_std.cpp | 8 +-- llarp/router.cpp | 14 ++--- llarp/router_contact.cpp | 8 ++- llarp/str.hpp | 5 +- llarp/threadpool.cpp | 36 +++++------- llarp/threadpool.hpp | 8 +-- llarp/time.cpp | 7 ++- test/test_async_dh.c | 42 ++++++-------- test/test_cpp.cpp | 5 +- 33 files changed, 252 insertions(+), 422 deletions(-) delete mode 100644 .clang-format diff --git a/.clang-format b/.clang-format deleted file mode 100644 index a8a7ddd4a..000000000 --- a/.clang-format +++ /dev/null @@ -1,108 +0,0 @@ ---- -Language: Cpp -# BasedOnStyle: LLVM -AccessModifierOffset: -2 -AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false -AlignEscapedNewlines: Right -AlignOperands: true -AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: false -BinPackArguments: true -BinPackParameters: true -BraceWrapping: - AfterClass: false - AfterControlStatement: false - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false - BeforeElse: false - IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true -BreakBeforeBinaryOperators: None -BreakBeforeBraces: Attach -BreakBeforeInheritanceComma: false -BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -BreakConstructorInitializers: BeforeColon -BreakAfterJavaFieldAnnotations: false -BreakStringLiterals: true -ColumnLimit: 80 -CommentPragmas: '^ IWYU pragma:' -CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: false -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: true -DerivePointerAlignment: false -DisableFormat: false -ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: true -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - - Regex: '^(<|"(gtest|gmock|isl|json)/)' - Priority: 3 - - Regex: '.*' - Priority: 1 -IncludeIsMainRegex: '(Test)?$' -IndentCaseLabels: false -IndentWidth: 2 -IndentWrappedFunctionNames: false -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: true -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBlockIndentWidth: 2 -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 60 -PointerAlignment: Right -ReflowComments: true -SortIncludes: true -SortUsingDeclarations: true -SpaceAfterCStyleCast: false -SpaceAfterTemplateKeyword: true -SpaceBeforeAssignmentOperators: true -SpaceBeforeParens: ControlStatements -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 -SpacesInAngles: false -SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -Standard: Cpp11 -TabWidth: 2 -UseTab: Never -... - diff --git a/Makefile b/Makefile index 8597284d8..a558c4fb4 100644 --- a/Makefile +++ b/Makefile @@ -45,8 +45,8 @@ REQUIRED_LDFLAGS = $(LDFLAGS) -ljemalloc $(SODIUM_LIBS) $(LIBUV_LIBS) -lm -lstdc all: build -format: $(HDRS) $(SRCS) - $(FORMAT) -i $^ +format: + $(FORMAT) -style=Google -i $(HDRS) $(SRCS) build: $(EXE) diff --git a/daemon/main.c b/daemon/main.c index 79cb307be..ee5ff839c 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -43,8 +43,7 @@ int shutdown_llarp(struct llarp_main *m) { int main(int argc, char *argv[]) { struct llarp_main llarp = {NULL, NULL, NULL, NULL}; const char *conffname = "daemon.ini"; - if (argc > 1) - conffname = argv[1]; + if (argc > 1) conffname = argv[1]; llarp_mem_jemalloc(); llarp_new_config(&llarp.config); llarp_ev_loop_alloc(&llarp.mainloop); @@ -55,8 +54,7 @@ int main(int argc, char *argv[]) { iter.user = &llarp; iter.visit = iter_main_config; llarp_config_iter(llarp.config, &iter); - if (!llarp.tp) - llarp.tp = llarp_init_threadpool(2); + if (!llarp.tp) llarp.tp = llarp_init_threadpool(2); llarp.router = llarp_init_router(llarp.tp); if (!llarp_configure_router(llarp.router, llarp.config)) { printf("Running\n"); diff --git a/include/llarp/crypto.h b/include/llarp/crypto.h index aaaea01d2..5f1a7bf1e 100644 --- a/include/llarp/crypto.h +++ b/include/llarp/crypto.h @@ -25,13 +25,13 @@ typedef uint8_t llarp_hmacsec_t[HMACSECSIZE]; typedef uint8_t llarp_sig_t[SIGSIZE]; typedef uint8_t llarp_tunnel_nounce_t[TUNNOUNCESIZE]; -struct llarp_keypair -{ +struct llarp_keypair { llarp_pubkey_t pub; llarp_seckey_t sec; }; -typedef bool (*llarp_dh_func)(llarp_sharedkey_t *, llarp_pubkey_t, llarp_tunnel_nounce_t, llarp_seckey_t); +typedef bool (*llarp_dh_func)(llarp_sharedkey_t *, llarp_pubkey_t, + llarp_tunnel_nounce_t, llarp_seckey_t); struct llarp_crypto { bool (*xchacha20)(llarp_buffer_t, llarp_sharedkey_t, llarp_nounce_t); diff --git a/include/llarp/crypto_async.h b/include/llarp/crypto_async.h index 0e027a3cc..1290127b8 100644 --- a/include/llarp/crypto_async.h +++ b/include/llarp/crypto_async.h @@ -8,28 +8,34 @@ extern "C" { #endif - struct llarp_async_dh; - - struct llarp_async_dh * llarp_async_dh_new(struct llarp_crypto * crypto, struct llarp_ev_loop * ev, struct llarp_threadpool * tp); - void llarp_async_dh_free(struct llarp_async_dh ** dh); - - struct llarp_dh_result; - - typedef void (*llarp_dh_complete_hook)(struct llarp_dh_result *); - - - struct llarp_dh_internal; - - struct llarp_dh_result - { - struct llarp_dh_internal * impl; - llarp_sharedkey_t result; - void * user; - llarp_dh_complete_hook hook; - }; - - void llarp_async_client_dh(struct llarp_async_dh * dh, llarp_seckey_t ourkey, llarp_pubkey_t theirkey, llarp_tunnel_nounce_t nounce, llarp_dh_complete_hook result, void * user); - void llarp_async_server_dh(struct llarp_async_dh * dh, llarp_seckey_t ourkey, llarp_pubkey_t theirkey, llarp_tunnel_nounce_t nounce, llarp_dh_complete_hook result, void * user); +struct llarp_async_dh; + +struct llarp_async_dh *llarp_async_dh_new(struct llarp_crypto *crypto, + struct llarp_ev_loop *ev, + struct llarp_threadpool *tp); +void llarp_async_dh_free(struct llarp_async_dh **dh); + +struct llarp_dh_result; + +typedef void (*llarp_dh_complete_hook)(struct llarp_dh_result *); + +struct llarp_dh_internal; + +struct llarp_dh_result { + struct llarp_dh_internal *impl; + llarp_sharedkey_t result; + void *user; + llarp_dh_complete_hook hook; +}; + +void llarp_async_client_dh(struct llarp_async_dh *dh, llarp_seckey_t ourkey, + llarp_pubkey_t theirkey, + llarp_tunnel_nounce_t nounce, + llarp_dh_complete_hook result, void *user); +void llarp_async_server_dh(struct llarp_async_dh *dh, llarp_seckey_t ourkey, + llarp_pubkey_t theirkey, + llarp_tunnel_nounce_t nounce, + llarp_dh_complete_hook result, void *user); #ifdef __cplusplus } diff --git a/include/llarp/ev.h b/include/llarp/ev.h index 746c8ec3a..f9eab59b5 100644 --- a/include/llarp/ev.h +++ b/include/llarp/ev.h @@ -34,33 +34,33 @@ int llarp_ev_add_udp_listener(struct llarp_ev_loop *ev, int llarp_ev_close_udp_listener(struct llarp_udp_listener *listener); - struct llarp_ev_async_call; - +struct llarp_ev_async_call; + typedef void (*llarp_ev_work_func)(struct llarp_ev_async_call *); +struct llarp_ev_caller; - struct llarp_ev_caller; - struct llarp_ev_async_call { /** the loop this job belongs to */ const struct llarp_ev_loop *loop; /** private implementation */ - const struct llarp_ev_caller * parent; + const struct llarp_ev_caller *parent; /** user data */ const void *user; - /** + /** work is called async when ready in the event loop thread must not free from inside this call as it is done elsewhere */ const llarp_ev_work_func work; }; - struct llarp_ev_caller * llarp_ev_prepare_async(struct llarp_ev_loop *ev, llarp_ev_work_func func); +struct llarp_ev_caller *llarp_ev_prepare_async(struct llarp_ev_loop *ev, + llarp_ev_work_func func); + +bool llarp_ev_call_async(struct llarp_ev_caller *c, void *user); - bool llarp_ev_call_async(struct llarp_ev_caller * c, void * user); +void llarp_ev_caller_stop(struct llarp_ev_caller *c); - void llarp_ev_caller_stop(struct llarp_ev_caller * c); - #ifdef __cplusplus } #endif diff --git a/include/llarp/router.h b/include/llarp/router.h index dba127822..b3a5cf961 100644 --- a/include/llarp/router.h +++ b/include/llarp/router.h @@ -24,8 +24,8 @@ void llarp_stop_router(struct llarp_router *router); /** get router's inbound link level frame queue */ struct llarp_link_queue *llarp_router_link_queue(struct llarp_router *router); /** get router's outbound link level frame dispatcher */ -struct llarp_link_dispatcher * -llarp_router_link_dispatcher(struct llarp_router *router); +struct llarp_link_dispatcher *llarp_router_link_dispatcher( + struct llarp_router *router); #ifdef __cplusplus } diff --git a/include/llarp/threadpool.h b/include/llarp/threadpool.h index cf289e84c..f5161bde8 100644 --- a/include/llarp/threadpool.h +++ b/include/llarp/threadpool.h @@ -10,17 +10,16 @@ struct llarp_threadpool; struct llarp_threadpool *llarp_init_threadpool(int workers); void llarp_free_threadpool(struct llarp_threadpool **tp); - typedef void (*llarp_thread_work_func)(void*); +typedef void (*llarp_thread_work_func)(void *); - /** job to be done in worker thread */ struct llarp_thread_job { /** called async after work is executed */ - struct llarp_ev_caller * caller; - void * data; - + struct llarp_ev_caller *caller; + void *data; + /** user data to pass to work function */ void *user; /** called in threadpool worker thread */ diff --git a/include/llarp/version.h b/include/llarp/version.h index 94ba65f31..03ca6d679 100644 --- a/include/llarp/version.h +++ b/include/llarp/version.h @@ -15,11 +15,11 @@ #ifndef LLARP_VERSION_NUM #ifdef GIT_REV -#define LLARP_VERSION_NUM \ - "-" LLARP_VERSION_MAJ "." LLARP_VERSION_MIN "." LLARP_VERSION_PATCH \ +#define LLARP_VERSION_NUM \ + "-" LLARP_VERSION_MAJ "." LLARP_VERSION_MIN "." LLARP_VERSION_PATCH \ "-" GIT_REV #else -#define LLARP_VERSION_NUM \ +#define LLARP_VERSION_NUM \ "-" LLARP_VERSION_MAJ "." LLARP_VERSION_MIN "." LLARP_VERSION_PATCH #endif #endif diff --git a/llarp/address_info.cpp b/llarp/address_info.cpp index 716251789..f7147a63a 100644 --- a/llarp/address_info.cpp +++ b/llarp/address_info.cpp @@ -4,7 +4,7 @@ namespace llarp { static void *ai_alloc(size_t sz, size_t align) {} -} // namespace llarp +} // namespace llarp extern "C" { @@ -19,8 +19,7 @@ void llarp_ai_list_iterate(struct llarp_ai_list *l, itr->list = l; struct llarp_ai_list *cur = l; do { - if (!itr->visit(itr, cur->data)) - return; + if (!itr->visit(itr, cur->data)) return; cur = cur->next; } while (cur->next); } @@ -36,4 +35,4 @@ bool BEncode(const llarp_ai &a, llarp_buffer_t *buff) { bencodeDict_Int(buff, "p", a.port) && bencodeDict_Int(buff, "v", 0) && bencodeEnd(buff); } -} // namespace llarp +} // namespace llarp diff --git a/llarp/address_info.hpp b/llarp/address_info.hpp index 095eb1e31..aec492cdf 100644 --- a/llarp/address_info.hpp +++ b/llarp/address_info.hpp @@ -1,8 +1,8 @@ #ifndef LLARP_AI_HPP #define LLARP_AI_HPP +#include #include #include -#include struct llarp_ai_list { llarp_ai *data; diff --git a/llarp/bencode.hpp b/llarp/bencode.hpp index 91dc60d0e..4c2fac8ac 100644 --- a/llarp/bencode.hpp +++ b/llarp/bencode.hpp @@ -1,14 +1,15 @@ #ifndef LLARP_BENCODE_HPP #define LLARP_BENCODE_HPP -#include #include +#include #include namespace llarp { template bool BEncode(const ValType &t, llarp_buffer_t *buff); -template bool BDecode(ValType &t, llarp_buffer_t *buff); +template +bool BDecode(ValType &t, llarp_buffer_t *buff); static bool bencodeDict(llarp_buffer_t *buff) { static uint8_t c = 'd'; @@ -50,12 +51,11 @@ template bool BEncode(const std::list &l, llarp_buffer_t *buff) { if (bencodeList(buff)) { for (const auto &itr : l) - if (!BEncode(itr, buff)) - return false; + if (!BEncode(itr, buff)) return false; return bencodeEnd(buff); } return false; } -} // namespace llarp +} // namespace llarp #endif diff --git a/llarp/config.cpp b/llarp/config.cpp index ffb46ff11..20a5ee3bf 100644 --- a/llarp/config.cpp +++ b/llarp/config.cpp @@ -1,15 +1,14 @@ #include "config.hpp" +#include #include "ini.hpp" #include "mem.hpp" -#include namespace llarp { template static Section find_section(Config &c, const std::string &name, const Section &fallback) { - if (c.sections.find(name) == c.sections.end()) - return fallback; + if (c.sections.find(name) == c.sections.end()) return fallback; return c.sections[name].values; } @@ -28,7 +27,7 @@ bool Config::Load(const char *fname) { return false; }; -} // namespace llarp +} // namespace llarp extern "C" { @@ -38,14 +37,12 @@ void llarp_new_config(struct llarp_config **conf) { } void llarp_free_config(struct llarp_config **conf) { - if (*conf) - delete *conf; + if (*conf) delete *conf; *conf = nullptr; } int llarp_load_config(struct llarp_config *conf, const char *fname) { - if (!conf->impl.Load(fname)) - return -1; + if (!conf->impl.Load(fname)) return -1; return 0; } diff --git a/llarp/config.hpp b/llarp/config.hpp index 492ddd3cf..6a3bcda27 100644 --- a/llarp/config.hpp +++ b/llarp/config.hpp @@ -16,7 +16,7 @@ struct Config { bool Load(const char *fname); }; -} // namespace llarp +} // namespace llarp extern "C" { struct llarp_config { diff --git a/llarp/crypto_async.c b/llarp/crypto_async.c index 54fd96e47..cac1958da 100644 --- a/llarp/crypto_async.c +++ b/llarp/crypto_async.c @@ -2,16 +2,14 @@ #include #include -struct llarp_async_dh -{ +struct llarp_async_dh { llarp_dh_func client; llarp_dh_func server; - struct llarp_threadpool * tp; - struct llarp_ev_caller * caller; + struct llarp_threadpool *tp; + struct llarp_ev_caller *caller; }; -struct llarp_dh_internal -{ +struct llarp_dh_internal { llarp_dh_func func; llarp_pubkey_t theirkey; llarp_seckey_t ourkey; @@ -19,22 +17,23 @@ struct llarp_dh_internal struct llarp_dh_result result; }; -static void llarp_crypto_dh_work(void * user) -{ - struct llarp_dh_internal * impl = (struct llarp_dh_internal *)user; +static void llarp_crypto_dh_work(void *user) { + struct llarp_dh_internal *impl = (struct llarp_dh_internal *)user; impl->func(&impl->result.result, impl->theirkey, impl->nounce, impl->ourkey); } -static void llarp_crypto_dh_result(struct llarp_ev_async_call * call) -{ - struct llarp_dh_internal * impl = (struct llarp_dh_internal *) call->user; +static void llarp_crypto_dh_result(struct llarp_ev_async_call *call) { + struct llarp_dh_internal *impl = (struct llarp_dh_internal *)call->user; impl->result.hook(&impl->result); llarp_g_mem.free(impl); } -static void llarp_async_dh_exec(struct llarp_async_dh * dh, llarp_dh_func func, llarp_seckey_t ourkey, llarp_pubkey_t theirkey, llarp_tunnel_nounce_t nounce, llarp_dh_complete_hook result, void * user) -{ - struct llarp_dh_internal * impl = llarp_g_mem.alloc(sizeof(struct llarp_dh_internal), 16); +static void llarp_async_dh_exec(struct llarp_async_dh *dh, llarp_dh_func func, + llarp_seckey_t ourkey, llarp_pubkey_t theirkey, + llarp_tunnel_nounce_t nounce, + llarp_dh_complete_hook result, void *user) { + struct llarp_dh_internal *impl = + llarp_g_mem.alloc(sizeof(struct llarp_dh_internal), 16); memcpy(impl->theirkey, theirkey, sizeof(llarp_pubkey_t)); memcpy(impl->ourkey, ourkey, sizeof(llarp_seckey_t)); memcpy(impl->nounce, nounce, sizeof(llarp_tunnel_nounce_t)); @@ -42,31 +41,32 @@ static void llarp_async_dh_exec(struct llarp_async_dh * dh, llarp_dh_func func, impl->result.user = user; impl->result.hook = result; impl->func = func; - struct llarp_thread_job job = { - .caller = dh->caller, - .data = impl, - .user = impl, - .work = &llarp_crypto_dh_work - }; + struct llarp_thread_job job = {.caller = dh->caller, + .data = impl, + .user = impl, + .work = &llarp_crypto_dh_work}; llarp_threadpool_queue_job(dh->tp, job); } - -void llarp_async_client_dh(struct llarp_async_dh * dh, llarp_seckey_t ourkey, llarp_pubkey_t theirkey, llarp_tunnel_nounce_t nounce, llarp_dh_complete_hook result, void * user) -{ +void llarp_async_client_dh(struct llarp_async_dh *dh, llarp_seckey_t ourkey, + llarp_pubkey_t theirkey, + llarp_tunnel_nounce_t nounce, + llarp_dh_complete_hook result, void *user) { llarp_async_dh_exec(dh, dh->client, ourkey, theirkey, nounce, result, user); } -void llarp_async_server_dh(struct llarp_async_dh * dh, llarp_seckey_t ourkey, llarp_pubkey_t theirkey, llarp_tunnel_nounce_t nounce, llarp_dh_complete_hook result, void * user) -{ +void llarp_async_server_dh(struct llarp_async_dh *dh, llarp_seckey_t ourkey, + llarp_pubkey_t theirkey, + llarp_tunnel_nounce_t nounce, + llarp_dh_complete_hook result, void *user) { llarp_async_dh_exec(dh, dh->server, ourkey, theirkey, nounce, result, user); } - - -struct llarp_async_dh * llarp_async_dh_new(struct llarp_crypto * crypto, struct llarp_ev_loop * ev, struct llarp_threadpool * tp) -{ - struct llarp_async_dh * dh = llarp_g_mem.alloc(sizeof(struct llarp_async_dh), 16); +struct llarp_async_dh *llarp_async_dh_new(struct llarp_crypto *crypto, + struct llarp_ev_loop *ev, + struct llarp_threadpool *tp) { + struct llarp_async_dh *dh = + llarp_g_mem.alloc(sizeof(struct llarp_async_dh), 16); dh->client = crypto->dh_client; dh->server = crypto->dh_server; dh->tp = tp; @@ -74,10 +74,8 @@ struct llarp_async_dh * llarp_async_dh_new(struct llarp_crypto * crypto, struct return dh; } -void llarp_async_dh_free(struct llarp_async_dh ** dh) -{ - if(*dh) - { +void llarp_async_dh_free(struct llarp_async_dh **dh) { + if (*dh) { llarp_ev_caller_stop((*dh)->caller); llarp_g_mem.free(*dh); *dh = NULL; diff --git a/llarp/crypto_libsodium.cpp b/llarp/crypto_libsodium.cpp index 955ade8e2..28025dffe 100644 --- a/llarp/crypto_libsodium.cpp +++ b/llarp/crypto_libsodium.cpp @@ -1,21 +1,21 @@ +#include #include #include -#include namespace llarp { namespace sodium { -static bool xchacha20(llarp_buffer_t buff, llarp_sharedkey_t k, llarp_nounce_t n) { +static bool xchacha20(llarp_buffer_t buff, llarp_sharedkey_t k, + llarp_nounce_t n) { uint8_t *base = (uint8_t *)buff.base; return crypto_stream_xchacha20_xor(base, base, buff.sz, n, k) == 0; } -static bool dh(llarp_sharedkey_t *shared, uint8_t *client_pk, uint8_t *server_pk, - uint8_t *remote_key, uint8_t *local_key) { +static bool dh(llarp_sharedkey_t *shared, uint8_t *client_pk, + uint8_t *server_pk, uint8_t *remote_key, uint8_t *local_key) { uint8_t *out = *shared; const size_t outsz = SHAREDKEYSIZE; crypto_generichash_state h; - if (crypto_scalarmult(out, local_key, remote_key) == -1) - return false; + if (crypto_scalarmult(out, local_key, remote_key) == -1) return false; crypto_generichash_init(&h, NULL, 0U, outsz); crypto_generichash_update(&h, client_pk, sizeof(llarp_pubkey_t)); crypto_generichash_update(&h, server_pk, sizeof(llarp_pubkey_t)); @@ -25,7 +25,7 @@ static bool dh(llarp_sharedkey_t *shared, uint8_t *client_pk, uint8_t *server_pk } static bool dh_client(llarp_sharedkey_t *shared, llarp_pubkey_t pk, - llarp_tunnel_nounce_t n, llarp_seckey_t sk) { + llarp_tunnel_nounce_t n, llarp_seckey_t sk) { llarp_pubkey_t local_pk; crypto_scalarmult_base(local_pk, sk); if (dh(shared, local_pk, pk, pk, sk)) { @@ -36,7 +36,7 @@ static bool dh_client(llarp_sharedkey_t *shared, llarp_pubkey_t pk, } static bool dh_server(llarp_sharedkey_t *shared, llarp_pubkey_t pk, - llarp_tunnel_nounce_t n, llarp_seckey_t sk) { + llarp_tunnel_nounce_t n, llarp_seckey_t sk) { llarp_pubkey_t local_pk; crypto_scalarmult_base(local_pk, sk); if (dh(shared, pk, local_pk, pk, sk)) { @@ -51,13 +51,15 @@ static bool hash(llarp_hash_t *result, llarp_buffer_t buff) { return crypto_generichash(*result, HASHSIZE, base, buff.sz, nullptr, 0) != -1; } -static bool hmac(llarp_hash_t *result, llarp_buffer_t buff, llarp_seckey_t secret) { +static bool hmac(llarp_hash_t *result, llarp_buffer_t buff, + llarp_seckey_t secret) { const uint8_t *base = (const uint8_t *)buff.base; return crypto_generichash(*result, sizeof(llarp_hash_t), base, buff.sz, secret, HMACSECSIZE) != -1; } -static bool sign(llarp_sig_t *result, llarp_seckey_t secret, llarp_buffer_t buff) { +static bool sign(llarp_sig_t *result, llarp_seckey_t secret, + llarp_buffer_t buff) { const uint8_t *base = (const uint8_t *)buff.base; return crypto_sign_detached(*result, nullptr, base, buff.sz, secret) != -1; } @@ -67,19 +69,17 @@ static bool verify(llarp_pubkey_t pub, llarp_buffer_t buff, llarp_sig_t sig) { return crypto_sign_verify_detached(sig, base, buff.sz, pub) != -1; } - static void randomize(llarp_buffer_t buff) - { - randombytes((unsigned char *)buff.base, buff.sz); - } +static void randomize(llarp_buffer_t buff) { + randombytes((unsigned char *)buff.base, buff.sz); +} - static void keygen(struct llarp_keypair * keys) - { - randombytes(keys->sec, sizeof(llarp_seckey_t)); - unsigned char sk[64]; - crypto_sign_seed_keypair(keys->pub, sk, keys->sec); - } -} // namespace sodium -} // namespace llarp +static void keygen(struct llarp_keypair *keys) { + randombytes(keys->sec, sizeof(llarp_seckey_t)); + unsigned char sk[64]; + crypto_sign_seed_keypair(keys->pub, sk, keys->sec); +} +} // namespace sodium +} // namespace llarp extern "C" { void llarp_crypto_libsodium_init(struct llarp_crypto *c) { diff --git a/llarp/ev.cpp b/llarp/ev.cpp index 2f07a415c..6f5abceb8 100644 --- a/llarp/ev.cpp +++ b/llarp/ev.cpp @@ -1,65 +1,48 @@ -#include "mem.hpp" #include #include +#include "mem.hpp" #include #include -struct llarp_ev_caller -{ - static void * operator new(size_t sz) - { +struct llarp_ev_caller { + static void *operator new(size_t sz) { return llarp::Alloc(); } - static void operator delete(void * ptr) - { - llarp_g_mem.free(ptr); - } - + static void operator delete(void *ptr) { llarp_g_mem.free(ptr); } - llarp_ev_caller(llarp_ev_loop * ev, llarp_ev_work_func func) : - loop(ev), - work(func) - { + llarp_ev_caller(llarp_ev_loop *ev, llarp_ev_work_func func) + : loop(ev), work(func) { async.data = this; } - ~llarp_ev_caller() - { - } + ~llarp_ev_caller() {} - bool appendCall(void * user) - { + bool appendCall(void *user) { std::unique_lock lock(access); bool should = pending.size() == 0; - llarp_ev_async_call * call = new llarp_ev_async_call{ - loop, - this, - user, - this->work}; + llarp_ev_async_call *call = + new llarp_ev_async_call{loop, this, user, this->work}; pending.push(call); return should; } - void Call() - { + void Call() { std::unique_lock lock(access); - while(pending.size() > 0) - { - auto & front = pending.front(); + while (pending.size() > 0) { + auto &front = pending.front(); front->work(front); pending.pop(); } } - + std::mutex access; - struct llarp_ev_loop * loop; + struct llarp_ev_loop *loop; uv_async_t async; std::queue pending; llarp_ev_work_func work; }; - struct llarp_ev_loop { uv_loop_t _loop; @@ -85,14 +68,12 @@ struct udp_listener { struct llarp_udp_listener *listener; void recvfrom(const struct sockaddr *addr, char *buff, ssize_t sz) { - if (listener->recvfrom) - listener->recvfrom(listener, addr, buff, sz); + if (listener->recvfrom) listener->recvfrom(listener, addr, buff, sz); } /** called after closed */ void closed() { - if (listener->closed) - listener->closed(listener); + if (listener->closed) listener->closed(listener); listener->impl = nullptr; } @@ -116,7 +97,7 @@ static void udp_close_cb(uv_handle_t *handle) { l->closed(); delete l; } -} // namespace llarp +} // namespace llarp namespace llarp { @@ -126,10 +107,10 @@ static void ev_caller_async_closed(uv_handle_t *handle) { } static void ev_handle_async_call(uv_async_t *handle) { - llarp_ev_caller * caller = static_cast(handle->data); + llarp_ev_caller *caller = static_cast(handle->data); caller->Call(); } -} // namespace llarp +} // namespace llarp extern "C" { void llarp_ev_loop_alloc(struct llarp_ev_loop **ev) { @@ -189,29 +170,26 @@ int llarp_ev_close_udp_listener(struct llarp_udp_listener *listener) { void llarp_ev_loop_stop(struct llarp_ev_loop *loop) { uv_stop(loop->loop()); } - struct llarp_ev_caller * llarp_ev_prepare_async(struct llarp_ev_loop * loop, llarp_ev_work_func work) -{ - llarp_ev_caller * caller = new llarp_ev_caller(loop, work); - if(uv_async_init(loop->loop(), &caller->async, llarp::ev_handle_async_call) == 0) +struct llarp_ev_caller *llarp_ev_prepare_async(struct llarp_ev_loop *loop, + llarp_ev_work_func work) { + llarp_ev_caller *caller = new llarp_ev_caller(loop, work); + if (uv_async_init(loop->loop(), &caller->async, + llarp::ev_handle_async_call) == 0) return caller; - else - { + else { delete caller; return nullptr; } } -bool llarp_ev_call_async(struct llarp_ev_caller * caller, void * user) -{ - if(caller->appendCall(user)) +bool llarp_ev_call_async(struct llarp_ev_caller *caller, void *user) { + if (caller->appendCall(user)) return uv_async_send(&caller->async) == 0; else return true; } -void llarp_ev_caller_stop(struct llarp_ev_caller * caller) -{ - uv_close((uv_handle_t*)&caller->async, llarp::ev_caller_async_closed); +void llarp_ev_caller_stop(struct llarp_ev_caller *caller) { + uv_close((uv_handle_t *)&caller->async, llarp::ev_caller_async_closed); } - } diff --git a/llarp/exit_info.cpp b/llarp/exit_info.cpp index 333b61013..cac0be313 100644 --- a/llarp/exit_info.cpp +++ b/llarp/exit_info.cpp @@ -14,4 +14,4 @@ bool BEncode(const llarp_xi &xi, llarp_buffer_t *buff) { bencodeDict_Bytes(buff, "b", &xi.netmask, sizeof(xi.netmask)) && bencodeDict_Int(buff, "v", 0) && bencodeEnd(buff); } -} // namespace llarp +} // namespace llarp diff --git a/llarp/exit_info.hpp b/llarp/exit_info.hpp index 206e0b377..e81b6ea69 100644 --- a/llarp/exit_info.hpp +++ b/llarp/exit_info.hpp @@ -1,7 +1,7 @@ #ifndef LLARP_XI_HPP #define LLARP_XI_HPP -#include #include +#include struct llarp_xi_list { std::list list; @@ -10,8 +10,7 @@ struct llarp_xi_list { static std::list xi_list_to_std(struct llarp_xi_list *l) { std::list list; if (l->list.size()) - for (const auto &xi : l->list) - list.push_back(xi); + for (const auto &xi : l->list) list.push_back(xi); return list; } diff --git a/llarp/ini.hpp b/llarp/ini.hpp index cb410a544..a677d4a22 100644 --- a/llarp/ini.hpp +++ b/llarp/ini.hpp @@ -46,7 +46,7 @@ struct Level { typedef std::list sections_t; value_map_t values; section_map_t sections; - values_t ordered_values; // original order in the ini file + values_t ordered_values; // original order in the ini file sections_t ordered_sections; Level *parent; size_t depth; @@ -58,20 +58,20 @@ struct Level { }; class Parser { -public: + public: Parser(const std::string &fname) : Parser(fname.c_str()) {} Parser(const char *fn); Parser(std::istream &f) : f_(&f), ln_(0) { parse(top_); } Level &top() { return top_; } void dump(std::ostream &s) { dump(s, top(), ""); } -private: + private: void dump(std::ostream &s, const Level &l, const std::string &sname); void parse(Level &l); void parseSLine(std::string &sname, size_t &depth); void err(const char *s); -private: + private: Level top_; std::ifstream f0_; std::istream *f_; @@ -90,17 +90,14 @@ inline std::string trim(const std::string &s) { long sp = 0; long ep = s.length() - 1; for (; sp <= ep; ++sp) - if (!strchr(p, s[sp])) - break; + if (!strchr(p, s[sp])) break; for (; ep >= 0; --ep) - if (!strchr(p, s[ep])) - break; + if (!strchr(p, s[ep])) break; return s.substr(sp, ep - sp + 1); } inline Parser::Parser(const char *fn) : f0_(fn), f_(&f0_), ln_(0) { - if (!f0_) - throw std::runtime_error(std::string("failed to open file: ") + fn); + if (!f0_) throw std::runtime_error(std::string("failed to open file: ") + fn); parse(top_); } @@ -108,8 +105,7 @@ inline Parser::Parser(const char *fn) : f0_(fn), f_(&f0_), ln_(0) { inline void Parser::parseSLine(std::string &sname, size_t &depth) { depth = 0; for (; depth < line_.length(); ++depth) - if (line_[depth] != '[') - break; + if (line_[depth] != '[') break; sname = line_.substr(depth, line_.length() - 2 * depth); } @@ -117,31 +113,26 @@ inline void Parser::parseSLine(std::string &sname, size_t &depth) { inline void Parser::parse(Level &l) { while (std::getline(*f_, line_)) { ++ln_; - if (line_[0] == '#' || line_[0] == ';') - continue; + if (line_[0] == '#' || line_[0] == ';') continue; line_ = trim(line_); - if (line_.empty()) - continue; + if (line_.empty()) continue; if (line_[0] == '[') { size_t depth; std::string sname; parseSLine(sname, depth); Level *lp = NULL; Level *parent = &l; - if (depth > l.depth + 1) - err("section with wrong depth"); + if (depth > l.depth + 1) err("section with wrong depth"); if (l.depth == depth - 1) lp = &l.sections[sname]; else { lp = l.parent; size_t n = l.depth - depth; - for (size_t i = 0; i < n; ++i) - lp = lp->parent; + for (size_t i = 0; i < n; ++i) lp = lp->parent; parent = lp; lp = &lp->sections[sname]; } - if (lp->depth != 0) - err("duplicate section name on the same level"); + if (lp->depth != 0) err("duplicate section name on the same level"); if (!lp->parent) { lp->depth = depth; lp->parent = parent; @@ -150,13 +141,11 @@ inline void Parser::parse(Level &l) { parse(*lp); } else { size_t n = line_.find('='); - if (n == std::string::npos) - err("no '=' found"); + if (n == std::string::npos) err("no '=' found"); std::pair res = l.values.insert( std::make_pair(trim(line_.substr(0, n)), trim(line_.substr(n + 1, line_.length() - n - 1)))); - if (!res.second) - err("duplicated key found"); + if (!res.second) err("duplicated key found"); l.ordered_values.push_back(res.first); } } @@ -164,16 +153,11 @@ inline void Parser::parse(Level &l) { inline void Parser::dump(std::ostream &s, const Level &l, const std::string &sname) { - if (!sname.empty()) - s << '\n'; - for (size_t i = 0; i < l.depth; ++i) - s << '['; - if (!sname.empty()) - s << sname; - for (size_t i = 0; i < l.depth; ++i) - s << ']'; - if (!sname.empty()) - s << std::endl; + if (!sname.empty()) s << '\n'; + for (size_t i = 0; i < l.depth; ++i) s << '['; + if (!sname.empty()) s << sname; + for (size_t i = 0; i < l.depth; ++i) s << ']'; + if (!sname.empty()) s << std::endl; for (Level::values_t::const_iterator it = l.ordered_values.begin(); it != l.ordered_values.end(); ++it) s << (*it)->first << '=' << (*it)->second << std::endl; @@ -184,6 +168,6 @@ inline void Parser::dump(std::ostream &s, const Level &l, } } -} // namespace ini +} // namespace ini -#endif // INI_HPP +#endif // INI_HPP diff --git a/llarp/link.cpp b/llarp/link.cpp index 0e02aa9b0..b471e4ba4 100644 --- a/llarp/link.cpp +++ b/llarp/link.cpp @@ -1,6 +1,6 @@ #include "link.hpp" -#include #include +#include bool operator<(const sockaddr_in6 addr0, const sockaddr_in6 addr1) { return memcmp(addr0.sin6_addr.s6_addr, addr1.sin6_addr.s6_addr, @@ -14,8 +14,7 @@ struct llarp_link *llarp_link_alloc() { } void llarp_link_free(struct llarp_link **l) { - if (*l) - delete *l; + if (*l) delete *l; *l = nullptr; } diff --git a/llarp/link.hpp b/llarp/link.hpp index 89c0388ec..8a770e449 100644 --- a/llarp/link.hpp +++ b/llarp/link.hpp @@ -1,15 +1,15 @@ #ifndef LLARP_LINK_HPP #define LLARP_LINK_HPP +#include +#include #include #include -#include #include #include -#include -#include "mem.hpp" #include #include +#include "mem.hpp" struct llarp_link { static void *operator new(size_t sz) { diff --git a/llarp/mem.hpp b/llarp/mem.hpp index 5f6f4fe38..1e8cff691 100644 --- a/llarp/mem.hpp +++ b/llarp/mem.hpp @@ -1,18 +1,17 @@ #ifndef LLARP_MEM_HPP #define LLARP_MEM_HPP -#include #include +#include namespace llarp { -template static constexpr size_t alignment() { +template +static constexpr size_t alignment() { return std::exp2(1 + std::floor(std::log2(sizeof(T)))); } - template - static T * Alloc(llarp_alloc * mem=&llarp_g_mem) - { - return static_cast( - mem->alloc(sizeof(T), alignment())); - } -} // namespace llarp +template +static T *Alloc(llarp_alloc *mem = &llarp_g_mem) { + return static_cast(mem->alloc(sizeof(T), alignment())); +} +} // namespace llarp #endif diff --git a/llarp/mem_jemalloc.cpp b/llarp/mem_jemalloc.cpp index fc603453e..7da50bc64 100644 --- a/llarp/mem_jemalloc.cpp +++ b/llarp/mem_jemalloc.cpp @@ -7,10 +7,9 @@ static void *jem_malloc(size_t sz, size_t align) { } static void jem_free(void *ptr) { - if (ptr) - free(ptr); + if (ptr) free(ptr); } -} // namespace llarp +} // namespace llarp extern "C" { void llarp_mem_jemalloc() { diff --git a/llarp/mem_std.cpp b/llarp/mem_std.cpp index 33db5dd2f..be497e6a9 100644 --- a/llarp/mem_std.cpp +++ b/llarp/mem_std.cpp @@ -4,17 +4,15 @@ namespace llarp { void *std_malloc(size_t sz, size_t align) { (void)align; void *ptr = malloc(sz); - if (ptr) - return ptr; + if (ptr) return ptr; abort(); } void std_free(void *ptr) { - if (ptr) - free(ptr); + if (ptr) free(ptr); } -} // namespace llarp +} // namespace llarp extern "C" { void llarp_mem_std() { diff --git a/llarp/router.cpp b/llarp/router.cpp index 08d3c6e5b..e415ac6fa 100644 --- a/llarp/router.cpp +++ b/llarp/router.cpp @@ -1,8 +1,8 @@ +#include +#include #include "link.hpp" #include "mem.hpp" #include "str.hpp" -#include -#include namespace llarp { void router_iter_config(llarp_config_iterator *iter, const char *section, @@ -12,7 +12,7 @@ struct router_links { struct router_links *next = nullptr; }; -} // namespace llarp +} // namespace llarp struct llarp_router { struct llarp_threadpool *tp; @@ -27,8 +27,7 @@ struct llarp_router { void AddLink(struct llarp_link *link) { llarp::router_links *head = &links; - while (head->next && head->link) - head = head->next; + while (head->next && head->link) head = head->next; if (head->link) head->next = new llarp::router_links{link, nullptr}; @@ -39,8 +38,7 @@ struct llarp_router { void ForEachLink(std::function visitor) { llarp::router_links *cur = &links; do { - if (cur->link) - visitor(cur->link); + if (cur->link) visitor(cur->link); cur = cur->next; } while (cur); } @@ -102,4 +100,4 @@ void router_iter_config(llarp_config_iterator *iter, const char *section, } } } -} // namespace llarp +} // namespace llarp diff --git a/llarp/router_contact.cpp b/llarp/router_contact.cpp index aa97f2819..6a11ebd45 100644 --- a/llarp/router_contact.cpp +++ b/llarp/router_contact.cpp @@ -3,7 +3,11 @@ #include "bencode.hpp" #include "exit_info.hpp" -extern "C" {} +extern "C" { +bool llarp_rc_bencode(struct llarp_rc *rc, llarp_buffer_t *buff) { + return llarp::BEncode(*rc, buff); +} +} namespace llarp { bool BEncode(const llarp_rc &a, llarp_buffer_t *buff) { @@ -17,4 +21,4 @@ bool BEncode(const llarp_rc &a, llarp_buffer_t *buff) { bencodeDict_Bytes(buff, "z", a.signature, sizeof(a.signature)) && bencodeEnd(buff); } -} // namespace llarp +} // namespace llarp diff --git a/llarp/str.hpp b/llarp/str.hpp index a130bf367..1e1b1b5ee 100644 --- a/llarp/str.hpp +++ b/llarp/str.hpp @@ -16,11 +16,10 @@ static size_t UStrLen(const uint8_t *data, size_t maxsz) { size_t sz = 0; while (*data++) { sz++; - if (maxsz >= sz) - return maxsz; + if (maxsz >= sz) return maxsz; } return sz; } -} // namespace llarp +} // namespace llarp #endif diff --git a/llarp/threadpool.cpp b/llarp/threadpool.cpp index 9feacfcdc..af647d13a 100644 --- a/llarp/threadpool.cpp +++ b/llarp/threadpool.cpp @@ -4,25 +4,23 @@ namespace llarp { namespace thread { Pool::Pool(size_t workers) { - stop.store(false); + stop = false; while (workers--) { threads.emplace_back([this] { + llarp_thread_job job; for (;;) { - llarp_thread_job job; { lock_t lock(this->queue_mutex); this->condition.wait( lock, [this] { return this->stop || !this->jobs.empty(); }); - if (this->stop && this->jobs.empty()) - return; + if (this->stop && this->jobs.empty()) return; job = std::move(this->jobs.front()); this->jobs.pop(); } // do work job.work(job.user); // inform result if needed - if (job.caller) - { + if (job.caller) { if (!llarp_ev_call_async(job.caller, job.data)) { std::cerr << "failed to queue result in thread worker" << std::endl; } @@ -35,11 +33,10 @@ Pool::Pool(size_t workers) { void Pool::Join() { { lock_t lock(queue_mutex); - stop.store(true); + stop = true; } condition.notify_all(); - for (auto &t : threads) - t.join(); + for (auto &t : threads) t.join(); } void Pool::QueueJob(llarp_thread_job job) { @@ -47,16 +44,15 @@ void Pool::QueueJob(llarp_thread_job job) { lock_t lock(queue_mutex); // don't allow enqueueing after stopping the pool - if (stop) - throw std::runtime_error("enqueue on stopped ThreadPool"); + if (stop) throw std::runtime_error("enqueue on stopped ThreadPool"); jobs.emplace(job); } condition.notify_one(); } -} // namespace thread -} // namespace llarp +} // namespace thread +} // namespace llarp struct llarp_threadpool { llarp::thread::Pool impl; @@ -75,16 +71,14 @@ struct llarp_threadpool *llarp_init_threadpool(int workers) { void llarp_threadpool_join(struct llarp_threadpool *pool) { pool->impl.Join(); } -void llarp_threadpool_start(struct llarp_threadpool * pool) -{ - /** no op */ +void llarp_threadpool_start(struct llarp_threadpool *pool) { /** no op */ +} + +void llarp_threadpool_queue_job(struct llarp_threadpool *pool, + struct llarp_thread_job job) { + pool->impl.QueueJob(job); } - void llarp_threadpool_queue_job(struct llarp_threadpool * pool, struct llarp_thread_job job) - { - pool->impl.QueueJob(job); - } - void llarp_free_threadpool(struct llarp_threadpool **pool) { delete *pool; *pool = nullptr; diff --git a/llarp/threadpool.hpp b/llarp/threadpool.hpp index 3d0e42136..e98d5b7b1 100644 --- a/llarp/threadpool.hpp +++ b/llarp/threadpool.hpp @@ -3,7 +3,6 @@ #include -#include #include #include #include @@ -15,7 +14,6 @@ namespace thread { typedef std::mutex mtx_t; typedef std::unique_lock lock_t; struct Pool { - Pool(size_t sz); void QueueJob(llarp_thread_job job); void Join(); @@ -24,10 +22,10 @@ struct Pool { mtx_t queue_mutex; std::condition_variable condition; - std::atomic stop; + bool stop; }; -} // namespace thread -} // namespace llarp +} // namespace thread +} // namespace llarp #endif diff --git a/llarp/time.cpp b/llarp/time.cpp index 0a9696ab6..351eda5bc 100644 --- a/llarp/time.cpp +++ b/llarp/time.cpp @@ -1,15 +1,16 @@ -#include #include +#include namespace llarp { typedef std::chrono::steady_clock clock_t; -template static IntType time_since_epoch() { +template +static IntType time_since_epoch() { return std::chrono::duration_cast( llarp::clock_t::now().time_since_epoch()) .count(); } -} // namespace llarp +} // namespace llarp extern "C" { llarp_time_t llarp_time_now_ms() { diff --git a/test/test_async_dh.c b/test/test_async_dh.c index 601543fd4..f258571c1 100644 --- a/test/test_async_dh.c +++ b/test/test_async_dh.c @@ -3,33 +3,28 @@ #include -struct dh_bench_main -{ +struct dh_bench_main { size_t completed; size_t num; - struct llarp_ev_loop * ev; - struct llarp_async_dh * dh; + struct llarp_ev_loop *ev; + struct llarp_async_dh *dh; }; -static void handle_dh_complete(struct llarp_dh_result * res) -{ - struct dh_bench_main * m = (struct dh_bench_main *) res->user; +static void handle_dh_complete(struct llarp_dh_result *res) { + struct dh_bench_main *m = (struct dh_bench_main *)res->user; m->completed++; - if(m->completed % 1000 == 0) - printf("completed %ld\n", m->completed); - if(m->completed == m->num) - { + if (m->completed % 1000 == 0) printf("completed %ld\n", m->completed); + if (m->completed == m->num) { printf("we done\n"); llarp_ev_loop_stop(m->ev); } } -int main(int argc, char * argv[]) -{ +int main(int argc, char *argv[]) { struct dh_bench_main dh_main; struct llarp_crypto crypto; - struct llarp_threadpool * tp; - + struct llarp_threadpool *tp; + llarp_mem_jemalloc(); llarp_crypto_libsodium_init(&crypto); llarp_ev_loop_alloc(&dh_main.ev); @@ -38,32 +33,31 @@ int main(int argc, char * argv[]) dh_main.dh = llarp_async_dh_new(&crypto, dh_main.ev, tp); llarp_threadpool_start(tp); - /* do work here */ - dh_main.num = 100000; + dh_main.num = 1000000; dh_main.completed = 0; struct llarp_keypair ourkey; struct llarp_keypair theirkey; crypto.keygen(&ourkey); crypto.keygen(&theirkey); - - + llarp_tunnel_nounce_t nounce; llarp_buffer_t n_buff; n_buff.base = nounce; n_buff.cur = n_buff.base; n_buff.sz = sizeof(llarp_tunnel_nounce_t); - + size_t sz = dh_main.num; printf("starting %ld dh jobs\n", sz); - while(sz--) - { + /* do work here */ + while (sz--) { crypto.randomize(n_buff); - llarp_async_client_dh(dh_main.dh, ourkey.sec, theirkey.pub, nounce, handle_dh_complete, &dh_main); + llarp_async_client_dh(dh_main.dh, ourkey.sec, theirkey.pub, nounce, + handle_dh_complete, &dh_main); } printf("started %ld dh jobs\n", dh_main.num); llarp_ev_loop_run(dh_main.ev); - + llarp_threadpool_join(tp); llarp_async_dh_free(&dh_main.dh); diff --git a/test/test_cpp.cpp b/test/test_cpp.cpp index 70b510c6e..58d66aa42 100644 --- a/test/test_cpp.cpp +++ b/test/test_cpp.cpp @@ -1,6 +1,3 @@ -int main(int argc, char * argv[]) -{ - return 0; -} +int main(int argc, char *argv[]) { return 0; }