mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-22 00:59:08 +01:00
eliminate datagram send timer
This commit is contained in:
parent
0639cce784
commit
a33cad4b70
2 changed files with 7 additions and 22 deletions
|
@ -34,12 +34,16 @@ namespace datagram
|
||||||
|
|
||||||
void DatagramDestination::SendDatagramTo(const uint8_t * payload, size_t len, const i2p::data::IdentHash & identity, uint16_t fromPort, uint16_t toPort)
|
void DatagramDestination::SendDatagramTo(const uint8_t * payload, size_t len, const i2p::data::IdentHash & identity, uint16_t fromPort, uint16_t toPort)
|
||||||
{
|
{
|
||||||
SendDatagram (ObtainSession(identity), payload, len, fromPort, toPort);
|
auto session = ObtainSession(identity);
|
||||||
|
SendDatagram (session, payload, len, fromPort, toPort);
|
||||||
|
FlushSendQueue (session);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatagramDestination::SendRawDatagramTo(const uint8_t * payload, size_t len, const i2p::data::IdentHash & identity, uint16_t fromPort, uint16_t toPort)
|
void DatagramDestination::SendRawDatagramTo(const uint8_t * payload, size_t len, const i2p::data::IdentHash & identity, uint16_t fromPort, uint16_t toPort)
|
||||||
{
|
{
|
||||||
SendRawDatagram (ObtainSession(identity), payload, len, fromPort, toPort);
|
auto session = ObtainSession(identity);
|
||||||
|
SendRawDatagram (session, payload, len, fromPort, toPort);
|
||||||
|
FlushSendQueue (session);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<DatagramSession> DatagramDestination::GetSession(const i2p::data::IdentHash & ident)
|
std::shared_ptr<DatagramSession> DatagramDestination::GetSession(const i2p::data::IdentHash & ident)
|
||||||
|
@ -218,7 +222,6 @@ namespace datagram
|
||||||
const i2p::data::IdentHash & remoteIdent) :
|
const i2p::data::IdentHash & remoteIdent) :
|
||||||
m_LocalDestination(localDestination),
|
m_LocalDestination(localDestination),
|
||||||
m_RemoteIdent(remoteIdent),
|
m_RemoteIdent(remoteIdent),
|
||||||
m_SendQueueTimer(localDestination->GetService()),
|
|
||||||
m_RequestingLS(false)
|
m_RequestingLS(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -226,12 +229,10 @@ namespace datagram
|
||||||
void DatagramSession::Start ()
|
void DatagramSession::Start ()
|
||||||
{
|
{
|
||||||
m_LastUse = i2p::util::GetMillisecondsSinceEpoch ();
|
m_LastUse = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
ScheduleFlushSendQueue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatagramSession::Stop ()
|
void DatagramSession::Stop ()
|
||||||
{
|
{
|
||||||
m_SendQueueTimer.cancel ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatagramSession::SendMsg(std::shared_ptr<I2NPMessage> msg)
|
void DatagramSession::SendMsg(std::shared_ptr<I2NPMessage> msg)
|
||||||
|
@ -383,7 +384,7 @@ namespace datagram
|
||||||
if (msg || m_SendQueue.empty ())
|
if (msg || m_SendQueue.empty ())
|
||||||
m_SendQueue.push_back(msg);
|
m_SendQueue.push_back(msg);
|
||||||
// flush queue right away if full
|
// flush queue right away if full
|
||||||
if(m_SendQueue.size() >= DATAGRAM_SEND_QUEUE_MAX_SIZE) FlushSendQueue();
|
if(!msg || m_SendQueue.size() >= DATAGRAM_SEND_QUEUE_MAX_SIZE) FlushSendQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatagramSession::FlushSendQueue ()
|
void DatagramSession::FlushSendQueue ()
|
||||||
|
@ -404,18 +405,5 @@ namespace datagram
|
||||||
}
|
}
|
||||||
m_SendQueue.clear();
|
m_SendQueue.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatagramSession::ScheduleFlushSendQueue()
|
|
||||||
{
|
|
||||||
boost::posix_time::milliseconds dlt(10);
|
|
||||||
m_SendQueueTimer.expires_from_now(dlt);
|
|
||||||
auto self = shared_from_this();
|
|
||||||
m_SendQueueTimer.async_wait([self](const boost::system::error_code & ec)
|
|
||||||
{
|
|
||||||
if(ec) return;
|
|
||||||
self->FlushSendQueue();
|
|
||||||
self->ScheduleFlushSendQueue();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,8 +85,6 @@ namespace datagram
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void ScheduleFlushSendQueue();
|
|
||||||
|
|
||||||
void HandleSend(std::shared_ptr<I2NPMessage> msg);
|
void HandleSend(std::shared_ptr<I2NPMessage> msg);
|
||||||
|
|
||||||
std::shared_ptr<i2p::garlic::GarlicRoutingPath> GetSharedRoutingPath();
|
std::shared_ptr<i2p::garlic::GarlicRoutingPath> GetSharedRoutingPath();
|
||||||
|
@ -101,7 +99,6 @@ namespace datagram
|
||||||
std::shared_ptr<i2p::garlic::GarlicRoutingSession> m_RoutingSession;
|
std::shared_ptr<i2p::garlic::GarlicRoutingSession> m_RoutingSession;
|
||||||
std::shared_ptr<const i2p::data::Lease> m_CurrentRemoteLease;
|
std::shared_ptr<const i2p::data::Lease> m_CurrentRemoteLease;
|
||||||
std::shared_ptr<i2p::tunnel::OutboundTunnel> m_CurrentOutboundTunnel;
|
std::shared_ptr<i2p::tunnel::OutboundTunnel> m_CurrentOutboundTunnel;
|
||||||
boost::asio::deadline_timer m_SendQueueTimer;
|
|
||||||
std::vector<std::shared_ptr<I2NPMessage> > m_SendQueue;
|
std::vector<std::shared_ptr<I2NPMessage> > m_SendQueue;
|
||||||
uint64_t m_LastUse;
|
uint64_t m_LastUse;
|
||||||
bool m_RequestingLS;
|
bool m_RequestingLS;
|
||||||
|
|
Loading…
Add table
Reference in a new issue