mirror of https://github.com/oxen-io/lokinet
clang-format
parent
a704a28f34
commit
de3ddbb93e
@ -0,0 +1,108 @@
|
||||
---
|
||||
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
|
||||
...
|
||||
|
@ -1,8 +1,8 @@
|
||||
#ifndef SARP_NET_H
|
||||
#define SARP_NET_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#endif
|
||||
|
@ -1,70 +1,61 @@
|
||||
#ifndef LLARP_BENCODE_HPP
|
||||
#define LLARP_BENCODE_HPP
|
||||
#include <llarp/buffer.h>
|
||||
#include <list>
|
||||
#include <llarp/buffer.h>
|
||||
#include <string>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
template<typename ValType>
|
||||
bool BEncode(const ValType & t, llarp_buffer_t * buff);
|
||||
namespace llarp {
|
||||
template <typename ValType>
|
||||
bool BEncode(const ValType &t, llarp_buffer_t *buff);
|
||||
|
||||
template<typename ValType>
|
||||
bool BDecode(ValType & t, llarp_buffer_t * buff);
|
||||
template <typename ValType> bool BDecode(ValType &t, llarp_buffer_t *buff);
|
||||
|
||||
static bool bencodeDict(llarp_buffer_t * buff)
|
||||
{
|
||||
static bool bencodeDict(llarp_buffer_t *buff) {
|
||||
static uint8_t c = 'd';
|
||||
return llarp_buffer_write(buff, &c, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static bool bencodeList(llarp_buffer_t * buff)
|
||||
{
|
||||
static bool bencodeList(llarp_buffer_t *buff) {
|
||||
static uint8_t c = 'l';
|
||||
return llarp_buffer_write(buff, &c, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static bool bencodeEnd(llarp_buffer_t * buff)
|
||||
{
|
||||
static bool bencodeEnd(llarp_buffer_t *buff) {
|
||||
static char c = 'e';
|
||||
return llarp_buffer_write(buff, &c, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static bool bencodeDictKey(llarp_buffer_t * buff, const std::string & key)
|
||||
{
|
||||
static bool bencodeDictKey(llarp_buffer_t *buff, const std::string &key) {
|
||||
std::string kstr = std::to_string(key.size()) + ":" + key;
|
||||
return llarp_buffer_write(buff, kstr.c_str(), kstr.size());
|
||||
}
|
||||
}
|
||||
|
||||
template<typename IntType>
|
||||
static bool bencodeDict_Int(llarp_buffer_t * buff, const std::string & key, IntType i)
|
||||
{
|
||||
template <typename IntType>
|
||||
static bool bencodeDict_Int(llarp_buffer_t *buff, const std::string &key,
|
||||
IntType i) {
|
||||
std::string istr = "i" + std::to_string(i) + "e";
|
||||
return bencodeDictKey(buff, key) &&
|
||||
llarp_buffer_write(buff, istr.c_str(), istr.size());
|
||||
}
|
||||
}
|
||||
|
||||
static bool bencodeDict_Bytes(llarp_buffer_t * buff, const std::string & key, const void * data, size_t sz)
|
||||
{
|
||||
static bool bencodeDict_Bytes(llarp_buffer_t *buff, const std::string &key,
|
||||
const void *data, size_t sz) {
|
||||
std::string sz_str = std::to_string(sz) + ":";
|
||||
return bencodeDictKey(buff, key) &&
|
||||
llarp_buffer_write(buff, sz_str.c_str(), sz_str.size()) &&
|
||||
llarp_buffer_write(buff, data, sz);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool BEncode(const std::list<T> & l, llarp_buffer_t * buff)
|
||||
{
|
||||
if(bencodeList(buff))
|
||||
{
|
||||
for(const auto & itr : l)
|
||||
if(!BEncode(itr, buff))
|
||||
template <typename T>
|
||||
bool BEncode(const std::list<T> &l, llarp_buffer_t *buff) {
|
||||
if (bencodeList(buff)) {
|
||||
for (const auto &itr : l)
|
||||
if (!BEncode(itr, buff))
|
||||
return false;
|
||||
return bencodeEnd(buff);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
||||
|
@ -1,33 +1,26 @@
|
||||
#ifndef LLARP_LINK_HPP
|
||||
#define LLARP_LINK_HPP
|
||||
#include <netinet/in.h>
|
||||
#include <llarp/crypto.h>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <llarp/crypto.h>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "mem.hpp"
|
||||
#include <llarp/ev.h>
|
||||
#include <llarp/router_contact.h>
|
||||
#include "mem.hpp"
|
||||
|
||||
|
||||
struct llarp_link
|
||||
{
|
||||
static void * operator new(size_t sz)
|
||||
{
|
||||
struct llarp_link {
|
||||
static void *operator new(size_t sz) {
|
||||
return llarp_g_mem.alloc(sz, llarp::alignment<llarp_link>());
|
||||
}
|
||||
|
||||
static void operator delete(void * ptr)
|
||||
{
|
||||
llarp_g_mem.free(ptr);
|
||||
}
|
||||
static void operator delete(void *ptr) { llarp_g_mem.free(ptr); }
|
||||
|
||||
struct sockaddr_in6 localaddr;
|
||||
int af;
|
||||
llarp_udp_listener listener;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1,8 +1,5 @@
|
||||
#include <llarp/mem.h>
|
||||
|
||||
extern "C" {
|
||||
struct llarp_alloc llarp_g_mem = {
|
||||
.alloc = nullptr,
|
||||
.free = nullptr
|
||||
};
|
||||
struct llarp_alloc llarp_g_mem = {.alloc = nullptr, .free = nullptr};
|
||||
}
|
||||
|
@ -1,14 +1,11 @@
|
||||
#ifndef LLARP_MEM_HPP
|
||||
#define LLARP_MEM_HPP
|
||||
#include <llarp/mem.h>
|
||||
#include <cmath>
|
||||
namespace llarp
|
||||
{
|
||||
template<typename T>
|
||||
static constexpr size_t alignment()
|
||||
{
|
||||
return std::exp2(1+std::floor(std::log2(sizeof(T))));
|
||||
}
|
||||
#include <llarp/mem.h>
|
||||
namespace llarp {
|
||||
template <typename T> static constexpr size_t alignment() {
|
||||
return std::exp2(1 + std::floor(std::log2(sizeof(T))));
|
||||
}
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
||||
|
@ -1,23 +1,20 @@
|
||||
#include <llarp/mem.h>
|
||||
#include <jemalloc/jemalloc.h>
|
||||
#include <llarp/mem.h>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
static void * jem_malloc(size_t sz, size_t align)
|
||||
{
|
||||
namespace llarp {
|
||||
static void *jem_malloc(size_t sz, size_t align) {
|
||||
return mallocx(sz, MALLOCX_ALIGN(align));
|
||||
}
|
||||
}
|
||||
|
||||
static void jem_free(void * ptr)
|
||||
{
|
||||
if(ptr) free(ptr);
|
||||
}
|
||||
static void jem_free(void *ptr) {
|
||||
if (ptr)
|
||||
free(ptr);
|
||||
}
|
||||
} // namespace llarp
|
||||
|
||||
extern "C" {
|
||||
void llarp_mem_jemalloc()
|
||||
{
|
||||
void llarp_mem_jemalloc() {
|
||||
llarp_g_mem.alloc = llarp::jem_malloc;
|
||||
llarp_g_mem.free = llarp::jem_free;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,24 @@
|
||||
#include <llarp/mem.h>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
void * std_malloc(size_t sz, size_t align)
|
||||
{
|
||||
(void) align;
|
||||
void * ptr = malloc(sz);
|
||||
if(ptr) return ptr;
|
||||
namespace llarp {
|
||||
void *std_malloc(size_t sz, size_t align) {
|
||||
(void)align;
|
||||
void *ptr = malloc(sz);
|
||||
if (ptr)
|
||||
return ptr;
|
||||
abort();
|
||||
}
|
||||
|
||||
void std_free(void * ptr)
|
||||
{
|
||||
if(ptr) free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
void std_free(void *ptr) {
|
||||
if (ptr)
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
} // namespace llarp
|
||||
|
||||
extern "C" {
|
||||
void llarp_mem_std()
|
||||
{
|
||||
void llarp_mem_std() {
|
||||
llarp_g_mem.alloc = llarp::std_malloc;
|
||||
llarp_g_mem.free = llarp::std_free;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,133 +1,105 @@
|
||||
#include <llarp/router.h>
|
||||
#include <llarp/link.h>
|
||||
#include "link.hpp"
|
||||
#include "mem.hpp"
|
||||
#include "str.hpp"
|
||||
#include <llarp/link.h>
|
||||
#include <llarp/router.h>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
void router_iter_config(llarp_config_iterator * iter, const char * section, const char * key, const char * val);
|
||||
struct router_links
|
||||
{
|
||||
struct llarp_link * link = nullptr;
|
||||
struct router_links * next = nullptr;
|
||||
};
|
||||
namespace llarp {
|
||||
void router_iter_config(llarp_config_iterator *iter, const char *section,
|
||||
const char *key, const char *val);
|
||||
struct router_links {
|
||||
struct llarp_link *link = nullptr;
|
||||
struct router_links *next = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace llarp
|
||||
|
||||
struct llarp_router
|
||||
{
|
||||
struct llarp_threadpool * tp;
|
||||
struct llarp_router {
|
||||
struct llarp_threadpool *tp;
|
||||
llarp::router_links links;
|
||||
llarp_crypto crypto;
|
||||
|
||||
|
||||
static void * operator new(size_t sz)
|
||||
{
|
||||
static void *operator new(size_t sz) {
|
||||
return llarp_g_mem.alloc(sz, llarp::alignment<llarp_router>());
|
||||
}
|
||||
|
||||
static void operator delete(void * ptr)
|
||||
{
|
||||
llarp_g_mem.free(ptr);
|
||||
}
|
||||
static void operator delete(void *ptr) { llarp_g_mem.free(ptr); }
|
||||
|
||||
void AddLink(struct llarp_link * link)
|
||||
{
|
||||
llarp::router_links * head = &links;
|
||||
while(head->next && head->link)
|
||||
void AddLink(struct llarp_link *link) {
|
||||
llarp::router_links *head = &links;
|
||||
while (head->next && head->link)
|
||||
head = head->next;
|
||||
|
||||
if(head->link)
|
||||
if (head->link)
|
||||
head->next = new llarp::router_links{link, nullptr};
|
||||
else
|
||||
head->link = link;
|
||||
}
|
||||
|
||||
void ForEachLink(std::function<void(llarp_link *)> visitor)
|
||||
{
|
||||
llarp::router_links * cur = &links;
|
||||
do
|
||||
{
|
||||
if(cur->link)
|
||||
void ForEachLink(std::function<void(llarp_link *)> visitor) {
|
||||
llarp::router_links *cur = &links;
|
||||
do {
|
||||
if (cur->link)
|
||||
visitor(cur->link);
|
||||
cur = cur->next;
|
||||
}
|
||||
while(cur);
|
||||
} while (cur);
|
||||
}
|
||||
|
||||
void Close()
|
||||
{
|
||||
ForEachLink(llarp_link_stop);
|
||||
}
|
||||
void Close() { ForEachLink(llarp_link_stop); }
|
||||
};
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
struct llarp_router * llarp_init_router(struct llarp_threadpool * tp)
|
||||
{
|
||||
llarp_router * router = new llarp_router;
|
||||
struct llarp_router *llarp_init_router(struct llarp_threadpool *tp) {
|
||||
llarp_router *router = new llarp_router;
|
||||
router->tp = tp;
|
||||
llarp_crypto_libsodium_init(&router->crypto);
|
||||
return router;
|
||||
}
|
||||
}
|
||||
|
||||
int llarp_configure_router(struct llarp_router * router, struct llarp_config * conf)
|
||||
{
|
||||
int llarp_configure_router(struct llarp_router *router,
|
||||
struct llarp_config *conf) {
|
||||
llarp_config_iterator iter;
|
||||
iter.user = router;
|
||||
iter.visit = llarp::router_iter_config;
|
||||
llarp_config_iter(conf, &iter);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void llarp_run_router(struct llarp_router * router, struct llarp_ev_loop * loop)
|
||||
{
|
||||
router->ForEachLink([loop](llarp_link * link) {
|
||||
void llarp_run_router(struct llarp_router *router, struct llarp_ev_loop *loop) {
|
||||
router->ForEachLink([loop](llarp_link *link) {
|
||||
llarp_ev_add_udp_listener(loop, llarp_link_udp_listener(link));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void llarp_stop_router(struct llarp_router * router)
|
||||
{
|
||||
router->Close();
|
||||
}
|
||||
void llarp_stop_router(struct llarp_router *router) { router->Close(); }
|
||||
|
||||
void llarp_free_router(struct llarp_router ** router)
|
||||
{
|
||||
if(*router)
|
||||
{
|
||||
(*router)->ForEachLink([](llarp_link * link) { llarp_g_mem.free(link); });
|
||||
void llarp_free_router(struct llarp_router **router) {
|
||||
if (*router) {
|
||||
(*router)->ForEachLink([](llarp_link *link) { llarp_g_mem.free(link); });
|
||||
delete *router;
|
||||
}
|
||||
*router = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace llarp {
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
||||
void router_iter_config(llarp_config_iterator * iter, const char * section, const char * key, const char * val)
|
||||
{
|
||||
llarp_router * self = static_cast<llarp_router *>(iter->user);
|
||||
if (StrEq(section, "links"))
|
||||
{
|
||||
if(StrEq(val, "ip"))
|
||||
{
|
||||
struct llarp_link * link = llarp_link_alloc();
|
||||
if(llarp_link_configure(link, key, AF_INET6))
|
||||
void router_iter_config(llarp_config_iterator *iter, const char *section,
|
||||
const char *key, const char *val) {
|
||||
llarp_router *self = static_cast<llarp_router *>(iter->user);
|
||||
if (StrEq(section, "links")) {
|
||||
if (StrEq(val, "ip")) {
|
||||
struct llarp_link *link = llarp_link_alloc();
|
||||
if (llarp_link_configure(link, key, AF_INET6))
|
||||
self->AddLink(link);
|
||||
else
|
||||
{
|
||||
else {
|
||||
llarp_link_free(&link);
|
||||
printf("failed to configure %s link for %s\n", val, key);
|
||||
}
|
||||
}
|
||||
else if (StrEq(val, "eth"))
|
||||
{
|
||||
} else if (StrEq(val, "eth")) {
|
||||
/** todo: ethernet link */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace llarp
|
||||
|
@ -1,24 +1,20 @@
|
||||
#include "router_contact.hpp"
|
||||
#include "exit_info.hpp"
|
||||
#include "address_info.hpp"
|
||||
#include "bencode.hpp"
|
||||
#include "exit_info.hpp"
|
||||
|
||||
extern "C" {
|
||||
|
||||
}
|
||||
extern "C" {}
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
bool BEncode(const llarp_rc & a, llarp_buffer_t * buff)
|
||||
{
|
||||
namespace llarp {
|
||||
bool BEncode(const llarp_rc &a, llarp_buffer_t *buff) {
|
||||
std::list<llarp_ai> addresses = ai_list_to_std(a.addrs);
|
||||
std::list<llarp_xi> exits = xi_list_to_std(a.exits);
|
||||
return bencodeDict(buff) &&
|
||||
bencodeDictKey(buff, "a") && BEncode(addresses, buff) &&
|
||||
return bencodeDict(buff) && bencodeDictKey(buff, "a") &&
|
||||
BEncode(addresses, buff) &&
|
||||
bencodeDict_Bytes(buff, "k", a.pubkey, sizeof(a.pubkey)) &&
|
||||
bencodeDict_Int(buff, "v", 0) &&
|
||||
bencodeDictKey(buff, "x") && BEncode(exits, buff) &&
|
||||
bencodeDict_Int(buff, "v", 0) && bencodeDictKey(buff, "x") &&
|
||||
BEncode(exits, buff) &&
|
||||
bencodeDict_Bytes(buff, "z", a.signature, sizeof(a.signature)) &&
|
||||
bencodeEnd(buff);
|
||||
}
|
||||
}
|
||||
} // namespace llarp
|
||||
|
@ -1,25 +1,22 @@
|
||||
#include <llarp/time.h>
|
||||
#include <chrono>
|
||||
#include <llarp/time.h>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
typedef std::chrono::steady_clock clock_t;
|
||||
namespace llarp {
|
||||
typedef std::chrono::steady_clock clock_t;
|
||||
|
||||
template<typename Res, typename IntType>
|
||||
static IntType time_since_epoch()
|
||||
{
|
||||
return std::chrono::duration_cast<Res>(llarp::clock_t::now().time_since_epoch()).count();
|
||||
}
|
||||
template <typename Res, typename IntType> static IntType time_since_epoch() {
|
||||
return std::chrono::duration_cast<Res>(
|
||||
llarp::clock_t::now().time_since_epoch())
|
||||
.count();
|
||||
}
|
||||
} // namespace llarp
|
||||
|
||||
extern "C" {
|
||||
llarp_time_t llarp_time_now_ms()
|
||||
{
|
||||
llarp_time_t llarp_time_now_ms() {
|
||||
return llarp::time_since_epoch<std::chrono::milliseconds, llarp_time_t>();
|
||||
}
|
||||
}
|
||||
|
||||
llarp_seconds_t llarp_time_now_sec()
|
||||
{
|
||||
llarp_seconds_t llarp_time_now_sec() {
|
||||
return llarp::time_since_epoch<std::chrono::seconds, llarp_seconds_t>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue