mirror of https://github.com/oxen-io/lokinet
refactor to use AlignedBuffer for public key, shared secret, nonce, secret key etc
parent
b354dbd492
commit
a8ab66f4f8
@ -0,0 +1,101 @@
|
||||
#ifndef LLARP_BENCODE_HPP
|
||||
#define LLARP_BENCODE_HPP
|
||||
|
||||
#include <llarp/bencode.h>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
bool
|
||||
BEncodeWriteDictMsgType(llarp_buffer_t* buf, const char* k, const char* t)
|
||||
{
|
||||
return bencode_write_bytestring(buf, k, 1)
|
||||
&& bencode_write_bytestring(buf, t, 1);
|
||||
}
|
||||
|
||||
template < typename Obj_t >
|
||||
bool
|
||||
BEncodeWriteDictEntry(const char* k, const Obj_t& o, llarp_buffer_t* buf)
|
||||
{
|
||||
return bencode_write_bytestring(buf, k, 1) && o.BEncode(buf);
|
||||
}
|
||||
|
||||
template < typename Item_t >
|
||||
bool
|
||||
BEncodeRead(Item_t& item, llarp_buffer_t* buf);
|
||||
|
||||
template < typename Item_t >
|
||||
bool
|
||||
BEncodeMaybeReadDictEntry(const char* k, Item_t& item, bool& read,
|
||||
llarp_buffer_t key, llarp_buffer_t* buf)
|
||||
{
|
||||
llarp_buffer_t strbuf;
|
||||
if(llarp_buffer_eq(key, k))
|
||||
{
|
||||
if(!bencode_read_string(buf, &strbuf))
|
||||
return false;
|
||||
if(!item.BDecode(buf))
|
||||
return false;
|
||||
read = true;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template < typename Item_t >
|
||||
bool
|
||||
BEncodeMaybeReadVersion(const char* k, Item_t& item, uint64_t expect,
|
||||
bool& read, llarp_buffer_t key, llarp_buffer_t* buf)
|
||||
{
|
||||
if(llarp_buffer_eq(key, k))
|
||||
{
|
||||
if(!bencode_read_integer(buf, &item))
|
||||
return false;
|
||||
read = item == expect;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template < typename Iter >
|
||||
bool
|
||||
BEncodeWriteList(Iter itr, Iter end, llarp_buffer_t* buf)
|
||||
{
|
||||
if(!bencode_start_list(buf))
|
||||
return false;
|
||||
while(itr != end)
|
||||
if(!itr->BEncode(buf))
|
||||
return false;
|
||||
else
|
||||
++itr;
|
||||
return bencode_end(buf);
|
||||
}
|
||||
|
||||
template < typename List_t >
|
||||
bool
|
||||
BEncodeReadList(List_t& result, llarp_buffer_t* buf)
|
||||
{
|
||||
if(*buf->cur != 'l') // ensure is a list
|
||||
return false;
|
||||
|
||||
buf->cur++;
|
||||
while(llarp_buffer_size_left(*buf) && *buf->cur != 'e')
|
||||
{
|
||||
if(!result.emplace(result.end())->BDecode(buf))
|
||||
return false;
|
||||
}
|
||||
if(*buf->cur != 'e') // make sure we're at a list end
|
||||
return false;
|
||||
buf->cur++;
|
||||
return true;
|
||||
}
|
||||
|
||||
template < typename List_t >
|
||||
bool
|
||||
BEncodeWriteDictList(const char* k, List_t& list, llarp_buffer_t* buf)
|
||||
{
|
||||
return bencode_write_bytestring(buf, k, 1)
|
||||
&& BEncodeWriteList(list.begin(), list.end(), buf);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,36 +0,0 @@
|
||||
#ifndef LLARP_OBMD_H_
|
||||
#define LLARP_OBMD_H_
|
||||
#include <llarp/buffer.h>
|
||||
#include <llarp/crypto.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* forward decl */
|
||||
struct llarp_link;
|
||||
|
||||
/**
|
||||
* link layer outbound message sending muxer
|
||||
*/
|
||||
struct llarp_link_dispatcher;
|
||||
|
||||
struct llarp_link_dispatcher *
|
||||
llarp_init_link_dispatcher();
|
||||
void
|
||||
llarp_free_link_dispatcher(struct llarp_link_dispatcher **dispatcher);
|
||||
|
||||
void
|
||||
llarp_link_sendto(struct llarp_link_dispatcher *dispatcher,
|
||||
llarp_pubkey_t pubkey, llarp_buffer_t msg);
|
||||
|
||||
void
|
||||
llarp_link_register(struct llarp_link_dispatcher *dispatcher,
|
||||
struct llarp_link *link);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,46 +0,0 @@
|
||||
#ifndef LLARP_ROUTER_IDENT_H
|
||||
#define LLARP_ROUTER_IDENT_H
|
||||
#include <llarp/address_info.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
|
||||
*/
|
||||
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;
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
Loading…
Reference in New Issue