-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made some requestors. PoolRequestor now retries. Tweaks necessary.
- Loading branch information
1 parent
a9677d8
commit 4ef85ac
Showing
85 changed files
with
15,676 additions
and
556 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ __pycache__ | |
CMakeLists.txt.user | ||
CMakeUserPresets.json | ||
*.orig | ||
.*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include "block_http_request.h" | ||
|
||
#include <services/network/public/cpp/resource_request.h> | ||
#include <services/network/public/cpp/simple_url_loader.h> | ||
#include <services/network/public/mojom/url_response_head.mojom.h> | ||
|
||
using Self = ipfs::BlockHttpRequest; | ||
|
||
namespace { | ||
constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation = | ||
net::DefineNetworkTrafficAnnotation("ipfs_gateway_request", R"( | ||
semantics { | ||
sender: "IPFS component" | ||
description: | ||
"Sends a request to an IPFS gateway." | ||
trigger: | ||
"Processing of an ipfs:// or ipns:// URL." | ||
data: "None" | ||
destination: WEBSITE | ||
} | ||
policy { | ||
cookies_allowed: NO | ||
setting: "EnableIpfs" | ||
} | ||
)"); | ||
} | ||
|
||
Self::BlockHttpRequest(ipfs::HttpRequestDescription req_inf, | ||
HttpCompleteCallback cb) | ||
: inf_{req_inf}, callback_{cb} {} | ||
Self::~BlockHttpRequest() noexcept {} | ||
|
||
void Self::send(raw_ptr<network::mojom::URLLoaderFactory> loader_factory) { | ||
auto req = std::make_unique<network::ResourceRequest>(); | ||
req->url = GURL{inf_.url}; | ||
req->priority = net::HIGHEST; // TODO | ||
if (!inf_.accept.empty()) { | ||
VLOG(2) << inf_.url << " has Accept header " << inf_.accept; | ||
req->headers.SetHeader("Accept", inf_.accept); | ||
} | ||
using L = network::SimpleURLLoader; | ||
loader_ = L::Create(std::move(req), kTrafficAnnotation, FROM_HERE); | ||
loader_->SetTimeoutDuration(base::Seconds(inf_.timeout_seconds)); | ||
loader_->SetAllowHttpErrorResults(true); | ||
auto bound = base::BindOnce(&Self::OnResponse, base::Unretained(this), | ||
shared_from_this()); | ||
DCHECK(loader_factory); | ||
loader_->DownloadToString(loader_factory, std::move(bound), | ||
gw::BLOCK_RESPONSE_BUFFER_SIZE); | ||
} | ||
void Self::OnResponse(std::shared_ptr<Self>, | ||
std::unique_ptr<std::string> body) { | ||
DCHECK(loader_); | ||
int status = loader_->NetError() ? 500 : 200; | ||
ContextApi::HeaderAccess header_accessor = [](auto) { return std::string{}; }; | ||
auto sz = body ? body->size() : 0UL; | ||
VLOG(1) << "Handling HTTP response body of size " << sz << " with NetErr " | ||
<< loader_->NetError() << " for " << inf_.url; | ||
auto const* head = loader_->ResponseInfo(); | ||
if (head) { | ||
DCHECK(head->headers); | ||
auto status_line = head->headers->GetStatusLine(); | ||
auto sp = status_line.find(' '); | ||
if (sp < status_line.size()) { | ||
VLOG(1) << "HTTP response status='" << status_line << "'."; | ||
status = std::atoi(status_line.c_str() + sp + 1); | ||
} else { | ||
LOG(WARNING) << "Status line malformed."; | ||
} | ||
header_accessor = [head](std::string_view k) { | ||
std::string val; | ||
head->headers->EnumerateHeader(nullptr, k, &val); | ||
return val; | ||
}; | ||
} else { | ||
LOG(WARNING) << "No response header info?"; | ||
} | ||
if (body) { | ||
callback_(status, *body, header_accessor); | ||
} else { | ||
callback_(status, "", header_accessor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef IPFS_BLOCK_HTTP_REQUEST_H_ | ||
#define IPFS_BLOCK_HTTP_REQUEST_H_ | ||
|
||
#include <ipfs_client/gw/gateway_request.h> | ||
|
||
#include <ipfs_client/context_api.h> | ||
|
||
namespace network { | ||
struct ResourceRequest; | ||
class SimpleURLLoader; | ||
} // namespace network | ||
namespace network::mojom { | ||
class URLLoaderFactory; | ||
} | ||
|
||
namespace ipfs { | ||
class BlockHttpRequest : public std::enable_shared_from_this<BlockHttpRequest> { | ||
// TODO ween oneself off of SimpleURLLoader | ||
// std::array<char, gw::BLOCK_RESPONSE_BUFFER_SIZE> buffer_; | ||
std::unique_ptr<network::SimpleURLLoader> loader_; | ||
|
||
public: | ||
using HttpCompleteCallback = ipfs::ContextApi::HttpCompleteCallback; | ||
BlockHttpRequest(ipfs::HttpRequestDescription, HttpCompleteCallback); | ||
~BlockHttpRequest() noexcept; | ||
|
||
void send(raw_ptr<network::mojom::URLLoaderFactory>); | ||
|
||
private: | ||
ipfs::HttpRequestDescription const inf_; | ||
HttpCompleteCallback callback_; | ||
|
||
void OnResponse(std::shared_ptr<BlockHttpRequest>, | ||
std::unique_ptr<std::string> body); | ||
}; | ||
} // namespace ipfs | ||
|
||
#endif // IPFS_BLOCK_HTTP_REQUEST_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.