clang format

pull/1/head
Jeff Becker 6 years ago
parent 84ab8a792a
commit 09be72b5b6
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -62,10 +62,10 @@ 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);
llarp.router = llarp_init_router(llarp.tp);
if (llarp_configure_router(llarp.router, llarp.config)) {
printf("Running\n");
llarp_run_router(llarp.router, llarp.mainloop);

@ -19,7 +19,6 @@ struct llarp_ai {
uint16_t port;
};
bool llarp_ai_bencode(struct llarp_ai *ai, llarp_buffer_t *buff);
bool llarp_ai_bdecode(struct llarp_ai *ai, llarp_buffer_t buff);

@ -1,66 +1,57 @@
#ifndef LLARP_BENCODE_H
#define LLARP_BENCODE_H
#include <llarp/buffer.h>
#include <llarp/common.h>
#include <llarp/proto.h>
#include <stdbool.h>
#include <stdint.h>
#include <llarp/buffer.h>
#include <llarp/proto.h>
#ifdef __cplusplus
extern "C" {
#endif
bool INLINE bencode_write_bytestring(llarp_buffer_t * buff, const void * data, size_t sz)
{
if(!llarp_buffer_writef(buff, "%ld:", sz)) return false;
return llarp_buffer_write(buff, data, sz);
}
bool INLINE bencode_write_bytestring(llarp_buffer_t* buff, const void* data,
size_t sz) {
if (!llarp_buffer_writef(buff, "%ld:", sz)) return false;
return llarp_buffer_write(buff, data, sz);
}
bool INLINE bencode_write_int(llarp_buffer_t* buff, int i) {
return llarp_buffer_writef(buff, "i%de", i);
}
bool INLINE bencode_write_int(llarp_buffer_t * buff, int i)
{
return llarp_buffer_writef(buff, "i%de", i);
}
bool INLINE bencode_write_uint16(llarp_buffer_t * buff, uint16_t i)
{
return llarp_buffer_writef(buff, "i%de", i);
}
bool INLINE bencode_write_uint16(llarp_buffer_t* buff, uint16_t i) {
return llarp_buffer_writef(buff, "i%de", i);
}
bool INLINE bencode_write_int64(llarp_buffer_t * buff, int64_t i)
{
return llarp_buffer_writef(buff, "i%lde", i);
}
bool INLINE bencode_write_uint64(llarp_buffer_t * buff, uint64_t i)
{
return llarp_buffer_writef(buff, "i%lde", i);
}
bool INLINE bencode_write_int64(llarp_buffer_t* buff, int64_t i) {
return llarp_buffer_writef(buff, "i%lde", i);
}
bool INLINE bencode_write_sizeint(llarp_buffer_t * buff, size_t i)
{
return llarp_buffer_writef(buff, "i%lde", i);
}
bool INLINE bencode_write_uint64(llarp_buffer_t* buff, uint64_t i) {
return llarp_buffer_writef(buff, "i%lde", i);
}
bool INLINE bencode_start_list(llarp_buffer_t * buff)
{
return llarp_buffer_write(buff, "l", 1);
}
bool INLINE bencode_start_dict(llarp_buffer_t * buff)
{
return llarp_buffer_write(buff, "d", 1);
}
bool INLINE bencode_end(llarp_buffer_t * buff)
{
return llarp_buffer_write(buff, "e", 1);
}
bool INLINE bencode_write_sizeint(llarp_buffer_t* buff, size_t i) {
return llarp_buffer_writef(buff, "i%lde", i);
}
bool INLINE bencode_start_list(llarp_buffer_t* buff) {
return llarp_buffer_write(buff, "l", 1);
}
bool INLINE bencode_start_dict(llarp_buffer_t* buff) {
return llarp_buffer_write(buff, "d", 1);
}
bool INLINE bencode_end(llarp_buffer_t* buff) {
return llarp_buffer_write(buff, "e", 1);
}
bool INLINE bencode_write_version_entry(llarp_buffer_t* buff) {
return llarp_buffer_writef(buff, "1:vi%de", LLARP_PROTO_VERSION);
}
bool INLINE bencode_write_version_entry(llarp_buffer_t * buff)
{
return llarp_buffer_writef(buff, "1:vi%de", LLARP_PROTO_VERSION);
}
#ifdef __cplusplus
}
#endif

@ -14,18 +14,18 @@ typedef struct llarp_buffer_t {
char *cur;
} llarp_buffer_t;
size_t INLINE llarp_buffer_size_left(llarp_buffer_t *buff)
{
size_t INLINE llarp_buffer_size_left(llarp_buffer_t *buff) {
size_t diff = buff->cur - buff->base;
if ( diff > buff->sz) return 0;
else return buff->sz - diff;
if (diff > buff->sz)
return 0;
else
return buff->sz - diff;
}
bool INLINE llarp_buffer_write(llarp_buffer_t *buff, const void *data, size_t sz)
{
bool INLINE llarp_buffer_write(llarp_buffer_t *buff, const void *data,
size_t sz) {
size_t left = llarp_buffer_size_left(buff);
if (left >= sz)
{
if (left >= sz) {
memcpy(buff->cur, data, sz);
buff->cur += sz;
return true;
@ -33,9 +33,8 @@ bool INLINE llarp_buffer_write(llarp_buffer_t *buff, const void *data, size_t sz
return false;
}
bool llarp_buffer_writef(llarp_buffer_t *buff, const char * fmt, ...);
bool llarp_buffer_writef(llarp_buffer_t *buff, const char *fmt, ...);
#ifdef __cplusplus
}
#endif

@ -5,7 +5,7 @@
#else
#define INLINE inline
#endif
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#endif

@ -1,7 +1,7 @@
#ifndef LLARP_CRYPTO_H_
#define LLARP_CRYPTO_H_
#include <llarp/common.h>
#include <llarp/buffer.h>
#include <llarp/common.h>
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus

@ -19,19 +19,17 @@ bool llarp_xi_bencode(struct llarp_xi *xi, llarp_buffer_t *buf);
struct llarp_xi_list;
struct llarp_xi_list * llarp_xi_list_new();
void llarp_xi_list_free(struct llarp_xi_list * l);
struct llarp_xi_list *llarp_xi_list_new();
void llarp_xi_list_free(struct llarp_xi_list *l);
struct llarp_xi_list_iter {
void *user;
struct llarp_xi_list *list;
bool (*visit)(struct llarp_xi_list_iter *, struct llarp_xi *);
};
struct llarp_xi_list_iter
{
void * user;
struct llarp_xi_list * list;
bool (*visit)(struct llarp_xi_list_iter *, struct llarp_xi *);
};
void llarp_xi_list_iterate(struct llarp_xi_list *l,
struct llarp_xi_list_iter *iter);
void llarp_xi_list_iterate(struct llarp_xi_list *l,
struct llarp_xi_list_iter *iter);
#ifdef __cplusplus
}

@ -7,18 +7,16 @@
extern "C" {
#endif
struct llarp_xr
{
struct llarp_xr {
struct in6_addr gateway;
struct in6_addr netmask;
struct in6_addr source;
uint64_t lifetime;
};
bool llarp_xr_bencode(struct llarp_xr * xr, llarp_buffer_t * buff);
bool llarp_xr_bdecode(struct llarp_xr * xr, llarp_buffer_t * buff);
bool llarp_xr_bencode(struct llarp_xr* xr, llarp_buffer_t* buff);
bool llarp_xr_bdecode(struct llarp_xr* xr, llarp_buffer_t* buff);
#ifdef __cplusplus
}
#endif

@ -9,15 +9,13 @@
extern "C" {
#endif
struct iwp_configure_args
{
struct llarp_crypto * crypto;
};
struct iwp_configure_args {
struct llarp_crypto* crypto;
};
bool iwp_link_init(struct llarp_link * link, struct iwp_configure_args args, struct llarp_msg_muxer * muxer);
bool iwp_link_init(struct llarp_link* link, struct iwp_configure_args args,
struct llarp_msg_muxer* muxer);
#ifdef __cplusplus
}
#endif

@ -1,10 +1,10 @@
#ifndef LLARP_LINK_H_
#define LLARP_LINK_H_
#include <llarp/crypto.h>
#include <llarp/ev.h>
#include <llarp/mem.h>
#include <llarp/msg_handler.h>
#include <llarp/obmd.h>
#include <llarp/ev.h>
#include <stdbool.h>
#include <stdint.h>
@ -12,15 +12,15 @@
#ifdef __cplusplus
extern "C" {
#endif
/**
* wire layer transport interface
* wire layer transport interface
*/
struct llarp_link;
/**
* wire layer transport session for point to point communication between us and another
* wire layer transport session for point to point communication between us and
* another
*/
struct llarp_link_session;
@ -47,20 +47,21 @@ struct llarp_link_session_iter {
bool (*visit)(struct llarp_link_session_iter *, struct llarp_link_session *);
};
struct llarp_link_ev_listener
{
void * user;
void (*established)(struct llarp_ev_listener *, struct llarp_link_session *, bool);
void (*timeout)(struct llarp_ev_listener *, struct llarp_link_session *, bool);
struct llarp_link_ev_listener {
void *user;
void (*established)(struct llarp_ev_listener *, struct llarp_link_session *,
bool);
void (*timeout)(struct llarp_ev_listener *, struct llarp_link_session *,
bool);
void (*tx)(struct llarp_ev_listener *, struct llarp_link_session *, size_t);
void (*rx)(struct llarp_ev_listener *, struct llarp_link_session *, size_t);
void (*error)(struct llarp_ev_listener *, struct llarp_link_session *, const char *);
void (*error)(struct llarp_ev_listener *, struct llarp_link_session *,
const char *);
};
struct llarp_link
{
void * impl;
const char * (*name)(struct llarp_link *);
struct llarp_link {
void *impl;
const char *(*name)(struct llarp_link *);
int (*register_listener)(struct llarp_link *, struct llarp_link_ev_listener);
void (*deregister_listener)(struct llarp_link *, int);
bool (*configure)(struct llarp_link *, const char *, int, uint16_t);
@ -68,17 +69,16 @@ struct llarp_link
bool (*stop_link)(struct llarp_link *);
bool (*put_ai)(struct llarp_link *, struct llarp_ai *);
void (*iter_sessions)(struct llarp_link *, struct llarp_link_session_iter);
void (*try_establish)(struct llarp_link *,
struct llarp_link_establish_job,
void (*try_establish)(struct llarp_link *, struct llarp_link_establish_job,
struct llarp_link_session_listener);
void (*free)(struct llarp_link *);
};
struct llarp_link_session
{
void * impl;
struct llarp_rc * (*remote_rc)(struct llarp_link_session *);
/** send an entire message, splits up into smaller pieces and does encryption */
struct llarp_link_session {
void *impl;
struct llarp_rc *(*remote_rc)(struct llarp_link_session *);
/** send an entire message, splits up into smaller pieces and does encryption
*/
ssize_t (*sendto)(struct llarp_link_session *, llarp_buffer_t);
/** return true if this session is timed out */
bool (*timeout)(struct llarp_link_session *);
@ -86,7 +86,6 @@ struct llarp_link_session
void (*close)(struct llarp_link_session *);
};
#ifdef __cplusplus
}
#endif

@ -16,7 +16,7 @@ struct llarp_router *llarp_init_router(struct llarp_threadpool *tp);
void llarp_free_router(struct llarp_router **router);
bool llarp_configure_router(struct llarp_router *router,
struct llarp_config *conf);
struct llarp_config *conf);
void llarp_run_router(struct llarp_router *router, struct llarp_ev_loop *loop);
void llarp_stop_router(struct llarp_router *router);

@ -1,36 +1,39 @@
#ifndef LLARP_ROUTER_IDENT_H
#define LLARP_ROUTER_IDENT_H
#include <llarp/address_info.h>
#include <llarp/router_contact.h>
#include <llarp/crypto.h>
#include <llarp/exit_info.h>
#include <llarp/router_contact.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* rotuer identity private info
/**
* rotuer identity private info
*/
struct llarp_router_ident
{
struct llarp_crypto * crypto;
struct llarp_router_ident {
struct llarp_crypto *crypto;
llarp_seckey_t signkey;
uint64_t updated;
uint16_t version;
struct llarp_ai_list * addrs;
struct llarp_xi_list * exits;
struct llarp_ai_list *addrs;
struct llarp_xi_list *exits;
};
void llarp_router_ident_new(struct llarp_router_ident ** ri, struct llarp_crypto * crypto);
void llarp_router_ident_new(struct llarp_router_ident **ri,
struct llarp_crypto *crypto);
void llarp_router_ident_append_ai(struct llarp_router_ident * ri, struct llarp_ai * ai);
bool llarp_router_ident_bdecode(struct llarp_router_ident *ri, llarp_buffer_t *buf);
bool llarp_router_ident_bencode(struct llarp_router_ident *ri, llarp_buffer_t *buf);
void llarp_router_ident_free(struct llarp_router_ident ** ri);
bool llarp_router_ident_generate_rc(struct llarp_router_ident * ri, struct llarp_rc ** rc);
void llarp_router_ident_append_ai(struct llarp_router_ident *ri,
struct llarp_ai *ai);
bool llarp_router_ident_bdecode(struct llarp_router_ident *ri,
llarp_buffer_t *buf);
bool llarp_router_ident_bencode(struct llarp_router_ident *ri,
llarp_buffer_t *buf);
void llarp_router_ident_free(struct llarp_router_ident **ri);
bool llarp_router_ident_generate_rc(struct llarp_router_ident *ri,
struct llarp_rc **rc);
#ifdef __cplusplus
}

@ -4,15 +4,13 @@
#ifdef __cplusplus
extern "C" {
#endif
size_t INLINE strnlen(const char * str, size_t sz)
{
size_t slen = 0;
while(sz-- && str[slen])
slen ++;
return slen;
}
size_t INLINE strnlen(const char* str, size_t sz) {
size_t slen = 0;
while (sz-- && str[slen]) slen++;
return slen;
}
#ifdef __cplusplus
}
#endif

@ -1,58 +1,58 @@
#include <arpa/inet.h>
#include <llarp/address_info.h>
#include <llarp/bencode.h>
#include <llarp/mem.h>
#include <llarp/string.h>
#include <arpa/inet.h>
bool llarp_ai_bencode(struct llarp_ai *ai, llarp_buffer_t *buff) {
char ipbuff [128] = {0};
const char * ipstr;
if(!bencode_start_dict(buff)) return false;
char ipbuff[128] = {0};
const char *ipstr;
if (!bencode_start_dict(buff)) return false;
/* rank */
if(!bencode_write_bytestring(buff, "c", 1)) return false;
if(!bencode_write_uint16(buff, ai->rank)) return false;
if (!bencode_write_bytestring(buff, "c", 1)) return false;
if (!bencode_write_uint16(buff, ai->rank)) return false;
/* dialect */
if(!bencode_write_bytestring(buff, "d", 1)) return false;
if(!bencode_write_bytestring(buff, ai->dialect, strnlen(ai->dialect, sizeof(ai->dialect)))) return false;
if (!bencode_write_bytestring(buff, "d", 1)) return false;
if (!bencode_write_bytestring(buff, ai->dialect,
strnlen(ai->dialect, sizeof(ai->dialect))))
return false;
/* encryption key */
if(!bencode_write_bytestring(buff, "e", 1)) return false;
if(!bencode_write_bytestring(buff, ai->enc_key, sizeof(llarp_pubkey_t))) return false;
if (!bencode_write_bytestring(buff, "e", 1)) return false;
if (!bencode_write_bytestring(buff, ai->enc_key, sizeof(llarp_pubkey_t)))
return false;
/** ip */
ipstr = inet_ntop(AF_INET6, &ai->ip, ipbuff, sizeof(ipbuff));
if(!ipstr) return false;
if(!bencode_write_bytestring(buff, "i", 1)) return false;
if(!bencode_write_bytestring(buff, ipstr, strnlen(ipstr, sizeof(ipbuff)))) return false;
if (!ipstr) return false;
if (!bencode_write_bytestring(buff, "i", 1)) return false;
if (!bencode_write_bytestring(buff, ipstr, strnlen(ipstr, sizeof(ipbuff))))
return false;
/** port */
if(!bencode_write_bytestring(buff, "p", 1)) return false;
if(!bencode_write_uint16(buff, ai->port)) return false;
if (!bencode_write_bytestring(buff, "p", 1)) return false;
if (!bencode_write_uint16(buff, ai->port)) return false;
/** version */
if(!bencode_write_version_entry(buff)) return false;
if (!bencode_write_version_entry(buff)) return false;
/** end */
return bencode_end(buff);
}
struct llarp_ai_list
{
struct llarp_ai_list * next;
struct llarp_ai_list {
struct llarp_ai_list *next;
struct llarp_ai data;
};
struct llarp_ai_list * llarp_ai_list_new()
{
struct llarp_ai_list *llarp_ai_list_new() {
return llarp_g_mem.alloc(sizeof(struct llarp_ai_list), 8);
}
void llarp_ai_list_free(struct llarp_ai_list * l)
{
struct llarp_ai_list * cur = l;
struct llarp_ai_list * tmp;
void llarp_ai_list_free(struct llarp_ai_list *l) {
struct llarp_ai_list *cur = l;
struct llarp_ai_list *tmp;
do {
tmp = cur->next;
llarp_g_mem.free(cur);
cur = tmp;
}while(cur->next);
} while (cur->next);
}
void llarp_ai_list_iterate(struct llarp_ai_list *l,

@ -3,16 +3,15 @@
#include <stdio.h>
extern "C" {
bool llarp_buffer_writef(llarp_buffer_t * buff, const char * fmt, ...)
{
int written;
size_t sz = llarp_buffer_size_left(buff);
va_list args;
va_start(args, fmt);
written = snprintf(buff->cur, sz, fmt, args);
va_end(args);
if (written == -1) return false;
buff->sz += written;
return true;
}
bool llarp_buffer_writef(llarp_buffer_t* buff, const char* fmt, ...) {
int written;
size_t sz = llarp_buffer_size_left(buff);
va_list args;
va_start(args, fmt);
written = snprintf(buff->cur, sz, fmt, args);
va_end(args);
if (written == -1) return false;
buff->sz += written;
return true;
}
}

@ -36,12 +36,10 @@ static void llarp_async_dh_exec(struct llarp_async_dh *dh, llarp_dh_func func,
llarp_dh_complete_hook result, void *user) {
struct llarp_dh_internal *impl =
llarp_g_mem.alloc(sizeof(struct llarp_dh_internal), 32);
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};
memcpy(impl->theirkey, theirkey, sizeof(llarp_pubkey_t));
memcpy(impl->nounce, nounce, sizeof(llarp_tunnel_nounce_t));
impl->ourkey = dh->ourkey;

@ -1,33 +1,34 @@
#include <llarp/exit_info.h>
#include <arpa/inet.h>
#include <llarp/bencode.h>
#include <llarp/exit_info.h>
#include <llarp/string.h>
#include <arpa/inet.h>
bool llarp_xi_bencode(struct llarp_xi *xi, llarp_buffer_t *buff) {
char addr_buff[128] = {0};
const char * addr;
if(!bencode_start_dict(buff)) return false;
const char *addr;
if (!bencode_start_dict(buff)) return false;
/** address */
addr = inet_ntop(AF_INET6, &xi->address, addr_buff, sizeof(addr_buff));
if(!addr) return false;
if(!bencode_write_bytestring(buff, "a", 1)) return false;
if(!bencode_write_bytestring(buff, addr, strnlen(addr, sizeof(addr_buff)))) return false;
if (!addr) return false;
if (!bencode_write_bytestring(buff, "a", 1)) return false;
if (!bencode_write_bytestring(buff, addr, strnlen(addr, sizeof(addr_buff))))
return false;
/** netmask */
addr = inet_ntop(AF_INET6, &xi->netmask, addr_buff, sizeof(addr_buff));
if(!addr) return false;
if(!bencode_write_bytestring(buff, "b", 1)) return false;
if(!bencode_write_bytestring(buff, addr, strnlen(addr, sizeof(addr_buff)))) return false;
if (!addr) return false;
if (!bencode_write_bytestring(buff, "b", 1)) return false;
if (!bencode_write_bytestring(buff, addr, strnlen(addr, sizeof(addr_buff))))
return false;
/** public key */
if(!bencode_write_bytestring(buff, "k", 1)) return false;
if(!bencode_write_bytestring(buff, xi->pubkey, sizeof(llarp_pubkey_t))) return false;
if (!bencode_write_bytestring(buff, "k", 1)) return false;
if (!bencode_write_bytestring(buff, xi->pubkey, sizeof(llarp_pubkey_t)))
return false;
/** version */
if(!bencode_write_version_entry(buff)) return false;
if (!bencode_write_version_entry(buff)) return false;
return bencode_end(buff);
}

@ -1,40 +1,41 @@
#include <llarp/exit_route.h>
#include <arpa/inet.h>
#include <llarp/bencode.h>
#include <llarp/exit_route.h>
#include <llarp/string.h>
#include <arpa/inet.h>
bool llarp_xr_bencode(struct llarp_xr * xr, llarp_buffer_t * buff)
{
bool llarp_xr_bencode(struct llarp_xr* xr, llarp_buffer_t* buff) {
char addr_buff[128] = {0};
const char* addr;
char addr_buff [128] = {0};
const char * addr;
if(!bencode_start_dict(buff)) return false;
if (!bencode_start_dict(buff)) return false;
/** gateway */
addr = inet_ntop(AF_INET6, &xr->gateway, addr_buff, sizeof(addr_buff));
if(!addr) return false;
if(!bencode_write_bytestring(buff, "a", 1)) return false;
if(!bencode_write_bytestring(buff, addr, strnlen(addr, sizeof(addr_buff)))) return false;
if (!addr) return false;
if (!bencode_write_bytestring(buff, "a", 1)) return false;
if (!bencode_write_bytestring(buff, addr, strnlen(addr, sizeof(addr_buff))))
return false;
/** netmask */
addr = inet_ntop(AF_INET6, &xr->netmask, addr_buff, sizeof(addr_buff));
if(!addr) return false;
if(!bencode_write_bytestring(buff, "b", 1)) return false;
if(!bencode_write_bytestring(buff, addr, strnlen(addr, sizeof(addr_buff)))) return false;
/** source */
if (!addr) return false;
if (!bencode_write_bytestring(buff, "b", 1)) return false;
if (!bencode_write_bytestring(buff, addr, strnlen(addr, sizeof(addr_buff))))
return false;
/** source */
addr = inet_ntop(AF_INET6, &xr->source, addr_buff, sizeof(addr_buff));
if(!addr) return false;
if(!bencode_write_bytestring(buff, "c", 1)) return false;
if(!bencode_write_bytestring(buff, addr, strnlen(addr, sizeof(addr_buff)))) return false;
if (!addr) return false;
if (!bencode_write_bytestring(buff, "c", 1)) return false;
if (!bencode_write_bytestring(buff, addr, strnlen(addr, sizeof(addr_buff))))
return false;
/** lifetime */
if(!bencode_write_bytestring(buff, "l", 1)) return false;
if(!bencode_write_uint64(buff, xr->lifetime)) return false;
if (!bencode_write_bytestring(buff, "l", 1)) return false;
if (!bencode_write_uint64(buff, xr->lifetime)) return false;
/** version */
if(!bencode_write_version_entry(buff)) return false;
if (!bencode_write_version_entry(buff)) return false;
/* end */
return bencode_end(buff);

@ -50,9 +50,9 @@ struct Level {
size_t depth;
static std::string default_value;
const std::string &operator[](const std::string &name) {
for (const auto & itr : values)
for (const auto &itr : values)
if (itr.first == name) return itr.second;
return default_value;
}
@ -144,9 +144,10 @@ inline void Parser::parse(Level &l) {
} else {
size_t n = line_.find('=');
if (n == std::string::npos) err("no '=' found");
auto p = std::make_pair(trim(line_.substr(0, n)),
trim(line_.substr(n + 1, line_.length() - n - 1)));
auto p =
std::make_pair(trim(line_.substr(0, n)),
trim(line_.substr(n + 1, line_.length() - n - 1)));
l.values.push_back(p);
}
}
@ -159,10 +160,10 @@ inline void Parser::dump(std::ostream &s, const Level &l,
if (!sname.empty()) s << sname;
for (size_t i = 0; i < l.depth; ++i) s << ']';
if (!sname.empty()) s << std::endl;
for( const auto & itr : l.values)
for (const auto &itr : l.values)
s << itr.first << '=' << itr.second << std::endl;
for (Level::sections_t::const_iterator it = l.ordered_sections.begin();
it != l.ordered_sections.end(); ++it) {
assert((*it)->second.depth == l.depth + 1);

@ -3,85 +3,72 @@
#include <list>
#include <string>
namespace iwp
{
struct link_impl
{
link_impl(llarp_seckey_t k, llarp_msg_muxer *m) : muxer(m)
{
memcpy(seckey, k, sizeof(seckey));
}
std::list<llarp_link_ev_listener> link_listeners;
llarp_seckey_t seckey;
llarp_msg_muxer * muxer;
std::string linkname;
bool configure(const char * ifname, int af, uint16_t port)
{
// todo: implement
linkname = std::string(ifname) + std::string("+") + std::to_string(port);
return false;
}
const char * name()
{
return linkname.c_str();
}
bool start(llarp_ev_loop * loop)
{
// todo: implement
return false;
}
bool stop()
{
// todo: implement
return false;
}
};
static bool configure(struct llarp_link * l, const char * ifname, int af, uint16_t port)
{
link_impl * link = static_cast<link_impl *>(l->impl);
return link->configure(ifname, af, port);
}
namespace iwp {
static bool start_link(struct llarp_link * l, struct llarp_ev_loop * loop)
{
link_impl * link = static_cast<link_impl *>(l->impl);
return link->start(loop);
struct link_impl {
link_impl(llarp_seckey_t k, llarp_msg_muxer *m) : muxer(m) {
memcpy(seckey, k, sizeof(seckey));
}
static bool stop_link(struct llarp_link * l)
{
link_impl * link = static_cast<link_impl *>(l->impl);
return link->stop();
std::list<llarp_link_ev_listener> link_listeners;
llarp_seckey_t seckey;
llarp_msg_muxer *muxer;
std::string linkname;
bool configure(const char *ifname, int af, uint16_t port) {
// todo: implement
linkname = std::string(ifname) + std::string("+") + std::to_string(port);
return false;
}
static void free_link(struct llarp_link * l)
{
link_impl * link = static_cast<link_impl *>(l->impl);
delete link;
const char *name() { return linkname.c_str(); }
bool start(llarp_ev_loop *loop) {
// todo: implement
return false;
}
static const char * link_name(struct llarp_link * l)
{
link_impl * link = static_cast<link_impl *>(l->impl);
return link->name();
bool stop() {
// todo: implement
return false;
}
};
static bool configure(struct llarp_link *l, const char *ifname, int af,
uint16_t port) {
link_impl *link = static_cast<link_impl *>(l->impl);
return link->configure(ifname, af, port);
}
static bool start_link(struct llarp_link *l, struct llarp_ev_loop *loop) {
link_impl *link = static_cast<link_impl *>(l->impl);
return link->start(loop);
}
static bool stop_link(struct llarp_link *l) {
link_impl *link = static_cast<link_impl *>(l->impl);
return link->stop();
}
static void free_link(struct llarp_link *l) {
link_impl *link = static_cast<link_impl *>(l->impl);
delete link;
}
static const char *link_name(struct llarp_link *l) {
link_impl *link = static_cast<link_impl *>(l->impl);
return link->name();
}
} // namespace iwp
extern "C" {
bool iwp_link_init(struct llarp_link * link, struct iwp_configure_args args, struct llarp_msg_muxer * muxer)
{
bool iwp_link_init(struct llarp_link *link, struct iwp_configure_args args,
struct llarp_msg_muxer *muxer) {
llarp_seckey_t seckey;
args.crypto->keygen(&seckey);
link->impl = new iwp::link_impl(seckey, muxer);
@ -93,5 +80,4 @@ bool iwp_link_init(struct llarp_link * link, struct iwp_configure_args args, str
link->free = &iwp::free_link;
return true;
}
}

@ -5,8 +5,7 @@ namespace llarp {
void *std_malloc(size_t sz, size_t align) {
(void)align;
void *ptr = malloc(sz);
if (ptr)
{
if (ptr) {
std::memset(ptr, 0, sz);
return ptr;
}

@ -1,9 +1,9 @@
#include "router.hpp"
#include <llarp/ibfq.h>
#include <llarp/link.h>
#include <llarp/router.h>
#include <llarp/iwp.h>
#include <llarp/link.h>
#include <llarp/proto.h>
#include <llarp/router.h>
#include "str.hpp"
namespace llarp {
@ -27,10 +27,7 @@ void llarp_router::AddLink(struct llarp_link *link) {
ready = true;
}
bool llarp_router::Ready()
{
return ready;
}
bool llarp_router::Ready() { return ready; }
void llarp_router::ForEachLink(std::function<void(llarp_link *)> visitor) {
llarp::router_links *cur = &links;
@ -40,7 +37,9 @@ void llarp_router::ForEachLink(std::function<void(llarp_link *)> visitor) {
} while (cur);
}
void llarp_router::Close() { ForEachLink([](llarp_link * l) { l->stop_link(l); }); }
void llarp_router::Close() {
ForEachLink([](llarp_link *l) { l->stop_link(l); });
}
extern "C" {
struct llarp_router *llarp_init_router(struct llarp_threadpool *tp) {
@ -51,7 +50,7 @@ struct llarp_router *llarp_init_router(struct llarp_threadpool *tp) {
}
bool llarp_configure_router(struct llarp_router *router,
struct llarp_config *conf) {
struct llarp_config *conf) {
llarp_config_iterator iter;
iter.user = router;
iter.visit = llarp::router_iter_config;
@ -61,9 +60,8 @@ bool llarp_configure_router(struct llarp_router *router,
void llarp_run_router(struct llarp_router *router, struct llarp_ev_loop *loop) {
router->ForEachLink([loop](llarp_link *link) {
int result = link->start_link(link, loop);
if(result == -1)
printf("link %s failed to start\n", link->name(link));
int result = link->start_link(link, loop);
if (result == -1) printf("link %s failed to start\n", link->name(link));
});
}
@ -86,36 +84,28 @@ void router_iter_config(llarp_config_iterator *iter, const char *section,
if (StrEq(section, "links")) {
if (StrEq(val, "eth")) {
struct llarp_link *link = llarp::Alloc<llarp_link>();
iwp_configure_args args = {
.crypto = &self->crypto
};
iwp_configure_args args = {.crypto = &self->crypto};
iwp_link_init(link, args, &self->muxer);
if (link->configure(link, key, AF_PACKET, LLARP_ETH_PROTO))
{
if (link->configure(link, key, AF_PACKET, LLARP_ETH_PROTO)) {
printf("ethernet link configured on %s\n", key);
self->AddLink(link);
}
else {
} else {
link->free(link);
printf("failed to configure ethernet link for %s\n", key);
}
} else {
struct llarp_link *link = llarp::Alloc<llarp_link>();
uint16_t port = std::atoi(val);
iwp_configure_args args = {
.crypto = &self->crypto
};
iwp_configure_args args = {.crypto = &self->crypto};
iwp_link_init(link, args, &self->muxer);
if (link->configure(link, key, AF_INET6, port))
{
if (link->configure(link, key, AF_INET6, port)) {
printf("inet link configured on %s port %d\n", key, port);
self->AddLink(link);
}
else {
} else {
link->free(link);
printf("failed to configure inet link for %s port %d\n", key, port);
}
}
}
}
}
} // namespace llarp

@ -1,74 +1,59 @@
#include "router_contact.hpp"
#include "address_info.hpp"
#include "exit_info.hpp"
#include <llarp/bencode.h>
#include <llarp/version.h>
#include "address_info.hpp"
#include "exit_info.hpp"
namespace llarp {
static bool bencode_rc_ai_write(struct llarp_ai_list_iter * i, struct llarp_ai * ai)
{
llarp_buffer_t * buff = static_cast<llarp_buffer_t *>(i->user);
return llarp_ai_bencode(ai, buff);
}
static bool bencode_rc_ai_write(struct llarp_ai_list_iter *i,
struct llarp_ai *ai) {
llarp_buffer_t *buff = static_cast<llarp_buffer_t *>(i->user);
return llarp_ai_bencode(ai, buff);
}
static bool bencode_rc_xi_write(struct llarp_xi_list_iter * i, struct llarp_xi * xi)
{
llarp_buffer_t * buff = static_cast<llarp_buffer_t *>(i->user);
return llarp_xi_bencode(xi, buff);
}
static bool bencode_rc_xi_write(struct llarp_xi_list_iter *i,
struct llarp_xi *xi) {
llarp_buffer_t *buff = static_cast<llarp_buffer_t *>(i->user);
return llarp_xi_bencode(xi, buff);
}
} // namespace llarp
extern "C" {
bool llarp_rc_bencode(struct llarp_rc *rc, llarp_buffer_t *buff) {
/* write dict begin */
if(!bencode_start_dict(buff))
return false;
if(rc->addrs)
{
if (!bencode_start_dict(buff)) return false;
if (rc->addrs) {
/* write ai if they exist */
if(!bencode_write_bytestring(buff, "a", 1))
return false;
if(!bencode_start_list(buff))
return false;
if (!bencode_write_bytestring(buff, "a", 1)) return false;
if (!bencode_start_list(buff)) return false;
struct llarp_ai_list_iter ai_itr = {
.user = buff,
.list = nullptr,
.visit = &llarp::bencode_rc_ai_write
};
.user = buff, .list = nullptr, .visit = &llarp::bencode_rc_ai_write};
llarp_ai_list_iterate(rc->addrs, &ai_itr);
if(!bencode_end(buff))
return false;
if (!bencode_end(buff)) return false;
}
/* write pubkey */
if(!bencode_write_bytestring(buff, "k", 1)) return false;
if(!bencode_write_bytestring(buff, rc->pubkey, sizeof(llarp_pubkey_t))) return false;
if (!bencode_write_bytestring(buff, "k", 1)) return false;
if (!bencode_write_bytestring(buff, rc->pubkey, sizeof(llarp_pubkey_t)))
return false;
/* write version */
if(!bencode_write_version_entry(buff)) return false;
if (!bencode_write_version_entry(buff)) return false;
if(rc->exits)
{
if (rc->exits) {
/* write ai if they exist */
if(!bencode_write_bytestring(buff, "x", 1))
return false;
if(!bencode_start_list(buff))
return false;
if (!bencode_write_bytestring(buff, "x", 1)) return false;
if (!bencode_start_list(buff)) return false;
struct llarp_xi_list_iter xi_itr = {
.user = buff,
.list = nullptr,
.visit = &llarp::bencode_rc_xi_write
};
.user = buff, .list = nullptr, .visit = &llarp::bencode_rc_xi_write};
llarp_xi_list_iterate(rc->exits, &xi_itr);
if(!bencode_end(buff))
return false;
if (!bencode_end(buff)) return false;
}
/* write signature */
if(!bencode_write_bytestring(buff, "z", 1)) return false;
if(!bencode_write_bytestring(buff, rc->signature, sizeof(llarp_sig_t))) return false;
if (!bencode_write_bytestring(buff, "z", 1)) return false;
if (!bencode_write_bytestring(buff, rc->signature, sizeof(llarp_sig_t)))
return false;
return bencode_end(buff);
}
}

Loading…
Cancel
Save