Skip to content

Commit c8b53e3

Browse files
committed
ud: add back in bridge code
1 parent a2a06dd commit c8b53e3

File tree

3 files changed

+87
-26
lines changed

3 files changed

+87
-26
lines changed

src/common/dns_utils.cpp

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include <boost/algorithm/string/join.hpp>
4242
#include <boost/optional.hpp>
4343
#include <boost/utility/string_ref.hpp>
44+
#include <rapidjson/document.h>
45+
4446
using namespace epee;
4547

4648
#undef scala_DEFAULT_LOG_CATEGORY
@@ -486,14 +488,85 @@ std::vector<std::string> addresses_from_url(const std::string& url, bool& dnssec
486488

487489
std::string get_account_address_as_str_from_url(const std::string& url, bool& dnssec_valid, std::function<std::string(const std::string&, const std::vector<std::string>&, bool)> dns_confirm)
488490
{
489-
// attempt to get address from dns query
490-
auto addresses = addresses_from_url(url, dnssec_valid);
491-
if (addresses.empty())
491+
std::vector<std::string> valid_ud_tlds{ ".crypto", ".nft", ".blockchain", ".bitcoin", ".wallet", ".888", ".dao", ".x", ".klever", ".zil", ".eth" };
492+
493+
bool valid_tld = false;
494+
495+
for (const auto& tld : valid_ud_tlds)
492496
{
493-
LOG_ERROR("wrong address: " << url);
494-
return {};
497+
if (url.find(tld) != std::string::npos)
498+
{
499+
valid_tld = true;
500+
break;
501+
}
495502
}
496-
return dns_confirm(url, addresses, dnssec_valid);
503+
504+
if (!valid_tld)
505+
{
506+
// attempt to get address from dns query
507+
auto addresses = addresses_from_url(url, dnssec_valid);
508+
if (addresses.empty())
509+
{
510+
LOG_ERROR("wrong address: " << url);
511+
return {};
512+
}
513+
return dns_confirm(url, addresses, dnssec_valid);
514+
} else {
515+
std::vector<std::string> addresses;
516+
std::vector<std::string> ud_addresses;
517+
std::string ud_bridge_api = "http://ud-bridge.scalaproject.io/fetch-records/" + url;
518+
519+
epee::net_utils::http::http_simple_client client;
520+
epee::net_utils::http::url_content u_c;
521+
522+
if (!epee::net_utils::parse_url(ud_bridge_api, u_c)){
523+
MERROR("Failed to parse URL " << ud_bridge_api);
524+
return {};
525+
}
526+
527+
epee::net_utils::ssl_support_t ssl_requirement = epee::net_utils::ssl_support_t::e_ssl_support_disabled;
528+
uint16_t port = 80;
529+
530+
client.set_server(u_c.host, std::to_string(port), boost::none, ssl_requirement);
531+
epee::net_utils::http::fields_list fields;
532+
const epee::net_utils::http::http_response_info *info = NULL;
533+
534+
535+
if (!client.invoke_get(u_c.uri, std::chrono::seconds(10), "", &info, fields)){
536+
LOG_ERROR(ud_bridge_api << " is not responding, skipping.");
537+
return {};
538+
} else{
539+
if (info->m_response_code != 200){
540+
LOG_ERROR("Failed to get address from " << ud_bridge_api << ", skipping.");
541+
return {};
542+
}
543+
544+
std::string response = info->m_body;
545+
rapidjson::Document doc;
546+
547+
548+
if (doc.Parse(response.c_str()).HasParseError()){
549+
LOG_ERROR("Failed to parse response from " << ud_bridge_api << ", skipping.");
550+
return {};
551+
}
552+
553+
if (!doc.HasMember("records")){
554+
LOG_ERROR("Failed to get records from " << ud_bridge_api << ", skipping.");
555+
return {};
556+
}
557+
558+
if (!doc["records"].HasMember("crypto.XLA.address")){
559+
LOG_ERROR("Failed to get XLA address from " << ud_bridge_api << ", skipping.");
560+
return {};
561+
} else {
562+
std::string address = doc["records"]["crypto.XLA.address"].GetString();
563+
564+
addresses.push_back(address);
565+
return dns_confirm(url, addresses, true);
566+
}
567+
}
568+
}
569+
497570
}
498571

499572
bool load_txt_records_from_dns(std::vector<std::string> &good_records, const std::vector<std::string> &dns_urls)

src/common/dns_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include <boost/optional/optional_fwd.hpp>
3535
#include <boost/utility/string_ref_fwd.hpp>
3636

37+
#include "net/http_client.h"
38+
3739
namespace tools
3840
{
3941

src/p2p/net_node.inl

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -702,18 +702,16 @@ namespace nodetool
702702
{
703703
std::set<std::string> full_addrs;
704704
if (m_nettype == cryptonote::TESTNET)
705-
{
706-
}
705+
{}
707706
else if (m_nettype == cryptonote::STAGENET)
708-
{
709-
}
707+
{}
710708
else if (m_nettype == cryptonote::FAKECHAIN)
711-
{
712-
}
709+
{}
713710
else
714711
{
715712
full_addrs.insert("65.21.221.2:11811");
716713
full_addrs.insert("65.21.221.3:11811");
714+
full_addrs.insert("95.111.237.231:11811");
717715
}
718716
return full_addrs;
719717
}
@@ -843,25 +841,13 @@ namespace nodetool
843841
case epee::net_utils::zone::tor:
844842
if (m_nettype == cryptonote::MAINNET)
845843
{
846-
return {
847-
"xwvz3ekocr3dkyxfkmgm2hvbpzx2ysqmaxgter7znnqrhoicygkfswid.onion:18083",
848-
"4pixvbejrvihnkxmduo2agsnmc3rrulrqc7s3cbwwrep6h6hrzsibeqd.onion:18083",
849-
"zbjkbsxc5munw3qusl7j2hpcmikhqocdf4pqhnhtpzw5nt5jrmofptid.onion:18083",
850-
"qz43zul2x56jexzoqgkx2trzwcfnr6l3hbtfcfx54g4r3eahy3bssjyd.onion:18083",
851-
"plowsof3t5hogddwabaeiyrno25efmzfxyro2vligremt7sxpsclfaid.onion:18083",
852-
"plowsoffjexmxalw73tkjmf422gq6575fc7vicuu4javzn2ynnte6tyd.onion:18083",
853-
};
844+
return {};
854845
}
855846
return {};
856847
case epee::net_utils::zone::i2p:
857848
if (m_nettype == cryptonote::MAINNET)
858849
{
859-
return {
860-
"s3l6ke4ed3df466khuebb4poienoingwof7oxtbo6j4n56sghe3a.b32.i2p:18080",
861-
"sel36x6fibfzujwvt4hf5gxolz6kd3jpvbjqg6o3ud2xtionyl2q.b32.i2p:18080",
862-
"uqj3aphckqtjsitz7kxx5flqpwjlq5ppr3chazfued7xucv3nheq.b32.i2p:18080",
863-
"vdmnehdjkpkg57nthgnjfuaqgku673r5bpbqg56ix6fyqoywgqrq.b32.i2p:18080",
864-
};
850+
return {};
865851
}
866852
return {};
867853
default:

0 commit comments

Comments
 (0)