Skip to content

Commit

Permalink
Fixes #39
Browse files Browse the repository at this point in the history
  • Loading branch information
John-LittleBearLabs committed Nov 8, 2023
1 parent 1c78f9c commit a08e2c9
Show file tree
Hide file tree
Showing 10 changed files with 486 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmake/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def electron_version(self, branch='main'):
def unavailable(self):
avail = list(map(as_int, self.available()))
version_set = {}
fuzz = 115
fuzz = 117
def check(version, version_set, s):
i = as_int(version)
by = (fuzz,0)
Expand Down
6 changes: 4 additions & 2 deletions component/gateway_requests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,14 @@ std::string Self::MimeType(std::string extension,
} else {
result.clear();
}
if (net::SniffMimeType({content.data(), content.size()}, GURL{url}, result,
auto head_size = std::min(content.size(), 2'000'000UL);
if (net::SniffMimeType({content.data(), head_size}, GURL{url}, result,
net::ForceSniffFileUrlsForHtml::kDisabled, &result)) {
VLOG(1) << "Got " << result << " from content of " << url;
}
if (result.empty() || result == "application/octet-stream") {
// C'mon, man
net::SniffMimeTypeFromLocalData({content.data(), content.size()}, &result);
net::SniffMimeTypeFromLocalData({content.data(), head_size}, &result);
LOG(INFO) << "Falling all the way back to content type " << result;
}
return result;
Expand Down Expand Up @@ -330,3 +331,4 @@ Self::~GatewayRequests() {
Self::GatewayUrlLoader::GatewayUrlLoader(BusyGateway&& bg)
: GatewayRequest(std::move(bg)) {}
Self::GatewayUrlLoader::~GatewayUrlLoader() noexcept {}

439 changes: 439 additions & 0 deletions component/patches/121.0.6103.3.patch

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions library/BUILD.gn.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ if (enable_ipfs) {
sources = cxx_sources - [
"src/ipfs_client/block_storage.cc",
"src/ipfs_client/dag_block.cc",
"src/ipfs_client/gw/gateway_request.cc",
"src/ipfs_client/gw/requestor.cc",
"src/ipfs_client/ipld/dag_node.cc",
"src/ipfs_client/ipns_names.cc",
"src/ipfs_client/ipns_record.cc",
Expand Down
3 changes: 3 additions & 0 deletions library/include/ipfs_client/gw/gateway_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ struct GatewayRequest {
std::string_view identity_data() const;
bool is_http() const;
std::optional<std::size_t> max_response_size() const;
std::string debug_string() const;

static std::shared_ptr<GatewayRequest> fromIpfsPath(SlashDelimited);
};

} // namespace ipfs::gw

std::ostream& operator<<(std::ostream&, ipfs::gw::Type);

#endif // IPFS_TRUSTLESS_REQUEST_H_
2 changes: 1 addition & 1 deletion library/include/ipfs_client/gw/requestor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace ipfs::ipld {
class DagNode;
}
namespace ipfs {
class Response;
struct Response;
} // namespace ipfs

namespace ipfs::gw {
Expand Down
2 changes: 1 addition & 1 deletion library/include/ipfs_client/ipns_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace libp2p::peer {
class PeerId;
}
namespace libp2p::multi {
class ContentIdentifier;
struct ContentIdentifier;
}

namespace ipfs {
Expand Down
27 changes: 27 additions & 0 deletions library/src/ipfs_client/gw/gateway_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,30 @@ std::optional<std::size_t> Self::max_response_size() const {
return std::nullopt;
}
}
std::ostream& operator<<(std::ostream& s, ipfs::gw::Type t) {
using ipfs::gw::Type;
switch (t) {
case Type::Block:
return s << "Block";
case Type::Car:
return s << "Car";
case Type::Ipns:
return s << "Ipns";
case Type::DnsLink:
return s << "DnsLink";
case Type::Providers:
return s << "Providers";
case Type::Identity:
return s << "Identity";
default:
return s << "InvalidType=" << static_cast<long>(t);
}
}
std::string Self::debug_string() const {
std::ostringstream oss;
oss << "Request{Type=" << type << ' ' << main_param;
if (!path.empty()) {
oss << ' ' << path;
}
return oss.str();
}
17 changes: 7 additions & 10 deletions library/src/ipfs_client/gw/requestor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ Self& Self::or_else(std::shared_ptr<Self> p) {
}
return *this;
}
template <class Stream>
Stream& operator<<(Stream s, ipfs::gw::GatewayRequest const& r) {
return s << static_cast<int>(r.type) << ' ' << r.main_param << ' ' << r.path;
}

void Self::request(ReqPtr req) {
switch (handle(req)) {
case HandleOutcome::NOT_HANDLED:
Expand All @@ -38,22 +35,22 @@ void Self::request(ReqPtr req) {
} else {
LOG(ERROR) << "Ran out of Requestors in the chain while looking for "
"one that can handle Request{type="
<< *req;
<< req->debug_string();
definitive_failure(req);
}
break;
case HandleOutcome::PENDING:
VLOG(1) << *req << " sent via requestor " << name();
VLOG(1) << req->debug_string() << " sent via requestor " << name();
break;
case HandleOutcome::DONE:
LOG(INFO) << *req << " finished synchronously: " << name();
LOG(INFO) << req->debug_string() << " finished synchronously: " << name();
break;
}
}
void Self::failure(ipfs::gw::RequestPtr r) const {
if (next_) {
LOG(WARNING) << name() << " failed on " << *r << " ... passing along to "
<< next_->name();
LOG(WARNING) << name() << " failed on " << r->debug_string()
<< " ... passing along to " << next_->name();
next_->request(r);
} else {
definitive_failure(r);
Expand Down Expand Up @@ -91,7 +88,7 @@ void Self::iterate_nodes(
void Self::receive_response(ipfs::gw::RequestPtr req,
ipfs::Response const& res) const {
if (!req->orchestrator) {
LOG(ERROR) << name() << ": Got response for " << *req
LOG(ERROR) << name() << ": Got response for " << req->debug_string()
<< " but it doesn't have its orchestrator pointer set, so can't "
"deliver response.";
return;
Expand Down
2 changes: 1 addition & 1 deletion library/src/ipfs_client/ipns_record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ auto ipfs::ValidatedIpns::operator=(ValidatedIpns const&)
ipfs::ValidatedIpns::ValidatedIpns(IpnsCborEntry const& e)
: value{e.value}, sequence{e.sequence} {
std::istringstream ss{e.validity};
std::tm t;
std::tm t = {};
ss >> std::get_time(&t, "%Y-%m-%dT%H:%M:%S");
long ttl = (e.ttl / 1'000'000'000UL) + 1;
use_until = std::mktime(&t);
Expand Down

0 comments on commit a08e2c9

Please sign in to comment.