Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base-16 support #46

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .idea/chromium-ipfs.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/ipfs-chromium.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmake/AppleClang.cmake
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
set(CHROMIUM_COMPILER_FLAGS -nostdinc++ -fno-rtti)
set(WARNING_FLAGS -Wall -Wextra -Werror=return-type -fmax-errors=3)
set(WARNING_FLAGS -Wall -Wextra -Werror=return-type )
63 changes: 44 additions & 19 deletions cmake/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,22 @@ def osname():
return 'Windows'


def as_int(v):
result = 0
for c in v.split('.'):
result *= 10000
result += int(c)
return result



class Patcher:
def __init__(self, chromium_source_dir, git_bin, build_type):
self.csrc = chromium_source_dir
self.pdir = realpath(join(dirname(__file__), '..', 'component', 'patches'))
self.gbin = git_bin
self.btyp = build_type
self.up_rels = {}

def create_patch_file(self):
tag = self.tag_name()
Expand Down Expand Up @@ -112,42 +122,57 @@ def maybe_newer(self, x, y):
def release_versions(self, channel, pfrm=None):
if pfrm is None:
pfrm = osname()
key = pfrm + channel
if key in self.up_rels:
return self.up_rels[key]
parms = {'platform': pfrm, 'channel': channel}
chrom_url = 'https://chromiumdash.appspot.com/fetch_releases'
resp = requests.get(url=chrom_url, params=parms)
result = list(map(lambda x: (x['time'] / 1000, x['version']), resp.json()))
elec_url = 'https://raw.githubusercontent.com/electron/electron/main/DEPS'
resp = requests.get(url=elec_url)
result.sort(reverse=True)
self.up_rels[key] = result
return result

def electron_version(self, branch='main'):
if 'electron-main' in self.up_rels:
return self.up_rels['electron-main']
resp = requests.get(f'https://raw.githubusercontent.com/electron/electron/{branch}/DEPS')
toks = resp.text.split("'")
i = toks.index('chromium_version') + 2
self.up_rels['electron-main'] = toks[i]
return toks[i]


