mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 02:44:15 +00:00
create SSU session in SSU thread
This commit is contained in:
parent
72785f6740
commit
fb2bdfb9ee
47
SSU.cpp
47
SSU.cpp
@ -284,34 +284,39 @@ namespace transport
|
|||||||
auto address = router->GetSSUAddress (!context.SupportsV6 ());
|
auto address = router->GetSSUAddress (!context.SupportsV6 ());
|
||||||
if (address)
|
if (address)
|
||||||
{
|
{
|
||||||
std::shared_ptr<SSUSession> session;
|
|
||||||
boost::asio::ip::udp::endpoint remoteEndpoint (address->host, address->port);
|
boost::asio::ip::udp::endpoint remoteEndpoint (address->host, address->port);
|
||||||
auto it = m_Sessions.find (remoteEndpoint);
|
auto& s = remoteEndpoint.address ().is_v6 () ? m_ServiceV6 : m_Service;
|
||||||
if (it != m_Sessions.end ())
|
s.post (std::bind (&SSUServer::CreateDirectSession, this, router, remoteEndpoint, peerTest));
|
||||||
{
|
|
||||||
session = it->second;
|
|
||||||
if (peerTest && session->GetState () == eSessionStateEstablished)
|
|
||||||
session->SendPeerTest ();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// otherwise create new session
|
|
||||||
session = std::make_shared<SSUSession> (*this, remoteEndpoint, router, peerTest);
|
|
||||||
{
|
|
||||||
std::unique_lock<std::mutex> l(m_SessionsMutex);
|
|
||||||
m_Sessions[remoteEndpoint] = session;
|
|
||||||
}
|
|
||||||
// connect
|
|
||||||
LogPrint ("Creating new SSU session to [", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), "] ",
|
|
||||||
remoteEndpoint.address ().to_string (), ":", remoteEndpoint.port ());
|
|
||||||
session->Connect ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 ())
|
||||||
|
{
|
||||||
|
auto session = it->second;
|
||||||
|
if (peerTest && session->GetState () == eSessionStateEstablished)
|
||||||
|
session->SendPeerTest ();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// otherwise create new session
|
||||||
|
auto session = std::make_shared<SSUSession> (*this, remoteEndpoint, router, peerTest);
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> l(m_SessionsMutex);
|
||||||
|
m_Sessions[remoteEndpoint] = session;
|
||||||
|
}
|
||||||
|
// connect
|
||||||
|
LogPrint ("Creating new SSU session to [", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), "] ",
|
||||||
|
remoteEndpoint.address ().to_string (), ":", remoteEndpoint.port ());
|
||||||
|
session->Connect ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SSUServer::CreateSessionThroughIntroducer (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest)
|
void SSUServer::CreateSessionThroughIntroducer (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest)
|
||||||
{
|
{
|
||||||
if (router && router->UsesIntroducer ())
|
if (router && router->UsesIntroducer ())
|
||||||
|
3
SSU.h
3
SSU.h
@ -41,7 +41,6 @@ namespace transport
|
|||||||
void Start ();
|
void Start ();
|
||||||
void Stop ();
|
void Stop ();
|
||||||
void CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest = false);
|
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 (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);
|
||||||
@ -72,6 +71,8 @@ namespace transport
|
|||||||
void HandleReceivedFromV6 (const boost::system::error_code& ecode, std::size_t bytes_transferred, SSUPacket * packet);
|
void HandleReceivedFromV6 (const boost::system::error_code& ecode, std::size_t bytes_transferred, SSUPacket * packet);
|
||||||
void HandleReceivedPackets (std::vector<SSUPacket *> packets);
|
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>
|
template<typename Filter>
|
||||||
std::shared_ptr<SSUSession> GetRandomSession (Filter filter);
|
std::shared_ptr<SSUSession> GetRandomSession (Filter filter);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user