mirror of https://github.com/oxen-io/lokinet
more
parent
dcc5e6e348
commit
8c2bbbb2eb
@ -0,0 +1,8 @@
|
||||
#ifndef LLARP_COMMON_H
|
||||
#define LLARP_COMMON_H
|
||||
#ifdef __STRICT_ANSI__
|
||||
#define INLINE __inline__
|
||||
#else
|
||||
#define INLINE inline
|
||||
#endif
|
||||
#endif
|
@ -0,0 +1,25 @@
|
||||
#ifndef LLARP_XR_H
|
||||
#define LLARP_XR_H
|
||||
#include <llarp/buffer.h>
|
||||
#include <llarp/net.h>
|
||||
#include <stdint.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
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);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
@ -0,0 +1,33 @@
|
||||
#include <llarp/exit_info.h>
|
||||
#include <llarp/bencode.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <string.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;
|
||||
|
||||
/** 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;
|
||||
|
||||
/** 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;
|
||||
|
||||
/** public key */
|
||||
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;
|
||||
|
||||
return bencode_end(buff);
|
||||
}
|
||||
|
@ -1,18 +0,0 @@
|
||||
#include "exit_info.hpp"
|
||||
#include "bencode.hpp"
|
||||
|
||||
namespace llarp {
|
||||
template <>
|
||||
bool BEncode(const struct llarp_xi &xi, llarp_buffer_t *buff) {
|
||||
return bencodeDict(buff) &&
|
||||
bencodeDict_Bytes(buff, "a", &xi.address, sizeof(xi.address)) &&
|
||||
bencodeDict_Bytes(buff, "b", &xi.netmask, sizeof(xi.netmask)) &&
|
||||
bencodeDict_Int(buff, "v", 0) && bencodeEnd(buff);
|
||||
}
|
||||
} // namespace llarp
|
||||
|
||||
extern "C" {
|
||||
bool llarp_xi_bencode(struct llarp_xi *xi, llarp_buffer_t *buff) {
|
||||
return llarp::BEncode(*xi, buff);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
#include <llarp/exit_route.h>
|
||||
#include <llarp/bencode.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
bool llarp_xr_bencode(struct llarp_xr * xr, llarp_buffer_t * buff)
|
||||
{
|
||||
char addr_buff [128] = {0};
|
||||
const char * addr;
|
||||
|
||||
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;
|
||||
|
||||
/** 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 */
|
||||
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;
|
||||
|
||||
/** lifetime */
|
||||
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;
|
||||
|
||||
/* end */
|
||||
return bencode_end(buff);
|
||||
}
|
Loading…
Reference in New Issue