1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00

limit calls

This commit is contained in:
Jeff Becker 2019-11-29 13:11:57 -05:00 committed by Jason Rhinelander
parent 5d8f547d33
commit 5924a2cec0
2 changed files with 16 additions and 3 deletions

View file

@ -35,8 +35,13 @@ namespace llarp
void
TunEndpoint::tunifTick(llarp_tun_io *tun)
{
auto *self = static_cast< TunEndpoint * >(tun->user);
LogicCall(self->m_router->logic(), [self]() { self->Flush(); });
auto *self = static_cast< TunEndpoint * >(tun->user);
const auto now = self->Now();
if(self->ShouldFlushNow(now))
{
self->m_LastFlushAt = now;
LogicCall(self->m_router->logic(), [self]() { self->Flush(); });
}
}
TunEndpoint::TunEndpoint(const std::string &nickname, AbstractRouter *r,

View file

@ -184,7 +184,15 @@ namespace llarp
ResetInternalState() override;
protected:
using PacketQueue_t = llarp::util::CoDelQueue<
bool
ShouldFlushNow(llarp_time_t now) const
{
static constexpr llarp_time_t FlushInterval = 50;
return now >= m_LastFlushAt + FlushInterval;
}
llarp_time_t m_LastFlushAt = 0;
using PacketQueue_t = llarp::util::CoDelQueue<
net::IPPacket, net::IPPacket::GetTime, net::IPPacket::PutTime,
net::IPPacket::CompareOrder, net::IPPacket::GetNow >;