Rename to ManagedBuffer

pull/266/head
Michael 5 years ago
parent 47380ba64b
commit 7ca3e13e78
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C

@ -606,7 +606,7 @@ extern "C"
void
llarp_handle_dns_recvfrom(struct llarp_udp_io *udp,
const struct sockaddr *addr, CopyableBuffer buf)
const struct sockaddr *addr, ManagedBuffer buf)
{
// auto buffer = llarp::StackBuffer< decltype(castBuf) >(castBuf);
dns_msg_header hdr;

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

@ -42,14 +42,14 @@ namespace llarp
void
Proxy::HandleUDPRecv_server(llarp_udp_io* u, const sockaddr* from,
CopyableBuffer buf)
ManagedBuffer buf)
{
static_cast< Proxy* >(u->user)->HandlePktServer(*from, &buf.underlying);
}
void
Proxy::HandleUDPRecv_client(llarp_udp_io* u, const sockaddr* from,
CopyableBuffer buf)
ManagedBuffer buf)
{
static_cast< Proxy* >(u->user)->HandlePktClient(*from, &buf.underlying);
}

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

@ -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, CopyableBuffer buf)
const struct sockaddr *saddr, ManagedBuffer buf)
{
if(!saddr)
{

@ -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, CopyableBuffer buf);
const struct sockaddr *addr, ManagedBuffer buf);
/// generic handler for processing DNS responses
/// this doesn't look like it exists

@ -14,7 +14,7 @@ constexpr size_t BUFFER_SIZE = 1500;
ssize_t
raw_sendto_dns_hook_func(void *sock, const struct sockaddr *from,
CopyableBuffer buf)
ManagedBuffer buf)
{
int *fd = (int *)sock;
// how do we get to these??
@ -25,7 +25,7 @@ raw_sendto_dns_hook_func(void *sock, const struct sockaddr *from,
ssize_t
llarp_sendto_dns_hook_func(void *sock, const struct sockaddr *from,
CopyableBuffer buf)
ManagedBuffer buf)
{
struct llarp_udp_io *udp = (struct llarp_udp_io *)sock;
if(!udp)
@ -75,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,
CopyableBuffer(llarp_buffer_t(buf, out_bytes)));
ManagedBuffer(llarp_buffer_t(buf, out_bytes)));
}
void
@ -141,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,
CopyableBuffer(llarp_buffer_t(buf, out_bytes)));
ManagedBuffer(llarp_buffer_t(buf, out_bytes)));
}
void
@ -179,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,
CopyableBuffer(llarp_buffer_t(buf, out_bytes)));
ManagedBuffer(llarp_buffer_t(buf, out_bytes)));
}
// FIXME: we need an DNS answer not a sockaddr
@ -245,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,
CopyableBuffer(llarp_buffer_t(buf, out_bytes)));
ManagedBuffer(llarp_buffer_t(buf, out_bytes)));
}
void
@ -286,7 +286,7 @@ writesend_dnss_mxresponse(uint16_t priority, std::string mx,
llarp::LogDebug("Sending found, ", out_bytes, " bytes");
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
request->sendto_hook(request->user, from,
CopyableBuffer(llarp_buffer_t(buf, out_bytes)));
ManagedBuffer(llarp_buffer_t(buf, out_bytes)));
}
void
@ -327,7 +327,7 @@ writesend_dnss_txtresponse(std::string txt, const struct sockaddr *from,
llarp::LogDebug("Sending found, ", out_bytes, " bytes");
// struct llarp_udp_io *udp = (struct llarp_udp_io *)request->user;
request->sendto_hook(request->user, from,
CopyableBuffer(llarp_buffer_t(buf, out_bytes)));
ManagedBuffer(llarp_buffer_t(buf, out_bytes)));
}
void
@ -347,7 +347,7 @@ handle_dnsc_result(dnsc_answer_request *client_request)
// bytes");
server_request->sendto_hook(server_request->user, server_request->from,
CopyableBuffer(llarp_buffer_t(test)));
ManagedBuffer(llarp_buffer_t(test)));
llarp_host_resolved(client_request);
return;
@ -514,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, CopyableBuffer buf)
const struct sockaddr *saddr, ManagedBuffer buf)
{
if(!dns_udp_tracker.dnsd)
{
@ -536,7 +536,7 @@ llarp_handle_dnsd_recvfrom(struct llarp_udp_io *udp,
void
raw_handle_recvfrom(int *sockfd, const struct sockaddr *saddr,
CopyableBuffer buffer)
ManagedBuffer buffer)
{
if(!dns_udp_tracker.dnsd)
{

@ -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, CopyableBuffer) >;
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, CopyableBuffer buf);
const struct sockaddr *addr, ManagedBuffer buf);
//
// output structures/functions:

@ -247,7 +247,7 @@ llarp_ev_tun_async_write(struct llarp_tun_io *tun, const llarp_buffer_t &buf)
bool
llarp_tcp_conn_async_write(struct llarp_tcp_conn *conn, const llarp_buffer_t &b)
{
CopyableBuffer buf{b};
ManagedBuffer buf{b};
llarp::tcp_conn *impl = static_cast< llarp::tcp_conn * >(conn->impl);
if(impl->_shouldClose)
{

@ -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 *,
CopyableBuffer);
ManagedBuffer);
};
/// add UDP handler

