mirror of https://github.com/oxen-io/lokinet
Merge remote-tracking branch 'ryan/master'
This commit is contained in:
commit
c2ef57d9a2
|
@ -142,8 +142,8 @@ main(int argc, char *argv[])
|
|||
"file\n");
|
||||
return 0;
|
||||
}
|
||||
bool genMode;
|
||||
bool updMode;
|
||||
bool genMode = false;
|
||||
bool updMode = false;
|
||||
int c;
|
||||
char *rcfname;
|
||||
while(1)
|
||||
|
@ -203,6 +203,7 @@ main(int argc, char *argv[])
|
|||
tmp.last_updated = llarp_time_now_ms();
|
||||
// load longterm identity
|
||||
llarp_crypto crypt;
|
||||
llarp_crypto_libsodium_init(&crypt);
|
||||
fs::path ident_keyfile = "identity.key";
|
||||
llarp_seckey_t identity;
|
||||
llarp_findOrCreateIdentity(&crypt, ident_keyfile.c_str(), identity);
|
||||
|
@ -210,7 +211,7 @@ main(int argc, char *argv[])
|
|||
uint8_t *pubkey = llarp_seckey_topublic(identity);
|
||||
llarp_rc_set_pubkey(&tmp, pubkey);
|
||||
// this causes a segfault
|
||||
// llarp_rc_sign(&crypt, &identity, &tmp);
|
||||
llarp_rc_sign(&crypt, identity, &tmp);
|
||||
// set filename
|
||||
fs::path our_rc_file = rcfname;
|
||||
// write file
|
||||
|
@ -220,7 +221,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
if(updMode)
|
||||
{
|
||||
printf("Loading [%s]\n", rcfname);
|
||||
printf("rcutil.cpp - Loading [%s]\n", rcfname);
|
||||
fs::path our_rc_file = rcfname;
|
||||
std::error_code ec;
|
||||
if(!fs::exists(our_rc_file, ec))
|
||||
|
@ -240,7 +241,7 @@ main(int argc, char *argv[])
|
|||
buf.cur = buf.base;
|
||||
buf.sz = sizeof(tmpc);
|
||||
f.read((char *)tmpc, sizeof(MAX_RC_SIZE));
|
||||
printf("contents[%s]\n", tmpc);
|
||||
// printf("contents[%s]\n", tmpc);
|
||||
if(!llarp_rc_bdecode(mem, &tmp, &buf))
|
||||
{
|
||||
printf("Can't decode\n");
|
||||
|
@ -250,12 +251,14 @@ main(int argc, char *argv[])
|
|||
tmp.last_updated = llarp_time_now_ms();
|
||||
// load longterm identity
|
||||
llarp_crypto crypt;
|
||||
llarp_crypto_libsodium_init(&crypt);
|
||||
fs::path ident_keyfile = "identity.key";
|
||||
llarp_seckey_t identity;
|
||||
llarp_findOrCreateIdentity(&crypt, ident_keyfile.c_str(), identity);
|
||||
// get identity public key
|
||||
uint8_t *pubkey = llarp_seckey_topublic(identity);
|
||||
llarp_rc_set_pubkey(&tmp, pubkey);
|
||||
llarp_rc_sign(&crypt, identity, &tmp);
|
||||
// set filename
|
||||
fs::path our_rc_file_out = "update_debug.rc";
|
||||
// write file
|
||||
|
|
|
@ -5,12 +5,19 @@
|
|||
#include <llarp/net.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* address_info.h
|
||||
*
|
||||
* utilities for handling addresses on the llarp network
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MAX_AI_DIALECT_SIZE 5
|
||||
|
||||
/// address information model
|
||||
struct llarp_ai
|
||||
{
|
||||
uint16_t rank;
|
||||
|
@ -20,52 +27,65 @@ struct llarp_ai
|
|||
uint16_t port;
|
||||
};
|
||||
|
||||
/// convert address information struct to bencoded buffer
|
||||
bool
|
||||
llarp_ai_bencode(struct llarp_ai *ai, llarp_buffer_t *buff);
|
||||
|
||||
/// convert bencoded buffer to address information struct
|
||||
bool
|
||||
llarp_ai_bdecode(struct llarp_ai *ai, llarp_buffer_t *buff);
|
||||
|
||||
struct llarp_ai_list;
|
||||
|
||||
/// list of address information initialization
|
||||
struct llarp_ai_list *
|
||||
llarp_ai_list_new(struct llarp_alloc *mem);
|
||||
|
||||
/// list of address information destruction
|
||||
void
|
||||
llarp_ai_list_free(struct llarp_ai_list *l);
|
||||
|
||||
/// copy AI
|
||||
void
|
||||
llarp_ai_copy(struct llarp_ai *dst, struct llarp_ai *src);
|
||||
|
||||
/// convert llarp_ai_list struct to bencoded buffer
|
||||
bool
|
||||
llarp_ai_list_bencode(struct llarp_ai_list *l, llarp_buffer_t *buff);
|
||||
|
||||
/// convert bencoded buffer to llarp_ai_list struct
|
||||
bool
|
||||
llarp_ai_list_bdecode(struct llarp_ai_list *l, llarp_buffer_t *buff);
|
||||
|
||||
/// return and remove first element from ai_list
|
||||
struct llarp_ai
|
||||
llarp_ai_list_popfront(struct llarp_ai_list *l);
|
||||
|
||||
/** pushes a copy of ai to the end of the list */
|
||||
/// pushes a copy of ai to the end of the list
|
||||
void
|
||||
llarp_ai_list_pushback(struct llarp_ai_list *l, struct llarp_ai *ai);
|
||||
|
||||
/// get the number of entries in list
|
||||
size_t
|
||||
llarp_ai_list_size(struct llarp_ai_list *l);
|
||||
|
||||
/// does this index exist in list
|
||||
bool
|
||||
llarp_ai_list_index(struct llarp_ai_list *l, ssize_t idx,
|
||||
struct llarp_ai *result);
|
||||
|
||||
/// ai_list iterator configuration
|
||||
struct llarp_ai_list_iter
|
||||
{
|
||||
/// a customizable pointer to pass data to iteration functor
|
||||
void *user;
|
||||
/** set by llarp_ai_list_iterate() */
|
||||
/// set by llarp_ai_list_iterate()
|
||||
struct llarp_ai_list *list;
|
||||
/** return false to break iteration */
|
||||
/// return false to break iteration early
|
||||
bool (*visit)(struct llarp_ai_list_iter *, struct llarp_ai *);
|
||||
};
|
||||
|
||||
/// iterator over list and call visit functor
|
||||
void
|
||||
llarp_ai_list_iterate(struct llarp_ai_list *l, struct llarp_ai_list_iter *iter);
|
||||
|
||||
|
|
|
@ -6,6 +6,14 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* bencode.h
|
||||
*
|
||||
* helper functions for handling bencoding
|
||||
* https://en.wikipedia.org/wiki/Bencode for more information on the format
|
||||
* we utilize llarp_buffer which provides memory management
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -127,7 +135,10 @@ bdecode_read_string(llarp_buffer_t* buffer, llarp_buffer_t* result)
|
|||
|
||||
struct dict_reader
|
||||
{
|
||||
/// makes passing data into on_key easier
|
||||
llarp_buffer_t* buffer;
|
||||
/// not currently used, maybe used in the future to pass additional
|
||||
/// information to on_key
|
||||
void* user;
|
||||
/**
|
||||
* called when we got a key string, return true to continue iteration
|
||||
|
@ -139,21 +150,21 @@ struct dict_reader
|
|||
static bool INLINE
|
||||
bdecode_read_dict(llarp_buffer_t* buff, struct dict_reader* r)
|
||||
{
|
||||
llarp_buffer_t strbuf;
|
||||
r->buffer = buff;
|
||||
if(*r->buffer->cur != 'd')
|
||||
llarp_buffer_t strbuf; // temporary buffer for current element
|
||||
r->buffer = buff; // set up dict_reader
|
||||
if(*r->buffer->cur != 'd') // ensure is a dictionary
|
||||
return false;
|
||||
r->buffer->cur++;
|
||||
while(llarp_buffer_size_left(r->buffer) && *r->buffer->cur != 'e')
|
||||
{
|
||||
if(bdecode_read_string(r->buffer, &strbuf))
|
||||
{
|
||||
if(!r->on_key(r, &strbuf))
|
||||
if(!r->on_key(r, &strbuf)) // check for early abort
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(*r->buffer->cur != 'e')
|
||||
if(*r->buffer->cur != 'e') // make sure we're at dictionary end
|
||||
return false;
|
||||
r->buffer->cur++;
|
||||
return r->on_key(r, 0);
|
||||
|
@ -161,8 +172,15 @@ bdecode_read_dict(llarp_buffer_t* buff, struct dict_reader* r)
|
|||
|
||||
struct list_reader
|
||||
{
|
||||
/// makes passing data into on_item easier
|
||||
llarp_buffer_t* buffer;
|
||||
/// not currently used, maybe used in the future to pass additional
|
||||
/// information to on_item
|
||||
void* user;
|
||||
/**
|
||||
* called when we got an element, return true to continue iteration
|
||||
* called with null item on iteration completion
|
||||
*/
|
||||
bool (*on_item)(struct list_reader*, bool);
|
||||
};
|
||||
|
||||
|
@ -170,16 +188,16 @@ static bool INLINE
|
|||
bdecode_read_list(llarp_buffer_t* buff, struct list_reader* r)
|
||||
{
|
||||
r->buffer = buff;
|
||||
if(*r->buffer->cur != 'l')
|
||||
if(*r->buffer->cur != 'l') // ensure is a list
|
||||
return false;
|
||||
|
||||
r->buffer->cur++;
|
||||
while(llarp_buffer_size_left(r->buffer) && *r->buffer->cur != 'e')
|
||||
{
|
||||
if(!r->on_item(r, true))
|
||||
if(!r->on_item(r, true)) // check for early abort
|
||||
return false;
|
||||
}
|
||||
if(*r->buffer->cur != 'e')
|
||||
if(*r->buffer->cur != 'e') // make sure we're at a list end
|
||||
return false;
|
||||
r->buffer->cur++;
|
||||
return r->on_item(r, false);
|
||||
|
|
|
@ -7,6 +7,12 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* buffer.h
|
||||
*
|
||||
* buffer used for bencoding
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -15,27 +21,35 @@ typedef uint8_t byte_t;
|
|||
|
||||
typedef struct llarp_buffer_t
|
||||
{
|
||||
/// starting memory address
|
||||
byte_t *base;
|
||||
/// memory address of stream position
|
||||
byte_t *cur;
|
||||
/// max size of buffer
|
||||
size_t sz;
|
||||
} llarp_buffer_t;
|
||||
|
||||
/// how much room is left in buffer
|
||||
size_t
|
||||
llarp_buffer_size_left(llarp_buffer_t *buff);
|
||||
|
||||
/// write a chunk of data size "sz"
|
||||
bool
|
||||
llarp_buffer_write(llarp_buffer_t *buff, const void *data, size_t sz);
|
||||
|
||||
/// write multiple strings
|
||||
bool
|
||||
llarp_buffer_writef(llarp_buffer_t *buff, const char *fmt, ...);
|
||||
|
||||
/// read from file into buff using allocator "mem"
|
||||
bool
|
||||
llarp_buffer_readfile(llarp_buffer_t *buff, FILE *f, struct llarp_alloc *mem);
|
||||
|
||||
/// read buffer upto character delimiter
|
||||
size_t
|
||||
llarp_buffer_read_until(llarp_buffer_t *buff, char delim, byte_t *result,
|
||||
size_t resultlen);
|
||||
|
||||
/// compare buffers, true if equal else false
|
||||
bool
|
||||
llarp_buffer_eq(llarp_buffer_t buff, const char *data);
|
||||
|
||||
|
|
|
@ -1,31 +1,43 @@
|
|||
#ifndef LLARP_CONFIG_H_
|
||||
#define LLARP_CONFIG_H_
|
||||
|
||||
/**
|
||||
* config.h
|
||||
*
|
||||
* library configuration utilties
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct llarp_config;
|
||||
|
||||
/// allocate config
|
||||
void
|
||||
llarp_new_config(struct llarp_config **conf);
|
||||
|
||||
/// deallocate config
|
||||
void
|
||||
llarp_free_config(struct llarp_config **conf);
|
||||
|
||||
/** @brief return -1 on fail otherwiwse 0 */
|
||||
/// @brief return -1 on fail otherwiwse 0
|
||||
int
|
||||
llarp_load_config(struct llarp_config *conf, const char *fname);
|
||||
|
||||
/// config iterator configuration
|
||||
struct llarp_config_iterator
|
||||
{
|
||||
/// a customizable pointer to pass data to iteration functor
|
||||
void *user;
|
||||
/** set by llarp_config_iter */
|
||||
/// set by llarp_config_iter
|
||||
struct llarp_config *conf;
|
||||
/** visit (self, section, key, value) */
|
||||
/// visit (self, section, key, value)
|
||||
void (*visit)(struct llarp_config_iterator *, const char *, const char *,
|
||||
const char *);
|
||||
};
|
||||
|
||||
/// iterator over "conf" and call visit functor defined in "iter"
|
||||
void
|
||||
llarp_config_iter(struct llarp_config *conf,
|
||||
struct llarp_config_iterator *iter);
|
||||
|
|
|
@ -4,6 +4,14 @@
|
|||
#include <llarp/common.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* crypto.h
|
||||
*
|
||||
* libsodium abstraction layer
|
||||
* potentially allow libssl support in the future
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -30,9 +38,11 @@ typedef byte_t llarp_hmacsec_t[HMACSECSIZE];
|
|||
typedef byte_t llarp_sig_t[SIGSIZE];
|
||||
typedef byte_t llarp_tunnel_nonce_t[TUNNONCESIZE];
|
||||
|
||||
/// get public key from secret
|
||||
byte_t *
|
||||
llarp_seckey_topublic(byte_t *secret);
|
||||
|
||||
/// label functors
|
||||
typedef bool (*llarp_dh_func)(llarp_sharedkey_t *, llarp_pubkey_t,
|
||||
llarp_tunnel_nonce_t, llarp_seckey_t);
|
||||
|
||||
|
@ -52,6 +62,7 @@ typedef bool (*llarp_sign_func)(byte_t *, const byte_t *, llarp_buffer_t);
|
|||
typedef bool (*llarp_verify_func)(const byte_t *, llarp_buffer_t,
|
||||
const byte_t *);
|
||||
|
||||
/// library crypto configuration
|
||||
struct llarp_crypto
|
||||
{
|
||||
llarp_sym_cipher_func xchacha20;
|
||||
|
@ -70,9 +81,11 @@ struct llarp_crypto
|
|||
void (*encryption_keygen)(byte_t *);
|
||||
};
|
||||
|
||||
/// allocate crypto
|
||||
void
|
||||
llarp_crypto_libsodium_init(struct llarp_crypto *c);
|
||||
|
||||
/// initialize crypto
|
||||
bool
|
||||
llarp_crypto_initialized(struct llarp_crypto *c);
|
||||
|
||||
|
|
|
@ -5,55 +5,74 @@
|
|||
#include <llarp/logic.h>
|
||||
#include <llarp/threadpool.h>
|
||||
|
||||
/**
|
||||
* crypto_async.h
|
||||
*
|
||||
* asynchronous crypto functions
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// defined in crypto_async.cpp
|
||||
struct llarp_async_iwp;
|
||||
|
||||
/// allocator
|
||||
struct llarp_async_iwp *
|
||||
llarp_async_iwp_new(struct llarp_alloc *mem, struct llarp_crypto *crypto,
|
||||
struct llarp_logic *logic, struct llarp_threadpool *worker);
|
||||
|
||||
/// deallocator
|
||||
void
|
||||
llarp_async_iwp_free(struct llarp_async_iwp *iwp);
|
||||
|
||||
struct iwp_async_keygen;
|
||||
|
||||
/// define functor for keygen
|
||||
typedef void (*iwp_keygen_hook)(struct iwp_async_keygen *);
|
||||
|
||||
/// key generation request
|
||||
struct iwp_async_keygen
|
||||
{
|
||||
/// internal wire protocol async configuration
|
||||
struct llarp_async_iwp *iwp;
|
||||
/// a customizable pointer to pass data to iteration functor
|
||||
void *user;
|
||||
/// destination key buffer
|
||||
uint8_t *keybuf;
|
||||
/// iteration functor
|
||||
iwp_keygen_hook hook;
|
||||
};
|
||||
|
||||
/// generate a key by iterating on "iwp" using "keygen" request
|
||||
void
|
||||
iwp_call_async_keygen(struct llarp_async_iwp *iwp,
|
||||
struct iwp_async_keygen *keygen);
|
||||
|
||||
struct iwp_async_intro;
|
||||
|
||||
/// iwp_async_intro functor
|
||||
typedef void (*iwp_intro_hook)(struct iwp_async_intro *);
|
||||
|
||||
/// iwp_async_intro request
|
||||
struct iwp_async_intro
|
||||
{
|
||||
struct llarp_async_iwp *iwp;
|
||||
void *user;
|
||||
uint8_t *buf;
|
||||
size_t sz;
|
||||
/** nonce paramter */
|
||||
/// nonce paramter
|
||||
uint8_t *nonce;
|
||||
/** remote public key */
|
||||
/// remote public key
|
||||
uint8_t *remote_pubkey;
|
||||
/** local private key */
|
||||
/// local private key
|
||||
uint8_t *secretkey;
|
||||
/** callback */
|
||||
/// callback
|
||||
iwp_intro_hook hook;
|
||||
};
|
||||
|
||||
/// introduce internal wire protocol "iwp" using "intro" request
|
||||
void
|
||||
iwp_call_async_gen_intro(struct llarp_async_iwp *iwp,
|
||||
struct iwp_async_intro *intro);
|
||||
|
@ -64,38 +83,44 @@ iwp_call_async_verify_intro(struct llarp_async_iwp *iwp,
|
|||
|
||||
struct iwp_async_introack;
|
||||
|
||||
/// introduction acknowledgement functor
|
||||
typedef void (*iwp_introack_hook)(struct iwp_async_introack *);
|
||||
|
||||
/// introduction acknowledgement request
|
||||
struct iwp_async_introack
|
||||
{
|
||||
struct llarp_async_iwp *iwp;
|
||||
void *user;
|
||||
uint8_t *buf;
|
||||
size_t sz;
|
||||
/** nonce paramter */
|
||||
/// nonce paramter
|
||||
uint8_t *nonce;
|
||||
/** token paramter */
|
||||
/// token paramter
|
||||
uint8_t *token;
|
||||
/** remote public key */
|
||||
/// remote public key
|
||||
uint8_t *remote_pubkey;
|
||||
/** local private key */
|
||||
/// local private key
|
||||
uint8_t *secretkey;
|
||||
/** callback */
|
||||
/// callback
|
||||
iwp_introack_hook hook;
|
||||
};
|
||||
|
||||
/// generate introduction acknowledgement "iwp" using "introack" request
|
||||
void
|
||||
iwp_call_async_gen_introack(struct llarp_async_iwp *iwp,
|
||||
struct iwp_async_introack *introack);
|
||||
|
||||
/// verify introduction acknowledgement "iwp" using "introack" request
|
||||
void
|
||||
iwp_call_async_verify_introack(struct llarp_async_iwp *iwp,
|
||||
struct iwp_async_introack *introack);
|
||||
|
||||
struct iwp_async_session_start;
|
||||
|
||||
/// start session functor
|
||||
typedef void (*iwp_session_start_hook)(struct iwp_async_session_start *);
|
||||
|
||||
/// start session request
|
||||
struct iwp_async_session_start
|
||||
{
|
||||
struct llarp_async_iwp *iwp;
|
||||
|
@ -110,16 +135,19 @@ struct iwp_async_session_start
|
|||
iwp_session_start_hook hook;
|
||||
};
|
||||
|
||||
/// generate session start "iwp" using "start" request
|
||||
void
|
||||
iwp_call_async_gen_session_start(struct llarp_async_iwp *iwp,
|
||||
struct iwp_async_session_start *start);
|
||||
|
||||
/// verify session start "iwp" using "start" request
|
||||
void
|
||||
iwp_call_async_verify_session_start(struct llarp_async_iwp *iwp,
|
||||
struct iwp_async_session_start *start);
|
||||
|
||||
struct iwp_async_frame;
|
||||
|
||||
/// internal wire protocol frame request
|
||||
typedef void (*iwp_async_frame_hook)(struct iwp_async_frame *);
|
||||
|
||||
struct iwp_async_frame
|
||||
|
@ -133,10 +161,12 @@ struct iwp_async_frame
|
|||
uint8_t buf[1500];
|
||||
};
|
||||
|
||||
/// decrypt iwp frame "iwp" using "frame" request
|
||||
void
|
||||
iwp_call_async_frame_decrypt(struct llarp_async_iwp *iwp,
|
||||
struct iwp_async_frame *frame);
|
||||
|
||||
/// encrypt iwp frame "iwp" using "frame" request
|
||||
void
|
||||
iwp_call_async_frame_encrypt(struct llarp_async_iwp *iwp,
|
||||
struct iwp_async_frame *frame);
|
||||
|
|
|
@ -1,13 +1,23 @@
|
|||
#ifndef LLARP_DHT_H_
|
||||
#define LLARP_DHT_H_
|
||||
|
||||
/**
|
||||
* dht.h
|
||||
*
|
||||
* DHT functions
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct llarp_dht_context;
|
||||
|
||||
/// allocator
|
||||
struct llarp_dht_context*
|
||||
llarp_dht_context_new();
|
||||
|
||||
/// deallocator
|
||||
void
|
||||
llarp_dht_context_free(struct llarp_dht_context* dht);
|
||||
|
||||
|
|
|
@ -4,10 +4,19 @@
|
|||
#include <llarp/link.h>
|
||||
#include <llarp/mem.h>
|
||||
|
||||
/**
|
||||
* dtls.h
|
||||
*
|
||||
* Datagram TLS functions
|
||||
* https://en.wikipedia.org/wiki/Datagram_Transport_Layer_Security for more info
|
||||
* on DTLS
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// DTLS configuration
|
||||
struct llarp_dtls_args
|
||||
{
|
||||
struct llarp_alloc* mem;
|
||||
|
@ -15,6 +24,7 @@ struct llarp_dtls_args
|
|||
const char* certfile;
|
||||
};
|
||||
|
||||
/// allocator
|
||||
void
|
||||
dtls_link_init(struct llarp_link* link, struct llarp_dtls_args args,
|
||||
struct llarp_msg_muxer* muxer);
|
||||
|
|
|
@ -7,23 +7,35 @@
|
|||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
/**
|
||||
* ev.h
|
||||
*
|
||||
* event handler (cross platform high performance event system for IO)
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct llarp_ev_loop;
|
||||
|
||||
/// allocator
|
||||
void
|
||||
llarp_ev_loop_alloc(struct llarp_ev_loop **ev);
|
||||
|
||||
// deallocator
|
||||
void
|
||||
llarp_ev_loop_free(struct llarp_ev_loop **ev);
|
||||
|
||||
/// run main loop
|
||||
int
|
||||
llarp_ev_loop_run(struct llarp_ev_loop *ev);
|
||||
/** stop event loop and wait for it to complete all jobs */
|
||||
|
||||
/// stop event loop and wait for it to complete all jobs
|
||||
void
|
||||
llarp_ev_loop_stop(struct llarp_ev_loop *ev);
|
||||
|
||||
/// UDP handling configuration
|
||||
struct llarp_udp_io
|
||||
{
|
||||
void *user;
|
||||
|
@ -33,14 +45,17 @@ struct llarp_udp_io
|
|||
ssize_t);
|
||||
};
|
||||
|
||||
/// add UDP handler
|
||||
int
|
||||
llarp_ev_add_udp(struct llarp_ev_loop *ev, struct llarp_udp_io *udp,
|
||||
const struct sockaddr *src);
|
||||
|
||||
/// schedule UDP packet
|
||||
int
|
||||
llarp_ev_udp_sendto(struct llarp_udp_io *udp, const struct sockaddr *to,
|
||||
const void *data, size_t sz);
|
||||
|
||||
/// close UDP handler
|
||||
int
|
||||
llarp_ev_close_udp(struct llarp_udp_io *udp);
|
||||
|
||||
|
|
|
@ -4,10 +4,17 @@
|
|||
#include <llarp/crypto.h>
|
||||
#include <llarp/net.h>
|
||||
|
||||
/**
|
||||
* exit_info.h
|
||||
*
|
||||
* utilities for handling exits on the llarp network
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// Exit info model
|
||||
struct llarp_xi
|
||||
{
|
||||
struct in6_addr address;
|
||||
|
|
|
@ -133,9 +133,8 @@ extern "C" {
|
|||
bool
|
||||
llarp_ai_bdecode(struct llarp_ai *ai, llarp_buffer_t *buff)
|
||||
{
|
||||
struct dict_reader reader;
|
||||
reader.user = ai;
|
||||
reader.on_key = &llarp_ai_decode_key;
|
||||
struct dict_reader reader = {
|
||||
.buffer = nullptr, .user = ai, .on_key = &llarp_ai_decode_key};
|
||||
return bdecode_read_dict(buff, &reader);
|
||||
}
|
||||
|
||||
|
@ -188,9 +187,8 @@ llarp_ai_list_bencode(struct llarp_ai_list *l, llarp_buffer_t *buff)
|
|||
{
|
||||
if(!bencode_start_list(buff))
|
||||
return false;
|
||||
struct llarp_ai_list_iter ai_itr;
|
||||
ai_itr.user = buff;
|
||||
ai_itr.visit = &llarp_ai_list_iter_bencode;
|
||||
struct llarp_ai_list_iter ai_itr = {
|
||||
.user = buff, .list = nullptr, .visit = &llarp_ai_list_iter_bencode};
|
||||
llarp_ai_list_iterate(l, &ai_itr);
|
||||
return bencode_end(buff);
|
||||
}
|
||||
|
@ -250,9 +248,8 @@ llarp_ai_list_index(struct llarp_ai_list *l, ssize_t idx, struct llarp_ai *dst)
|
|||
bool
|
||||
llarp_ai_list_bdecode(struct llarp_ai_list *l, llarp_buffer_t *buff)
|
||||
{
|
||||
struct list_reader r;
|
||||
r.user = l;
|
||||
r.on_item = &llarp_ai_list_bdecode_item;
|
||||
struct list_reader r = {
|
||||
.buffer = nullptr, .user = l, .on_item = &llarp_ai_list_bdecode_item};
|
||||
return bdecode_read_list(buff, &r);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ namespace iwp
|
|||
size() const
|
||||
{
|
||||
uint16_t sz = (ptr[3] | 0x00ff) << 8;
|
||||
sz |= (ptr[2] & 0x00ff);
|
||||
sz |= (ptr[2] & 0x00ff);
|
||||
return sz;
|
||||
}
|
||||
|
||||
|
@ -213,12 +213,13 @@ namespace iwp
|
|||
{
|
||||
}
|
||||
|
||||
bool reassemble(std::vector<byte_t> & buffer)
|
||||
bool
|
||||
reassemble(std::vector< byte_t > &buffer)
|
||||
{
|
||||
// TODO: implement
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
put_message(llarp_buffer_t &buf, const byte_t *hash, uint64_t id,
|
||||
uint16_t mtu = 1024)
|
||||
|
@ -260,12 +261,12 @@ namespace iwp
|
|||
typedef std::vector< byte_t > sendbuf_t;
|
||||
std::queue< sendbuf_t > sendqueue;
|
||||
|
||||
llarp::FrameHandler * handler = nullptr;
|
||||
llarp::FrameHandler *handler = nullptr;
|
||||
|
||||
void
|
||||
inbound_frame_complete(uint64_t id)
|
||||
{
|
||||
std::vector<byte_t> buf;
|
||||
std::vector< byte_t > buf;
|
||||
if(rx[id].reassemble(buf) && handler)
|
||||
{
|
||||
if(handler->Process(buf))
|
||||
|
@ -275,7 +276,7 @@ namespace iwp
|
|||
}
|
||||
rx.erase(id);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
init_sendbuf(sendbuf_t &buf, msgtype t, uint16_t sz, uint8_t flags)
|
||||
{
|
||||
|
@ -346,7 +347,8 @@ namespace iwp
|
|||
{
|
||||
// short XMIT , no fragments so just ack
|
||||
auto id = x.msgid();
|
||||
push_ackfor(id, 0); // TODO: should this be before or after handling frame?
|
||||
push_ackfor(
|
||||
id, 0); // TODO: should this be before or after handling frame?
|
||||
inbound_frame_complete(id);
|
||||
}
|
||||
}
|
||||
|
@ -553,7 +555,7 @@ namespace iwp
|
|||
return;
|
||||
}
|
||||
printf("session start okay\n");
|
||||
|
||||
|
||||
// auto msg = new transit_message;
|
||||
|
||||
// auto buffer = llarp::EncodeLIM< decltype(buf) >(buf, our_router);
|
||||
|
@ -685,7 +687,7 @@ namespace iwp
|
|||
// TODO don't hard code 1500
|
||||
if(sz > 1500)
|
||||
return nullptr;
|
||||
|
||||
|
||||
iwp_async_frame *frame = new iwp_async_frame;
|
||||
if(buf)
|
||||
memcpy(frame->buf, buf, sz);
|
||||
|
@ -700,8 +702,8 @@ namespace iwp
|
|||
{
|
||||
printf("encrypt frame of size %ld\n", sz);
|
||||
// 64 bytes frame overhead for nonce and hmac
|
||||
auto frame = alloc_frame(nullptr, sz+64);
|
||||
memcpy(frame->buf +64, buf, sz-64);
|
||||
auto frame = alloc_frame(nullptr, sz + 64);
|
||||
memcpy(frame->buf + 64, buf, sz - 64);
|
||||
frame->hook = &handle_frame_encrypt;
|
||||
iwp_call_async_frame_encrypt(iwp, frame);
|
||||
}
|
||||
|
|
|
@ -355,10 +355,7 @@ llarp_rc_sign(llarp_crypto *crypto, const byte_t *seckey, struct llarp_rc *rc)
|
|||
{
|
||||
// sign
|
||||
signbuf.sz = signbuf.cur - signbuf.base;
|
||||
printf("router.cpp::llarp_rc_sign - sized [%zu/%zu]\n", signbuf.sz,
|
||||
MAX_RC_SIZE);
|
||||
crypto->sign(rc->signature, seckey, signbuf);
|
||||
printf("router.cpp::llarp_rc_sign - signed\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue