diff --git a/Datagram.cpp b/Datagram.cpp index 705e10ef..c501edf2 100644 --- a/Datagram.cpp +++ b/Datagram.cpp @@ -99,6 +99,8 @@ namespace datagram size_t uncompressedLen = m_Inflator.Inflate (buf, len, uncompressed, MAX_DATAGRAM_SIZE); if (uncompressedLen) HandleDatagram (fromPort, toPort, uncompressed, uncompressedLen); + else + LogPrint (eLogWarning, "Datagram: decompression failed"); } std::shared_ptr DatagramDestination::CreateDataMessage (const uint8_t * payload, size_t len, uint16_t fromPort, uint16_t toPort) @@ -134,6 +136,7 @@ namespace datagram if (now - it->second->LastActivity() >= DATAGRAM_SESSION_MAX_IDLE) { LogPrint(eLogInfo, "DatagramDestination: expiring idle session with ", it->first.ToBase32()); + it->second->Stop (); it = m_Sessions.erase (it); // we are expired } else @@ -149,6 +152,7 @@ namespace datagram if (itr == m_Sessions.end()) { // not found, create new session session = std::make_shared(m_Owner, identity); + session->Start (); m_Sessions[identity] = session; } else { session = itr->second; @@ -172,11 +176,20 @@ namespace datagram m_RemoteIdent(remoteIdent), m_SendQueueTimer(localDestination->GetService()), m_RequestingLS(false) + { + } + + void DatagramSession::Start () { m_LastUse = i2p::util::GetMillisecondsSinceEpoch (); ScheduleFlushSendQueue(); } + void DatagramSession::Stop () + { + m_SendQueueTimer.cancel (); + } + void DatagramSession::SendMsg(std::shared_ptr msg) { // we used this session diff --git a/Datagram.h b/Datagram.h index a10f2646..b317d101 100644 --- a/Datagram.h +++ b/Datagram.h @@ -37,8 +37,10 @@ namespace datagram class DatagramSession : public std::enable_shared_from_this { public: - DatagramSession(i2p::client::ClientDestination * localDestination, - const i2p::data::IdentHash & remoteIdent); + DatagramSession(i2p::client::ClientDestination * localDestination, const i2p::data::IdentHash & remoteIdent); + + void Start (); + void Stop (); /** @brief ack the garlic routing path */