|
|
@ -101,7 +101,16 @@ namespace data |
|
|
|
r += ReadString (value, s); |
|
|
|
r += ReadString (value, s); |
|
|
|
s.seekg (1, std::ios_base::cur); r++; // ;
|
|
|
|
s.seekg (1, std::ios_base::cur); r++; // ;
|
|
|
|
if (!strcmp (key, "host")) |
|
|
|
if (!strcmp (key, "host")) |
|
|
|
address.host = value; |
|
|
|
{ |
|
|
|
|
|
|
|
boost::system::error_code ecode; |
|
|
|
|
|
|
|
address.host = boost::asio::ip::address::from_string (value, ecode); |
|
|
|
|
|
|
|
if (ecode) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// TODO: we should try to resolve address here
|
|
|
|
|
|
|
|
LogPrint ("Unexpected address ", value); |
|
|
|
|
|
|
|
SetUnreachable (true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else if (!strcmp (key, "port")) |
|
|
|
else if (!strcmp (key, "port")) |
|
|
|
address.port = boost::lexical_cast<int>(value); |
|
|
|
address.port = boost::lexical_cast<int>(value); |
|
|
|
} |
|
|
|
} |
|
|
@ -166,7 +175,7 @@ namespace data |
|
|
|
std::stringstream properties; |
|
|
|
std::stringstream properties; |
|
|
|
WriteString ("host", properties); |
|
|
|
WriteString ("host", properties); |
|
|
|
properties << '='; |
|
|
|
properties << '='; |
|
|
|
WriteString (address.host, properties); |
|
|
|
WriteString (address.host.to_string (), properties); |
|
|
|
properties << ';'; |
|
|
|
properties << ';'; |
|
|
|
WriteString ("port", properties); |
|
|
|
WriteString ("port", properties); |
|
|
|
properties << '='; |
|
|
|
properties << '='; |
|
|
@ -237,7 +246,7 @@ namespace data |
|
|
|
void RouterInfo::AddNTCPAddress (const char * host, int port) |
|
|
|
void RouterInfo::AddNTCPAddress (const char * host, int port) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Address addr; |
|
|
|
Address addr; |
|
|
|
addr.host = host; |
|
|
|
addr.host = boost::asio::ip::address::from_string (host); |
|
|
|
addr.port = port; |
|
|
|
addr.port = port; |
|
|
|
addr.transportStyle = eTransportNTCP; |
|
|
|
addr.transportStyle = eTransportNTCP; |
|
|
|
addr.cost = 2; |
|
|
|
addr.cost = 2; |
|
|
@ -266,23 +275,29 @@ namespace data |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool RouterInfo::IsNTCP () const |
|
|
|
bool RouterInfo::IsNTCP (bool v4only) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (auto& address : m_Addresses) |
|
|
|
for (auto& address : m_Addresses) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (address.transportStyle == eTransportNTCP) |
|
|
|
if (address.transportStyle == eTransportNTCP) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!v4only || address.host.is_v4 ()) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
RouterInfo::Address * RouterInfo::GetNTCPAddress () |
|
|
|
RouterInfo::Address * RouterInfo::GetNTCPAddress (bool v4only) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (auto& address : m_Addresses) |
|
|
|
for (auto& address : m_Addresses) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (address.transportStyle == eTransportNTCP) |
|
|
|
if (address.transportStyle == eTransportNTCP) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!v4only || address.host.is_v4 ()) |
|
|
|
return &address; |
|
|
|
return &address; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|