From 5973fe3f620a84fab42b9177e79c52bf0143e46a Mon Sep 17 00:00:00 2001 From: John Turpish Date: Wed, 31 Jan 2024 13:14:09 -0500 Subject: [PATCH] TestContext might work now. --- component/cache_requestor.cc | 7 ++-- component/chromium_ipfs_context.cc | 4 +- component/dns_txt_request.cc | 2 +- component/inter_request_state.cc | 2 +- component/ipfs_url_loader.cc | 6 +-- library/src/ipfs_client/gateways.cc | 42 +++++++++---------- .../src/ipfs_client/gw/dnslink_requestor.cc | 6 +-- library/src/ipfs_client/gw/gateway_request.cc | 8 ++-- .../ipfs_client/gw/multi_gateway_requestor.cc | 5 +-- library/src/ipfs_client/ipns_record.cc | 6 +-- library/src/ipfs_client/orchestrator.cc | 10 +---- library/src/ipfs_client/test_context.cc | 4 +- 12 files changed, 45 insertions(+), 57 deletions(-) diff --git a/component/cache_requestor.cc b/component/cache_requestor.cc index d82e5b5e..49d3cb7c 100644 --- a/component/cache_requestor.cc +++ b/component/cache_requestor.cc @@ -91,7 +91,6 @@ std::shared_ptr GetEntry(dc::EntryResult& result) { void Self::OnOpen(Task task, dc::EntryResult res) { if (res.net_error() != net::OK) { - VLOG(2) << "Failed to find " << task.key << " in " << name(); Miss(task); return; } @@ -135,7 +134,7 @@ void Self::OnBodyRead(Task task, int code) { bool valid = false; task.request->RespondSuccessfully(task.body, api_, &valid); if (valid) { - LOG(INFO) << "Cache hit for " << task.key; + VLOG(1) << "Cache hit for " << task.key; } else { LOG(ERROR) << "Had a bad or expired cached response for " << task.key; Expire(task.key); @@ -144,8 +143,8 @@ void Self::OnBodyRead(Task task, int code) { } } void Self::Store(std::string key, std::string headers, std::string body) { - LOG(INFO) << "Store(" << name() << ',' << key << ',' << headers.size() << ',' - << body.size() << ')'; + VLOG(1) << "Store(" << name() << ',' << key << ',' << headers.size() << ',' + << body.size() << ')'; auto bound = base::BindOnce(&Self::OnEntryCreated, base::Unretained(this), key, headers, body); auto res = cache_->OpenOrCreateEntry(key, net::LOW, std::move(bound)); diff --git a/component/chromium_ipfs_context.cc b/component/chromium_ipfs_context.cc index 3e91cdaf..0ee65023 100644 --- a/component/chromium_ipfs_context.cc +++ b/component/chromium_ipfs_context.cc @@ -61,8 +61,8 @@ void Self::SendDnsTextRequest(std::string host, DnsTextResultsCallback res, DnsTextCompleteCallback don) { if (dns_reqs_.find(host) != dns_reqs_.end()) { - LOG(WARNING) << "Requested resolution of DNSLink host " << host - << " multiple times."; + LOG(INFO) << "Requested resolution of DNSLink host " << host + << " multiple times."; } auto don_wrap = [don, this, host]() { don(); diff --git a/component/dns_txt_request.cc b/component/dns_txt_request.cc index 2a37ad88..7e26cf28 100644 --- a/component/dns_txt_request.cc +++ b/component/dns_txt_request.cc @@ -26,7 +26,7 @@ Self::DnsTxtRequest(std::string host, Self::~DnsTxtRequest() {} void Self::OnTextResults(std::vector const& results) { - LOG(INFO) << "Hit " << results.size() << " DNS TXT results."; + VLOG(1) << "Hit " << results.size() << " DNS TXT results."; results_callback_(results); } void Self::OnComplete(int32_t result, diff --git a/component/inter_request_state.cc b/component/inter_request_state.cc index b05a0aee..a4831477 100644 --- a/component/inter_request_state.cc +++ b/component/inter_request_state.cc @@ -20,7 +20,7 @@ constexpr char user_data_key[] = "ipfs_request_userdata"; void Self::CreateForBrowserContext(content::BrowserContext* c, PrefService* p) { DCHECK(c); DCHECK(p); - LOG(INFO) << "Creating new IPFS state for this browser context."; + VLOG(1) << "Creating new IPFS state for this browser context."; auto owned = std::make_unique(c->GetPath(), p); c->SetUserData(user_data_key, std::move(owned)); } diff --git a/component/ipfs_url_loader.cc b/component/ipfs_url_loader.cc index eb85fd2a..678cf08f 100644 --- a/component/ipfs_url_loader.cc +++ b/component/ipfs_url_loader.cc @@ -25,8 +25,8 @@ ipfs::IpfsUrlLoader::IpfsUrlLoader( : state_{state}, lower_loader_factory_{handles_http}, api_{state_->api()} {} ipfs::IpfsUrlLoader::~IpfsUrlLoader() noexcept { if (!complete_) { - LOG(ERROR) << "Premature IPFS URLLoader dtor, uri was '" << original_url_ - << "' " << base::debug::StackTrace(); + LOG(WARNING) << "Premature IPFS URLLoader dtor, uri was '" << original_url_ + << "' " << base::debug::StackTrace(); } } @@ -180,7 +180,7 @@ void ipfs::IpfsUrlLoader::BlocksComplete(std::string mime_type) { void ipfs::IpfsUrlLoader::DoesNotExist(std::string_view cid, std::string_view path) { - LOG(ERROR) << "Immutable data 404 for " << cid << '/' << path; + LOG(WARNING) << "Immutable data 404 for " << cid << '/' << path; complete_ = true; client_->OnComplete( network::URLLoaderCompletionStatus{net::ERR_FILE_NOT_FOUND}); diff --git a/library/src/ipfs_client/gateways.cc b/library/src/ipfs_client/gateways.cc index cf52c003..fdc80820 100644 --- a/library/src/ipfs_client/gateways.cc +++ b/library/src/ipfs_client/gateways.cc @@ -100,29 +100,29 @@ auto ipfs::Gateways::DefaultGateways() -> GatewayList { } return result; } - return {{"http://localhost:8080/"s, 6001}, - {"https://jcsl.hopto.org/"s, 746}, - {"https://ipfs.io/"s, 732}, - {"https://gateway.ipfs.io/"s, 619}, + return {{"http://localhost:8080/"s, 6004}, + {"https://jcsl.hopto.org/"s, 744}, + {"https://ipfs.io/"s, 736}, + {"https://gateway.ipfs.io/"s, 622}, {"https://human.mypinata.cloud/"s, 342}, - {"https://dag.w3s.link/", 215}, - {"https://ipfs.runfission.com/"s, 108}, - {"https://delegated-ipfs.dev/"s, 68}, - {"https://permaweb.eu.org/"s, 63}, - {"https://dweb.link/"s, 60}, - {"https://cesginc.com/", 53}, - {"https://http.f02620.devtty.eu/", 40}, - {"https://f010479.twinquasar.io/", 27}, - {"https://ipfs.omnicloudstorage.com:9443/", 20}, - {"https://gateway.pinata.cloud/"s, 19}, - {"http://f02095132.datasetcreators.com/", 18}, - {"https://ipfs.joaoleitao.org/"s, 10}, + {"https://dag.w3s.link/", 216}, + {"https://ipfs.runfission.com/"s, 111}, + {"https://delegated-ipfs.dev/"s, 71}, + {"https://permaweb.eu.org/"s, 64}, + {"https://dweb.link/"s, 63}, + {"https://cesginc.com/", 56}, + {"https://http.f02620.devtty.eu/", 43}, + {"https://f010479.twinquasar.io/", 30}, + {"https://ipfs.omnicloudstorage.com:9443/", 23}, + {"https://gateway.pinata.cloud/"s, 22}, + {"http://f02095132.datasetcreators.com/", 21}, + {"https://ipfs.joaoleitao.org/"s, 13}, {"https://data.filstorage.io/", 9}, - {"https://nftstorage.link/"s, 6}, - {"https://ipfs.fleek.co/"s, 5}, - {"https://w3s.link/"s, 4}, - {"https://hardbin.com/"s, 3}, - {"https://ipfs.jpu.jp/"s, 2}, + {"https://nftstorage.link/"s, 5}, + {"https://ipfs.fleek.co/"s, 4}, + {"https://w3s.link/"s, 3}, + {"https://hardbin.com/"s, 2}, + {"https://ipfs.jpu.jp/"s, 1}, {"https://jorropo.net/"s, 1}, {"https://ipfs.soul-network.com/"s, 0}}; } diff --git a/library/src/ipfs_client/gw/dnslink_requestor.cc b/library/src/ipfs_client/gw/dnslink_requestor.cc index 07ad79c7..4659fbc7 100644 --- a/library/src/ipfs_client/gw/dnslink_requestor.cc +++ b/library/src/ipfs_client/gw/dnslink_requestor.cc @@ -51,11 +51,11 @@ bool parse_results(ipfs::gw::RequestPtr req, std::vector const& results, std::shared_ptr const& api) { constexpr auto prefix = "dnslink="sv; - LOG(INFO) << "Scanning " << results.size() << " DNS TXT records for " - << req->main_param << " looking for dnslink..."; + VLOG(1) << "Scanning " << results.size() << " DNS TXT records for " + << req->main_param << " looking for dnslink..."; for (auto& result : results) { if (starts_with(result, prefix)) { - LOG(INFO) << "DNSLink result=" << result; + VLOG(1) << "DNSLink result=" << result; req->RespondSuccessfully(result.substr(prefix.size()), api); return true; } else { diff --git a/library/src/ipfs_client/gw/gateway_request.cc b/library/src/ipfs_client/gw/gateway_request.cc index 8edb5b2f..ef81fdf8 100644 --- a/library/src/ipfs_client/gw/gateway_request.cc +++ b/library/src/ipfs_client/gw/gateway_request.cc @@ -111,11 +111,11 @@ std::string_view Self::accept() const { short Self::timeout_seconds() const { switch (type) { case Type::DnsLink: - return 16; + return 8; case Type::Block: - return 32; + return 16; case Type::Providers: - return 33; + return 32; case Type::Ipns: return 64; case Type::Car: @@ -309,7 +309,7 @@ bool Self::RespondSuccessfully(std::string_view bytes, } break; case Type::DnsLink: { - LOG(INFO) << "Resolved " << debug_string() << " to " << bytes; + VLOG(1) << "Resolved " << debug_string() << " to " << bytes; auto node = std::make_shared(bytes); if (orchestrator_) { success = orchestrator_->add_node(main_param, node); diff --git a/library/src/ipfs_client/gw/multi_gateway_requestor.cc b/library/src/ipfs_client/gw/multi_gateway_requestor.cc index cfdae734..2bcdb3cb 100644 --- a/library/src/ipfs_client/gw/multi_gateway_requestor.cc +++ b/library/src/ipfs_client/gw/multi_gateway_requestor.cc @@ -72,9 +72,6 @@ bool Self::Process(RequestPtr const& req) { std::advance(state_iter, 1); } if (std::get<2>(over_rate)) { - if (candidates.empty()) { - VLOG(2) << "Overburdened."; - } candidates.push_back(over_rate); } if (candidates.empty() && config_idx <= req->failures.size()) { @@ -164,7 +161,7 @@ void Self::HandleResponse(HttpRequestDescription const& desc, auto old_rpm = rpm; if (status == 408 || status == 504 || status == 429 || status == 110 || timed_out) { - LOG(WARNING) << gw << " timed out on request " << req->debug_string(); + VLOG(1) << gw << " timed out on request " << req->debug_string(); if (req->type == Type::Block) { if (state_.end() != i) { i->second.timed_out(); diff --git a/library/src/ipfs_client/ipns_record.cc b/library/src/ipfs_client/ipns_record.cc index 37e2dba8..19f6b95c 100644 --- a/library/src/ipfs_client/ipns_record.cc +++ b/library/src/ipfs_client/ipns_record.cc @@ -144,8 +144,8 @@ auto ipfs::ValidateIpnsRecord(ipfs::ByteView top_level_bytes, LOG(ERROR) << "Failed to parse public key bytes"; return {}; } - LOG(INFO) << "Record contains a public key of type " << pk.type() - << " and points to " << entry.value(); + VLOG(1) << "Record contains a public key of type " << pk.type() + << " and points to " << entry.value(); auto& signature_str = entry.signaturev2(); ByteView signature{reinterpret_cast(signature_str.data()), signature_str.size()}; @@ -223,7 +223,7 @@ ipfs::ValidatedIpns::ValidatedIpns(IpnsCborEntry const& e) #else use_until = timegm(&t); #endif - LOG(INFO) << "use_until=" << use_until << " based on " << e.validity; + VLOG(1) << "use_until=" << use_until << " based on " << e.validity; cache_until = std::time(nullptr) + ttl; } diff --git a/library/src/ipfs_client/orchestrator.cc b/library/src/ipfs_client/orchestrator.cc index 53cfb796..f4890875 100644 --- a/library/src/ipfs_client/orchestrator.cc +++ b/library/src/ipfs_client/orchestrator.cc @@ -93,10 +93,6 @@ void Self::from_tree(std::shared_ptr req, req->finish(Response::IMMUTABLY_GONE); } else { auto& mps = std::get(result).ipfs_abs_paths_; - for (auto& mp : mps) { - VLOG(2) << "Attempt to resolve " << relative_path << " for " - << req->path() << " leads to request for " << mp; - } if (std::any_of(mps.begin(), mps.end(), [this, &req, &affinity](auto& p) { return gw_request(req, SlashDelimited{p}, affinity); })) { @@ -108,7 +104,6 @@ bool Self::gw_request(std::shared_ptr ir, ipfs::SlashDelimited path, std::string const& aff) { auto req = gw::GatewayRequest::fromIpfsPath(path); - VLOG(2) << "Seeking " << path.to_string() << " -> " << req->debug_string(); if (req) { req->dependent = ir; req->orchestrator(shared_from_this()); @@ -127,12 +122,11 @@ bool Self::add_node(std::string key, ipfs::ipld::NodePtr p) { } auto [it, first] = dags_.insert({key, p}); if (first) { - LOG(INFO) << "First node showed up for [" << key << "]."; + VLOG(1) << "First node showed up for [" << key << "]."; } else if (p->PreferOver(*it->second)) { it->second = p; } else { - LOG(INFO) << "Already had a [" << key - << "] node that was at least as good."; + // VLOG(2) << "Already had a [" << key << "] node that was as good."; return false; } p->set_api(api_); diff --git a/library/src/ipfs_client/test_context.cc b/library/src/ipfs_client/test_context.cc index 56fb18f1..b94ff948 100644 --- a/library/src/ipfs_client/test_context.cc +++ b/library/src/ipfs_client/test_context.cc @@ -41,9 +41,8 @@ static void c_ares_c_callback(void* vp, delete cbcb; } } -/* Self::TestContext(boost::asio::io_context& io) - : gateways_{Gateways::DefaultGateways()}, io_{io} { + : ContextApi(&io), io_{io}, gateways_{Gateways::DefaultGateways()} { std::sort(gateways_.begin(), gateways_.end(), [](auto& a, auto& b) { return a.prefix < b.prefix; }); if (ares_library_init(ARES_LIB_INIT_ALL)) { @@ -53,7 +52,6 @@ Self::TestContext(boost::asio::io_context& io) throw std::runtime_error("Failed to initialize c-ares channel."); } } - */ Self::~TestContext() { pending_dns_.clear(); ares_destroy(ares_channel_);