Browse Source

resolve address for NTCP

pull/150/head
orignal 10 years ago
parent
commit
bf7b53a2a6
  1. 12
      RouterInfo.cpp
  2. 5
      RouterInfo.h
  3. 4
      Transports.cpp
  4. 2
      Transports.h

12
RouterInfo.cpp

@ -150,10 +150,18 @@ namespace data
address.host = boost::asio::ip::address::from_string (value, ecode); address.host = boost::asio::ip::address::from_string (value, ecode);
if (ecode) if (ecode)
{ {
// TODO: we should try to resolve address here if (address.transportStyle == eTransportNTCP)
LogPrint (eLogWarning, "Unexpected address ", value); {
m_SupportedTransports |= eNTCPV4; // TODO:
address.addressString = value;
}
else
{
// TODO: resolve address for SSU
LogPrint (eLogWarning, "Unexpected SSU address ", value);
isValidAddress = false; isValidAddress = false;
} }
}
else else
{ {
// add supported protocol // add supported protocol

5
RouterInfo.h

@ -69,7 +69,7 @@ namespace data
{ {
TransportStyle transportStyle; TransportStyle transportStyle;
boost::asio::ip::address host; boost::asio::ip::address host;
char * addressString; std::string addressString;
int port, mtu; int port, mtu;
uint64_t date; uint64_t date;
uint8_t cost; uint8_t cost;
@ -77,9 +77,6 @@ namespace data
Tag<32> key; // intro key for SSU Tag<32> key; // intro key for SSU
std::vector<Introducer> introducers; std::vector<Introducer> introducers;
Address (): addressString (nullptr) {};
~Address () { if (addressString) delete[] addressString; };
bool IsCompatible (const boost::asio::ip::address& other) const bool IsCompatible (const boost::asio::ip::address& other) const
{ {
return (host.is_v4 () && other.is_v4 ()) || return (host.is_v4 () && other.is_v4 ()) ||

4
Transports.cpp

@ -232,7 +232,7 @@ namespace transport
} }
else // we don't have address else // we don't have address
{ {
if (address->addressString) // trying to resolve if (address->addressString.length () > 0) // trying to resolve
{ {
LogPrint (eLogInfo, "Resolving ", address->addressString); LogPrint (eLogInfo, "Resolving ", address->addressString);
NTCPResolve (address->addressString, ident); NTCPResolve (address->addressString, ident);
@ -287,7 +287,7 @@ namespace transport
} }
} }
void Transports::NTCPResolve (const char * addr, const i2p::data::IdentHash& ident) void Transports::NTCPResolve (const std::string& addr, const i2p::data::IdentHash& ident)
{ {
auto resolver = std::make_shared<boost::asio::ip::tcp::resolver>(m_Service); auto resolver = std::make_shared<boost::asio::ip::tcp::resolver>(m_Service);
resolver->async_resolve (boost::asio::ip::tcp::resolver::query (addr), resolver->async_resolve (boost::asio::ip::tcp::resolver::query (addr),

2
Transports.h

@ -94,7 +94,7 @@ namespace transport
void PostCloseSession (std::shared_ptr<const i2p::data::RouterInfo> router); void PostCloseSession (std::shared_ptr<const i2p::data::RouterInfo> router);
bool ConnectToPeer (const i2p::data::IdentHash& ident, Peer& peer); bool ConnectToPeer (const i2p::data::IdentHash& ident, Peer& peer);
void NTCPResolve (const char * 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,
const i2p::data::IdentHash& ident, std::shared_ptr<boost::asio::ip::tcp::resolver> resolver); const i2p::data::IdentHash& ident, std::shared_ptr<boost::asio::ip::tcp::resolver> resolver);

Loading…
Cancel
Save