Browse Source

create SSU session in SSU thread

pull/306/head
orignal 9 years ago
parent
commit
fb2bdfb9ee
  1. 19
      SSU.cpp
  2. 3
      SSU.h

19
SSU.cpp

@ -284,19 +284,28 @@ namespace transport @@ -284,19 +284,28 @@ namespace transport
auto address = router->GetSSUAddress (!context.SupportsV6 ());
if (address)
{
std::shared_ptr<SSUSession> session;
boost::asio::ip::udp::endpoint remoteEndpoint (address->host, address->port);
auto& s = remoteEndpoint.address ().is_v6 () ? m_ServiceV6 : m_Service;
s.post (std::bind (&SSUServer::CreateDirectSession, this, router, remoteEndpoint, peerTest));
}
else
LogPrint (eLogWarning, "Router ", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), " doesn't have SSU address");
}
}
void SSUServer::CreateDirectSession (std::shared_ptr<const i2p::data::RouterInfo> router, boost::asio::ip::udp::endpoint remoteEndpoint, bool peerTest)
{
auto it = m_Sessions.find (remoteEndpoint);
if (it != m_Sessions.end ())
{
session = it->second;
auto session = it->second;
if (peerTest && session->GetState () == eSessionStateEstablished)
session->SendPeerTest ();
}
else
{
// otherwise create new session
session = std::make_shared<SSUSession> (*this, remoteEndpoint, router, peerTest);
auto session = std::make_shared<SSUSession> (*this, remoteEndpoint, router, peerTest);
{
std::unique_lock<std::mutex> l(m_SessionsMutex);
m_Sessions[remoteEndpoint] = session;
@ -307,10 +316,6 @@ namespace transport @@ -307,10 +316,6 @@ namespace transport
session->Connect ();
}
}
else
LogPrint (eLogWarning, "Router ", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), " doesn't have SSU address");
}
}
void SSUServer::CreateSessionThroughIntroducer (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest)
{

3
SSU.h

@ -41,7 +41,6 @@ namespace transport @@ -41,7 +41,6 @@ namespace transport
void Start ();
void Stop ();
void CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest = false);
void CreateSessionThroughIntroducer (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);
@ -72,6 +71,8 @@ namespace transport @@ -72,6 +71,8 @@ namespace transport
void HandleReceivedFromV6 (const boost::system::error_code& ecode, std::size_t bytes_transferred, SSUPacket * packet);
void HandleReceivedPackets (std::vector<SSUPacket *> packets);
void CreateSessionThroughIntroducer (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest = false);
void CreateDirectSession (std::shared_ptr<const i2p::data::RouterInfo> router, boost::asio::ip::udp::endpoint remoteEndpoint, bool peerTest);
template<typename Filter>
std::shared_ptr<SSUSession> GetRandomSession (Filter filter);

Loading…
Cancel
Save