def unavailable(self):
avail = list(self.available())
avail = list(map(as_int, self.available()))
version_set = {}
for channel in ['Dev', 'Beta', 'Stable', 'Extended']:
for pfrm in ['Linux', 'Mac', 'Windows']:
try:
when, version = self.release_versions(channel, pfrm)[0]
if version in avail:
continue
# print(version,'has been the current',platform,channel,'release since',ctime(when),' and we have no patch file for it.')
if version not in version_set:
sortable = [int(c) for c in version.split('.')]
version_set[version] = [sortable, version]
version_set[version].append(f"{channel}-{pfrm}-{when}")
except IndexError:
pass # One may assume this is Linux Extended
e = self.electron_version()
if e not in version_set:
sortable = [int(c) for c in e.split('.')]
version_set[e] = [sortable, e]
version_set[e].append("electron-main")
fuzz = 99999
def check(version, version_set, s):
i = as_int(version)
if any(abs(a-i)<fuzz for a in avail):
return True
if version not in version_set:
sortable = [int(c) for c in version.split('.')]
print('Adding',version,s)
version_set[version] = [sortable, version, s]
elif s not in version_set[version]:
print('2 Adding',version,s)
version_set[version].append(s)
return False
while fuzz >= 0 and len(version_set) < 2:
fuzz -= 1
for channel in ['Dev', 'Beta', 'Stable', 'Extended']:
for pfrm in ['Linux', 'Mac', 'Windows']:
try:
when, version = self.release_versions(channel, pfrm)[0]
s = f"{channel}-{pfrm}-{when}"
check(version, version_set, s)
except IndexError:
pass # One may assume this is Linux Extended
e = self.electron_version()
check(e, version_set, 'electron-main')
result = list(version_set.values())
result.sort(reverse=True)
return map(lambda x: x[1:], result)
Expand Down
4 changes: 2 additions & 2 deletions component/cache_requestor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ void Self::OnBodyRead(Task task, int code) {
if (task.listener) {
VLOG(1) << "Cache hit on " << task.key;
task.SetHeaders(name());
auto& stor = state_.storage();
auto& stor = state_->storage();
stor.Store(task.key, std::move(task.header), std::move(task.body));
state_.scheduler().IssueRequests(state_.api());
state_->scheduler().IssueRequests(state_->api());
} else {
task.hit(task.body, task.header);
}
Expand Down
3 changes: 2 additions & 1 deletion component/cache_requestor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <net/base/io_buffer.h>
#include <net/disk_cache/disk_cache.h>

#include <base/memory/raw_ref.h>
#include <base/memory/scoped_refptr.h>
#include <base/time/time.h>

Expand Down Expand Up @@ -49,7 +50,7 @@ class CacheRequestor : public BlockRequestor {
void Fail();
};
net::CacheType const type_;
InterRequestState& state_;
raw_ref<InterRequestState> state_;
std::unique_ptr<disk_cache::Backend> cache_;
bool pending_ = false;
base::FilePath path_;
Expand Down
22 changes: 11 additions & 11 deletions component/gateway_requests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ auto Self::InitiateGatewayRequest(BusyGateway assigned)
// out->listener = listener;
auto cb = base::BindOnce(&Self::OnResponse, base::Unretained(this),
shared_from_this(), out, start_time);
// LOG(INFO) << "InitiateGatewayRequest(" << url << ")";
VLOG(2) << "InitiateGatewayRequest(" << url << ")";
DCHECK(loader_factory_);
// TODO - proper requesting with full features (SetPriority, etc.).
out->loader->DownloadToString(loader_factory_, std::move(cb), 2UL * MB);
Expand All @@ -131,12 +131,12 @@ void Self::OnResponse(std::shared_ptr<ContextApi> api,
auto& ldr = req->loader;
// auto listener = req->listener;
if (ProcessResponse(bg, ldr.get(), body.get(), start_time)) {
bg.Success(state_.gateways(), shared_from_this());
bg.Success(state_->gateways(), shared_from_this());
} else {
bg.Failure(state_.gateways(), shared_from_this());
bg.Failure(state_->gateways(), shared_from_this());
}
state_.storage().CheckListening();
state_.scheduler().IssueRequests(api);
state_->storage().CheckListening();
state_->scheduler().IssueRequests(api);
}

bool Self::ProcessResponse(BusyGateway& gw,
Expand Down Expand Up @@ -180,13 +180,13 @@ bool Self::ProcessResponse(BusyGateway& gw,
<< " strongly implying that it's a full request, not a single "
"block. TODO: Remove "
<< gw->url_prefix() << " from list of gateways?\n";
state_.gateways().demote(gw->url_prefix());
state_->gateways().demote(gw->url_prefix());
return false;
}
auto cid_str = gw.task();
cid_str.erase(0, 5); // ipfs/
cid_str.erase(cid_str.find('?'));
if (state_.storage().Get(cid_str)) {
if (state_->storage().Get(cid_str)) {
// LOG(INFO) << "Got multiple successful responses for " << cid_str;
return true;
}
Expand Down Expand Up @@ -218,7 +218,7 @@ bool Self::ProcessResponse(BusyGateway& gw,
ValidatedIpns entry{record.value()};
entry.resolution_ms = duration;
entry.gateway_source = gw->url_prefix();
state_.names().AssignName(cid_str, std::move(entry));
state_->names().AssignName(cid_str, std::move(entry));
scheduler().IssueRequests(shared_from_this());
return true;
} else {
Expand All @@ -233,8 +233,8 @@ bool Self::ProcessResponse(BusyGateway& gw,
"Server-Timing",
"gateway-fetch-" + cid_str + ";desc=\"" + gw->url_prefix() +
" : load over http(s)\";dur=" + std::to_string(duration));
state_.storage().Store(cid_str, cid.value(), head->headers->raw_headers(),
*body);
state_->storage().Store(cid_str, cid.value(),
head->headers->raw_headers(), *body);
scheduler().IssueRequests(shared_from_this());
return true;
} else {
Expand Down Expand Up @@ -303,7 +303,7 @@ void Self::RequestByCid(std::string cid,

Self::GatewayRequests(InterRequestState& state)
: state_{state},
sched_([this]() { return state_.gateways().GenerateList(); }) {}
sched_([this]() { return state_->gateways().GenerateList(); }) {}
Self::~GatewayRequests() {
LOG(WARNING) << "API dtor - are all URIs loaded?";
}
Expand Down
3 changes: 2 additions & 1 deletion component/gateway_requests.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <ipfs_client/context_api.h>
#include <ipfs_client/scheduler.h>

#include <base/memory/raw_ref.h>
#include <base/time/time.h>

#include <vocab/raw_ptr.h>
Expand All @@ -31,7 +32,7 @@ class GatewayRequests final : public ContextApi {
};

raw_ptr<network::mojom::URLLoaderFactory> loader_factory_ = nullptr;
InterRequestState& state_;
raw_ref<InterRequestState> state_;
Scheduler sched_;
std::function<void(std::vector<std::string>)> disc_cb_;

Expand Down
14 changes: 7 additions & 7 deletions component/ipfs_url_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
ipfs::IpfsUrlLoader::IpfsUrlLoader(
network::mojom::URLLoaderFactory& handles_http,
InterRequestState& state)
: state_{state}, lower_loader_factory_{handles_http}, api_{state_.api()} {}
: 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_
Expand Down Expand Up @@ -87,7 +87,7 @@ void ipfs::IpfsUrlLoader::StartRequest(
}

void ipfs::IpfsUrlLoader::StartUnixFsProc(ptr me, std::string_view ipfs_ref) {
LOG(INFO) << "Requesting " << ipfs_ref << " by blocks.";
VLOG(1) << "Requesting " << ipfs_ref << " by blocks.";
DCHECK_EQ(ipfs_ref.substr(0, 5), "ipfs/");
auto second_slash = ipfs_ref.find_first_of("/?", 5);
auto cid = ipfs_ref.substr(5, second_slash - 5);
Expand All @@ -102,9 +102,9 @@ void ipfs::IpfsUrlLoader::StartUnixFsProc(ptr me, std::string_view ipfs_ref) {
VLOG(1) << "cid=" << cid << " remainder=" << remainder;
me->root_ = cid;
me->resolver_ = std::make_shared<UnixFsPathResolver>(
me->state_.storage(), me->state_.requestor(), std::string{cid}, remainder,
me->api_);
me->api_->SetLoaderFactory(lower_loader_factory_);
me->state_->storage(), me->state_->requestor(), std::string{cid},
remainder, me->api_);
me->api_->SetLoaderFactory(*lower_loader_factory_);
me->stepper_ = std::make_unique<base::RepeatingTimer>();
me->stepper_->Start(FROM_HERE, base::Milliseconds(500),
base::BindRepeating(&IpfsUrlLoader::TakeStep, me));
Expand Down Expand Up @@ -165,7 +165,7 @@ void ipfs::IpfsUrlLoader::BlocksComplete(std::string mime_type) {
LOG(INFO) << "Appending 'additional' header:" << n << '=' << v << '.';
head->headers->AddHeader(n, v);
}
LOG(INFO) << "Calling PopulateParsedHeaders";
VLOG(1) << "Calling PopulateParsedHeaders";
head->parsed_headers =
network::PopulateParsedHeaders(head->headers.get(), GURL{original_url_});
LOG(INFO) << "Sending response for " << original_url_ << " with mime type "
Expand Down Expand Up @@ -199,5 +199,5 @@ void ipfs::IpfsUrlLoader::ReceiveBlockBytes(std::string_view content) {
void ipfs::IpfsUrlLoader::AppendGatewayHeaders(
std::vector<std::string> const& cids,
net::HttpResponseHeaders& out) {
summarize_headers(cids, root_, out, state_.storage());
summarize_headers(cids, root_, out, state_->storage());
}
4 changes: 2 additions & 2 deletions component/ipfs_url_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ class IpfsUrlLoader final : public network::mojom::URLLoader,
private:
using RequestHandle = std::unique_ptr<network::SimpleURLLoader>;

InterRequestState& state_;
raw_ref<InterRequestState> state_;
mojo::Receiver<network::mojom::URLLoader> receiver_{this};
mojo::Remote<network::mojom::URLLoaderClient> client_;
network::mojom::URLLoaderFactory& lower_loader_factory_;
raw_ref<network::mojom::URLLoaderFactory> lower_loader_factory_;
mojo::ScopedDataPipeProducerHandle pipe_prod_ = {};
mojo::ScopedDataPipeConsumerHandle pipe_cons_ = {};
bool complete_ = false;
Expand Down
32 changes: 16 additions & 16 deletions component/ipns_url_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ void ipfs::IpnsUrlLoader::OnTextResults(
}
}
if (result.empty()) {
state_.names().NoSuchName(host_);
state_->names().NoSuchName(host_);
LOG(ERROR)
<< "_dnslink. domain exists, but contains no /ipfs or /ipns entry";
} else {
state_.names().AssignDnsLink(host_, result);
state_->names().AssignDnsLink(host_, result);
}
}
void ipfs::IpnsUrlLoader::OnComplete(
Expand All @@ -83,12 +83,12 @@ void ipfs::IpnsUrlLoader::OnComplete(
Next();
} else {
LOG(ERROR) << "Error resolving _dnslink." << host_ << " : " << result;
state_.names().NoSuchName(host_);
state_->names().NoSuchName(host_);
FailNameResolution();
}
}
void ipfs::IpnsUrlLoader::Next() {
auto resolved = state_.names().NameResolvedTo(host_);
auto resolved = state_->names().NameResolvedTo(host_);
if (resolved.empty()) {
if (!RequestIpnsRecord()) {
LOG(INFO) << "Treating '" << host_ << "' as a DNSLink host.";
Expand All @@ -107,7 +107,7 @@ void ipfs::IpnsUrlLoader::Next() {
}
}
void ipfs::IpnsUrlLoader::DoIpfs() {
auto resolved = state_.names().NameResolvedTo(host_);
auto resolved = state_->names().NameResolvedTo(host_);
auto from_url = request_.value().url;
std::string to{resolved};
DCHECK_GT(to.size(), 5U);
Expand All @@ -134,7 +134,7 @@ void ipfs::IpnsUrlLoader::DoIpfs() {
GURL to_url{to};
VLOG(1) << "Treating " << from_url << " as " << to_url;
ipfs_loader_->OverrideUrl(from_url);
auto* entry = state_.names().Entry(host_);
auto* entry = state_->names().Entry(host_);
if (entry) {
auto duration = entry->resolution_ms;
ipfs_loader_->AddHeader(
Expand Down Expand Up @@ -215,11 +215,11 @@ bool ipfs::IpnsUrlLoader::RequestIpnsRecord() {
if (api_) {
// true because this is true IPNS
// ... but return early because we have already requested it
state_.scheduler().IssueRequests(api_);
state_->scheduler().IssueRequests(api_);
return true;
}
auto key = "ipns/" + host_;
auto caches = state_.serialized_caches();
auto caches = state_->serialized_caches();
auto check =
[this, key](
std::function<void()> fail,
Expand Down Expand Up @@ -249,22 +249,22 @@ void ipfs::IpnsUrlLoader::CacheHit(std::shared_ptr<CacheRequestor> cache,
cache->Expire("ipns/" + host_);
RequestFromGateway();
} else {
state_.names().AssignName(host_, result);
state_->names().AssignName(host_, result);
Complete();
}
}
void ipfs::IpnsUrlLoader::RequestFromGateway() {
api_ = state_.api();
api_->SetLoaderFactory(http_loader_);
state_.scheduler().Enqueue(api_, {}, shared_from_this(),
"ipns/" + host_ + "?format=ipns-record", 3);
state_.scheduler().IssueRequests(api_);
api_ = state_->api();
api_->SetLoaderFactory(*http_loader_);
state_->scheduler().Enqueue(api_, {}, shared_from_this(),
"ipns/" + host_ + "?format=ipns-record", 3);
state_->scheduler().IssueRequests(api_);
}
void ipfs::IpnsUrlLoader::Complete() {
LOG(INFO) << "NameListener's Complete called for an IpnsLoader!";
auto* entry = state_.names().Entry(host_);
auto* entry = state_->names().Entry(host_);
DCHECK(entry);
auto caches = state_.serialized_caches();
auto caches = state_->serialized_caches();
LOG(INFO) << "Storing the resolution of ipns://" << host_ << " in "
<< caches.size() << " cache backends.";
for (auto cache : caches) {
Expand Down
Loading