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

[WIP] add ignoreRedirect flag in p2pConfig to skip redirect #327

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct P2PConfig : public ConfigUtils::Config {
APPCFG_CLASS

APPCFG_PARA(enable, bool, false);
APPCFG_PARA(ignoreRedirect, bool, false);
APPCFG_PARA(address, std::string, "http://localhost:9731/accelerator");
};

Expand Down
2 changes: 1 addition & 1 deletion src/image_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ int ImageService::init() {
bool ImageService::enable_acceleration() {
auto conf = global_conf.p2pConfig();
if (conf.enable() && check_accelerate_url(conf.address())) {
((RegistryFS*)global_fs.underlay_registryfs)->setAccelerateAddress(conf.address().c_str());
((RegistryFS*)global_fs.underlay_registryfs)->setAccelerateAddress(conf.ignoreRedirect(), conf.address().c_str());
global_fs.remote_fs = global_fs.srcfs;
return true;
} else {
Expand Down
27 changes: 17 additions & 10 deletions src/overlaybd/registryfs/registryfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,21 @@ class RegistryFSImpl : public RegistryFS {
long GET(const char *url, photon::net::HeaderMap *headers, off_t offset, size_t count,
photon::net::IOVWriter *writer, uint64_t timeout) {
Timeout tmo(timeout);
long ret = 0;
UrlInfo *actual_info = m_url_info.acquire(url, [&]() -> UrlInfo * {
return getActualUrl(url, tmo.timeout(), ret);
});
if (actual_info == nullptr)
return ret;
const char *actual_url = url;

const char *actual_url = url;
if (actual_info->mode == UrlMode::Redirect)
actual_url = actual_info->info.data();
// skip resolving source url if p2p is enabled and ignoreRedirect is set to true
if !(m_accelerate.size() > 0 && m_ignoreRedirect) {
long ret = 0;
UrlInfo *actual_info = m_url_info.acquire(url, [&]() -> UrlInfo * {
return getActualUrl(url, tmo.timeout(), ret);
});
if (actual_info == nullptr)
return ret;

if (actual_info->mode == UrlMode::Redirect)
actual_url = actual_info->info.data();
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getActualUrl() will get the 'Bearer Token' and put it to HTTP Header, see
https://github.com/containerd/overlaybd/blob/main/src/overlaybd/registryfs/registryfs.cpp#L145

If ignoreRedirect is true,
overlaybd will send the request URL to Kraken listened port without any authentication ? is this what you want?

//use p2p proxy
estring accelerate_url;
if (m_accelerate.size() > 0) {
Expand Down Expand Up @@ -253,7 +258,8 @@ class RegistryFSImpl : public RegistryFS {
LOG_ERROR_RETURN(0, nullptr, "Failed to get actual url ", VALUE(url), VALUE(ret));
}

virtual int setAccelerateAddress(const char* addr = "") override {
virtual int setAccelerateAddress(const bool ignoreRedirect, const char* addr = "") override {
m_ignoreRedirect = ignoreRedirect;
m_accelerate = estring(addr);
return 0;
}
Expand All @@ -262,6 +268,7 @@ class RegistryFSImpl : public RegistryFS {
using CURLPool = IdentityPool<photon::net::cURL, 4>;
CURLPool m_curl_pool;
PasswordCB m_callback;
bool m_ignoreRedirect;
estring m_accelerate;
estring m_caFile;
uint64_t m_timeout;
Expand Down
Loading