Browse Source

handle ipv6 sessions in separate thread

pull/113/head
orignal 10 years ago
parent
commit
e6c92a535d
  1. 37
      SSU.cpp
  2. 7
      SSU.h

37
SSU.cpp

@ -9,9 +9,10 @@ namespace i2p
{ {
namespace transport namespace transport
{ {
SSUServer::SSUServer (int port): m_Thread (nullptr), m_Work (m_Service), SSUServer::SSUServer (int port): m_Thread (nullptr), m_ThreadV6 (nullptr), m_Work (m_Service),
m_Endpoint (boost::asio::ip::udp::v4 (), port), m_EndpointV6 (boost::asio::ip::udp::v6 (), port), m_WorkV6 (m_ServiceV6),m_Endpoint (boost::asio::ip::udp::v4 (), port),
m_Socket (m_Service, m_Endpoint), m_SocketV6 (m_Service), m_IntroducersUpdateTimer (m_Service) m_EndpointV6 (boost::asio::ip::udp::v6 (), port), m_Socket (m_Service, m_Endpoint),
m_SocketV6 (m_ServiceV6), m_IntroducersUpdateTimer (m_Service)
{ {
m_Socket.set_option (boost::asio::socket_base::receive_buffer_size (65535)); m_Socket.set_option (boost::asio::socket_base::receive_buffer_size (65535));
m_Socket.set_option (boost::asio::socket_base::send_buffer_size (65535)); m_Socket.set_option (boost::asio::socket_base::send_buffer_size (65535));
@ -35,7 +36,10 @@ namespace transport
m_Thread = new std::thread (std::bind (&SSUServer::Run, this)); m_Thread = new std::thread (std::bind (&SSUServer::Run, this));
m_Service.post (std::bind (&SSUServer::Receive, this)); m_Service.post (std::bind (&SSUServer::Receive, this));
if (context.SupportsV6 ()) if (context.SupportsV6 ())
m_Service.post (std::bind (&SSUServer::ReceiveV6, this)); {
m_ThreadV6 = new std::thread (std::bind (&SSUServer::RunV6, this));
m_ServiceV6.post (std::bind (&SSUServer::ReceiveV6, this));
}
if (i2p::context.IsUnreachable ()) if (i2p::context.IsUnreachable ())
ScheduleIntroducersUpdateTimer (); ScheduleIntroducersUpdateTimer ();
} }
@ -46,11 +50,19 @@ namespace transport
m_IsRunning = false; m_IsRunning = false;
m_Service.stop (); m_Service.stop ();
m_Socket.close (); m_Socket.close ();
m_ServiceV6.stop ();
m_SocketV6.close ();
if (m_Thread) if (m_Thread)
{ {
m_Thread->join (); m_Thread->join ();
delete m_Thread; delete m_Thread;
m_Thread = 0; m_Thread = nullptr;
}
if (m_ThreadV6)
{
m_ThreadV6->join ();
delete m_ThreadV6;
m_ThreadV6 = nullptr;
} }
} }
@ -69,6 +81,21 @@ namespace transport
} }
} }
void SSUServer::RunV6 ()
{
while (m_IsRunning)
{
try
{
m_ServiceV6.run ();
}
catch (std::exception& ex)
{
LogPrint (eLogError, "SSU V6 server: ", ex.what ());
}
}
}
void SSUServer::AddRelay (uint32_t tag, const boost::asio::ip::udp::endpoint& relay) void SSUServer::AddRelay (uint32_t tag, const boost::asio::ip::udp::endpoint& relay)
{ {
m_Relays[tag] = relay; m_Relays[tag] = relay;

7
SSU.h

@ -47,6 +47,7 @@ namespace transport
private: private:
void Run (); void Run ();
void RunV6 ();
void Receive (); void Receive ();
void ReceiveV6 (); void ReceiveV6 ();
void HandleReceivedFrom (const boost::system::error_code& ecode, std::size_t bytes_transferred); void HandleReceivedFrom (const boost::system::error_code& ecode, std::size_t bytes_transferred);
@ -63,9 +64,9 @@ namespace transport
private: private:
bool m_IsRunning; bool m_IsRunning;
std::thread * m_Thread; std::thread * m_Thread, * m_ThreadV6;
boost::asio::io_service m_Service; boost::asio::io_service m_Service, m_ServiceV6;
boost::asio::io_service::work m_Work; boost::asio::io_service::work m_Work, m_WorkV6;
boost::asio::ip::udp::endpoint m_Endpoint, m_EndpointV6; boost::asio::ip::udp::endpoint m_Endpoint, m_EndpointV6;
boost::asio::ip::udp::socket m_Socket, m_SocketV6; boost::asio::ip::udp::socket m_Socket, m_SocketV6;
boost::asio::ip::udp::endpoint m_SenderEndpoint, m_SenderEndpointV6; boost::asio::ip::udp::endpoint m_SenderEndpoint, m_SenderEndpointV6;

Loading…
Cancel
Save