limit calls

pull/935/head
Jeff Becker 5 years ago committed by Jason Rhinelander
parent 5d8f547d33
commit 5924a2cec0

@ -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,

@ -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 >;

Loading…
Cancel
Save