Browse Source

bind SSU2 socket to specified interface

pull/1769/head
orignal 3 years ago
parent
commit
2cc106b43e
  1. 14
      libi2pd/SSU2.cpp
  2. 4
      libi2pd/SSU2.h
  3. 2
      libi2pd/Transports.cpp

14
libi2pd/SSU2.cpp

@ -20,6 +20,7 @@ namespace transport @@ -20,6 +20,7 @@ namespace transport
SSU2Server::SSU2Server ():
RunnableServiceWithWork ("SSU2"), m_ReceiveService ("SSU2r"),
m_SocketV4 (m_ReceiveService.GetService ()), m_SocketV6 (m_ReceiveService.GetService ()),
m_AddressV4 (boost::asio::ip::address_v4()), m_AddressV6 (boost::asio::ip::address_v6()),
m_TerminationTimer (GetService ()), m_ResendTimer (GetService ())
{
}
@ -52,7 +53,7 @@ namespace transport @@ -52,7 +53,7 @@ namespace transport
if (address->IsV4 ())
{
found = true;
OpenSocket (boost::asio::ip::udp::endpoint (boost::asio::ip::udp::v4(), port));
OpenSocket (boost::asio::ip::udp::endpoint (m_AddressV4, port));
m_ReceiveService.GetService ().post(
[this]()
{
@ -62,7 +63,7 @@ namespace transport @@ -62,7 +63,7 @@ namespace transport
if (address->IsV6 ())
{
found = true;
OpenSocket (boost::asio::ip::udp::endpoint (boost::asio::ip::udp::v6(), port));
OpenSocket (boost::asio::ip::udp::endpoint (m_AddressV6, port));
m_ReceiveService.GetService ().post(
[this]()
{
@ -99,6 +100,15 @@ namespace transport @@ -99,6 +100,15 @@ namespace transport
StopIOService ();
}
void SSU2Server::SetLocalAddress (const boost::asio::ip::address& localAddress)
{
if (localAddress.is_unspecified ()) return;
if (localAddress.is_v4 ())
m_AddressV4 = localAddress;
else if (localAddress.is_v6 ())
m_AddressV6 = localAddress;
}
boost::asio::ip::udp::socket& SSU2Server::OpenSocket (const boost::asio::ip::udp::endpoint& localEndpoint)
{
boost::asio::ip::udp::socket& socket = localEndpoint.address ().is_v6 () ? m_SocketV6 : m_SocketV4;

4
libi2pd/SSU2.h

@ -48,7 +48,8 @@ namespace transport @@ -48,7 +48,8 @@ namespace transport
void Start ();
void Stop ();
boost::asio::io_service& GetService () { return GetIOService (); };
void SetLocalAddress (const boost::asio::ip::address& localAddress);
void AddSession (std::shared_ptr<SSU2Session> session);
void RemoveSession (uint64_t connID);
void AddSessionByRouterHash (std::shared_ptr<SSU2Session> session);
@ -97,6 +98,7 @@ namespace transport @@ -97,6 +98,7 @@ namespace transport
ReceiveService m_ReceiveService;
boost::asio::ip::udp::socket m_SocketV4, m_SocketV6;
boost::asio::ip::address m_AddressV4, m_AddressV6;
std::unordered_map<uint64_t, std::shared_ptr<SSU2Session> > m_Sessions;
std::map<i2p::data::IdentHash, std::shared_ptr<SSU2Session> > m_SessionsByRouterHash;
std::map<boost::asio::ip::udp::endpoint, std::shared_ptr<SSU2Session> > m_PendingOutgoingSessions;

2
libi2pd/Transports.cpp

@ -233,6 +233,7 @@ namespace transport @@ -233,6 +233,7 @@ namespace transport
{
if (m_NTCP2Server) m_NTCP2Server->SetLocalAddress (addr);
if (m_SSUServer) m_SSUServer->SetLocalAddress (addr);
if (m_SSU2Server) m_SSU2Server->SetLocalAddress (addr);
}
}
}
@ -249,6 +250,7 @@ namespace transport @@ -249,6 +250,7 @@ namespace transport
{
if (m_NTCP2Server) m_NTCP2Server->SetLocalAddress (addr);
if (m_SSUServer) m_SSUServer->SetLocalAddress (addr);
if (m_SSU2Server) m_SSU2Server->SetLocalAddress (addr);
}
}
}

Loading…
Cancel
Save