Add implicit conversion from ManagedBuffer to llarp_buffer_t

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

@ -683,7 +683,7 @@ llarp_handle_dnsc_recvfrom(struct llarp_udp_io *const udp,
// sometimes we'll get double responses
if(request)
{
generic_handle_dnsc_recvfrom(request, buf.underlying, &hdr);
generic_handle_dnsc_recvfrom(request, buf, &hdr);
}
else
{

@ -365,9 +365,8 @@ namespace llarp
void
ExitEndpoint::OnInetPacket(const llarp_buffer_t &buf)
{
m_InetToNetwork.EmplaceIf([b = ManagedBuffer(buf)](Pkt_t &pkt) -> bool {
return pkt.Load(b.underlying);
});
m_InetToNetwork.EmplaceIf(
[b = ManagedBuffer(buf)](Pkt_t &pkt) -> bool { return pkt.Load(b); });
}
bool

@ -581,7 +581,7 @@ namespace llarp
return m_NetworkToUserPktQueue.EmplaceIf(
[buf, themIP, usIP](net::IPv4Packet &pkt) -> bool {
// load
if(!pkt.Load(buf.underlying))
if(!pkt.Load(buf))
return false;
// filter out:
// - packets smaller than minimal IPv4 header
@ -727,7 +727,7 @@ namespace llarp
ManagedBuffer buf(b);
if(!self->m_UserToNetworkPktQueue.EmplaceIf(
[buf](net::IPv4Packet &pkt) -> bool {
return pkt.Load(buf.underlying) && pkt.Header()->version == 4;
return pkt.Load(buf) && pkt.Header()->version == 4;
}))
{
#if defined(DEBUG) || !defined(RELEASE_MOTTO)

@ -32,10 +32,11 @@
ALWAYS pass a llarp_buffer_t * if you plan on advancing the stream position
ALWAYS pass a llarp_buffer_t if you are doing a read only operation that does
not modify the buffer
ALWAYS pass a const llarp_buffer_t & if you are doing a read only operation
that does not modify the buffer
ALWAYS pass a llarp_buffer_t if you don't want to advance the stream position
ALWAYS pass a const llarp_buffer_t & if you don't want to advance the stream
position
ALWAYS bail out of the current operation if you run out of space in a buffer
@ -117,16 +118,26 @@ struct llarp_buffer_t
llarp_buffer_t(llarp_buffer_t &&) = default;
};
/**
Provide a copyable/moveable wrapper around `llarp_buffer_t`.
*/
struct ManagedBuffer
{
llarp_buffer_t underlying;
ManagedBuffer() = delete;
explicit ManagedBuffer(const llarp_buffer_t &b) : underlying(b)
{
}
ManagedBuffer(ManagedBuffer &&) = default;
ManagedBuffer(const ManagedBuffer &) = default;
operator const llarp_buffer_t &() const
{
return underlying;
}
};
/// how much room is left in buffer

Loading…
Cancel
Save