Browse Source

update datagram session logic

pull/628/head
Jeff Becker 8 years ago
parent
commit
7cc805b203
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
  1. 25
      Datagram.cpp

25
Datagram.cpp

@ -146,7 +146,6 @@ namespace datagram
LogPrint(eLogInfo, "DatagramDestination: expiring idle session with ", ident.ToBase32()); LogPrint(eLogInfo, "DatagramDestination: expiring idle session with ", ident.ToBase32());
m_Sessions.erase(ident); m_Sessions.erase(ident);
} }
m_Owner->CleanupExpiredTags();
ScheduleCleanup(); ScheduleCleanup();
} }
@ -174,7 +173,7 @@ namespace datagram
} }
return nullptr; return nullptr;
} }
DatagramSession::DatagramSession(i2p::client::ClientDestination * localDestination, DatagramSession::DatagramSession(i2p::client::ClientDestination * localDestination,
const i2p::data::IdentHash & remoteIdent) : const i2p::data::IdentHash & remoteIdent) :
m_LocalDestination(localDestination), m_LocalDestination(localDestination),
@ -215,9 +214,14 @@ namespace datagram
else else
return DatagramSession::Info{nullptr, nullptr, m_LastUse, m_LastSuccess}; return DatagramSession::Info{nullptr, nullptr, m_LastUse, m_LastSuccess};
} }
void DatagramSession::HandleSend(std::shared_ptr<I2NPMessage> msg) void DatagramSession::HandleSend(std::shared_ptr<I2NPMessage> msg)
{ {
if(!m_RoutingSession)
{
// try to get one
if(m_RemoteLeaseSet) m_RoutingSession = m_LocalDestination->GetRoutingSession(m_RemoteLeaseSet, true);
}
// do we have a routing session? // do we have a routing session?
if(m_RoutingSession) if(m_RoutingSession)
{ {
@ -226,7 +230,11 @@ namespace datagram
{ {
LogPrint(eLogDebug, "DatagramSession: try getting new routing path"); LogPrint(eLogDebug, "DatagramSession: try getting new routing path");
// try switching paths // try switching paths
UpdateRoutingPath (GetNextRoutingPath ()); auto path = GetNextRoutingPath();
if(path)
UpdateRoutingPath (path);
else
ResetRoutingPath();
} }
auto routingPath = m_RoutingSession->GetSharedRoutingPath (); auto routingPath = m_RoutingSession->GetSharedRoutingPath ();
// make sure we have a routing path // make sure we have a routing path
@ -282,7 +290,6 @@ namespace datagram
bool DatagramSession::ShouldSwitchLease() const bool DatagramSession::ShouldSwitchLease() const
{ {
auto now = i2p::util::GetMillisecondsSinceEpoch ();
std::shared_ptr<i2p::garlic::GarlicRoutingPath> routingPath = nullptr; std::shared_ptr<i2p::garlic::GarlicRoutingPath> routingPath = nullptr;
std::shared_ptr<const i2p::data::Lease> currentLease = nullptr; std::shared_ptr<const i2p::data::Lease> currentLease = nullptr;
if(m_RoutingSession) if(m_RoutingSession)
@ -290,7 +297,7 @@ namespace datagram
if(routingPath) if(routingPath)
currentLease = routingPath->remoteLease; currentLease = routingPath->remoteLease;
if(currentLease) // if we have a lease return true if it's about to expire otherwise return false if(currentLease) // if we have a lease return true if it's about to expire otherwise return false
return now - currentLease->ExpiresWithin( DATAGRAM_SESSION_LEASE_HANDOVER_WINDOW, DATAGRAM_SESSION_LEASE_HANDOVER_FUDGE ); return currentLease->ExpiresWithin( DATAGRAM_SESSION_LEASE_HANDOVER_WINDOW, DATAGRAM_SESSION_LEASE_HANDOVER_FUDGE );
// we have no current lease, we should switch // we have no current lease, we should switch
return true; return true;
} }
@ -418,7 +425,11 @@ namespace datagram
m_InvalidIBGW.clear(); m_InvalidIBGW.clear();
m_RemoteLeaseSet = remoteIdent; m_RemoteLeaseSet = remoteIdent;
// update routing path // update routing path
UpdateRoutingPath(GetNextRoutingPath()); auto path = GetNextRoutingPath();
if (path)
UpdateRoutingPath(path);
else
ResetRoutingPath();
// send the message that was queued if it was provided // send the message that was queued if it was provided
if(msg) if(msg)
HandleSend(msg); HandleSend(msg);

Loading…
Cancel
Save