check if we can send HolePunch to partcular address

This commit is contained in:
orignal 2022-06-21 16:20:39 -04:00
parent 22f9abc2f1
commit dda25d431c
4 changed files with 23 additions and 1 deletions

View file

@ -109,6 +109,21 @@ namespace transport
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& socket = localEndpoint.address ().is_v6 () ? m_SocketV6 : m_SocketV4;

View file

@ -49,6 +49,7 @@ namespace transport
void Stop ();
boost::asio::io_service& GetService () { return GetIOService (); };
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 RemoveSession (uint64_t connID);

View file

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

View file

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