Browse Source

replace GetSession to CreateSession

pull/304/head
orignal 9 years ago
parent
commit
e194854c6d
  1. 6
      SSU.cpp
  2. 2
      SSU.h
  3. 15
      Transports.cpp

6
SSU.cpp

@ -272,7 +272,7 @@ namespace transport
return nullptr; return nullptr;
} }
std::shared_ptr<SSUSession> SSUServer::GetSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest) void SSUServer::CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest)
{ {
std::shared_ptr<SSUSession> session; std::shared_ptr<SSUSession> session;
if (router) if (router)
@ -350,7 +350,6 @@ namespace transport
LogPrint (eLogWarning, "Can't connect to unreachable router. No introducers presented"); LogPrint (eLogWarning, "Can't connect to unreachable router. No introducers presented");
std::unique_lock<std::mutex> l(m_SessionsMutex); std::unique_lock<std::mutex> l(m_SessionsMutex);
m_Sessions.erase (remoteEndpoint); m_Sessions.erase (remoteEndpoint);
session.reset ();
} }
} }
} }
@ -358,7 +357,6 @@ namespace transport
else else
LogPrint (eLogWarning, "Router ", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), " doesn't have SSU address"); LogPrint (eLogWarning, "Router ", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), " doesn't have SSU address");
} }
return session;
} }
void SSUServer::DeleteSession (std::shared_ptr<SSUSession> session) void SSUServer::DeleteSession (std::shared_ptr<SSUSession> session)
@ -491,7 +489,7 @@ namespace transport
{ {
auto introducer = i2p::data::netdb.GetRandomIntroducer (); auto introducer = i2p::data::netdb.GetRandomIntroducer ();
if (introducer) if (introducer)
GetSession (introducer); CreateSession (introducer);
} }
ScheduleIntroducersUpdateTimer (); ScheduleIntroducersUpdateTimer ();
} }

2
SSU.h

@ -40,7 +40,7 @@ namespace transport
~SSUServer (); ~SSUServer ();
void Start (); void Start ();
void Stop (); void Stop ();
std::shared_ptr<SSUSession> GetSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest = false); void CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest = false);
std::shared_ptr<SSUSession> FindSession (std::shared_ptr<const i2p::data::RouterInfo> router) const; std::shared_ptr<SSUSession> FindSession (std::shared_ptr<const i2p::data::RouterInfo> router) const;
std::shared_ptr<SSUSession> FindSession (const boost::asio::ip::udp::endpoint& e) const; std::shared_ptr<SSUSession> FindSession (const boost::asio::ip::udp::endpoint& e) const;
std::shared_ptr<SSUSession> GetRandomEstablishedSession (std::shared_ptr<const SSUSession> excluded); std::shared_ptr<SSUSession> GetRandomEstablishedSession (std::shared_ptr<const SSUSession> excluded);

15
Transports.cpp

@ -290,8 +290,11 @@ namespace transport
peer.numAttempts++; peer.numAttempts++;
if (m_SSUServer) if (m_SSUServer)
{ {
if (m_SSUServer->GetSession (peer.router)) if (peer.router->IsSSU (!context.SupportsV6 ()))
{
m_SSUServer->CreateSession (peer.router);
return true; return true;
}
} }
} }
LogPrint (eLogError, "No NTCP and SSU addresses available"); LogPrint (eLogError, "No NTCP and SSU addresses available");
@ -389,14 +392,14 @@ namespace transport
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
auto router = i2p::data::netdb.GetRandomPeerTestRouter (); auto router = i2p::data::netdb.GetRandomPeerTestRouter ();
if (router && router->IsSSU ()) if (router && router->IsSSU (!context.SupportsV6 ()))
m_SSUServer->GetSession (router, true); // peer test m_SSUServer->CreateSession (router, true); // peer test
else else
{ {
// if not peer test capable routers found pick any // if not peer test capable routers found pick any
router = i2p::data::netdb.GetRandomRouter (); router = i2p::data::netdb.GetRandomRouter ();
if (router && router->IsSSU ()) if (router && router->IsSSU ())
m_SSUServer->GetSession (router); // no peer test m_SSUServer->CreateSession (router); // no peer test
} }
} }
} }
@ -412,14 +415,14 @@ namespace transport
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
auto router = i2p::data::netdb.GetRandomPeerTestRouter (); auto router = i2p::data::netdb.GetRandomPeerTestRouter ();
if (router && router->IsSSU ()) if (router && router->IsSSU (!context.SupportsV6 ()))
{ {
if (!statusChanged) if (!statusChanged)
{ {
statusChanged = true; statusChanged = true;
i2p::context.SetStatus (eRouterStatusTesting); // first time only i2p::context.SetStatus (eRouterStatusTesting); // first time only
} }
m_SSUServer->GetSession (router, true); // peer test m_SSUServer->CreateSession (router, true); // peer test
} }
} }
} }

Loading…
Cancel
Save