some tweaks and fixups

pull/23/head
cathugger 6 years ago
parent 4971fae171
commit e1c7d8a696

@ -120,12 +120,14 @@ namespace llarp
struct dotLokiLookup dll; struct dotLokiLookup dll;
/// maps ip to service address (host byte order) /// maps ip to service address (host byte order)
std::unordered_map< huint32_t, service::Address > m_IPToAddr; std::unordered_map< huint32_t, service::Address, huint32_t::Hash >
m_IPToAddr;
/// maps service address to ip (host byte order) /// maps service address to ip (host byte order)
std::unordered_map< service::Address, huint32_t, service::Address::Hash > std::unordered_map< service::Address, huint32_t, service::Address::Hash >
m_AddrToIP; m_AddrToIP;
/// maps ip address to timestamp last active /// maps ip address to timestamp last active
std::unordered_map< huint32_t, llarp_time_t > m_IPActivity; std::unordered_map< huint32_t, llarp_time_t, huint32_t::Hash >
m_IPActivity;
/// our ip address (host byte order) /// our ip address (host byte order)
huint32_t m_OurIP; huint32_t m_OurIP;
/// next ip address to allocate (host byte order) /// next ip address to allocate (host byte order)

@ -51,16 +51,12 @@ llarp_getPrivateIfs();
namespace llarp namespace llarp
{ {
struct huint32_t;
struct nuint32_t;
// clang-format off // clang-format off
struct huint32_t struct huint32_t
{ {
uint32_t h; uint32_t h;
//inline operator nuint32_t() const { return xhtonl(*this); }
constexpr huint32_t operator &(huint32_t x) const { return huint32_t{h & x.h}; } constexpr huint32_t operator &(huint32_t x) const { return huint32_t{h & x.h}; }
constexpr huint32_t operator |(huint32_t x) const { return huint32_t{h | x.h}; } constexpr huint32_t operator |(huint32_t x) const { return huint32_t{h | x.h}; }
constexpr huint32_t operator ~() const { return huint32_t{~h}; } constexpr huint32_t operator ~() const { return huint32_t{~h}; }
@ -68,13 +64,21 @@ namespace llarp
inline huint32_t operator --() { --h; return *this; } inline huint32_t operator --() { --h; return *this; }
constexpr bool operator <(huint32_t x) const { return h < x.h; } constexpr bool operator <(huint32_t x) const { return h < x.h; }
constexpr bool operator ==(huint32_t x) const { return h == x.h; } constexpr bool operator ==(huint32_t x) const { return h == x.h; }
struct Hash
{
inline size_t
operator()(huint32_t x) const
{
return std::hash< uint32_t >{}(x.h);
}
};
}; };
struct nuint32_t struct nuint32_t
{ {
uint32_t n; uint32_t n;
//inline operator huint32_t() const { return xntohl(*this); }
constexpr nuint32_t operator &(nuint32_t x) const { return nuint32_t{n & x.n}; } constexpr nuint32_t operator &(nuint32_t x) const { return nuint32_t{n & x.n}; }
constexpr nuint32_t operator |(nuint32_t x) const { return nuint32_t{n | x.n}; } constexpr nuint32_t operator |(nuint32_t x) const { return nuint32_t{n | x.n}; }
constexpr nuint32_t operator ~() const { return nuint32_t{~n}; } constexpr nuint32_t operator ~() const { return nuint32_t{~n}; }
@ -82,6 +86,15 @@ namespace llarp
inline nuint32_t operator --() { --n; return *this; } inline nuint32_t operator --() { --n; return *this; }
constexpr bool operator <(nuint32_t x) const { return n < x.n; } constexpr bool operator <(nuint32_t x) const { return n < x.n; }
constexpr bool operator ==(nuint32_t x) const { return n == x.n; } constexpr bool operator ==(nuint32_t x) const { return n == x.n; }
struct Hash
{
inline size_t
operator()(nuint32_t x) const
{
return std::hash< uint32_t >{}(x.n);
}
};
}; };
// clang-format on // clang-format on
@ -97,33 +110,7 @@ namespace llarp
{ {
return nuint32_t{htonl(x.h)}; return nuint32_t{htonl(x.h)};
} }
} // namespace llarp
namespace std
{
template <>
struct hash< llarp::huint32_t >
{
inline size_t
operator()(llarp::huint32_t x) const
{
return hash< uint32_t >{}(x.h);
}
};
template <>
struct hash< llarp::nuint32_t >
{
inline size_t
operator()(llarp::nuint32_t x) const
{
return hash< uint32_t >{}(x.n);
}
};
} // namespace std
namespace llarp
{
struct Addr struct Addr
{ {
// network order // network order

@ -474,17 +474,8 @@ namespace llarp
llarp::LogDebug("got pkt ", sz, " bytes"); llarp::LogDebug("got pkt ", sz, " bytes");
if(!self->m_UserToNetworkPktQueue.EmplaceIf( if(!self->m_UserToNetworkPktQueue.EmplaceIf(
[self, buf, sz](net::IPv4Packet &pkt) -> bool { [self, buf, sz](net::IPv4Packet &pkt) -> bool {
if(pkt.Load(llarp::InitBuffer(buf, sz)) return pkt.Load(llarp::InitBuffer(buf, sz))
&& pkt.Header()->version == 4) && pkt.Header()->version == 4;
{
// clear addresses
pkt.src(0);
pkt.dst(0);
// clear checksum
pkt.Header()->check = 0;
return true;
}
return false;
})) }))
{ {
llarp::LogInfo("Failed to parse ipv4 packet"); llarp::LogInfo("Failed to parse ipv4 packet");

Loading…
Cancel
Save