Merge remote-tracking branch 'origin/staging' into staging

pull/268/head
Jeff Becker 5 years ago
commit 00eede9160
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -60,11 +60,13 @@ namespace abyss
}
static void
OnRead(llarp_tcp_conn* conn, llarp_buffer_t buf)
OnRead(llarp_tcp_conn* conn, const llarp_buffer_t& buf)
{
ConnImpl* self = static_cast< ConnImpl* >(conn->user);
if(!self->ProcessRead((const char*)buf.base, buf.sz))
{
self->CloseError();
}
}
static void
@ -220,7 +222,7 @@ namespace abyss
body.size());
if(sz <= 0)
return;
if(!llarp_tcp_conn_async_write(m_Conn, llarp::InitBuffer(buf, sz)))
if(!llarp_tcp_conn_async_write(m_Conn, llarp_buffer_t(buf, sz)))
{
llarp::LogError("failed to write first part of request");
CloseError();
@ -237,15 +239,14 @@ namespace abyss
{
// header name
if(!llarp_tcp_conn_async_write(
m_Conn,
llarp::InitBuffer(item.first.c_str(), item.first.size())))
m_Conn, llarp_buffer_t(item.first.c_str(), item.first.size())))
{
CloseError();
return;
}
// header delimiter
if(!llarp_tcp_conn_async_write(
m_Conn, llarp::InitBuffer(buf, 2 * sizeof(char))))
if(!llarp_tcp_conn_async_write(m_Conn,
llarp_buffer_t(buf, 2 * sizeof(char))))
{
CloseError();
return;
@ -253,14 +254,14 @@ namespace abyss
// header value
if(!llarp_tcp_conn_async_write(
m_Conn,
llarp::InitBuffer(item.second.c_str(), item.second.size())))
llarp_buffer_t(item.second.c_str(), item.second.size())))
{
CloseError();
return;
}
// CRLF
if(!llarp_tcp_conn_async_write(
m_Conn, llarp::InitBuffer(buf + 2, 2 * sizeof(char))))
m_Conn, llarp_buffer_t(buf + 2, 2 * sizeof(char))))
{
CloseError();
return;
@ -268,14 +269,14 @@ namespace abyss
}
// CRLF
if(!llarp_tcp_conn_async_write(
m_Conn, llarp::InitBuffer(buf + 2, 2 * sizeof(char))))
m_Conn, llarp_buffer_t(buf + 2, 2 * sizeof(char))))
{
CloseError();
return;
}
// request body
if(!llarp_tcp_conn_async_write(
m_Conn, llarp::InitBuffer(body.c_str(), body.size())))
m_Conn, llarp_buffer_t(body.c_str(), body.size())))
{
CloseError();
return;

@ -112,13 +112,13 @@ namespace abyss
code, msg.c_str(), contentType, contentLength);
if(sz <= 0)
return false;
if(!llarp_tcp_conn_async_write(_conn, llarp::InitBuffer(buf, sz)))
if(!llarp_tcp_conn_async_write(_conn, llarp_buffer_t(buf, sz)))
return false;
m_State = eWriteHTTPBody;
return llarp_tcp_conn_async_write(
_conn, llarp::InitBuffer(content, contentLength));
_conn, llarp_buffer_t(content, contentLength));
}
bool
@ -260,7 +260,7 @@ namespace abyss
}
static void
OnRead(llarp_tcp_conn* conn, llarp_buffer_t buf)
OnRead(llarp_tcp_conn* conn, const llarp_buffer_t& buf)
{
ConnImpl* self = static_cast< ConnImpl* >(conn->user);
if(!self->ProcessRead((const char*)buf.base, buf.sz))

@ -4,7 +4,7 @@
#include <crypto/constants.hpp>
#include <crypto/types.hpp>
#include <util/buffer.h>
#include <util/buffer.hpp>
#include <functional>
#include <stdbool.h>
@ -28,7 +28,8 @@ namespace llarp
SharedSecret &, const PubKey &, const SecretKey &, const TunnelNonce &) >;
/// SH(result, body)
using shorthash_func = std::function< bool(ShortHash &, llarp_buffer_t) >;
using shorthash_func =
std::function< bool(ShortHash &, const llarp_buffer_t &) >;
/// library crypto configuration
struct Crypto
@ -37,12 +38,13 @@ namespace llarp
/// xchacha symmetric cipher
virtual bool
xchacha20(llarp_buffer_t, const SharedSecret &, const TunnelNonce &) = 0;
xchacha20(const llarp_buffer_t &, const SharedSecret &,
const TunnelNonce &) = 0;
/// xchacha symmetric cipher (multibuffer)
virtual bool
xchacha20_alt(llarp_buffer_t, llarp_buffer_t, const SharedSecret &,
const byte_t *) = 0;
xchacha20_alt(const llarp_buffer_t &, const llarp_buffer_t &,
const SharedSecret &, const byte_t *) = 0;
/// path dh creator's side
virtual bool
@ -62,24 +64,25 @@ namespace llarp
const TunnelNonce &) = 0;
/// blake2b 512 bit
virtual bool
hash(byte_t *, llarp_buffer_t) = 0;
hash(byte_t *, const llarp_buffer_t &) = 0;
/// blake2b 256 bit
virtual bool
shorthash(ShortHash &, llarp_buffer_t) = 0;
shorthash(ShortHash &, const llarp_buffer_t &) = 0;
/// blake2s 256 bit hmac
virtual bool
hmac(byte_t *, llarp_buffer_t, const SharedSecret &) = 0;
hmac(byte_t *, const llarp_buffer_t &, const SharedSecret &) = 0;
/// ed25519 sign
virtual bool
sign(Signature &, const SecretKey &, llarp_buffer_t) = 0;
sign(Signature &, const SecretKey &, const llarp_buffer_t &) = 0;
/// ed25519 verify
virtual bool
verify(const PubKey &, llarp_buffer_t, const Signature &) = 0;
verify(const PubKey &, const llarp_buffer_t &, const Signature &) = 0;
/// seed to secretkey
virtual bool
seed_to_secretkey(llarp::SecretKey &, const llarp::IdentitySecret &) = 0;
/// randomize buffer
virtual void randomize(llarp_buffer_t) = 0;
virtual void
randomize(const llarp_buffer_t &) = 0;
/// randomizer memory
virtual void
randbytes(void *, size_t) = 0;

