Browse Source

check if we can send HolePunch to partcular address

pull/1769/head
orignal 2 years ago
parent
commit
dda25d431c
  1. 15
      libi2pd/SSU2.cpp
  2. 1
      libi2pd/SSU2.h
  3. 7
      libi2pd/SSU2Session.cpp
  4. 1
      libi2pd/SSU2Session.h

15
libi2pd/SSU2.cpp

@ -108,6 +108,21 @@ namespace transport
else if (localAddress.is_v6 ()) else if (localAddress.is_v6 ())
m_AddressV6 = localAddress; m_AddressV6 = localAddress;
} }
bool SSU2Server::IsSupported (const boost::asio::ip::address& addr) const
{
if (addr.is_v4 ())
{
if (m_SocketV4.is_open ())
return true;
}
else if (addr.is_v6 ())
{
if (m_SocketV6.is_open ())
return true;
}
return false;
}
boost::asio::ip::udp::socket& SSU2Server::OpenSocket (const boost::asio::ip::udp::endpoint& localEndpoint) boost::asio::ip::udp::socket& SSU2Server::OpenSocket (const boost::asio::ip::udp::endpoint& localEndpoint)
{ {

1
libi2pd/SSU2.h

@ -49,6 +49,7 @@ namespace transport
void Stop (); void Stop ();
boost::asio::io_service& GetService () { return GetIOService (); }; boost::asio::io_service& GetService () { return GetIOService (); };
void SetLocalAddress (const boost::asio::ip::address& localAddress); void SetLocalAddress (const boost::asio::ip::address& localAddress);
bool IsSupported (const boost::asio::ip::address& addr) const;
void AddSession (std::shared_ptr<SSU2Session> session); void AddSession (std::shared_ptr<SSU2Session> session);
void RemoveSession (uint64_t connID); void RemoveSession (uint64_t connID);

7
libi2pd/SSU2Session.cpp

@ -1344,7 +1344,12 @@ namespace transport
{ {
auto addr = ep.address ().is_v6 () ? r->GetSSU2V6Address () : r->GetSSU2V4Address (); auto addr = ep.address ().is_v6 () ? r->GetSSU2V6Address () : r->GetSSU2V4Address ();
if (addr) if (addr)
SendHolePunch (bufbe32toh (buf + 33), ep, addr->i); {
if (m_Server.IsSupported (ep.address ()))
SendHolePunch (bufbe32toh (buf + 33), ep, addr->i);
else
code = eSSU2RelayResponseCodeCharlieUnsupportedAddress;
}
else else
{ {
LogPrint (eLogWarning, "SSU2: RelayInfo unknown address"); LogPrint (eLogWarning, "SSU2: RelayInfo unknown address");

1
libi2pd/SSU2Session.h

@ -108,6 +108,7 @@ namespace transport
{ {
eSSU2RelayResponseCodeAccept = 0, eSSU2RelayResponseCodeAccept = 0,
eSSU2RelayResponseCodeBobRelayTagNotFound = 5, eSSU2RelayResponseCodeBobRelayTagNotFound = 5,
eSSU2RelayResponseCodeCharlieUnsupportedAddress = 65,
eSSU2RelayResponseCodeCharlieSignatureFailure = 67, eSSU2RelayResponseCodeCharlieSignatureFailure = 67,
eSSU2RelayResponseCodeCharlieAliceIsUnknown = 70 eSSU2RelayResponseCodeCharlieAliceIsUnknown = 70
}; };

Loading…
Cancel
Save