diff --git a/libi2pd_client/UDPTunnel.cpp b/libi2pd_client/UDPTunnel.cpp index 1b0bd48c..b8df8559 100644 --- a/libi2pd_client/UDPTunnel.cpp +++ b/libi2pd_client/UDPTunnel.cpp @@ -35,10 +35,7 @@ namespace client { uint32_t seqn = 0; if (options->Get (UDP_SESSION_SEQN, seqn) && seqn > m_LastSession->m_LastReceivedPacketNum) - { m_LastSession->m_LastReceivedPacketNum = seqn; - LogPrint (eLogDebug, "UDP Server: Received packet with seqn ", seqn); - } } } @@ -158,7 +155,12 @@ namespace client { LogPrint(eLogDebug, "UDPSession: Forward ", len, "B from ", FromEndpoint); auto ts = i2p::util::GetMillisecondsSinceEpoch(); - auto session = m_Destination->GetSession (Identity); + auto session = m_LastDatagramSession.lock (); + if (!session) + { + session = m_Destination->GetSession (Identity); + m_LastDatagramSession = session; + } if (ts > LastActivity + I2P_UDP_REPLIABLE_DATAGRAM_INTERVAL) { i2p::util::Mapping options; @@ -356,7 +358,12 @@ namespace client // send off to remote i2p destination auto ts = i2p::util::GetMillisecondsSinceEpoch (); LogPrint (eLogDebug, "UDP Client: Send ", transferred, " to ", m_RemoteAddr->identHash.ToBase32 (), ":", RemotePort); - auto session = m_LocalDest->GetDatagramDestination ()->GetSession (m_RemoteAddr->identHash); + auto session = m_LastDatagramSession.lock (); + if (!session) + { + session = m_LocalDest->GetDatagramDestination ()->GetSession (m_RemoteAddr->identHash); + m_LastDatagramSession = session; + } if (ts > m_LastSession->second + I2P_UDP_REPLIABLE_DATAGRAM_INTERVAL) { i2p::util::Mapping options; @@ -424,7 +431,15 @@ namespace client const uint8_t * buf, size_t len, const i2p::util::Mapping * options) { if (m_RemoteAddr && from.GetIdentHash() == m_RemoteAddr->identHash) + { + if (options) + { + uint32_t seqn = 0; + if (options->Get (UDP_SESSION_SEQN, seqn) && seqn > m_LastReceivedPacketNum) + m_LastReceivedPacketNum = seqn; + } HandleRecvFromI2PRaw (fromPort, toPort, buf, len); + } else LogPrint(eLogWarning, "UDP Client: Unwarranted traffic from ", from.GetIdentHash().ToBase32 ()); } diff --git a/libi2pd_client/UDPTunnel.h b/libi2pd_client/UDPTunnel.h index 848ed679..44293e82 100644 --- a/libi2pd_client/UDPTunnel.h +++ b/libi2pd_client/UDPTunnel.h @@ -36,6 +36,7 @@ namespace client struct UDPSession { i2p::datagram::DatagramDestination * m_Destination; + std::weak_ptr m_LastDatagramSession; boost::asio::ip::udp::socket IPSocket; i2p::data::IdentHash Identity; boost::asio::ip::udp::endpoint FromEndpoint; @@ -181,6 +182,7 @@ namespace client bool m_Gzip; i2p::datagram::DatagramVersion m_DatagramVersion; std::shared_ptr m_LastSession; + std::weak_ptr m_LastDatagramSession; uint32_t m_NextSendPacketNum, m_LastReceivedPacketNum; public: