Skip to content

Commit

Permalink
replace GetSession to CreateSession
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Nov 25, 2015
1 parent d01d033 commit e194854
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 2 additions & 4 deletions SSU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ namespace transport
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;
if (router)
Expand Down Expand Up @@ -350,15 +350,13 @@ namespace transport
LogPrint (eLogWarning, "Can't connect to unreachable router. No introducers presented");
std::unique_lock<std::mutex> l(m_SessionsMutex);
m_Sessions.erase (remoteEndpoint);
session.reset ();
}
}
}
}
else
LogPrint (eLogWarning, "Router ", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), " doesn't have SSU address");
}
return session;
}

void SSUServer::DeleteSession (std::shared_ptr<SSUSession> session)
Expand Down Expand Up @@ -491,7 +489,7 @@ namespace transport
{
auto introducer = i2p::data::netdb.GetRandomIntroducer ();
if (introducer)
GetSession (introducer);
CreateSession (introducer);
}
ScheduleIntroducersUpdateTimer ();
}
Expand Down
2 changes: 1 addition & 1 deletion SSU.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace transport
~SSUServer ();
void Start ();
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 (const boost::asio::ip::udp::endpoint& e) const;
std::shared_ptr<SSUSession> GetRandomEstablishedSession (std::shared_ptr<const SSUSession> excluded);
Expand Down
15 changes: 9 additions & 6 deletions Transports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,11 @@ namespace transport
peer.numAttempts++;
if (m_SSUServer)
{
if (m_SSUServer->GetSession (peer.router))
if (peer.router->IsSSU (!context.SupportsV6 ()))
{
m_SSUServer->CreateSession (peer.router);
return true;
}
}
}
LogPrint (eLogError, "No NTCP and SSU addresses available");
Expand Down Expand Up @@ -389,14 +392,14 @@ namespace transport
for (int i = 0; i < 5; i++)
{
auto router = i2p::data::netdb.GetRandomPeerTestRouter ();
if (router && router->IsSSU ())
m_SSUServer->GetSession (router, true); // peer test
if (router && router->IsSSU (!context.SupportsV6 ()))
m_SSUServer->CreateSession (router, true); // peer test
else
{
// if not peer test capable routers found pick any
router = i2p::data::netdb.GetRandomRouter ();
if (router && router->IsSSU ())
m_SSUServer->GetSession (router); // no peer test
m_SSUServer->CreateSession (router); // no peer test
}
}
}
Expand All @@ -412,14 +415,14 @@ namespace transport
for (int i = 0; i < 5; i++)
{
auto router = i2p::data::netdb.GetRandomPeerTestRouter ();
if (router && router->IsSSU ())
if (router && router->IsSSU (!context.SupportsV6 ()))
{
if (!statusChanged)
{
statusChanged = true;
i2p::context.SetStatus (eRouterStatusTesting); // first time only
}
m_SSUServer->GetSession (router, true); // peer test
m_SSUServer->CreateSession (router, true); // peer test
}
}
}
Expand Down

0 comments on commit e194854

Please sign in to comment.