@ -89,8 +89,8 @@ namespace llarp
}
bool
CryptoLibSodium::xchacha20(llarp_buffer_t buff, const SharedSecret &k,
const TunnelNonce &n)
CryptoLibSodium::xchacha20(const llarp_buffer_t &buff,
const SharedSecret &k, const TunnelNonce &n)
{
return crypto_stream_xchacha20_xor(buff.base, buff.base, buff.sz,
n.data(), k.data())
@ -98,7 +98,8 @@ namespace llarp
}
bool
CryptoLibSodium::xchacha20_alt(llarp_buffer_t out, llarp_buffer_t in,
CryptoLibSodium::xchacha20_alt(const llarp_buffer_t &out,
const llarp_buffer_t &in,
const SharedSecret &k, const byte_t *n)
{
if(in.sz > out.sz)
@ -138,7 +139,7 @@ namespace llarp
}
bool
CryptoLibSodium::hash(uint8_t *result, llarp_buffer_t buff)
CryptoLibSodium::hash(uint8_t *result, const llarp_buffer_t &buff)
{
return crypto_generichash_blake2b(result, HASHSIZE, buff.base, buff.sz,
nullptr, 0)
@ -146,7 +147,7 @@ namespace llarp
}
bool
CryptoLibSodium::shorthash(ShortHash &result, llarp_buffer_t buff)
CryptoLibSodium::shorthash(ShortHash &result, const llarp_buffer_t &buff)
{
return crypto_generichash_blake2b(result.data(), ShortHash::SIZE,
buff.base, buff.sz, nullptr, 0)
@ -154,7 +155,7 @@ namespace llarp
}
bool
CryptoLibSodium::hmac(byte_t *result, llarp_buffer_t buff,
CryptoLibSodium::hmac(byte_t *result, const llarp_buffer_t &buff,
const SharedSecret &secret)
{
return crypto_generichash_blake2b(result, HMACSIZE, buff.base, buff.sz,
@ -164,7 +165,7 @@ namespace llarp
bool
CryptoLibSodium::sign(Signature &result, const SecretKey &secret,
llarp_buffer_t buff)
const llarp_buffer_t &buff)
{
int rc = crypto_sign_detached(result.data(), nullptr, buff.base, buff.sz,
secret.data());
@ -172,7 +173,7 @@ namespace llarp
}
bool
CryptoLibSodium::verify(const PubKey &pub, llarp_buffer_t buff,
CryptoLibSodium::verify(const PubKey &pub, const llarp_buffer_t &buff,
const Signature &sig)
{
int rc = crypto_sign_verify_detached(sig.data(), buff.base, buff.sz,
@ -190,7 +191,7 @@ namespace llarp
}
void
CryptoLibSodium::randomize(llarp_buffer_t buff)
CryptoLibSodium::randomize(const llarp_buffer_t &buff)
{
randombytes((unsigned char *)buff.base, buff.sz);
}

@ -17,13 +17,13 @@ namespace llarp
/// xchacha symmetric cipher
bool
xchacha20(llarp_buffer_t, const SharedSecret &,
xchacha20(const llarp_buffer_t &, const SharedSecret &,
const TunnelNonce &) override;
/// xchacha symmetric cipher (multibuffer)
bool
xchacha20_alt(llarp_buffer_t, llarp_buffer_t, const SharedSecret &,
const byte_t *) override;
xchacha20_alt(const llarp_buffer_t &, const llarp_buffer_t &,
const SharedSecret &, const byte_t *) override;
/// path dh creator's side
bool
@ -43,25 +43,27 @@ namespace llarp
const TunnelNonce &) override;
/// blake2b 512 bit
bool
hash(byte_t *, llarp_buffer_t) override;
hash(byte_t *, const llarp_buffer_t &) override;
/// blake2b 256 bit
bool
shorthash(ShortHash &, llarp_buffer_t) override;
shorthash(ShortHash &, const llarp_buffer_t &) override;
/// blake2s 256 bit hmac
bool
hmac(byte_t *, llarp_buffer_t, const SharedSecret &) override;
hmac(byte_t *, const llarp_buffer_t &, const SharedSecret &) override;
/// ed25519 sign
bool
sign(Signature &, const SecretKey &, llarp_buffer_t) override;
sign(Signature &, const SecretKey &, const llarp_buffer_t &) override;
/// ed25519 verify
bool
verify(const PubKey &, llarp_buffer_t, const Signature &) override;
verify(const PubKey &, const llarp_buffer_t &,
const Signature &) override;
/// seed to secretkey
bool
seed_to_secretkey(llarp::SecretKey &,
const llarp::IdentitySecret &) override;
/// randomize buffer
void randomize(llarp_buffer_t) override;
void
randomize(const llarp_buffer_t &) override;
/// randomizer memory
void
randbytes(void *, size_t) override;

@ -4,7 +4,7 @@
#include <constants/link_layer.hpp>
#include <util/aligned.hpp>
#include <util/bencode.h>
#include <util/buffer.h>
#include <util/buffer.hpp>
#include <util/mem.hpp>
#include <vector>
@ -84,7 +84,7 @@ namespace llarp
Encrypted&
operator=(const Encrypted& other)
{
return (*this) = other.Buffer();
return Encrypted::operator=(llarp_buffer_t(other));
}
Encrypted&
@ -102,9 +102,7 @@ namespace llarp
void
Fill(byte_t fill)
{
size_t idx = 0;
while(idx < _sz)
_buf[idx++] = fill;
std::fill(_buf.begin(), _buf.begin() + _sz, fill);
}
void
@ -135,12 +133,6 @@ namespace llarp
return &m_Buffer;
}
llarp_buffer_t
Buffer() const
{
return m_Buffer;
}
size_t
size()
{

@ -41,7 +41,7 @@ namespace llarp
return true;
}
std::array< byte_t, 128 > tmp;
llarp_buffer_t buf = llarp::Buffer(tmp);
llarp_buffer_t buf(tmp);
if(sz > sizeof(tmp))
{
return false;
@ -53,8 +53,8 @@ namespace llarp
bool
SecretKey::SaveToFile(const char* fname) const
{
byte_t tmp[128];
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, 128 > tmp;
llarp_buffer_t buf(tmp);
if(!BEncode(&buf))
{
return false;

@ -3,7 +3,7 @@
#include <crypto/crypto.hpp>
#include <router_contact.hpp>
#include <util/buffer.h>
#include <util/buffer.hpp>
/**
* dht.h

@ -12,7 +12,7 @@ namespace llarp
}
bool
FindIntroMessage::DecodeKey(llarp_buffer_t k, llarp_buffer_t* val)
FindIntroMessage::DecodeKey(const llarp_buffer_t &k, llarp_buffer_t* val)
{
bool read = false;

@ -51,7 +51,7 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* val) override;
bool
HandleMessage(

@ -94,7 +94,7 @@ namespace llarp
}
bool
FindRouterMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *val)
FindRouterMessage::DecodeKey(const llarp_buffer_t &key, llarp_buffer_t *val)
{
llarp_buffer_t strbuf;

@ -31,7 +31,7 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* val) override;
virtual bool
HandleMessage(

@ -80,7 +80,7 @@ namespace llarp
}
bool
GotIntroMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf)
GotIntroMessage::DecodeKey(const llarp_buffer_t &key, llarp_buffer_t *buf)
{
if(llarp_buffer_eq(key, "I"))
{

@ -40,7 +40,7 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* val) override;
virtual bool
HandleMessage(

@ -49,7 +49,7 @@ namespace llarp
}
bool
GotRouterMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *val)
GotRouterMessage::DecodeKey(const llarp_buffer_t &key, llarp_buffer_t *val)
{
if(llarp_buffer_eq(key, "K"))
{

@ -38,7 +38,7 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* val) override;
virtual bool
HandleMessage(

@ -15,7 +15,7 @@ namespace llarp
}
bool
PublishIntroMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *val)
PublishIntroMessage::DecodeKey(const llarp_buffer_t &key, llarp_buffer_t *val)
{
bool read = false;
if(llarp_buffer_eq(key, "E"))

@ -35,7 +35,7 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* val) override;
virtual bool
HandleMessage(

@ -1,5 +1,6 @@
#include <dnsd.hpp> // for llarp_handle_dnsd_recvfrom, dnsc
#include <util/buffer.hpp>
#include <util/endian.hpp>
#include <util/logger.hpp>
@ -605,17 +606,17 @@ extern "C"
void
llarp_handle_dns_recvfrom(struct llarp_udp_io *udp,
const struct sockaddr *addr, llarp_buffer_t buf)
const struct sockaddr *addr, ManagedBuffer buf)
{
// auto buffer = llarp::StackBuffer< decltype(castBuf) >(castBuf);
dns_msg_header hdr;
if(!decode_hdr(&buf, &hdr))
if(!decode_hdr(&buf.underlying, &hdr))
{
llarp::LogError("failed to decode dns header");
return;
}
// rewind
buf.cur = buf.base;
buf.underlying.cur = buf.underlying.base;
llarp::LogDebug("msg id ", hdr.id);
llarp::LogDebug("msg qr ", (uint8_t)hdr.qr);
if(!udp)

@ -147,6 +147,6 @@ extern "C"
void
llarp_handle_dns_recvfrom(struct llarp_udp_io *udp,
const struct sockaddr *addr, llarp_buffer_t buf);
const struct sockaddr *addr, ManagedBuffer buf);
}
#endif

@ -5,6 +5,8 @@
#include <util/endian.hpp>
#include <util/logger.hpp>
#include <array>
namespace llarp
{
namespace dns
@ -175,13 +177,14 @@ namespace llarp
hdr_fields |= (1 << 15);
const auto& question = questions[0];
answers.emplace_back();
auto& rec = answers.back();
rec.rr_name = question.qname;
rec.rr_type = question.qtype;
rec.rr_class = qClassIN;
rec.ttl = ttl;
byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
auto& rec = answers.back();
rec.rr_name = question.qname;
rec.rr_type = question.qtype;
rec.rr_class = qClassIN;
rec.ttl = ttl;
std::array< byte_t, 512 > tmp = {0};
;
llarp_buffer_t buf(tmp);
if(EncodeName(&buf, name))
{
buf.sz = buf.cur - buf.base;
@ -199,13 +202,13 @@ namespace llarp
hdr_fields |= (1 << 15);
const auto& question = questions[0];
answers.emplace_back();
auto& rec = answers.back();
rec.rr_name = question.qname;
rec.rr_type = qTypeCNAME;
rec.rr_class = qClassIN;
rec.ttl = ttl;
byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
auto& rec = answers.back();
rec.rr_name = question.qname;
rec.rr_type = qTypeCNAME;
rec.rr_class = qClassIN;
rec.ttl = ttl;
std::array< byte_t, 512 > tmp = {0};
llarp_buffer_t buf(tmp);
if(EncodeName(&buf, name))
{
buf.sz = buf.cur - buf.base;
@ -223,13 +226,13 @@ namespace llarp
hdr_fields |= (1 << 15);
const auto& question = questions[0];
answers.emplace_back();
auto& rec = answers.back();
rec.rr_name = question.qname;
rec.rr_type = qTypeMX;
rec.rr_class = qClassIN;
rec.ttl = ttl;
byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
auto& rec = answers.back();
rec.rr_name = question.qname;
rec.rr_type = qTypeMX;
rec.rr_class = qClassIN;
rec.ttl = ttl;
std::array< byte_t, 512 > tmp = {0};
llarp_buffer_t buf(tmp);
llarp_buffer_put_uint16(&buf, priority);
if(EncodeName(&buf, name))
{

@ -2,7 +2,7 @@
#define LLARP_DNS_NAME_HPP
#include <net/net_int.hpp>
#include <util/buffer.h>
#include <util/buffer.hpp>
#include <string>

@ -1,8 +1,8 @@
#ifndef LLARP_DNS_REC_TYPES_HPP
#define LLARP_DNS_REC_TYPES_HPP
#include <net/net.hpp> // for llarp::Addr , llarp::huint32_t
#include <util/buffer.h> // for byte_t
#include <net/net.hpp> // for llarp::Addr , llarp::huint32_t
#include <util/types.hpp> // for byte_t
#include <vector>

@ -1,7 +1,7 @@
#ifndef LLARP_DNS_SERIALIZE_HPP
#define LLARP_DNS_SERIALIZE_HPP
#include <util/buffer.h>
#include <util/buffer.hpp>
#include <vector>

@ -2,6 +2,8 @@
#include <crypto/crypto.hpp>
#include <array>
namespace llarp
{
namespace dns
@ -40,16 +42,16 @@ namespace llarp
void
Proxy::HandleUDPRecv_server(llarp_udp_io* u, const sockaddr* from,
llarp_buffer_t buf)
ManagedBuffer buf)
{
static_cast< Proxy* >(u->user)->HandlePktServer(*from, &buf);
static_cast< Proxy* >(u->user)->HandlePktServer(*from, &buf.underlying);
}
void
Proxy::HandleUDPRecv_client(llarp_udp_io* u, const sockaddr* from,
llarp_buffer_t buf)
ManagedBuffer buf)
{
static_cast< Proxy* >(u->user)->HandlePktClient(*from, &buf);
static_cast< Proxy* >(u->user)->HandlePktClient(*from, &buf.underlying);
}
llarp::Addr
@ -73,8 +75,8 @@ namespace llarp
void
Proxy::SendMessageTo(llarp::Addr to, Message msg)
{
byte_t tmp[1500] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, 1500 > tmp = {0};
llarp_buffer_t buf(tmp);
if(msg.Encode(&buf))
{
buf.sz = buf.cur - buf.base;

@ -42,10 +42,10 @@ namespace llarp
/// low level packet handler
static void
HandleUDPRecv_client(llarp_udp_io*, const struct sockaddr*,
llarp_buffer_t);
ManagedBuffer);
static void
HandleUDPRecv_server(llarp_udp_io*, const struct sockaddr*,
llarp_buffer_t);
ManagedBuffer);
/// low level ticker
static void

@ -151,7 +151,7 @@ answer_request_alloc(struct dnsc_context *dnsc, void *sock, const char *url,
/// generic dnsc handler
void
generic_handle_dnsc_recvfrom(dnsc_answer_request *request,
llarp_buffer_t buffer, dns_msg_header *hdr)
const llarp_buffer_t &buffer, dns_msg_header *hdr)
{
if(!request)
{
@ -659,7 +659,7 @@ raw_resolve_host(struct dnsc_context *const dnsc, const char *url,
/// intermediate udp_io handler
void
llarp_handle_dnsc_recvfrom(struct llarp_udp_io *const udp,
const struct sockaddr *saddr, llarp_buffer_t buf)
const struct sockaddr *saddr, ManagedBuffer buf)
{
if(!saddr)
{
@ -667,12 +667,12 @@ llarp_handle_dnsc_recvfrom(struct llarp_udp_io *const udp,
}
// auto buffer = llarp::StackBuffer< decltype(castBuf) >(castBuf);
dns_msg_header hdr;
if(!decode_hdr(&buf, &hdr))
if(!decode_hdr(&buf.underlying, &hdr))
{
llarp::LogError("failed to decode dns header");
return;
}
buf.cur = buf.base; // reset cursor to beginning
buf.underlying.cur = buf.underlying.base; // reset cursor to beginning
llarp::LogDebug("Header got client responses for id: ", hdr.id);
@ -754,7 +754,7 @@ llarp_resolve_host(struct dnsc_context *const dnsc, const char *url,
// ssize_t ret = llarp_ev_udp_sendto(dnsc->udp, dnsc->server, bytes, length);
ssize_t ret = llarp_ev_udp_sendto(
dnsc->udp, dnsc->resolvers[0],
llarp::InitBuffer(dns_packet->request, dns_packet->length));
llarp_buffer_t(dns_packet->request, dns_packet->length));
delete dns_packet;
if(ret < 0)
{

@ -54,7 +54,7 @@ struct dnsc_answer_request
/// event handler for processing DNS responses
void
llarp_handle_dnsc_recvfrom(struct llarp_udp_io *const udp,
const struct sockaddr *addr, llarp_buffer_t buf);
const struct sockaddr *addr, ManagedBuffer buf);
/// generic handler for processing DNS responses
/// this doesn't look like it exists
@ -71,7 +71,7 @@ raw_handle_recvfrom(int *sockfd, const struct sockaddr *addr, const void *buf,
// removed saddr, if needed get through request
void
generic_handle_dnsc_recvfrom(dnsc_answer_request *request,
llarp_buffer_t buffer, dns_msg_header *hdr);
const llarp_buffer_t &buffer, dns_msg_header *hdr);
/// DNS client context (one needed per upstream DNS server)
struct dnsc_context

@ -1,4 +1,6 @@
#include <dnsd.hpp>
#include <util/buffer.hpp>
#include <net/net.hpp>
extern dns_tracker dns_udp_tracker;
@ -12,17 +14,18 @@ constexpr size_t BUFFER_SIZE = 1500;
ssize_t
raw_sendto_dns_hook_func(void *sock, const struct sockaddr *from,
llarp_buffer_t buf)
ManagedBuffer buf)
{
int *fd = (int *)sock;
// how do we get to these??
socklen_t addrLen = sizeof(struct sockaddr_in);
return sendto(*fd, (const char *)buf.base, buf.sz, 0, from, addrLen);
return sendto(*fd, (const char *)buf.underlying.base, buf.underlying.sz, 0,
from, addrLen);
}
ssize_t
llarp_sendto_dns_hook_func(void *sock, const struct sockaddr *from,
llarp_buffer_t buf)
ManagedBuffer buf)
{
struct llarp_udp_io *udp = (struct llarp_udp_io *)sock;
if(!udp)
@ -35,7 +38,7 @@ llarp_sendto_dns_hook_func(void *sock, const struct sockaddr *from,
// this call isn't calling the function...
// llarp::ev_io * evio = static_cast< llarp::ev_io * >(udp->impl);
// printf("ev_io[%x]\n", evio);
return llarp_ev_udp_sendto(udp, from, buf);
return llarp_ev_udp_sendto(udp, from, buf.underlying);
}
void
@ -72,7 +75,7 @@ write404_dnss_response(const dnsd_question_request *request)
llarp::LogDebug("Sending 404, ", out_bytes, " bytes");
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
request->sendto_hook(request->user, request->from,
llarp::InitBuffer(buf, out_bytes));
ManagedBuffer(llarp_buffer_t(buf, out_bytes)));
}
void
@ -138,7 +141,7 @@ writecname_dnss_response(std::string cname,
llarp::LogDebug("Sending cname, ", out_bytes, " bytes");
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
request->sendto_hook(request->user, request->from,
llarp::InitBuffer(buf, out_bytes));
ManagedBuffer(llarp_buffer_t(buf, out_bytes)));
}
void
@ -176,7 +179,7 @@ writesend_dnss_revresponse(std::string reverse,
llarp::LogDebug("Sending reverse: ", reverse, " ", out_bytes, " bytes");
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
request->sendto_hook(request->user, request->from,
llarp::InitBuffer(buf, out_bytes));
ManagedBuffer(llarp_buffer_t(buf, out_bytes)));
}
// FIXME: we need an DNS answer not a sockaddr
@ -242,7 +245,7 @@ writesend_dnss_response(llarp::huint32_t *hostRes,
llarp::LogDebug("Sending found, ", out_bytes, " bytes");
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
request->sendto_hook(request->user, request->from,
llarp::InitBuffer(buf, out_bytes));
ManagedBuffer(llarp_buffer_t(buf, out_bytes)));
}
void
@ -282,7 +285,8 @@ writesend_dnss_mxresponse(uint16_t priority, std::string mx,
uint32_t out_bytes = write_buffer - bufferBegin;
llarp::LogDebug("Sending found, ", out_bytes, " bytes");
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
request->sendto_hook(request->user, from, llarp::InitBuffer(buf, out_bytes));
request->sendto_hook(request->user, from,
ManagedBuffer(llarp_buffer_t(buf, out_bytes)));
}
void
@ -322,7 +326,8 @@ writesend_dnss_txtresponse(std::string txt, const struct sockaddr *from,
uint32_t out_bytes = write_buffer - bufferBegin;
llarp::LogDebug("Sending found, ", out_bytes, " bytes");
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
request->sendto_hook(request->user, from, llarp::InitBuffer(buf, out_bytes));
request->sendto_hook(request->user, from,
ManagedBuffer(llarp_buffer_t(buf, out_bytes)));
}
void
@ -342,7 +347,7 @@ handle_dnsc_result(dnsc_answer_request *client_request)
// bytes");
server_request->sendto_hook(server_request->user, server_request->from,
llarp::Buffer(test));
ManagedBuffer(llarp_buffer_t(test)));
llarp_host_resolved(client_request);
return;
@ -509,7 +514,7 @@ handle_recvfrom(llarp_buffer_t *buffer, dnsd_question_request *request)
void
llarp_handle_dnsd_recvfrom(struct llarp_udp_io *udp,
const struct sockaddr *saddr, llarp_buffer_t buf)
const struct sockaddr *saddr, ManagedBuffer buf)
{
if(!dns_udp_tracker.dnsd)
{
@ -526,12 +531,12 @@ llarp_handle_dnsd_recvfrom(struct llarp_udp_io *udp,
llarp_dns_request->sendto_hook =
&llarp_sendto_dns_hook_func; // set sock hook
// llarp::LogInfo("Server request's UDP ", llarp_dns_request->user);
handle_recvfrom(&buf, llarp_dns_request);
handle_recvfrom(&buf.underlying, llarp_dns_request);
}
void
raw_handle_recvfrom(int *sockfd, const struct sockaddr *saddr,
llarp_buffer_t buffer)
ManagedBuffer buffer)
{
if(!dns_udp_tracker.dnsd)
{
@ -546,7 +551,7 @@ raw_handle_recvfrom(int *sockfd, const struct sockaddr *saddr,
llarp_dns_request->llarp = false;
llarp_dns_request->sendto_hook = &raw_sendto_dns_hook_func;
handle_recvfrom(&buffer, llarp_dns_request);
handle_recvfrom(&buffer.underlying, llarp_dns_request);
}
bool

@ -16,7 +16,7 @@ struct dnsd_context;
/// sendto hook functor
using sendto_dns_hook_func = std::function< ssize_t(
void *sock, const struct sockaddr *from, llarp_buffer_t) >;
void *sock, const struct sockaddr *from, ManagedBuffer) >;
// FIXME: llarp::Addr
/// DNS server query request
@ -53,7 +53,7 @@ struct dnsd_query_hook_response
/// called by the llarp_handle_dns_recvfrom generic (dnsd/dnsc) handler in dns
void
llarp_handle_dnsd_recvfrom(struct llarp_udp_io *udp,
const struct sockaddr *addr, llarp_buffer_t buf);
const struct sockaddr *addr, ManagedBuffer buf);
//
// output structures/functions:

@ -115,7 +115,7 @@ llarp_ev_loop_stop(struct llarp_ev_loop *loop)
int
llarp_ev_udp_sendto(struct llarp_udp_io *udp, const sockaddr *to,
llarp_buffer_t buf)
const llarp_buffer_t &buf)
{
auto ret =
static_cast< llarp::ev_io * >(udp->impl)->sendto(to, buf.base, buf.sz);
@ -221,7 +221,7 @@ llarp_ev_add_tun(llarp_ev_loop *loop, llarp_tun_io *tun)
#ifndef _WIN32
bool
llarp_ev_tun_async_write(struct llarp_tun_io *tun, llarp_buffer_t buf)
llarp_ev_tun_async_write(struct llarp_tun_io *tun, const llarp_buffer_t &buf)
{
if(buf.sz > EV_WRITE_BUF_SZ)
{
@ -232,7 +232,7 @@ llarp_ev_tun_async_write(struct llarp_tun_io *tun, llarp_buffer_t buf)
}
#else
bool
llarp_ev_tun_async_write(struct llarp_tun_io *tun, llarp_buffer_t buf)
llarp_ev_tun_async_write(struct llarp_tun_io *tun, const llarp_buffer_t &buf)
{
if(buf.sz > EV_WRITE_BUF_SZ)
{
@ -245,24 +245,27 @@ llarp_ev_tun_async_write(struct llarp_tun_io *tun, llarp_buffer_t buf)
#endif
bool
llarp_tcp_conn_async_write(struct llarp_tcp_conn *conn, llarp_buffer_t buf)
llarp_tcp_conn_async_write(struct llarp_tcp_conn *conn, const llarp_buffer_t &b)
{
ManagedBuffer buf{b};
llarp::tcp_conn *impl = static_cast< llarp::tcp_conn * >(conn->impl);
if(impl->_shouldClose)
{
llarp::LogError("write on closed connection");
return false;
}
size_t sz = buf.sz;
buf.cur = buf.base;
size_t sz = buf.underlying.sz;
buf.underlying.cur = buf.underlying.base;
while(sz > EV_WRITE_BUF_SZ)
{
if(!impl->queue_write(buf.cur, EV_WRITE_BUF_SZ))
if(!impl->queue_write(buf.underlying.cur, EV_WRITE_BUF_SZ))
{
return false;
buf.cur += EV_WRITE_BUF_SZ;
}
buf.underlying.cur += EV_WRITE_BUF_SZ;
sz -= EV_WRITE_BUF_SZ;
}
return impl->queue_write(buf.cur, sz);
return impl->queue_write(buf.underlying.cur, sz);
}
void

@ -1,7 +1,7 @@
#ifndef LLARP_EV_H
#define LLARP_EV_H
#include <util/buffer.h>
#include <util/buffer.hpp>
#include <util/time.hpp>
#include <tuntap.h>
@ -77,7 +77,7 @@ struct llarp_udp_io
void (*tick)(struct llarp_udp_io *);
/// sockaddr * is the source address
void (*recvfrom)(struct llarp_udp_io *, const struct sockaddr *,
llarp_buffer_t);
ManagedBuffer);
};
/// add UDP handler
@ -88,7 +88,7 @@ llarp_ev_add_udp(struct llarp_ev_loop *ev, struct llarp_udp_io *udp,
/// send a UDP packet
int
llarp_ev_udp_sendto(struct llarp_udp_io *udp, const struct sockaddr *to,
llarp_buffer_t pkt);
const llarp_buffer_t &pkt);
/// close UDP handler
int
@ -107,7 +107,7 @@ struct llarp_tcp_conn
/// parent loop (dont set me)
struct llarp_ev_loop *loop;
/// handle read event
void (*read)(struct llarp_tcp_conn *, llarp_buffer_t);
void (*read)(struct llarp_tcp_conn *, const llarp_buffer_t &);
/// handle close event (free-ing is handled by event loop)
void (*closed)(struct llarp_tcp_conn *);
/// handle event loop tick
@ -117,7 +117,7 @@ struct llarp_tcp_conn
/// queue async write a buffer in full
/// return if we queueed it or not
bool
llarp_tcp_conn_async_write(struct llarp_tcp_conn *, llarp_buffer_t);
llarp_tcp_conn_async_write(struct llarp_tcp_conn *, const llarp_buffer_t &);
/// close a tcp connection
void
@ -203,7 +203,7 @@ struct llarp_tun_io
void (*before_write)(struct llarp_tun_io *);
/// called every event loop tick after reads
void (*tick)(struct llarp_tun_io *);
void (*recvpkt)(struct llarp_tun_io *, llarp_buffer_t);
void (*recvpkt)(struct llarp_tun_io *, const llarp_buffer_t &);
};
/// create tun interface with network interface name ifname
@ -214,6 +214,6 @@ llarp_ev_add_tun(struct llarp_ev_loop *ev, struct llarp_tun_io *tun);
/// async write a packet on tun interface
/// returns true if queued, returns false on drop
bool
llarp_ev_tun_async_write(struct llarp_tun_io *tun, llarp_buffer_t);
llarp_ev_tun_async_write(struct llarp_tun_io *tun, const llarp_buffer_t &);
#endif

@ -2,7 +2,7 @@
#define LLARP_EV_HPP
#include <ev/ev.h>
#include <util/buffer.h>
#include <util/buffer.hpp>
#include <util/codel.hpp>
#include <util/threading.hpp>

@ -4,7 +4,7 @@
#include <ev/ev.hpp>
#include <net/net.h>
#include <net/net.hpp>
#include <util/buffer.h>
#include <util/buffer.hpp>
#include <util/buffer.hpp>
#include <util/logger.hpp>
#include <util/mem.hpp>

@ -8,7 +8,7 @@ namespace llarp
if(sz == 0)
{
if(tcp.read)
tcp.read(&tcp, llarp::InitBuffer(nullptr, 0));
tcp.read(&tcp, {nullptr, nullptr, 0});
return 0;
}
if(_shouldClose)
@ -19,7 +19,7 @@ namespace llarp
if(amount >= 0)
{
if(tcp.read)
tcp.read(&tcp, llarp::InitBuffer(buf, amount));
tcp.read(&tcp, llarp_buffer_t(buf, amount));
}
else
{
@ -148,7 +148,7 @@ namespace llarp
llarp::LogWarn("no source addr");
}
// Addr is the source
udp->recvfrom(udp, addr, llarp::InitBuffer(buf, ret));
udp->recvfrom(udp, addr, ManagedBuffer{llarp_buffer_t(buf, ret)});
return 0;
}
@ -237,7 +237,7 @@ namespace llarp
{
buf += offset;
ret -= offset;
auto pkt = llarp::InitBuffer(buf, ret);
llarp_buffer_t pkt(buf, ret);
t->recvpkt(t, pkt);
}
return ret;

@ -4,7 +4,7 @@
#include <ev/ev.hpp>
#include <net/net.h>
#include <net/net.hpp>
#include <util/buffer.h>
#include <util/buffer.hpp>
#include <util/logger.hpp>
#include <sys/un.h>

@ -3,7 +3,7 @@
#include <ev/ev.hpp>
#include <net/net.h>
#include <net/net.hpp>
#include <util/buffer.h>
#include <util/buffer.hpp>
#include <util/logger.hpp>
#include <windows.h>

@ -24,7 +24,7 @@ namespace llarp
}
bool
CloseExitMessage::DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf)
CloseExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
{
bool read = false;
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
@ -41,8 +41,8 @@ namespace llarp
bool
CloseExitMessage::Verify(llarp::Crypto* c, const llarp::PubKey& pk) const
{
byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, 512 > tmp;
llarp_buffer_t buf(tmp);
CloseExitMessage copy;
copy = *this;
copy.Z.Zero();
@ -55,8 +55,8 @@ namespace llarp
bool
CloseExitMessage::Sign(llarp::Crypto* c, const llarp::SecretKey& sk)
{
byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, 512 > tmp;
llarp_buffer_t buf(tmp);
Z.Zero();
Y.Randomize();
if(!BEncode(&buf))

@ -86,14 +86,14 @@ namespace llarp
}
bool
Endpoint::QueueOutboundTraffic(llarp_buffer_t buf, uint64_t counter)
Endpoint::QueueOutboundTraffic(ManagedBuffer buf, uint64_t counter)
{
// queue overflow
if(m_UpstreamQueue.size() > MaxUpstreamQueueSize)
return false;
llarp::net::IPv4Packet pkt;
if(!pkt.Load(buf))
if(!pkt.Load(buf.underlying))
return false;
huint32_t dst;
@ -103,16 +103,16 @@ namespace llarp
dst = pkt.dst();
pkt.UpdateIPv4PacketOnDst(m_IP, dst);
m_UpstreamQueue.emplace(pkt, counter);
m_TxRate += buf.sz;
m_TxRate += buf.underlying.sz;
m_LastActive = m_Parent->Now();
return true;
}
bool
Endpoint::QueueInboundTraffic(llarp_buffer_t buf)
Endpoint::QueueInboundTraffic(ManagedBuffer buf)
{
llarp::net::IPv4Packet pkt;
if(!pkt.Load(buf))
if(!pkt.Load(buf.underlying))
return false;
huint32_t src;
@ -121,13 +121,13 @@ namespace llarp
else
src = pkt.src();
pkt.UpdateIPv4PacketOnDst(src, m_IP);
auto pktbuf = pkt.Buffer();
uint8_t queue_idx = pktbuf.sz / llarp::routing::ExitPadSize;
auto& queue = m_DownstreamQueues[queue_idx];
const llarp_buffer_t& pktbuf = pkt.Buffer(); // life time extension
uint8_t queue_idx = pktbuf.sz / llarp::routing::ExitPadSize;
auto& queue = m_DownstreamQueues[queue_idx];
if(queue.size() == 0)
{
queue.emplace_back();
return queue.back().PutBuffer(buf, m_Counter++);
return queue.back().PutBuffer(buf.underlying, m_Counter++);
}
auto& msg = queue.back();
if(msg.Size() + pktbuf.sz > llarp::routing::ExitPadSize)

@ -48,7 +48,7 @@ namespace llarp
/// queue traffic from service node / internet to be transmitted
bool
QueueInboundTraffic(llarp_buffer_t buff);
QueueInboundTraffic(ManagedBuffer buff);
/// flush inbound and outbound traffic queues
bool
@ -57,7 +57,7 @@ namespace llarp
/// queue outbound traffic
/// does ip rewrite here
bool
QueueOutboundTraffic(llarp_buffer_t pkt, uint64_t counter);
QueueOutboundTraffic(ManagedBuffer pkt, uint64_t counter);
/// update local path id and cascade information to parent
/// return true if success

@ -26,7 +26,7 @@ namespace llarp
}
bool
GrantExitMessage::DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf)
GrantExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
{
bool read = false;
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
@ -45,8 +45,8 @@ namespace llarp
bool
GrantExitMessage::Verify(llarp::Crypto* c, const llarp::PubKey& pk) const
{
byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, 512 > tmp;
llarp_buffer_t buf(tmp);
GrantExitMessage copy;
copy = *this;
copy.Z.Zero();
@ -59,8 +59,8 @@ namespace llarp
bool
GrantExitMessage::Sign(llarp::Crypto* c, const llarp::SecretKey& sk)
{
byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, 512 > tmp;
llarp_buffer_t buf(tmp);
Z.Zero();
Y.Randomize();
if(!BEncode(&buf))

@ -9,9 +9,9 @@ namespace llarp
bool
ObtainExitMessage::Sign(llarp::Crypto* c, const llarp::SecretKey& sk)
{
byte_t tmp[1024] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
I = llarp::seckey_topublic(sk);
std::array< byte_t, 1024 > tmp;
llarp_buffer_t buf(tmp);
I = llarp::seckey_topublic(sk);
Z.Zero();
if(!BEncode(&buf))
{
@ -24,8 +24,8 @@ namespace llarp
bool
ObtainExitMessage::Verify(llarp::Crypto* c) const
{
byte_t tmp[1024] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, 1024 > tmp;
llarp_buffer_t buf(tmp);
ObtainExitMessage copy;
copy = *this;
copy.Z.Zero();
@ -67,7 +67,7 @@ namespace llarp
}
bool
ObtainExitMessage::DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf)
ObtainExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
{
bool read = false;
if(!BEncodeMaybeReadDictList("B", B, read, k, buf))

@ -25,7 +25,7 @@ namespace llarp
}
bool
Policy::DecodeKey(llarp_buffer_t k, llarp_buffer_t *buf)
Policy::DecodeKey(const llarp_buffer_t &k, llarp_buffer_t *buf)
{
bool read = false;
if(!BEncodeMaybeReadDictInt("a", proto, read, k, buf))

@ -16,7 +16,7 @@ namespace llarp
uint64_t drop;
bool
DecodeKey(llarp_buffer_t k, llarp_buffer_t* val) override;
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* val) override;
bool
BEncode(llarp_buffer_t* buf) const override;

@ -30,7 +30,7 @@ namespace llarp
}
bool
RejectExitMessage::DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf)
RejectExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
{
bool read = false;
if(!BEncodeMaybeReadDictInt("B", B, read, k, buf))
@ -66,8 +66,8 @@ namespace llarp
bool
RejectExitMessage::Sign(llarp::Crypto* c, const llarp::SecretKey& sk)
{
byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, 512 > tmp;
llarp_buffer_t buf(tmp);
Z.Zero();
Y.Randomize();
if(!BEncode(&buf))
@ -79,8 +79,8 @@ namespace llarp
bool
RejectExitMessage::Verify(llarp::Crypto* c, const llarp::PubKey& pk) const
{
byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, 512 > tmp;
llarp_buffer_t buf(tmp);
RejectExitMessage copy;
copy = *this;
copy.Z.Zero();

@ -7,9 +7,10 @@ namespace llarp
{
namespace exit
{
BaseSession::BaseSession(const llarp::RouterID& router,
std::function< bool(llarp_buffer_t) > writepkt,
llarp::Router* r, size_t numpaths, size_t hoplen)
BaseSession::BaseSession(
const llarp::RouterID& router,
std::function< bool(const llarp_buffer_t&) > writepkt, llarp::Router* r,
size_t numpaths, size_t hoplen)
: llarp::path::Builder(r, r->dht, numpaths, hoplen)
, m_ExitRouter(router)
, m_WritePacket(writepkt)
@ -117,7 +118,7 @@ namespace llarp
}
bool
BaseSession::HandleTraffic(llarp::path::Path* p, llarp_buffer_t buf,
BaseSession::HandleTraffic(llarp::path::Path* p, const llarp_buffer_t& buf,
uint64_t counter)
{
(void)p;
@ -148,8 +149,8 @@ namespace llarp
BaseSession::QueueUpstreamTraffic(llarp::net::IPv4Packet pkt,
const size_t N)
{
auto buf = pkt.Buffer();
auto& queue = m_Upstream[buf.sz / N];
const llarp_buffer_t& buf = pkt.Buffer();
auto& queue = m_Upstream[buf.sz / N];
// queue overflow
if(queue.size() >= MaxUpstreamQueueLength)
return false;
@ -219,10 +220,10 @@ namespace llarp
return true;
}
SNodeSession::SNodeSession(const llarp::RouterID& snodeRouter,
std::function< bool(llarp_buffer_t) > writepkt,
llarp::Router* r, size_t numpaths, size_t hoplen,
bool useRouterSNodeKey)
SNodeSession::SNodeSession(
const llarp::RouterID& snodeRouter,
std::function< bool(const llarp_buffer_t&) > writepkt, llarp::Router* r,
size_t numpaths, size_t hoplen, bool useRouterSNodeKey)
: BaseSession(snodeRouter, writepkt, r, numpaths, hoplen)
{
if(useRouterSNodeKey)

@ -13,14 +13,14 @@ namespace llarp
{
namespace exit
{
/// a persisiting exit session with an exit router
/// a persisting exit session with an exit router
struct BaseSession : public llarp::path::Builder
{
static constexpr size_t MaxUpstreamQueueLength = 256;
static constexpr llarp_time_t LifeSpan = 60 * 10 * 1000;
BaseSession(const llarp::RouterID& exitRouter,
std::function< bool(llarp_buffer_t) > writepkt,
std::function< bool(const llarp_buffer_t&) > writepkt,
llarp::Router* r, size_t numpaths, size_t hoplen);
virtual ~BaseSession();
@ -64,7 +64,7 @@ namespace llarp
protected:
llarp::RouterID m_ExitRouter;
llarp::SecretKey m_ExitIdentity;
std::function< bool(llarp_buffer_t) > m_WritePacket;
std::function< bool(const llarp_buffer_t&) > m_WritePacket;
virtual void
PopulateRequest(llarp::routing::ObtainExitMessage& msg) const = 0;
@ -77,7 +77,8 @@ namespace llarp
HandleGotExit(llarp::path::Path* p, llarp_time_t b);
bool
HandleTraffic(llarp::path::Path* p, llarp_buffer_t buf, uint64_t seqno);
HandleTraffic(llarp::path::Path* p, const llarp_buffer_t& buf,
uint64_t seqno);
private:
using UpstreamTrafficQueue_t =
@ -108,7 +109,7 @@ namespace llarp
struct ExitSession final : public BaseSession
{
ExitSession(const llarp::RouterID& snodeRouter,
std::function< bool(llarp_buffer_t) > writepkt,
std::function< bool(const llarp_buffer_t&) > writepkt,
llarp::Router* r, size_t numpaths, size_t hoplen)
: BaseSession(snodeRouter, writepkt, r, numpaths, hoplen){};
@ -127,7 +128,7 @@ namespace llarp
struct SNodeSession final : public BaseSession
{
SNodeSession(const llarp::RouterID& snodeRouter,
std::function< bool(llarp_buffer_t) > writepkt,
std::function< bool(const llarp_buffer_t&) > writepkt,
llarp::Router* r, size_t numpaths, size_t hoplen,
bool useRouterSNodeKey = false);

@ -17,7 +17,8 @@ namespace llarp
}
bool
TransferTrafficMessage::PutBuffer(llarp_buffer_t buf, uint64_t counter)
TransferTrafficMessage::PutBuffer(const llarp_buffer_t& buf,
uint64_t counter)
{
if(buf.sz > MaxExitMTU)
return false;
@ -48,7 +49,8 @@ namespace llarp
}
bool
TransferTrafficMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf)
TransferTrafficMessage::DecodeKey(const llarp_buffer_t& key,
llarp_buffer_t* buf)
{
bool read = false;
if(!BEncodeMaybeReadDictInt("S", S, read, key, buf))

@ -26,7 +26,7 @@ namespace llarp
}
bool
UpdateExitMessage::DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf)
UpdateExitMessage::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
{
bool read = false;
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))
@ -46,8 +46,8 @@ namespace llarp
UpdateExitMessage::Verify(llarp::Crypto* c, const llarp::PubKey& pk) const
{
byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, 512 > tmp;
llarp_buffer_t buf(tmp);
UpdateExitMessage copy;
copy = *this;
copy.Z.Zero();
@ -72,8 +72,8 @@ namespace llarp
bool
UpdateExitMessage::Sign(llarp::Crypto* c, const llarp::SecretKey& sk)
{
byte_t tmp[512] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, 512 > tmp;
llarp_buffer_t buf(tmp);
Y.Randomize();
if(!BEncode(&buf))
return false;
@ -104,7 +104,8 @@ namespace llarp
}
bool
UpdateExitVerifyMessage::DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf)
UpdateExitVerifyMessage::DecodeKey(const llarp_buffer_t& k,
llarp_buffer_t* buf)
{
bool read = false;
if(!BEncodeMaybeReadDictInt("S", S, read, k, buf))

@ -12,7 +12,7 @@ namespace llarp
namespace handlers
{
static void
ExitHandlerRecvPkt(llarp_tun_io *tun, llarp_buffer_t buf)
ExitHandlerRecvPkt(llarp_tun_io *tun, const llarp_buffer_t &buf)
{
static_cast< ExitEndpoint * >(tun->user)->OnInetPacket(buf);
}
@ -186,7 +186,7 @@ namespace llarp
}
else
{
if(!ep->QueueInboundTraffic(pkt.Buffer()))
if(!ep->QueueInboundTraffic(ManagedBuffer{pkt.Buffer()}))
{
LogWarn(Name(), " dropped inbound traffic for session ", pk,
" as we are overloaded (probably)");
@ -338,7 +338,7 @@ namespace llarp
}
bool
ExitEndpoint::QueueOutboundTraffic(llarp_buffer_t buf)
ExitEndpoint::QueueOutboundTraffic(const llarp_buffer_t &buf)
{
return llarp_ev_tun_async_write(&m_Tun, buf);
}
@ -363,14 +363,14 @@ namespace llarp
}
void
ExitEndpoint::OnInetPacket(llarp_buffer_t buf)
ExitEndpoint::OnInetPacket(const llarp_buffer_t &buf)
{
m_InetToNetwork.EmplaceIf(
[buf](Pkt_t &pkt) -> bool { return pkt.Load(buf); });
[b = ManagedBuffer(buf)](Pkt_t &pkt) -> bool { return pkt.Load(b); });
}
bool
ExitEndpoint::QueueSNodePacket(llarp_buffer_t buf, huint32_t from)
ExitEndpoint::QueueSNodePacket(const llarp_buffer_t &buf, huint32_t from)
{
net::IPv4Packet pkt;
if(!pkt.Load(buf))

@ -47,7 +47,7 @@ namespace llarp
/// handle ip packet from outside
void
OnInetPacket(llarp_buffer_t buf);
OnInetPacket(const llarp_buffer_t& buf);
Router*
GetRouter();
@ -80,7 +80,7 @@ namespace llarp
RemoveExit(const exit::Endpoint* ep);
bool
QueueOutboundTraffic(llarp_buffer_t buf);
QueueOutboundTraffic(const llarp_buffer_t& buf);
/// sets up networking and starts traffic
bool
@ -114,7 +114,7 @@ namespace llarp
ObtainServiceNodeIP(const RouterID& router);
bool
QueueSNodePacket(llarp_buffer_t buf, huint32_t from);
QueueSNodePacket(const llarp_buffer_t & buf, huint32_t from);
void
MarkIPActive(huint32_t ip);

@ -13,8 +13,9 @@ namespace llarp
llarp::service::Context *parent)
: llarp::service::Endpoint(name, r, parent){};
bool HandleWriteIPPacket(llarp_buffer_t,
std::function< huint32_t(void) >) override
bool
HandleWriteIPPacket(const llarp_buffer_t &,
std::function< huint32_t(void) >) override
{
return true;
}

@ -249,7 +249,7 @@ namespace llarp
llarp::service::Address addr;
// forward dns
if(msg.questions[0].qname == "localhost.loki"
|| msg.questions[0].qname == "localhost.loki.")
|| msg.questions[0].qname == "localhost.loki.")
{
size_t counter = 0;
context->ForEachService(
@ -344,7 +344,7 @@ namespace llarp
if(msg.questions[0].qname == "random.snode"
|| msg.questions[0].qname == "random.snode.")
return true;
// hook localhost.loki
// hook localhost.loki
if(msg.questions[0].qname == "localhost.loki"
|| msg.questions[0].qname == "localhost.loki.")
return true;
@ -532,7 +532,7 @@ namespace llarp
TunEndpoint::FlushSend()
{
m_UserToNetworkPktQueue.Process([&](net::IPv4Packet &pkt) {
std::function< bool(llarp_buffer_t) > sendFunc;
std::function< bool(const llarp_buffer_t &) > sendFunc;
auto itr = m_IPToAddr.find(pkt.dst());
if(itr == m_IPToAddr.end())
{
@ -570,13 +570,14 @@ namespace llarp
}
bool
TunEndpoint::HandleWriteIPPacket(llarp_buffer_t buf,
TunEndpoint::HandleWriteIPPacket(const llarp_buffer_t &b,
std::function< huint32_t(void) > getFromIP)
{
// llarp::LogInfo("got packet from ", msg->sender.Addr());
auto themIP = getFromIP();
// llarp::LogInfo("themIP ", themIP);
auto usIP = m_OurIP;
ManagedBuffer buf(b);
return m_NetworkToUserPktQueue.EmplaceIf(
[buf, themIP, usIP](net::IPv4Packet &pkt) -> bool {
// load
@ -719,10 +720,11 @@ namespace llarp
}
void
TunEndpoint::tunifRecvPkt(llarp_tun_io *tun, llarp_buffer_t buf)
TunEndpoint::tunifRecvPkt(llarp_tun_io *tun, const llarp_buffer_t &b)
{
// called for every packet read from user in isolated network thread
TunEndpoint *self = static_cast< TunEndpoint * >(tun->user);
ManagedBuffer buf(b);
if(!self->m_UserToNetworkPktQueue.EmplaceIf(
[buf](net::IPv4Packet &pkt) -> bool {
return pkt.Load(buf) && pkt.Header()->version == 4;
@ -730,7 +732,7 @@ namespace llarp
{
#if defined(DEBUG) || !defined(RELEASE_MOTTO)
llarp::LogInfo("invalid pkt");
llarp::DumpBuffer(buf);
llarp::DumpBuffer(buf.underlying);
#endif
}
}

@ -64,7 +64,7 @@ namespace llarp
/// overrides Endpoint
/// handle inbound traffic
bool
HandleWriteIPPacket(llarp_buffer_t buf,
HandleWriteIPPacket(const llarp_buffer_t& buf,
std::function< huint32_t(void) > getFromIP) override;
/// queue outbound packet to the world
@ -99,7 +99,7 @@ namespace llarp
/// called every time we wish to read a packet from the tun interface
static void
tunifRecvPkt(llarp_tun_io* t, llarp_buffer_t buf);
tunifRecvPkt(llarp_tun_io* t, const llarp_buffer_t& buf);
/// called in the endpoint logic thread
static void
@ -176,11 +176,13 @@ namespace llarp
private:
bool
QueueInboundPacketForExit(llarp_buffer_t buf)
QueueInboundPacketForExit(const llarp_buffer_t& buf)
{
ManagedBuffer copy{buf};
return m_NetworkToUserPktQueue.EmplaceIf(
[&](llarp::net::IPv4Packet& pkt) -> bool {
if(!pkt.Load(buf))
if(!pkt.Load(copy.underlying))
return false;
pkt.UpdateIPv4PacketOnDst(pkt.src(), m_OurIP);
return true;

@ -35,7 +35,7 @@ namespace llarp
TickIO(llarp_time_t now);
bool
QueueMessageBuffer(llarp_buffer_t buf);
QueueMessageBuffer(const llarp_buffer_t &buf);
/// return true if the session is established and handshaked and all that
/// jazz
@ -142,7 +142,7 @@ namespace llarp
}
bool
Encode(llarp_buffer_t *buf, llarp_buffer_t body)
Encode(llarp_buffer_t *buf, const llarp_buffer_t &body)
{
if(body.sz > fragsize)
return false;
@ -184,7 +184,7 @@ namespace llarp
}
/// outbound
MessageState(llarp_buffer_t buf)
MessageState(const llarp_buffer_t &buf)
{
sz = std::min(buf.sz, MAX_LINK_MSG_SIZE);
memcpy(msg.data(), buf.base, sz);
@ -234,7 +234,7 @@ namespace llarp
hdr.seqno = seqno;
hdr.cmd = XMIT;
AlignedBuffer< fragoverhead + fragsize > frag;
auto buf = frag.as_buffer();
llarp_buffer_t buf(frag);
const byte_t *ptr = msg.data();
Fragno_t idx = 0;
FragLen_t len = sz;
@ -245,7 +245,7 @@ namespace llarp
{
hdr.fragno = idx;
hdr.fraglen = l;
if(!hdr.Encode(&buf, llarp::InitBuffer(ptr, l)))
if(!hdr.Encode(&buf, llarp_buffer_t(ptr, l)))
return false;
buf.sz = buf.cur - buf.base;
buf.cur = buf.base;
@ -281,8 +281,8 @@ namespace llarp
hdr.fraglen = 0;
hdr.fragno = 0;
AlignedBuffer< fragoverhead > frag;
auto buf = frag.as_buffer();
if(!hdr.Encode(&buf, llarp::InitBuffer(nullptr, 0)))
llarp_buffer_t buf(frag);
if(!hdr.Encode(&buf, llarp_buffer_t(nullptr, nullptr, 0)))
return false;
return write_pkt(buf.base, buf.sz) == int(buf.sz);
}

@ -250,7 +250,7 @@ namespace llarp
}
bool
ILinkLayer::SendTo(const RouterID& remote, llarp_buffer_t buf)
ILinkLayer::SendTo(const RouterID& remote, const llarp_buffer_t& buf)
{
ILinkSession* s = nullptr;
{

@ -16,10 +16,11 @@ namespace llarp
{
/// handle a link layer message
using LinkMessageHandler =
std::function< bool(ILinkSession*, llarp_buffer_t) >;
std::function< bool(ILinkSession*, const llarp_buffer_t&) >;
/// sign a buffer with identity key
using SignBufferFunc = std::function< bool(Signature&, llarp_buffer_t) >;
using SignBufferFunc =
std::function< bool(Signature&, const llarp_buffer_t&) >;
/// handle connection timeout
using TimeoutHandler = std::function< void(ILinkSession*) >;
@ -75,7 +76,7 @@ namespace llarp
}
static void
udp_recv_from(llarp_udp_io* udp, const sockaddr* from, llarp_buffer_t buf)
udp_recv_from(llarp_udp_io* udp, const sockaddr* from, ManagedBuffer buf)
{
if(!udp)
{
@ -84,7 +85,8 @@ namespace llarp
}
// maybe check from too?
// no it's never null
static_cast< ILinkLayer* >(udp->user)->RecvFrom(*from, buf.base, buf.sz);
static_cast< ILinkLayer* >(udp->user)->RecvFrom(
*from, buf.underlying.base, buf.underlying.sz);
}
void
@ -128,7 +130,7 @@ namespace llarp
KeepAliveSessionTo(const RouterID& remote);
bool
SendTo(const RouterID& remote, llarp_buffer_t buf);
SendTo(const RouterID& remote, const llarp_buffer_t& buf);
bool
GetOurAddressInfo(AddressInfo& addr) const;

@ -24,7 +24,7 @@ namespace llarp
std::function< void(llarp_time_t) > Tick;
/// send a message buffer to the remote endpoint
std::function< bool(llarp_buffer_t) > SendMessageBuffer;
std::function< bool(const llarp_buffer_t &) > SendMessageBuffer;
/// start the connection
std::function< void(void) > Start;

@ -140,7 +140,7 @@ namespace llarp
std::copy(K.begin(), K.end(), tmp.begin());
std::copy(n.begin(), n.end(), tmp.begin() + K.size());
// t_h = HS(K + L.n)
if(!Crypto()->shorthash(t_h, ConstBuffer(tmp)))
if(!Crypto()->shorthash(t_h, llarp_buffer_t(tmp)))
{
llarp::LogError("failed to mix key to ", remoteAddr);
return false;
@ -160,7 +160,7 @@ namespace llarp
Session::MutateKey(SharedSecret& K, const AlignedBuffer< 24 >& A)
{
AlignedBuffer< 56 > tmp;
auto buf = tmp.as_buffer();
llarp_buffer_t buf{tmp};
std::copy(K.begin(), K.end(), buf.cur);
buf.cur += K.size();
std::copy(A.begin(), A.end(), buf.cur);
@ -580,8 +580,8 @@ namespace llarp
&& now - lastActive > 5000)
{
DiscardMessage msg;
byte_t tmp[128] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, 128 > tmp;
llarp_buffer_t buf(tmp);
if(!msg.BEncode(&buf))
return false;
buf.sz = buf.cur - buf.base;
@ -622,9 +622,9 @@ namespace llarp
remoteTransportPubKey = addr.pubkey;
remoteRC = rc;
RouterID rid = remoteRC.pubkey;
Crypto()->shorthash(txKey, rid.as_buffer());
Crypto()->shorthash(txKey, llarp_buffer_t(rid));
rid = p->GetOurRC().pubkey;
Crypto()->shorthash(rxKey, rid.as_buffer());
Crypto()->shorthash(rxKey, llarp_buffer_t(rid));
sock = s;
assert(utp_set_userdata(sock, this) == this);
@ -638,7 +638,7 @@ namespace llarp
Session::Session(LinkLayer* p, utp_socket* s, const Addr& addr) : Session(p)
{
RouterID rid = p->GetOurRC().pubkey;
Crypto()->shorthash(rxKey, rid.as_buffer());
Crypto()->shorthash(rxKey, llarp_buffer_t(rid));
remoteRC.Clear();
sock = s;
assert(s == sock);
@ -665,7 +665,7 @@ namespace llarp
if(!gotLIM)
{
remoteRC = msg->rc;
Crypto()->shorthash(txKey, remoteRC.pubkey.as_buffer());
Crypto()->shorthash(txKey, llarp_buffer_t(remoteRC.pubkey));
if(!DoKeyExchange(std::bind(&Crypto::transport_dh_server, Crypto(), _1,
_2, _3, _4),
@ -673,8 +673,8 @@ namespace llarp
parent->TransportSecretKey()))
return false;
byte_t tmp[LinkIntroMessage::MaxSize];
auto buf = StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, LinkIntroMessage::MaxSize > tmp;
llarp_buffer_t buf(tmp);
LinkIntroMessage replymsg;
replymsg.rc = parent->GetOurRC();
if(!replymsg.rc.Verify(Crypto(), parent->Now()))
@ -736,7 +736,7 @@ namespace llarp
}
bool
Session::QueueWriteBuffers(llarp_buffer_t buf)
Session::QueueWriteBuffers(const llarp_buffer_t& buf)
{
if(sendq.size() >= MaxSendQueueSize)
return false;
@ -785,8 +785,8 @@ namespace llarp
void
Session::OutboundHandshake()
{
byte_t tmp[LinkIntroMessage::MaxSize];
auto buf = StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, LinkIntroMessage::MaxSize > tmp;
llarp_buffer_t buf(tmp);
// build our RC
LinkIntroMessage msg;
msg.rc = parent->GetOurRC();
@ -955,8 +955,8 @@ namespace llarp
// put body
memcpy(body, ptr, length);
auto payload =
InitBuffer(base, FragmentBufferSize - FragmentOverheadSize);
llarp_buffer_t payload(base, base,
FragmentBufferSize - FragmentOverheadSize);
TunnelNonce nonce(noncePtr);
@ -997,7 +997,7 @@ namespace llarp
}
// set remote rc
remoteRC = msg->rc;
// recalcuate rx key
// recalculate rx key
return DoKeyExchange(
std::bind(&Crypto::transport_dh_server, Crypto(), _1, _2, _3, _4),
rxKey, msg->N, remoteRC.enckey, parent->RouterEncryptionSecret());
@ -1006,14 +1006,15 @@ namespace llarp
bool
Session::Rehandshake()
{
byte_t tmp[LinkIntroMessage::MaxSize];
LinkIntroMessage lim;
lim.rc = parent->GetOurRC();
lim.N.Randomize();
lim.P = 60 * 1000 * 10;
if(!lim.Sign(parent->Sign))
return false;
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, LinkIntroMessage::MaxSize > tmp;
llarp_buffer_t buf(tmp);
if(!lim.BEncode(&buf))
return false;
// rewind and resize buffer
@ -1034,8 +1035,8 @@ namespace llarp
llarp::LogDebug("verify then decrypt ", remoteAddr);
ShortHash digest;
auto hbuf = InitBuffer(ptr + FragmentHashSize,
FragmentBufferSize - FragmentHashSize);
llarp_buffer_t hbuf(ptr + FragmentHashSize,
FragmentBufferSize - FragmentHashSize);
if(!Crypto()->hmac(digest.data(), hbuf, rxKey))
{
llarp::LogError("keyed hash failed");
@ -1050,13 +1051,14 @@ namespace llarp
return false;
}
auto in = InitBuffer(ptr + FragmentOverheadSize,
FragmentBufferSize - FragmentOverheadSize);
llarp_buffer_t in(ptr + FragmentOverheadSize,
FragmentBufferSize - FragmentOverheadSize);
llarp_buffer_t out = rxFragBody.as_buffer();
llarp_buffer_t out(rxFragBody);
// decrypt
if(!Crypto()->xchacha20_alt(out, in, rxKey, ptr + FragmentHashSize))
if(!Crypto()->xchacha20_alt(out, in, rxKey,
ptr + FragmentHashSize))
{
llarp::LogError("failed to decrypt message from ", remoteAddr);
return false;
@ -1080,7 +1082,8 @@ namespace llarp
llarp::LogError("failed to read the rest of the header");
return false;
}
if(length > (out.sz - (out.cur - out.base)))
if(length
> (out.sz - (out.cur - out.base)))
{
// too big length
llarp::LogError("fragment body too big");
@ -1116,14 +1119,14 @@ namespace llarp
{
// we done with this guy, prune next tick
itr->second.lastActive = 0;
llarp_buffer_t buf = itr->second.buffer;
ManagedBuffer buf(itr->second.buffer);
// resize
buf.sz = buf.cur - buf.base;
buf.underlying.sz = buf.underlying.cur - buf.underlying.base;
// rewind
buf.cur = buf.base;
buf.underlying.cur = buf.underlying.base;
// process buffer
llarp::LogDebug("got message ", msgid, " from ", remoteAddr);
return parent->HandleMessage(this, buf);
return parent->HandleMessage(this, buf.underlying);
}
return true;
}

@ -61,10 +61,17 @@ namespace llarp
/// for accessing message buffer
llarp_buffer_t buffer;
InboundMessage() : lastActive(0), _msg(), buffer(_msg.as_buffer())
InboundMessage() : lastActive(0), _msg(), buffer(_msg)
{
}
InboundMessage(const InboundMessage& other)
: lastActive(other.lastActive), _msg(other._msg), buffer(_msg)
{
buffer.cur = buffer.base + (other.buffer.cur - other.buffer.base);
buffer.sz = other.buffer.sz;
}
bool
operator==(const InboundMessage& other) const
{
@ -197,7 +204,7 @@ namespace llarp
/// queue a fully formed message
bool
QueueWriteBuffers(llarp_buffer_t buf);
QueueWriteBuffers(const llarp_buffer_t& buf);
/// prune expired inbound messages
void

@ -18,7 +18,7 @@ namespace llarp
~DHTMessage();
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* val) override;
bool
BEncode(llarp_buffer_t* buf) const override;

@ -15,7 +15,7 @@ namespace llarp
}
bool
DHTImmediateMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf)
DHTImmediateMessage::DecodeKey(const llarp_buffer_t &key, llarp_buffer_t *buf)
{
if(llarp_buffer_eq(key, "m"))
return llarp::dht::DecodeMesssageList(dht::Key_t(session->GetPubKey()),

@ -19,7 +19,7 @@ namespace llarp
std::vector< std::unique_ptr< llarp::dht::IMessage > > msgs;
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* buf) override;
bool
BEncode(llarp_buffer_t* buf) const override;

@ -32,7 +32,7 @@ namespace llarp
}
bool
DecodeKey(__attribute__((unused)) llarp_buffer_t key,
DecodeKey(__attribute__((unused)) const llarp_buffer_t& key,
__attribute__((unused)) llarp_buffer_t* buf) override
{
return false;
@ -73,7 +73,7 @@ namespace llarp
}
bool
DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf) override
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf) override
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("P", P, read, k, buf))

@ -53,7 +53,7 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* buf) override;
bool
HandleMessage(IMessageHandler* h, llarp::Router* r) const override;
@ -86,7 +86,7 @@ namespace llarp
Verify(llarp::Crypto* c, const llarp::PubKey& pk) const;
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* buf) override;
bool
HandleMessage(IMessageHandler* h, llarp::Router* r) const override;
@ -140,7 +140,7 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* buf) override;
bool
HandleMessage(IMessageHandler* h, llarp::Router* r) const override;
@ -182,7 +182,7 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* buf) override;
bool
HandleMessage(IMessageHandler* h, llarp::Router* r) const override;
@ -217,7 +217,7 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* buf) override;
bool
HandleMessage(IMessageHandler* h, llarp::Router* r) const override;
@ -254,7 +254,7 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
bool
HandleMessage(IMessageHandler* h, llarp::Router* r) const override;

@ -12,7 +12,7 @@ namespace llarp
}
bool
LinkIntroMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf)
LinkIntroMessage::DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf)
{
if(llarp_buffer_eq(key, "a"))
{
@ -133,11 +133,11 @@ namespace llarp
bool
LinkIntroMessage::Sign(
std::function< bool(Signature&, llarp_buffer_t) > signer)
std::function< bool(Signature&, const llarp_buffer_t&) > signer)
{
Z.Zero();
byte_t tmp[MaxSize] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, MaxSize > tmp;
llarp_buffer_t buf(tmp);
if(!BEncode(&buf))
return false;
buf.sz = buf.cur - buf.base;
@ -151,8 +151,8 @@ namespace llarp
LinkIntroMessage copy;
copy = *this;
copy.Z.Zero();
byte_t tmp[MaxSize] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, MaxSize > tmp;
llarp_buffer_t buf(tmp);
if(!copy.BEncode(&buf))
return false;
buf.sz = buf.cur - buf.base;

@ -28,7 +28,7 @@ namespace llarp
operator=(const LinkIntroMessage& msg);
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf) override;
bool
BEncode(llarp_buffer_t* buf) const override;
@ -37,7 +37,7 @@ namespace llarp
HandleMessage(llarp::Router* router) const override;
bool
Sign(std::function< bool(Signature&, llarp_buffer_t) > signer);
Sign(std::function< bool(Signature&, const llarp_buffer_t&) > signer);
bool
Verify(llarp::Crypto* c) const;

@ -90,7 +90,8 @@ namespace llarp
}
bool
InboundMessageParser::ProcessFrom(ILinkSession* src, llarp_buffer_t buf)
InboundMessageParser::ProcessFrom(ILinkSession* src,
const llarp_buffer_t& buf)
{
if(!src)
{
@ -101,7 +102,8 @@ namespace llarp
reader.on_key = &OnKey;
from = src;
firstkey = true;
return bencode_read_dict(&buf, &reader);
ManagedBuffer copy(buf);
return bencode_read_dict(&copy.underlying, &reader);
}
void

@ -20,7 +20,7 @@ namespace llarp
/// start processig message from a link session
bool
ProcessFrom(ILinkSession* from, llarp_buffer_t buf);
ProcessFrom(ILinkSession* from, const llarp_buffer_t& buf);
/// called when the message is fully read
/// return true when the message was accepted otherwise returns false

@ -19,7 +19,7 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* val) override;
bool
HandleMessage(IMessageHandler* h, llarp::Router* r) const override;

@ -17,7 +17,7 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* val) override;
void
Clear() override

@ -25,7 +25,7 @@ namespace llarp
~PathTransferMessage();
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* val) override;
bool
BEncode(llarp_buffer_t* buf) const override;

@ -41,7 +41,8 @@ namespace llarp
}
bool
RelayUpstreamMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf)
RelayUpstreamMessage::DecodeKey(const llarp_buffer_t &key,
llarp_buffer_t *buf)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf))
@ -62,7 +63,7 @@ namespace llarp
auto path = r->paths.GetByDownstream(session->GetPubKey(), pathid);
if(path)
{
return path->HandleUpstream(X.Buffer(), Y, r);
return path->HandleUpstream(llarp_buffer_t(X), Y, r);
}
return false;
}
@ -103,7 +104,8 @@ namespace llarp
}
bool
RelayDownstreamMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf)
RelayDownstreamMessage::DecodeKey(const llarp_buffer_t &key,
llarp_buffer_t *buf)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf))
@ -124,7 +126,7 @@ namespace llarp
auto path = r->paths.GetByUpstream(session->GetPubKey(), pathid);
if(path)
{
return path->HandleDownstream(X.Buffer(), Y, r);
return path->HandleDownstream(llarp_buffer_t(X), Y, r);
}
llarp::LogWarn("unhandled downstream message");
return false;

@ -21,7 +21,7 @@ namespace llarp
~RelayUpstreamMessage();
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* buf) override;
bool
BEncode(llarp_buffer_t* buf) const override;
@ -43,7 +43,7 @@ namespace llarp
~RelayDownstreamMessage();
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* buf) override;
bool
BEncode(llarp_buffer_t* buf) const override;

@ -14,7 +14,7 @@ namespace llarp
}
bool
LR_CommitMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf)
LR_CommitMessage::DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf)
{
if(llarp_buffer_eq(key, "c"))
{
@ -279,7 +279,7 @@ namespace llarp
return;
}
// generate hash of hop key for nonce mutation
crypto->shorthash(self->hop->nonceXOR, self->hop->pathKey.as_buffer());
crypto->shorthash(self->hop->nonceXOR, llarp_buffer_t(self->hop->pathKey));
using namespace std::placeholders;
if(self->record.work
&& self->record.work->IsValid(

@ -58,7 +58,7 @@ namespace llarp
Clear();
bool
DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf);
DecodeKey(const llarp_buffer_t &key, llarp_buffer_t *buf);
bool
BEncode(llarp_buffer_t *buf) const;

@ -36,13 +36,13 @@ namespace llarp
/// append buffer to X
bool
PutBuffer(llarp_buffer_t buf, uint64_t counter);
PutBuffer(const llarp_buffer_t& buf, uint64_t counter);
bool
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t k, llarp_buffer_t* val) override;
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* val) override;
bool
HandleMessage(IMessageHandler* h, llarp::Router* r) const override;

@ -42,7 +42,7 @@ namespace llarp
}
bool
AddressInfo::DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf)
AddressInfo::DecodeKey(const llarp_buffer_t &key, llarp_buffer_t *buf)
{
uint64_t i;
char tmp[128] = {0};

@ -50,7 +50,7 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf) override;
friend std::ostream&
operator<<(std::ostream& out, const AddressInfo& a)

@ -68,7 +68,7 @@ namespace llarp
}
bool
ExitInfo::DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf)
ExitInfo::DecodeKey(const llarp_buffer_t &k, llarp_buffer_t* buf)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("k", pubkey, read, k, buf))

@ -50,7 +50,7 @@ namespace llarp
BEncode(llarp_buffer_t *buf) const override;
bool
DecodeKey(llarp_buffer_t k, llarp_buffer_t *buf) override;
DecodeKey(const llarp_buffer_t &k, llarp_buffer_t *buf) override;
ExitInfo &
operator=(const ExitInfo &other);

@ -16,7 +16,7 @@ namespace llarp
namespace net
{
bool
IPv4Packet::Load(llarp_buffer_t pkt)
IPv4Packet::Load(const llarp_buffer_t &pkt)
{
if(pkt.sz > sizeof(buf))
return false;
@ -28,13 +28,13 @@ namespace llarp
llarp_buffer_t
IPv4Packet::ConstBuffer() const
{
return llarp::InitBuffer(buf, sz);
return {buf, sz};
}
llarp_buffer_t
IPv4Packet::Buffer()
{
return llarp::InitBuffer(buf, sz);
return {buf, sz};
}
#if 0

@ -3,7 +3,7 @@
#include <ev/ev.h>
#include <net/net.hpp>
#include <util/buffer.h>
#include <util/buffer.hpp>
#include <util/time.hpp>
#ifndef _WIN32
@ -96,7 +96,7 @@ namespace llarp
ConstBuffer() const;
bool
Load(llarp_buffer_t buf);
Load(const llarp_buffer_t& buf);
struct GetTime
{

@ -102,8 +102,8 @@ llarp_nodedb::InsertAsync(llarp::RouterContact rc)
bool
llarp_nodedb::Insert(const llarp::RouterContact &rc)
{
byte_t tmp[MAX_RC_SIZE];
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, MAX_RC_SIZE > tmp;
llarp_buffer_t buf(tmp);
{
llarp::util::Lock lock(access);
entries.emplace(rc.pubkey.as_array(), rc);

@ -503,7 +503,7 @@ namespace llarp
}
bool
Path::HandleUpstream(llarp_buffer_t buf, const TunnelNonce& Y,
Path::HandleUpstream(const llarp_buffer_t& buf, const TunnelNonce& Y,
llarp::Router* r)
{
TunnelNonce n = Y;
@ -542,7 +542,7 @@ namespace llarp
}
bool
Path::HandleDownstream(llarp_buffer_t buf, const TunnelNonce& Y,
Path::HandleDownstream(const llarp_buffer_t& buf, const TunnelNonce& Y,
llarp::Router* r)
{
TunnelNonce n = Y;
@ -555,7 +555,7 @@ namespace llarp
}
bool
Path::HandleRoutingMessage(llarp_buffer_t buf, llarp::Router* r)
Path::HandleRoutingMessage(const llarp_buffer_t& buf, llarp::Router* r)
{
if(!r->ParseRoutingMessageBuffer(buf, this, RXID()))
{
@ -588,8 +588,8 @@ namespace llarp
Path::SendRoutingMessage(const llarp::routing::IMessage* msg,
llarp::Router* r)
{
byte_t tmp[MAX_LINK_MSG_SIZE / 2];
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, MAX_LINK_MSG_SIZE / 2 > tmp;
llarp_buffer_t buf(tmp);
// should help prevent bad paths with uninitialised members
// FIXME: Why would we get uninitialised IMessages?
if(msg->version != LLARP_PROTO_VERSION)
@ -840,7 +840,7 @@ namespace llarp
return false;
uint64_t counter = bufbe64toh(pkt.data());
m_ExitTrafficHandler(
this, llarp::InitBuffer(pkt.data() + 8, pkt.size() - 8), counter);
this, llarp_buffer_t(pkt.data() + 8, pkt.size() - 8), counter);
}
return sent;
}

@ -116,12 +116,12 @@ namespace llarp
// handle data in upstream direction
virtual bool
HandleUpstream(llarp_buffer_t X, const TunnelNonce& Y,
HandleUpstream(const llarp_buffer_t& X, const TunnelNonce& Y,
llarp::Router* r) = 0;
// handle data in downstream direction
virtual bool
HandleDownstream(llarp_buffer_t X, const TunnelNonce& Y,
HandleDownstream(const llarp_buffer_t& X, const TunnelNonce& Y,
llarp::Router* r) = 0;
/// return timestamp last remote activity happened at
@ -256,12 +256,12 @@ namespace llarp
// handle data in upstream direction
bool
HandleUpstream(llarp_buffer_t X, const TunnelNonce& Y,
HandleUpstream(const llarp_buffer_t& X, const TunnelNonce& Y,
llarp::Router* r) override;
// handle data in downstream direction
bool
HandleDownstream(llarp_buffer_t X, const TunnelNonce& Y,
HandleDownstream(const llarp_buffer_t& X, const TunnelNonce& Y,
llarp::Router* r) override;
};
@ -302,7 +302,7 @@ namespace llarp
using ExitUpdatedFunc = std::function< bool(Path*) >;
using ExitClosedFunc = std::function< bool(Path*) >;
using ExitTrafficHandlerFunc =
std::function< bool(Path*, llarp_buffer_t, uint64_t) >;
std::function< bool(Path*, const llarp_buffer_t&, uint64_t) >;
/// (path, backoff) backoff is 0 on success
using ObtainedExitHandler = std::function< bool(Path*, llarp_time_t) >;
@ -475,16 +475,16 @@ namespace llarp
llarp::Router* r) override;
bool
HandleRoutingMessage(llarp_buffer_t buf, llarp::Router* r);
HandleRoutingMessage(const llarp_buffer_t& buf, llarp::Router* r);
// handle data in upstream direction
bool
HandleUpstream(llarp_buffer_t X, const TunnelNonce& Y,
HandleUpstream(const llarp_buffer_t& X, const TunnelNonce& Y,
llarp::Router* r) override;
// handle data in downstream direction
bool
HandleDownstream(llarp_buffer_t X, const TunnelNonce& Y,
HandleDownstream(const llarp_buffer_t& X, const TunnelNonce& Y,
llarp::Router* r) override;
bool

@ -57,7 +57,7 @@ namespace llarp
return;
}
// generate nonceXOR valueself->hop->pathKey
ctx->crypto->shorthash(hop.nonceXOR, hop.shared.as_buffer());
ctx->crypto->shorthash(hop.nonceXOR, llarp_buffer_t(hop.shared));
++ctx->idx;
bool isFarthestHop = ctx->idx == ctx->path->hops.size();

@ -59,8 +59,9 @@ namespace llarp
{
if(!IsEndpoint(r->pubkey()))
return false;
byte_t tmp[MAX_LINK_MSG_SIZE - 128];
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, MAX_LINK_MSG_SIZE - 128 > tmp;
llarp_buffer_t buf(tmp);
if(!msg->BEncode(&buf))
{
llarp::LogError("failed to encode routing message");
@ -83,8 +84,8 @@ namespace llarp
}
bool
TransitHop::HandleDownstream(llarp_buffer_t buf, const TunnelNonce& Y,
llarp::Router* r)
TransitHop::HandleDownstream(const llarp_buffer_t& buf,
const TunnelNonce& Y, llarp::Router* r)
{
RelayDownstreamMessage msg;
msg.pathid = info.rxID;
@ -97,7 +98,7 @@ namespace llarp
}
bool
TransitHop::HandleUpstream(llarp_buffer_t buf, const TunnelNonce& Y,
TransitHop::HandleUpstream(const llarp_buffer_t& buf, const TunnelNonce& Y,
llarp::Router* r)
{
r->crypto->xchacha20(buf, pathKey, Y);
@ -269,7 +270,8 @@ namespace llarp
continue;
uint64_t counter = bufbe64toh(pkt.data());
sent &= endpoint->QueueOutboundTraffic(
llarp::InitBuffer(pkt.data() + 8, pkt.size() - 8), counter);
ManagedBuffer(llarp_buffer_t(pkt.data() + 8, pkt.size() - 8)),
counter);
}
return sent;
}
@ -291,8 +293,8 @@ namespace llarp
return SendRoutingMessage(&discarded, r);
}
byte_t tmp[service::MAX_PROTOCOL_MESSAGE_SIZE];
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, service::MAX_PROTOCOL_MESSAGE_SIZE > tmp;
llarp_buffer_t buf(tmp);
if(!msg->T.BEncode(&buf))
{
llarp::LogWarn(info, " failed to transfer data message, encode failed");

@ -11,7 +11,7 @@ namespace llarp
}
bool
PoW::DecodeKey(__attribute__((unused)) llarp_buffer_t k,
PoW::DecodeKey(__attribute__((unused)) const llarp_buffer_t& k,
__attribute__((unused)) llarp_buffer_t* val)
{
// TODO: implement me
@ -34,8 +34,8 @@ namespace llarp
return false;
ShortHash digest;
byte_t tmp[MaxSize];
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, MaxSize > tmp;
llarp_buffer_t buf(tmp);
// encode
if(!BEncode(&buf))
return false;

@ -21,7 +21,7 @@ namespace llarp
IsValid(shorthash_func hashfunc, llarp_time_t now) const;
bool
DecodeKey(llarp_buffer_t k, llarp_buffer_t* val) override;
DecodeKey(const llarp_buffer_t &k, llarp_buffer_t* val) override;
bool
BEncode(llarp_buffer_t* buf) const override;

@ -25,7 +25,7 @@ namespace llarp
}
bool
RouterProfile::DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf)
RouterProfile::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
{
bool read = false;
if(!BEncodeMaybeReadDictInt("g", connectGoodCount, read, k, buf))
@ -101,7 +101,7 @@ namespace llarp
size_t sz = (m_Profiles.size() * (RouterProfile::MaxSize + 32 + 8)) + 8;
std::vector< byte_t > tmp(sz, 0);
auto buf = llarp::Buffer(tmp);
llarp_buffer_t buf(tmp);
auto res = BEncode(&buf);
if(res)
{
@ -134,7 +134,7 @@ namespace llarp
}
bool
Profiling::DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf)
Profiling::DecodeKey(const llarp_buffer_t& k, llarp_buffer_t* buf)
{
if(k.sz != 32)
return false;

@ -26,7 +26,7 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t &k, llarp_buffer_t* buf) override;
bool
IsGood(uint64_t chances) const;
@ -55,7 +55,7 @@ namespace llarp
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(llarp_buffer_t k, llarp_buffer_t* buf) override;
DecodeKey(const llarp_buffer_t &k, llarp_buffer_t* buf) override;
bool
Load(const char* fname);

@ -233,7 +233,7 @@ namespace llarp
bool
Router::HandleRecvLinkMessageBuffer(llarp::ILinkSession *session,
llarp_buffer_t buf)
const llarp_buffer_t &buf)
{
if(_stopping)
return true;
@ -298,8 +298,7 @@ namespace llarp
outboundMessageQueue.insert(std::make_pair(remote, MessageQueue()));
}
// encode
llarp_buffer_t buf =
llarp::StackBuffer< decltype(linkmsg_buffer) >(linkmsg_buffer);
llarp_buffer_t buf(linkmsg_buffer);
if(!msg->BEncode(&buf))
return false;
// queue buffer
@ -561,7 +560,7 @@ namespace llarp
}
bool
Router::ParseRoutingMessageBuffer(llarp_buffer_t buf,
Router::ParseRoutingMessageBuffer(const llarp_buffer_t &buf,
routing::IMessageHandler *h, PathID_t rxid)
{
return inbound_routing_msg_parser.ParseMessageBuffer(buf, h, rxid, this);
@ -818,7 +817,7 @@ namespace llarp
}
bool
Router::Sign(llarp::Signature &sig, llarp_buffer_t buf) const
Router::Sign(llarp::Signature &sig, const llarp_buffer_t &buf) const
{
return crypto->sign(sig, identity, buf);
}
@ -827,8 +826,7 @@ namespace llarp
Router::SendTo(llarp::RouterID remote, const llarp::ILinkMessage *msg,
llarp::ILinkLayer *selected)
{
llarp_buffer_t buf =
llarp::StackBuffer< decltype(linkmsg_buffer) >(linkmsg_buffer);
llarp_buffer_t buf(linkmsg_buffer);
if(!msg->BEncode(&buf))
{
@ -908,7 +906,7 @@ namespace llarp
}
while(itr->second.size())
{
auto buf = llarp::ConstBuffer(itr->second.front());
llarp_buffer_t buf(itr->second.front());
if(!chosen->SendTo(remote, buf))
llarp::LogWarn("failed to send outbound message to ", remote, " via ",
chosen->Name());
@ -1008,7 +1006,7 @@ namespace llarp
}
if(whitelistRouters)
{
rpcCaller = std::make_unique<llarp::rpc::Caller>(this);
rpcCaller = std::make_unique< llarp::rpc::Caller >(this);
rpcCaller->SetBasicAuth(lokidRPCUser, lokidRPCPassword);
while(!rpcCaller->Start(lokidRPCAddr))
{
@ -1635,7 +1633,7 @@ namespace llarp
else if(StrEq(section, "connect")
|| (StrEq(section, "bootstrap") && StrEq(key, "add-node")))
{
//llarp::LogDebug("connect section has ", key, "=", val);
// llarp::LogDebug("connect section has ", key, "=", val);
self->bootstrapRCList.emplace_back();
auto &rc = self->bootstrapRCList.back();
if(!rc.Read(val))

@ -16,7 +16,7 @@
#include <routing/message_parser.hpp>
#include <rpc/rpc.hpp>
#include <service/context.hpp>
#include <util/buffer.h>
#include <util/buffer.hpp>
#include <util/fs.hpp>
#include <util/logic.hpp>
#include <util/mem.hpp>
@ -115,12 +115,12 @@ namespace llarp
llarp_dht_context *dht = nullptr;
bool
Sign(Signature &sig, llarp_buffer_t buf) const;
Sign(Signature &sig, const llarp_buffer_t &buf) const;
llarp_nodedb *nodedb;
// buffer for serializing link messages
byte_t linkmsg_buffer[MAX_LINK_MSG_SIZE];
std::array< byte_t, MAX_LINK_MSG_SIZE > linkmsg_buffer;
/// always maintain this many connections to other routers
size_t minConnectedRouters = 1;
@ -228,7 +228,8 @@ namespace llarp
OnSessionEstablished(llarp::RouterContact rc);
bool
HandleRecvLinkMessageBuffer(llarp::ILinkSession *from, llarp_buffer_t msg);
HandleRecvLinkMessageBuffer(llarp::ILinkSession *from,
const llarp_buffer_t &msg);
void
AddInboundLink(std::unique_ptr< llarp::ILinkLayer > &link);
@ -394,8 +395,8 @@ namespace llarp
/// successful parsing return true on parse and handle success otherwise
/// return false
bool
ParseRoutingMessageBuffer(llarp_buffer_t buf, routing::IMessageHandler *h,
PathID_t rxid);
ParseRoutingMessageBuffer(const llarp_buffer_t &buf,
routing::IMessageHandler *h, PathID_t rxid);
void
ConnectToRandomRouters(int N);

@ -152,7 +152,7 @@ namespace llarp
}
bool
RouterContact::DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf)
RouterContact::DecodeKey(const llarp_buffer_t &key, llarp_buffer_t *buf)
{
bool read = false;
if(!BEncodeMaybeReadDictList("a", addrs, read, key, buf))
@ -243,9 +243,9 @@ namespace llarp
bool
RouterContact::Sign(llarp::Crypto *crypto, const SecretKey &secretkey)
{
pubkey = llarp::seckey_topublic(secretkey);
byte_t tmp[MAX_RC_SIZE] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
pubkey = llarp::seckey_topublic(secretkey);
std::array< byte_t, MAX_RC_SIZE > tmp;
llarp_buffer_t buf(tmp);
signature.Zero();
last_updated = time_now_ms();
if(!BEncode(&buf))
@ -296,8 +296,8 @@ namespace llarp
RouterContact copy;
copy = *this;
copy.signature.Zero();
byte_t tmp[MAX_RC_SIZE] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, MAX_RC_SIZE > tmp;
llarp_buffer_t buf(tmp);
if(!copy.BEncode(&buf))
{
llarp::LogError("bencode failed");
@ -311,8 +311,8 @@ namespace llarp
bool
RouterContact::Write(const char *fname) const
{
byte_t tmp[MAX_RC_SIZE] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, MAX_RC_SIZE > tmp;
llarp_buffer_t buf(tmp);
if(!BEncode(&buf))
return false;
buf.sz = buf.cur - buf.base;
@ -328,7 +328,8 @@ namespace llarp
bool
RouterContact::Read(const char *fname)
{
byte_t tmp[MAX_RC_SIZE] = {0};
std::array< byte_t, MAX_RC_SIZE > tmp;
llarp_buffer_t buf(tmp);
std::ifstream f;
f.open(fname, std::ios::binary);
if(!f.is_open())
@ -338,11 +339,10 @@ namespace llarp
}
f.seekg(0, std::ios::end);
size_t l = f.tellg();
if(l > sizeof(tmp))
if(l > tmp.size())
return false;
f.seekg(0, std::ios::beg);
f.read((char *)tmp, l);
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
f.read((char *)tmp.data(), l);
return BDecode(&buf);
}

@ -127,7 +127,7 @@ namespace llarp
}
bool
DecodeKey(llarp_buffer_t k, llarp_buffer_t *buf) override;
DecodeKey(const llarp_buffer_t &k, llarp_buffer_t *buf) override;
RouterContact &
operator=(const RouterContact &other);

@ -11,7 +11,7 @@ namespace llarp
}
bool
DHTMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* val)
DHTMessage::DecodeKey(const llarp_buffer_t &key, llarp_buffer_t* val)
{
llarp::dht::Key_t from;
from.Zero();

@ -6,7 +6,7 @@
#include <messages/path_latency.hpp>
#include <messages/path_transfer.hpp>
#include <messages/transfer_traffic.hpp>
#include <util/buffer.h>
#include <util/buffer.hpp>
namespace llarp
{

@ -3,7 +3,7 @@
#include <path/path_types.hpp>
#include <util/bencode.hpp>
#include <util/buffer.h>
#include <util/buffer.hpp>
namespace llarp
{

@ -87,7 +87,7 @@ namespace llarp
}
bool
InboundMessageParser::ParseMessageBuffer(llarp_buffer_t buf,
InboundMessageParser::ParseMessageBuffer(const llarp_buffer_t& buf,
IMessageHandler* h,
const PathID_t& from,
llarp::Router* r)
@ -95,7 +95,9 @@ namespace llarp
bool result = false;
msg = nullptr;
firstKey = true;
if(bencode_read_dict(&buf, &reader))
ManagedBuffer copiedBuf(buf);
auto& copy = copiedBuf.underlying;
if(bencode_read_dict(&copy, &reader))
{
msg->from = from;
result = msg->HandleMessage(h, r);

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save