mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
move unsent I2NP messages to new session if replaced
This commit is contained in:
parent
4100249313
commit
a1322d4667
|
@ -455,10 +455,12 @@ namespace transport
|
|||
if (ident)
|
||||
{
|
||||
auto ret = m_SessionsByRouterHash.emplace (ident->GetIdentHash (), session);
|
||||
if (!ret.second)
|
||||
if (!ret.second && ret.first->second != session)
|
||||
{
|
||||
// session already exists
|
||||
LogPrint (eLogWarning, "SSU2: Session to ", ident->GetIdentHash ().ToBase64 (), " already exists");
|
||||
// move unsent msgs to new session
|
||||
ret.first->second->MoveSendQueue (session);
|
||||
// terminate existing
|
||||
GetService ().post (std::bind (&SSU2Session::RequestTermination, ret.first->second, eSSU2TerminationReasonReplacedByNewSession));
|
||||
// update session
|
||||
|
|
|
@ -313,6 +313,7 @@ namespace transport
|
|||
m_SentHandshakePacket.reset (nullptr);
|
||||
m_ConnectTimer.cancel ();
|
||||
SetTerminationTimeout (SSU2_TERMINATION_TIMEOUT);
|
||||
SendQueue ();
|
||||
transports.PeerConnected (shared_from_this ());
|
||||
if (m_OnEstablished)
|
||||
{
|
||||
|
@ -389,9 +390,24 @@ namespace transport
|
|||
SetSendQueueSize (m_SendQueue.size ());
|
||||
}
|
||||
|
||||
void SSU2Session::MoveSendQueue (std::shared_ptr<SSU2Session> other)
|
||||
{
|
||||
if (!other || m_SendQueue.empty ()) return;
|
||||
std::vector<std::shared_ptr<I2NPMessage> > msgs;
|
||||
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||
for (auto it: m_SendQueue)
|
||||
if (!it->IsExpired (ts))
|
||||
msgs.push_back (it);
|
||||
else
|
||||
it->Drop ();
|
||||
m_SendQueue.clear ();
|
||||
if (!msgs.empty ())
|
||||
other->PostI2NPMessages (msgs);
|
||||
}
|
||||
|
||||
bool SSU2Session::SendQueue ()
|
||||
{
|
||||
if (!m_SendQueue.empty () && m_SentPackets.size () <= m_WindowSize)
|
||||
if (!m_SendQueue.empty () && m_SentPackets.size () <= m_WindowSize && IsEstablished ())
|
||||
{
|
||||
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||
uint64_t mts = i2p::util::GetMonotonicMicroseconds ();
|
||||
|
|
|
@ -255,6 +255,7 @@ namespace transport
|
|||
void Done () override;
|
||||
void SendLocalRouterInfo (bool update) override;
|
||||
void SendI2NPMessages (const std::vector<std::shared_ptr<I2NPMessage> >& msgs) override;
|
||||
void MoveSendQueue (std::shared_ptr<SSU2Session> other);
|
||||
uint32_t GetRelayTag () const override { return m_RelayTag; };
|
||||
size_t Resend (uint64_t ts); // return number of resent packets
|
||||
uint64_t GetLastResendTime () const { return m_LastResendTime; };
|
||||
|
|
Loading…
Reference in a new issue