mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 23:34:14 +00:00
remember tunnels selection for following messages
This commit is contained in:
parent
1da5be2871
commit
9b6c229b71
15
Garlic.cpp
15
Garlic.cpp
@ -125,6 +125,14 @@ namespace garlic
|
|||||||
else
|
else
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
CleanupUnconfirmedTags ();
|
||||||
|
return !m_SessionTags.empty () || !m_UnconfirmedTagsMsgs.empty ();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GarlicRoutingSession::CleanupUnconfirmedTags ()
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
|
||||||
// delete expired unconfirmed tags
|
// delete expired unconfirmed tags
|
||||||
for (auto it = m_UnconfirmedTagsMsgs.begin (); it != m_UnconfirmedTagsMsgs.end ();)
|
for (auto it = m_UnconfirmedTagsMsgs.begin (); it != m_UnconfirmedTagsMsgs.end ();)
|
||||||
{
|
{
|
||||||
@ -133,12 +141,13 @@ namespace garlic
|
|||||||
if (m_Owner)
|
if (m_Owner)
|
||||||
m_Owner->RemoveDeliveryStatusSession ((*it)->msgID);
|
m_Owner->RemoveDeliveryStatusSession ((*it)->msgID);
|
||||||
it = m_UnconfirmedTagsMsgs.erase (it);
|
it = m_UnconfirmedTagsMsgs.erase (it);
|
||||||
|
ret = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
return !m_SessionTags.empty () || !m_UnconfirmedTagsMsgs.empty ();
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<I2NPMessage> GarlicRoutingSession::WrapSingleMessage (std::shared_ptr<const I2NPMessage> msg)
|
std::shared_ptr<I2NPMessage> GarlicRoutingSession::WrapSingleMessage (std::shared_ptr<const I2NPMessage> msg)
|
||||||
{
|
{
|
||||||
@ -625,7 +634,7 @@ namespace garlic
|
|||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GarlicDestination::RemoveDeliveryStatusSession (uint32_t msgID)
|
void GarlicDestination::RemoveDeliveryStatusSession (uint32_t msgID)
|
||||||
{
|
{
|
||||||
m_DeliveryStatusSessions.erase (msgID);
|
m_DeliveryStatusSessions.erase (msgID);
|
||||||
|
1
Garlic.h
1
Garlic.h
@ -98,6 +98,7 @@ namespace garlic
|
|||||||
std::shared_ptr<I2NPMessage> WrapSingleMessage (std::shared_ptr<const I2NPMessage> msg);
|
std::shared_ptr<I2NPMessage> WrapSingleMessage (std::shared_ptr<const I2NPMessage> msg);
|
||||||
void MessageConfirmed (uint32_t msgID);
|
void MessageConfirmed (uint32_t msgID);
|
||||||
bool CleanupExpiredTags (); // returns true if something left
|
bool CleanupExpiredTags (); // returns true if something left
|
||||||
|
bool CleanupUnconfirmedTags (); // returns true if something has been deleted
|
||||||
|
|
||||||
void SetLeaseSetUpdated ()
|
void SetLeaseSetUpdated ()
|
||||||
{
|
{
|
||||||
|
44
I2CP.cpp
44
I2CP.cpp
@ -87,23 +87,51 @@ namespace client
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool I2CPDestination::SendMsg (std::shared_ptr<I2NPMessage> msg, std::shared_ptr<const i2p::data::LeaseSet> remote)
|
bool I2CPDestination::SendMsg (std::shared_ptr<I2NPMessage> msg, std::shared_ptr<const i2p::data::LeaseSet> remote)
|
||||||
{
|
{
|
||||||
auto outboundTunnel = GetTunnelPool ()->GetNextOutboundTunnel ();
|
auto remoteSession = GetRoutingSession (remote, true);
|
||||||
auto leases = remote->GetNonExpiredLeases ();
|
if (!remoteSession)
|
||||||
if (!leases.empty () && outboundTunnel)
|
{
|
||||||
|
LogPrint (eLogError, "I2CP: Failed to create remote session");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto path = remoteSession->GetSharedRoutingPath ();
|
||||||
|
std::shared_ptr<i2p::tunnel::OutboundTunnel> outboundTunnel;
|
||||||
|
std::shared_ptr<const i2p::data::Lease> remoteLease;
|
||||||
|
if (path)
|
||||||
|
{
|
||||||
|
if (!remoteSession->CleanupUnconfirmedTags ()) // no stuck tags
|
||||||
|
{
|
||||||
|
outboundTunnel = path->outboundTunnel;
|
||||||
|
remoteLease = path->remoteLease;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
remoteSession->SetSharedRoutingPath (nullptr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto outboundTunnel = GetTunnelPool ()->GetNextOutboundTunnel ();
|
||||||
|
auto leases = remote->GetNonExpiredLeases ();
|
||||||
|
if (!leases.empty ())
|
||||||
|
remoteLease = leases[rand () % leases.size ()];
|
||||||
|
if (remoteLease && outboundTunnel)
|
||||||
|
remoteSession->SetSharedRoutingPath (std::make_shared<i2p::garlic::GarlicRoutingPath> (
|
||||||
|
i2p::garlic::GarlicRoutingPath{outboundTunnel, remoteLease, 10000, 0, 0})); // 10 secs RTT
|
||||||
|
else
|
||||||
|
remoteSession->SetSharedRoutingPath (nullptr);
|
||||||
|
}
|
||||||
|
if (remoteLease && outboundTunnel)
|
||||||
{
|
{
|
||||||
std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
|
std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
|
||||||
uint32_t i = rand () % leases.size ();
|
auto garlic = remoteSession->WrapSingleMessage (msg);
|
||||||
auto garlic = WrapMessage (remote, msg, true);
|
|
||||||
msgs.push_back (i2p::tunnel::TunnelMessageBlock
|
msgs.push_back (i2p::tunnel::TunnelMessageBlock
|
||||||
{
|
{
|
||||||
i2p::tunnel::eDeliveryTypeTunnel,
|
i2p::tunnel::eDeliveryTypeTunnel,
|
||||||
leases[i]->tunnelGateway, leases[i]->tunnelID,
|
remoteLease->tunnelGateway, remoteLease->tunnelID,
|
||||||
garlic
|
garlic
|
||||||
});
|
});
|
||||||
outboundTunnel->SendTunnelDataMsg (msgs);
|
outboundTunnel->SendTunnelDataMsg (msgs);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (outboundTunnel)
|
if (outboundTunnel)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user