consolidate rx message handling in iwp

* add toggle flag for using multi ack
* check replay filter before processing message
pull/1535/head
Jeff Becker 3 years ago
parent e6ac7e721d
commit 5cffc3b0f8
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -775,14 +775,7 @@ namespace llarp
return;
}
}
auto msg = std::move(itr->second);
const llarp_buffer_t buf(msg.m_Data);
m_Parent->HandleMessage(this, buf);
if (m_ReplayFilter.emplace(rxid, m_Parent->Now()).second)
{
EncryptAndSend(msg.ACKS());
}
m_RXMsgs.erase(rxid);
HandleRecvMsgCompleted(itr->second);
}
}
else
@ -829,22 +822,34 @@ namespace llarp
{
if (itr->second.Verify())
{
auto msg = std::move(itr->second);
const llarp_buffer_t buf(msg.m_Data);
m_Parent->HandleMessage(this, buf);
if (m_ReplayFilter.emplace(itr->first, m_Parent->Now()).second)
{
EncryptAndSend(msg.ACKS());
}
HandleRecvMsgCompleted(itr->second);
}
else
{
LogError("hash mismatch for message ", itr->first);
}
m_RXMsgs.erase(itr);
}
}
void
Session::HandleRecvMsgCompleted(const InboundMessage& msg)
{
/// should we send a multiack?
constexpr bool UseMACK = false;
const auto rxid = msg.m_MsgID;
if (m_ReplayFilter.emplace(rxid, m_Parent->Now()).second)
{
const llarp_buffer_t buf(msg.m_Data);
m_Parent->HandleMessage(this, buf);
if (UseMACK)
m_SendMACKs.emplace(rxid);
else
EncryptAndSend(msg.ACKS());
}
m_RXMsgs.erase(rxid);
}
void
Session::HandleACKS(Packet_t data)
{

@ -192,7 +192,7 @@ namespace llarp
/// maps rxid to time recieved
std::unordered_map<uint64_t, llarp_time_t> m_ReplayFilter;
/// rx messages to send in next round of multiacks
std::priority_queue<uint64_t, std::vector<uint64_t>, std::greater<uint64_t>> m_SendMACKs;
std::priority_queue<uint64_t> m_SendMACKs;
using CryptoQueue_t = std::vector<Packet_t>;
@ -228,6 +228,9 @@ namespace llarp
void
SendMACK();
void
HandleRecvMsgCompleted(const InboundMessage& msg);
void
GenerateAndSendIntro();

Loading…
Cancel
Save