@ -148,7 +148,7 @@ namespace llarp
llarp::LogWarn("no source addr");
}
// Addr is the source
udp->recvfrom(udp, addr, CopyableBuffer{llarp_buffer_t(buf, ret)});
udp->recvfrom(udp, addr, ManagedBuffer{llarp_buffer_t(buf, ret)});
return 0;
}

@ -86,7 +86,7 @@ namespace llarp
}
bool
Endpoint::QueueOutboundTraffic(CopyableBuffer buf, uint64_t counter)
Endpoint::QueueOutboundTraffic(ManagedBuffer buf, uint64_t counter)
{
// queue overflow
if(m_UpstreamQueue.size() > MaxUpstreamQueueSize)
@ -109,7 +109,7 @@ namespace llarp
}
bool
Endpoint::QueueInboundTraffic(CopyableBuffer buf)
Endpoint::QueueInboundTraffic(ManagedBuffer buf)
{
llarp::net::IPv4Packet pkt;
if(!pkt.Load(buf.underlying))

@ -48,7 +48,7 @@ namespace llarp
/// queue traffic from service node / internet to be transmitted
bool
QueueInboundTraffic(CopyableBuffer 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(CopyableBuffer pkt, uint64_t counter);
QueueOutboundTraffic(ManagedBuffer pkt, uint64_t counter);
/// update local path id and cascade information to parent
/// return true if success

@ -186,7 +186,7 @@ namespace llarp
}
else
{
if(!ep->QueueInboundTraffic(CopyableBuffer{pkt.Buffer()}))
if(!ep->QueueInboundTraffic(ManagedBuffer{pkt.Buffer()}))
{
LogWarn(Name(), " dropped inbound traffic for session ", pk,
" as we are overloaded (probably)");
@ -365,7 +365,7 @@ namespace llarp
void
ExitEndpoint::OnInetPacket(const llarp_buffer_t &buf)
{
m_InetToNetwork.EmplaceIf([b = CopyableBuffer(buf)](Pkt_t &pkt) -> bool {
m_InetToNetwork.EmplaceIf([b = ManagedBuffer(buf)](Pkt_t &pkt) -> bool {
return pkt.Load(b.underlying);
});
}

@ -577,7 +577,7 @@ namespace llarp
auto themIP = getFromIP();
// llarp::LogInfo("themIP ", themIP);
auto usIP = m_OurIP;
CopyableBuffer buf(b);
ManagedBuffer buf(b);
return m_NetworkToUserPktQueue.EmplaceIf(
[buf, themIP, usIP](net::IPv4Packet &pkt) -> bool {
// load
@ -724,7 +724,7 @@ namespace llarp
{
// called for every packet read from user in isolated network thread
TunEndpoint *self = static_cast< TunEndpoint * >(tun->user);
CopyableBuffer buf(b);
ManagedBuffer buf(b);
if(!self->m_UserToNetworkPktQueue.EmplaceIf(
[buf](net::IPv4Packet &pkt) -> bool {
return pkt.Load(buf.underlying) && pkt.Header()->version == 4;

@ -178,7 +178,7 @@ namespace llarp
bool
QueueInboundPacketForExit(const llarp_buffer_t& buf)
{
CopyableBuffer copy{buf};
ManagedBuffer copy{buf};
return m_NetworkToUserPktQueue.EmplaceIf(
[&](llarp::net::IPv4Packet& pkt) -> bool {

@ -76,7 +76,7 @@ namespace llarp
}
static void
udp_recv_from(llarp_udp_io* udp, const sockaddr* from, CopyableBuffer buf)
udp_recv_from(llarp_udp_io* udp, const sockaddr* from, ManagedBuffer buf)
{
if(!udp)
{

@ -1119,7 +1119,7 @@ namespace llarp
{
// we done with this guy, prune next tick
itr->second.lastActive = 0;
CopyableBuffer buf(itr->second.buffer);
ManagedBuffer buf(itr->second.buffer);
// resize
buf.underlying.sz = buf.underlying.cur - buf.underlying.base;
// rewind

@ -102,7 +102,7 @@ namespace llarp
reader.on_key = &OnKey;
from = src;
firstkey = true;
CopyableBuffer copy(buf);
ManagedBuffer copy(buf);
return bencode_read_dict(&copy.underlying, &reader);
}

@ -270,7 +270,7 @@ namespace llarp
continue;
uint64_t counter = bufbe64toh(pkt.data());
sent &= endpoint->QueueOutboundTraffic(
CopyableBuffer(llarp_buffer_t(pkt.data() + 8, pkt.size() - 8)),
ManagedBuffer(llarp_buffer_t(pkt.data() + 8, pkt.size() - 8)),
counter);
}
return sent;

@ -95,7 +95,7 @@ namespace llarp
bool result = false;
msg = nullptr;
firstKey = true;
CopyableBuffer copiedBuf(buf);
ManagedBuffer copiedBuf(buf);
auto& copy = copiedBuf.underlying;
if(bencode_read_dict(&copy, &reader))
{

@ -193,10 +193,10 @@ namespace llarp
memcpy(payload.data(), buf.base, buf.sz);
}
CopyableBuffer
ManagedBuffer
Buffer()
{
return CopyableBuffer{llarp_buffer_t(payload)};
return ManagedBuffer{llarp_buffer_t(payload)};
}
};

@ -70,7 +70,7 @@ llarp_buffer_read_until(llarp_buffer_t* buff, char delim, byte_t* result,
bool
llarp_buffer_eq(const llarp_buffer_t& buf, const char* str)
{
CopyableBuffer copy{buf};
ManagedBuffer copy{buf};
while(*str
&& copy.underlying.cur != (copy.underlying.base + copy.underlying.sz))
{

@ -56,7 +56,7 @@
*/
struct CopyableBuffer;
struct ManagedBuffer;
struct llarp_buffer_t
{
@ -80,8 +80,8 @@ struct llarp_buffer_t
{
}
llarp_buffer_t(const CopyableBuffer &) = delete;
llarp_buffer_t(CopyableBuffer &&) = delete;
llarp_buffer_t(const ManagedBuffer &) = delete;
llarp_buffer_t(ManagedBuffer &&) = delete;
template < typename T >
llarp_buffer_t(T *buf, size_t _sz)
@ -112,21 +112,21 @@ struct llarp_buffer_t
}
private:
friend struct CopyableBuffer;
friend struct ManagedBuffer;
llarp_buffer_t(const llarp_buffer_t &) = default;
llarp_buffer_t(llarp_buffer_t &&) = default;
};
struct CopyableBuffer
struct ManagedBuffer
{
llarp_buffer_t underlying;
explicit CopyableBuffer(const llarp_buffer_t &b) : underlying(b)
explicit ManagedBuffer(const llarp_buffer_t &b) : underlying(b)
{
}
CopyableBuffer(CopyableBuffer &&) = default;
CopyableBuffer(const CopyableBuffer &) = default;
ManagedBuffer(ManagedBuffer &&) = default;
ManagedBuffer(const ManagedBuffer &) = default;
};
/// how much room is left in buffer

@ -180,7 +180,7 @@ TEST_F(LinkLayerTest, TestUTPAliceRenegWithBob)
else
{
llarp::LinkIntroMessage msg;
CopyableBuffer copy{buf};
ManagedBuffer copy{buf};
if(!msg.BDecode(&copy.underlying))
return false;
if(!s->GotLIM(&msg))
@ -220,7 +220,7 @@ TEST_F(LinkLayerTest, TestUTPAliceRenegWithBob)
[&]() -> const llarp::RouterContact& { return Bob.GetRC(); },
[&](llarp::ILinkSession* s, const llarp_buffer_t& buf) -> bool {
llarp::LinkIntroMessage msg;
CopyableBuffer copy{buf};
ManagedBuffer copy{buf};
if(!msg.BDecode(&copy.underlying))
return false;
if(!s->GotLIM(&msg))
@ -270,7 +270,7 @@ TEST_F(LinkLayerTest, TestUTPAliceConnectToBob)
else
{
llarp::LinkIntroMessage msg;
CopyableBuffer copy{buf};
ManagedBuffer copy{buf};
if(!msg.BDecode(&copy.underlying))
return false;
if(!s->GotLIM(&msg))
@ -310,7 +310,7 @@ TEST_F(LinkLayerTest, TestUTPAliceConnectToBob)
[&]() -> const llarp::RouterContact& { return Bob.GetRC(); },
[&](llarp::ILinkSession* s, const llarp_buffer_t& buf) -> bool {
llarp::LinkIntroMessage msg;
CopyableBuffer copy{buf};
ManagedBuffer copy{buf};
if(!msg.BDecode(&copy.underlying))
return false;
if(!s->GotLIM(&msg))

@ -197,7 +197,7 @@ TEST_F(DNSTest, handleDNSrecvFrom)
std::fill(buffer.begin(), buffer.end(), 0);
// hdr->qr decides dnsc (1) or dnsd (0)
llarp_handle_dns_recvfrom((llarp_udp_io *)&udp, &addr,
CopyableBuffer(llarp_buffer_t(buffer)));
ManagedBuffer(llarp_buffer_t(buffer)));
// llarp_handle_dnsc_recvfrom
// llarp_handle_dnsd_recvfrom
}

@ -12,7 +12,7 @@ std::string g_result = "";
ssize_t
test_sendto_dns_hook(__attribute__((unused)) void *sock,
__attribute__((unused)) const struct sockaddr *from,
CopyableBuffer buf)
ManagedBuffer buf)
{
char *hex_buffer = new char[buf.underlying.sz * 3 + 1];
hex_buffer[buf.underlying.sz * 3] = 0;

Loading…
Cancel
Save