Skip to content

Commit

Permalink
rm ChromiumIpfsContext
Browse files Browse the repository at this point in the history
  • Loading branch information
John-LittleBearLabs committed Feb 12, 2024
1 parent cd55a1e commit d0aa471
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 64 deletions.
2 changes: 2 additions & 0 deletions cmake/inc_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions component/cache_requestor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
36 changes: 14 additions & 22 deletions component/chromium_ipfs_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@

#include <ipfs_client/crypto/openssl_signature_verifier.h>
#include <ipfs_client/ipfs_request.h>
#include <ipfs_client/ipns_record.h>

using Self = ipfs::ChromiumIpfsContext;

void Self::SetupHttp(network::mojom::URLLoaderFactory& lf) {
http_api_ = std::make_unique<ChromiumHttp>(lf);
}

namespace {
std::string DeduceMimeType(std::string extension,
Expand Down Expand Up @@ -59,20 +52,19 @@ std::string Unescape(std::string_view comp) {
}
} // namespace

Self::ChromiumIpfsContext(InterRequestState& state, PrefService* prefs) {
with(std::make_unique<ChromiumIpfsGatewayConfig>(prefs));
with(std::make_unique<ChromiumDnsTxtLookup>(state));
with(&DeduceMimeType);
with(&Unescape);
with(std::make_unique<ChromiumCborAdapter>());
with(std::make_unique<JsonParserAdapter>());
auto ipfs::CreateContext(InterRequestState& stat, PrefService* pref)
-> std::shared_ptr<ContextApi> {
using K = crypto::SigningKeyType;
with(K::RSA,
std::make_unique<crypto::OpensslSignatureVerifier>(EVP_PKEY_RSA));
with(K::Ed25519,
std::make_unique<crypto::OpensslSignatureVerifier>(EVP_PKEY_ED25519));
}
Self::~ChromiumIpfsContext() noexcept {
LOG(WARNING) << "API dtor - are all URIs loaded?";
auto result = std::make_shared<ContextApi>();
result->with(std::make_unique<ChromiumIpfsGatewayConfig>(pref))
.with(std::make_unique<ChromiumDnsTxtLookup>(stat))
.with(&DeduceMimeType)
.with(&Unescape)
.with(std::make_unique<ChromiumCborAdapter>())
.with(std::make_unique<JsonParserAdapter>())
.with(K::RSA,
std::make_unique<crypto::OpensslSignatureVerifier>(EVP_PKEY_RSA))
.with(K::Ed25519, std::make_unique<crypto::OpensslSignatureVerifier>(
EVP_PKEY_ED25519));
return result;
}

18 changes: 2 additions & 16 deletions component/chromium_ipfs_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContextApi> CreateContext(InterRequestState&,
PrefService* prefs);

} // namespace ipfs

Expand Down
4 changes: 2 additions & 2 deletions component/inter_request_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ auto Self::FromBrowserContext(content::BrowserContext* context)
return static_state;
}
}
std::shared_ptr<ipfs::ChromiumIpfsContext> Self::api() {
std::shared_ptr<ipfs::ContextApi> Self::api() {
return api_;
}
auto Self::cache() -> std::shared_ptr<CacheRequestor>& {
Expand All @@ -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<ChromiumIpfsContext>(*this, prefs)}, disk_path_{p} {
: api_{CreateContext(*this, prefs)}, disk_path_{p} {
api_->with(std::make_unique<JsonParserAdapter>());
DCHECK(prefs);
}
Expand Down
5 changes: 2 additions & 3 deletions component/inter_request_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChromiumIpfsContext> api_;
std::shared_ptr<ContextApi> api_;
std::time_t last_discovery_ = 0;
std::shared_ptr<CacheRequestor> cache_;
base::FilePath const disk_path_;
Expand All @@ -37,7 +36,7 @@ class COMPONENT_EXPORT(IPFS) InterRequestState

IpnsNames& names() { return names_; }
Scheduler& scheduler();
std::shared_ptr<ChromiumIpfsContext> api();
std::shared_ptr<ContextApi> api();
std::array<std::shared_ptr<CacheRequestor>,2> serialized_caches();
Orchestrator& orchestrator();
void network_context(network::mojom::NetworkContext*);
Expand Down
4 changes: 3 additions & 1 deletion component/ipfs_url_loader.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ipfs_url_loader.h"

#include "chromium_http.h"
#include "chromium_ipfs_context.h"
#include "inter_request_state.h"

Expand Down Expand Up @@ -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<ChromiumHttp>(*(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_ << ')';
Expand Down
4 changes: 2 additions & 2 deletions component/ipfs_url_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <list>

namespace ipfs {
class ChromiumIpfsContext;
class ContextApi;
} // namespace ipfs

namespace network::mojom {
Expand Down Expand Up @@ -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<ChromiumIpfsContext> api_;
std::shared_ptr<ContextApi> api_;
std::string original_url_;
std::string partial_block_;
std::vector<std::pair<std::string,std::string>> additional_outgoing_headers_;
Expand Down
29 changes: 14 additions & 15 deletions library/src/ipfs_client/ctx/default_gateways.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,24 @@ bool ctx::LoadGatewaysFromEnvironmentVariable(ipfs::ctx::GatewayConfig& cfg) {

void ctx::LoadStaticGatewayList(ipfs::ctx::GatewayConfig& cfg) {
auto static_list = {
std::pair<std::string_view, int>{"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<std::string_view, int>{"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},
Expand Down
2 changes: 1 addition & 1 deletion library/src/ipfs_client/ctx/transitory_gateway_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d0aa471

Please sign in to comment.