small optimizations and fixes

- Ensure ip header struct is packed
- Use fmt
- add missing header
pull/1969/head
Jeff Becker 2 years ago committed by Jason Rhinelander
parent cfd80f6a17
commit beb07bf46f
No known key found for this signature in database
GPG Key ID: C4992CE7A88D4262

@ -24,6 +24,7 @@
#include <llarp/quic/tunnel.hpp>
#include <llarp/rpc/endpoint_rpc.hpp>
#include <llarp/util/str.hpp>
#include <llarp/util/logging/buffer.hpp>
#include <llarp/dns/srv_data.hpp>
#include <llarp/constants/net.hpp>
#include <llarp/constants/platform.hpp>

@ -126,21 +126,22 @@ namespace llarp::net
SockAddr
IPPacket::src() const
{
auto port = SrcPort();
const auto port = SrcPort().value_or(net::port_t{});
if (IsV4())
return SockAddr{ToNet(srcv4()), *port};
return SockAddr{ToNet(srcv4()), port};
else
return SockAddr{ToNet(srcv6()), *port};
return SockAddr{ToNet(srcv6()), port};
}
SockAddr
IPPacket::dst() const
{
auto port = DstPort();
auto port = *DstPort();
if (IsV4())
return SockAddr{ToNet(dstv4()), *port};
return SockAddr{ToNet(dstv4()), port};
else
return SockAddr{ToNet(dstv6()), *port};
return SockAddr{ToNet(dstv6()), port};
}
IPPacket::IPPacket(std::vector<byte_t>&& stolen) : _buf{stolen}
@ -171,7 +172,8 @@ namespace llarp::net
std::optional<nuint16_t>
IPPacket::SrcPort() const
{
switch (IPProtocol{Header()->protocol})
IPProtocol proto{Header()->protocol};
switch (proto)
{
case IPProtocol::TCP:
case IPProtocol::UDP:

@ -10,6 +10,7 @@
namespace llarp::net
{
#pragma pack(push, 1)
template <bool is_little_endian>
struct ip_header_le
{
@ -41,6 +42,7 @@ namespace llarp::net
uint32_t saddr;
uint32_t daddr;
};
#pragma pack(pop)
using ip_header = ip_header_le<oxenc::little_endian>;

@ -288,10 +288,7 @@ namespace llarp
// TODO: review
if (isEmpty())
return "";
std::string str = hostString();
str.append(1, ':');
str.append(std::to_string(getPort()));
return str;
return fmt::format("{}:{}", hostString(), port());
}
std::string

@ -115,7 +115,6 @@ llarp_buffer_t::copy() const
return copy;
}
namespace llarp
{
std::vector<byte_t>

@ -168,10 +168,12 @@ struct [[deprecated("this type is stupid, use something else")]] llarp_buffer_t
return {cur, size_left()};
}
/// Part of the curse. Returns true if the remaining buffer space starts with the given string view.
/// Part of the curse. Returns true if the remaining buffer space starts with the given string
/// view.
bool startswith(std::string_view prefix_str) const
{
llarp::byte_view_t prefix{reinterpret_cast<const byte_t*>(prefix_str.data()), prefix_str.size()};
llarp::byte_view_t prefix{
reinterpret_cast<const byte_t*>(prefix_str.data()), prefix_str.size()};
return view_remaining().substr(0, prefix.size()) == prefix;
}

@ -5,6 +5,7 @@
#include "handle.hpp"
#include <llarp/util/thread/queue.hpp>
#include <llarp/util/logging.hpp>
#include <llarp/util/logging/buffer.hpp>
#include <thread>
extern "C"
{

Loading…
Cancel
Save