Browse Source

allow DNS names for SSU

pull/307/head
orignal 9 years ago
parent
commit
bf47df46c9
  1. 5
      RouterInfo.cpp
  2. 42
      Transports.cpp
  3. 3
      Transports.h

5
RouterInfo.cpp

@ -171,9 +171,8 @@ namespace data
} }
else else
{ {
// TODO: resolve address for SSU m_SupportedTransports |= eSSUV4; // TODO:
LogPrint (eLogWarning, "Unexpected SSU address ", value); address.addressString = value;
isValidAddress = false;
} }
} }
else else

42
Transports.cpp

@ -278,7 +278,7 @@ namespace transport
{ {
if (address->addressString.length () > 0) // trying to resolve if (address->addressString.length () > 0) // trying to resolve
{ {
LogPrint (eLogInfo, "Resolving ", address->addressString); LogPrint (eLogInfo, "Resolving NTCP ", address->addressString);
NTCPResolve (address->addressString, ident); NTCPResolve (address->addressString, ident);
return true; return true;
} }
@ -304,6 +304,15 @@ namespace transport
m_SSUServer->CreateSession (peer.router, address->host, address->port); m_SSUServer->CreateSession (peer.router, address->host, address->port);
return true; return true;
} }
else // we don't have address
{
if (address->addressString.length () > 0) // trying to resolve
{
LogPrint (eLogInfo, "Resolving SSU ", address->addressString);
SSUResolve (address->addressString, ident);
return true;
}
}
} }
} }
LogPrint (eLogError, "No NTCP and SSU addresses available"); LogPrint (eLogError, "No NTCP and SSU addresses available");
@ -376,6 +385,37 @@ namespace transport
} }
} }
void Transports::SSUResolve (const std::string& addr, const i2p::data::IdentHash& ident)
{
auto resolver = std::make_shared<boost::asio::ip::tcp::resolver>(m_Service);
resolver->async_resolve (boost::asio::ip::tcp::resolver::query (addr, ""),
std::bind (&Transports::HandleSSUResolve, this,
std::placeholders::_1, std::placeholders::_2, ident, resolver));
}
void Transports::HandleSSUResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it,
i2p::data::IdentHash ident, std::shared_ptr<boost::asio::ip::tcp::resolver> resolver)
{
auto it1 = m_Peers.find (ident);
if (it1 != m_Peers.end ())
{
auto& peer = it1->second;
if (!ecode && peer.router)
{
auto address = (*it).endpoint ().address ();
LogPrint (eLogInfo, (*it).host_name (), " has been resolved to ", address);
auto addr = peer.router->GetSSUAddress (!context.SupportsV6 ());;
if (addr)
{
m_SSUServer->CreateSession (peer.router, address, addr->port);
return;
}
}
LogPrint (eLogError, "Unable to resolve SSU address: ", ecode.message ());
m_Peers.erase (it1);
}
}
void Transports::CloseSession (std::shared_ptr<const i2p::data::RouterInfo> router) void Transports::CloseSession (std::shared_ptr<const i2p::data::RouterInfo> router)
{ {
if (!router) return; if (!router) return;

3
Transports.h

@ -114,6 +114,9 @@ namespace transport
void NTCPResolve (const std::string& addr, const i2p::data::IdentHash& ident); void NTCPResolve (const std::string& addr, const i2p::data::IdentHash& ident);
void HandleNTCPResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it, void HandleNTCPResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it,
i2p::data::IdentHash ident, std::shared_ptr<boost::asio::ip::tcp::resolver> resolver); i2p::data::IdentHash ident, std::shared_ptr<boost::asio::ip::tcp::resolver> resolver);
void SSUResolve (const std::string& addr, const i2p::data::IdentHash& ident);
void HandleSSUResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it,
i2p::data::IdentHash ident, std::shared_ptr<boost::asio::ip::tcp::resolver> resolver);
void UpdateBandwidth (); void UpdateBandwidth ();
void DetectExternalIP (); void DetectExternalIP ();

Loading…
Cancel
Save