From d0aa4710808684ef2438d66fcb3bc51f1cd58971 Mon Sep 17 00:00:00 2001 From: John Turpish Date: Mon, 12 Feb 2024 12:04:25 -0500 Subject: [PATCH] rm ChromiumIpfsContext --- cmake/inc_link.py | 2 ++ component/cache_requestor.cc | 4 +-- component/chromium_ipfs_context.cc | 36 ++++++++----------- component/chromium_ipfs_context.h | 18 ++-------- component/inter_request_state.cc | 4 +-- component/inter_request_state.h | 5 ++- component/ipfs_url_loader.cc | 4 ++- component/ipfs_url_loader.h | 4 +-- .../src/ipfs_client/ctx/default_gateways.cc | 29 ++++++++------- .../ctx/transitory_gateway_config.cc | 2 +- 10 files changed, 44 insertions(+), 64 deletions(-) diff --git a/cmake/inc_link.py b/cmake/inc_link.py index 65930363..0396c71d 100755 --- a/cmake/inc_link.py +++ b/cmake/inc_link.py @@ -172,6 +172,8 @@ def search() -> bool: verbose('existing_dir_map=',existing_dir_map) elif len(existing_dir_map): t, f = existing_dir_map.pop() + if not isdir(f): + continue for entry in listdir(f): source = join(f,entry) target = join(t,entry) diff --git a/component/cache_requestor.cc b/component/cache_requestor.cc index 2be44eee..86688c00 100644 --- a/component/cache_requestor.cc +++ b/component/cache_requestor.cc @@ -133,7 +133,7 @@ void Self::OnBodyRead(Task task, int code) { bool valid = false; task.request->RespondSuccessfully(task.body, api_, &valid); if (valid) { - VLOG(1) << "Cache hit for " << task.key; + VLOG(2) << "Cache hit for " << task.key; } else { LOG(ERROR) << "Had a bad or expired cached response for " << task.key; Expire(task.key); @@ -142,7 +142,7 @@ void Self::OnBodyRead(Task task, int code) { } } void Self::Store(std::string key, std::string headers, std::string body) { - VLOG(1) << "Store(" << name() << ',' << key << ',' << headers.size() << ',' + VLOG(2) << "Store(" << name() << ',' << key << ',' << headers.size() << ',' << body.size() << ')'; auto bound = base::BindOnce(&Self::OnEntryCreated, base::Unretained(this), key, headers, body); diff --git a/component/chromium_ipfs_context.cc b/component/chromium_ipfs_context.cc index 7966ec5a..14e4e650 100644 --- a/component/chromium_ipfs_context.cc +++ b/component/chromium_ipfs_context.cc @@ -22,13 +22,6 @@ #include #include -#include - -using Self = ipfs::ChromiumIpfsContext; - -void Self::SetupHttp(network::mojom::URLLoaderFactory& lf) { - http_api_ = std::make_unique(lf); -} namespace { std::string DeduceMimeType(std::string extension, @@ -59,20 +52,19 @@ std::string Unescape(std::string_view comp) { } } // namespace -Self::ChromiumIpfsContext(InterRequestState& state, PrefService* prefs) { - with(std::make_unique(prefs)); - with(std::make_unique(state)); - with(&DeduceMimeType); - with(&Unescape); - with(std::make_unique()); - with(std::make_unique()); +auto ipfs::CreateContext(InterRequestState& stat, PrefService* pref) + -> std::shared_ptr { using K = crypto::SigningKeyType; - with(K::RSA, - std::make_unique(EVP_PKEY_RSA)); - with(K::Ed25519, - std::make_unique(EVP_PKEY_ED25519)); -} -Self::~ChromiumIpfsContext() noexcept { - LOG(WARNING) << "API dtor - are all URIs loaded?"; + auto result = std::make_shared(); + result->with(std::make_unique(pref)) + .with(std::make_unique(stat)) + .with(&DeduceMimeType) + .with(&Unescape) + .with(std::make_unique()) + .with(std::make_unique()) + .with(K::RSA, + std::make_unique(EVP_PKEY_RSA)) + .with(K::Ed25519, std::make_unique( + EVP_PKEY_ED25519)); + return result; } - diff --git a/component/chromium_ipfs_context.h b/component/chromium_ipfs_context.h index e35e446f..0d3deefa 100644 --- a/component/chromium_ipfs_context.h +++ b/component/chromium_ipfs_context.h @@ -16,25 +16,11 @@ class PrefService; -namespace network { -class SimpleURLLoader; -namespace mojom { -class URLLoaderFactory; -} -} // namespace network - namespace ipfs { class InterRequestState; -class IpfsRequest; -class NetworkRequestor; - -class ChromiumIpfsContext final : public ContextApi { - public: - ChromiumIpfsContext(InterRequestState&, PrefService* prefs); - ~ChromiumIpfsContext() noexcept override; - void SetupHttp(network::mojom::URLLoaderFactory&); -}; +std::shared_ptr CreateContext(InterRequestState&, + PrefService* prefs); } // namespace ipfs diff --git a/component/inter_request_state.cc b/component/inter_request_state.cc index 36bec5b9..589fb967 100644 --- a/component/inter_request_state.cc +++ b/component/inter_request_state.cc @@ -41,7 +41,7 @@ auto Self::FromBrowserContext(content::BrowserContext* context) return static_state; } } -std::shared_ptr Self::api() { +std::shared_ptr Self::api() { return api_; } auto Self::cache() -> std::shared_ptr& { @@ -64,7 +64,7 @@ network::mojom::NetworkContext* Self::network_context() const { return network_context_; } Self::InterRequestState(base::FilePath p, PrefService* prefs) - : api_{std::make_shared(*this, prefs)}, disk_path_{p} { + : api_{CreateContext(*this, prefs)}, disk_path_{p} { api_->with(std::make_unique()); DCHECK(prefs); } diff --git a/component/inter_request_state.h b/component/inter_request_state.h index a7c2184a..dffb033d 100644 --- a/component/inter_request_state.h +++ b/component/inter_request_state.h @@ -18,11 +18,10 @@ class BrowserContext; namespace ipfs { class Scheduler; -class ChromiumIpfsContext; class COMPONENT_EXPORT(IPFS) InterRequestState : public base::SupportsUserData::Data { IpnsNames names_; - std::shared_ptr api_; + std::shared_ptr api_; std::time_t last_discovery_ = 0; std::shared_ptr cache_; base::FilePath const disk_path_; @@ -37,7 +36,7 @@ class COMPONENT_EXPORT(IPFS) InterRequestState IpnsNames& names() { return names_; } Scheduler& scheduler(); - std::shared_ptr api(); + std::shared_ptr api(); std::array,2> serialized_caches(); Orchestrator& orchestrator(); void network_context(network::mojom::NetworkContext*); diff --git a/component/ipfs_url_loader.cc b/component/ipfs_url_loader.cc index 1f61b48d..5716f3c2 100644 --- a/component/ipfs_url_loader.cc +++ b/component/ipfs_url_loader.cc @@ -1,5 +1,6 @@ #include "ipfs_url_loader.h" +#include "chromium_http.h" #include "chromium_ipfs_context.h" #include "inter_request_state.h" @@ -74,7 +75,8 @@ void ipfs::IpfsUrlLoader::StartRequest( auto path = resource_request.url.path(); auto abs_path = "/" + ns + "/" + cid_str + path; me->root_ = cid_str; - me->api_->SetupHttp(*(me->lower_loader_factory_)); + me->api_->with( + std::make_unique(*(me->lower_loader_factory_))); auto whendone = [me](IpfsRequest const& req, ipfs::Response const& res) { VLOG(2) << "whendone(" << req.path().to_string() << ',' << res.status_ << ',' << res.body_.size() << "B mime=" << res.mime_ << ')'; diff --git a/component/ipfs_url_loader.h b/component/ipfs_url_loader.h index dc324f7b..2c5f1ef3 100644 --- a/component/ipfs_url_loader.h +++ b/component/ipfs_url_loader.h @@ -13,7 +13,7 @@ #include namespace ipfs { -class ChromiumIpfsContext; +class ContextApi; } // namespace ipfs namespace network::mojom { @@ -68,7 +68,7 @@ class IpfsUrlLoader final : public network::mojom::URLLoader { mojo::ScopedDataPipeProducerHandle pipe_prod_ = {}; mojo::ScopedDataPipeConsumerHandle pipe_cons_ = {}; bool complete_ = false; - std::shared_ptr api_; + std::shared_ptr api_; std::string original_url_; std::string partial_block_; std::vector> additional_outgoing_headers_; diff --git a/library/src/ipfs_client/ctx/default_gateways.cc b/library/src/ipfs_client/ctx/default_gateways.cc index 678a613a..4048109a 100644 --- a/library/src/ipfs_client/ctx/default_gateways.cc +++ b/library/src/ipfs_client/ctx/default_gateways.cc @@ -27,25 +27,24 @@ bool ctx::LoadGatewaysFromEnvironmentVariable(ipfs::ctx::GatewayConfig& cfg) { void ctx::LoadStaticGatewayList(ipfs::ctx::GatewayConfig& cfg) { auto static_list = { - std::pair{"http://localhost:8080/", 11'000}, - {"https://ipfs.io/", 747}, - {"https://jcsl.hopto.org/", 740}, - {"https://gateway.ipfs.io/", 619}, - {"https://human.mypinata.cloud/", 326}, + std::pair{"http://localhost:8080/", 12'000}, + {"https://ipfs.io/", 749}, {"https://dag.w3s.link/", 214}, - {"https://ipfs.runfission.com/", 117}, + {"https://gateway.ipfs.io/", 619}, + {"https://jcsl.hopto.org/", 720}, + {"https://ipfs.runfission.com/", 118}, {"https://delegated-ipfs.dev/", 74}, - {"https://cesginc.com/", 55}, + {"https://human.mypinata.cloud/", 319}, + {"https://cesginc.com/", 50}, + {"https://permaweb.eu.org/", 53}, {"https://dweb.link/", 53}, - {"https://permaweb.eu.org/", 52}, - {"https://http.f02620.devtty.eu/", 49}, + {"https://http.f02620.devtty.eu/", 50}, {"https://f010479.twinquasar.io/", 36}, - {"https://ipfs.omnicloudstorage.com:9443/", 28}, - {"http://f02095132.datasetcreators.com/", 23}, - {"https://ipfs.joaoleitao.org/", 32}, - {"https://nftstorage.link/", 25}, - {"https://gateway.pinata.cloud/", 16}, - {"https://ipfs.fleek.co/", 9}, + {"https://ipfs.joaoleitao.org/", 33}, + {"http://f02095132.datasetcreators.com/", 13}, + {"https://gateway.pinata.cloud/", 15}, + {"https://nftstorage.link/", 7}, + {"https://ipfs.fleek.co/", 5}, {"https://data.filstorage.io/", 4}, {"https://w3s.link/", 3}, {"https://hardbin.com/", 2}, diff --git a/library/src/ipfs_client/ctx/transitory_gateway_config.cc b/library/src/ipfs_client/ctx/transitory_gateway_config.cc index 28a241e2..1eeeb272 100644 --- a/library/src/ipfs_client/ctx/transitory_gateway_config.cc +++ b/library/src/ipfs_client/ctx/transitory_gateway_config.cc @@ -38,7 +38,7 @@ void Self::AddGateway(std::string_view prefix) { void Self::SetGatewayRate(std::string_view prefix, unsigned int rate) { auto it = FindGateway(prefix); if (gateways_.end() != it && it->prefix == prefix) { - VLOG(1) << "Set gateway rate for " << prefix << " to " << rate; + VLOG(2) << "Set gateway rate for " << prefix << " to " << rate; it->rate = rate; } else { LOG(INFO) << "Attempted to set the rate of an unknown gateway " << prefix