Skip to content

Commit

Permalink
TestContext might work now.
Browse files Browse the repository at this point in the history
  • Loading branch information
John-LittleBearLabs committed Jan 31, 2024
1 parent 33700c6 commit 5973fe3
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 57 deletions.
7 changes: 3 additions & 4 deletions component/cache_requestor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ std::shared_ptr<dc::Entry> 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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions component/chromium_ipfs_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion component/dns_txt_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Self::DnsTxtRequest(std::string host,
Self::~DnsTxtRequest() {}

void Self::OnTextResults(std::vector<std::string> 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,
Expand Down
2 changes: 1 addition & 1 deletion component/inter_request_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<ipfs::InterRequestState>(c->GetPath(), p);
c->SetUserData(user_data_key, std::move(owned));
}
Expand Down
6 changes: 3 additions & 3 deletions component/ipfs_url_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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});
Expand Down
42 changes: 21 additions & 21 deletions library/src/ipfs_client/gateways.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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}};
}
6 changes: 3 additions & 3 deletions library/src/ipfs_client/gw/dnslink_requestor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ bool parse_results(ipfs::gw::RequestPtr req,
std::vector<std::string> const& results,
std::shared_ptr<ipfs::ContextApi> 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 {
Expand Down
8 changes: 4 additions & 4 deletions library/src/ipfs_client/gw/gateway_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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<ipld::DnsLinkName>(bytes);
if (orchestrator_) {
success = orchestrator_->add_node(main_param, node);
Expand Down
5 changes: 1 addition & 4 deletions library/src/ipfs_client/gw/multi_gateway_requestor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions library/src/ipfs_client/ipns_record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<ipfs::Byte const*>(signature_str.data()),
signature_str.size()};
Expand Down Expand Up @@ -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;
}

Expand Down
10 changes: 2 additions & 8 deletions library/src/ipfs_client/orchestrator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ void Self::from_tree(std::shared_ptr<IpfsRequest> req,
req->finish(Response::IMMUTABLY_GONE);
} else {
auto& mps = std::get<ipld::MoreDataNeeded>(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);
})) {
Expand All @@ -108,7 +104,6 @@ bool Self::gw_request(std::shared_ptr<IpfsRequest> 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());
Expand All @@ -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_);
Expand Down
4 changes: 1 addition & 3 deletions library/src/ipfs_client/test_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand 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_);
Expand Down

0 comments on commit 5973fe3

Please sign in to comment.