code review fixes:

* use std::unordered_set
* use default for ctor/dtor
* don't crash on short packet with nack
pull/783/head
Jeff Becker 5 years ago
parent 647f874d0f
commit 6a48a3b402
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -204,7 +204,7 @@ namespace llarp
{
uint16_t proto = 0;
std::set< std::string > parsed_opts;
std::unordered_set< std::string > parsed_opts;
std::string v = tostr(val);
std::string::size_type idx;
do
@ -220,7 +220,7 @@ namespace llarp
parsed_opts.insert(v);
}
} while(idx != std::string::npos);
std::set< std::string > opts;
std::unordered_set< std::string > opts;
/// for each option
for(const auto &item : parsed_opts)
{

@ -12,6 +12,7 @@
#include <string>
#include <utility>
#include <vector>
#include <unordered_set>
namespace llarp
{
@ -195,7 +196,7 @@ namespace llarp
static constexpr int Port = 2;
static constexpr int Options = 3;
using ServerOptions = std::set< std::string >;
using ServerOptions = std::unordered_set< std::string >;
using LinkInfo = std::tuple< std::string, int, uint16_t, ServerOptions >;
using Links = std::vector< LinkInfo >;

@ -5,10 +5,6 @@ namespace llarp
{
namespace iwp
{
OutboundMessage::OutboundMessage() : m_Size{0}
{
}
OutboundMessage::OutboundMessage(uint64_t msgid, const llarp_buffer_t &pkt,
ILinkSession::CompletionHandler handler)
: m_Size{(uint16_t)std::min(pkt.sz, MAX_LINK_MSG_SIZE)}
@ -17,6 +13,8 @@ namespace llarp
{
m_Data.Zero();
std::copy_n(pkt.base, m_Size, m_Data.begin());
const llarp_buffer_t buf{m_Data.data(), m_Size};
CryptoManager::instance()->shorthash(digest, buf);
}
std::vector< byte_t >
@ -26,11 +24,7 @@ namespace llarp
LLARP_PROTO_VERSION, Command::eXMIT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
htobe16buf(xmit.data() + 2, m_Size);
htobe64buf(xmit.data() + 4, m_MsgID);
const llarp_buffer_t buf{m_Data.data(), m_Size};
ShortHash H;
CryptoManager::instance()->shorthash(H, buf);
std::copy(H.begin(), H.end(), std::back_inserter(xmit));
LogDebug("xmit H=", H.ToHex());
std::copy(digest.begin(), digest.end(), std::back_inserter(xmit));
return xmit;
}
@ -101,10 +95,6 @@ namespace llarp
return true;
}
InboundMessage::InboundMessage() : m_Size{0}
{
}
InboundMessage::InboundMessage(uint64_t msgid, uint16_t sz, ShortHash h)
: m_Digset{std::move(h)}, m_Size{sz}, m_MsgID{msgid}
{

@ -31,7 +31,7 @@ namespace llarp
struct OutboundMessage
{
OutboundMessage();
OutboundMessage() = default;
OutboundMessage(uint64_t msgid, const llarp_buffer_t &pkt,
ILinkSession::CompletionHandler handler);
@ -41,6 +41,7 @@ namespace llarp
std::bitset< MAX_LINK_MSG_SIZE / FragmentSize > m_Acks;
ILinkSession::CompletionHandler m_Completed;
llarp_time_t m_LastFlush = 0;
ShortHash digest;
std::vector< byte_t >
XMIT() const;
@ -64,7 +65,7 @@ namespace llarp
struct InboundMessage
{
InboundMessage();
InboundMessage() = default;
InboundMessage(uint64_t msgid, uint16_t sz, ShortHash h);
AlignedBuffer< MAX_LINK_MSG_SIZE > m_Data;

@ -33,10 +33,6 @@ namespace llarp
GotLIM = util::memFn(&Session::GotInboundLIM, this);
}
Session::~Session()
{
}
void
Session::Send_LL(const llarp_buffer_t& pkt)
{
@ -444,6 +440,11 @@ namespace llarp
void
Session::HandleNACK(std::vector< byte_t > data)
{
if(data.size() < 10)
{
LogError("short nack from ", m_RemoteAddr);
return;
}
uint64_t txid = bufbe64toh(data.data() + 2);
LogDebug("got nack on ", txid, " from ", m_RemoteAddr);
auto itr = m_TXMsgs.find(txid);

@ -17,7 +17,7 @@ namespace llarp
/// inbound session
Session(LinkLayer* parent, Addr from);
~Session();
~Session() = default;
void
Pump() override;

Loading…
Cancel
Save