Skip to content

Commit

Permalink
Enable VPNLess support for Metro remote manifold cache
Browse files Browse the repository at this point in the history
Summary: Metro's manifold cache can be accessed via x2p. To have full remote cache capabilities off of vpn, we're wiring this up.

Reviewed By: robhogan

Differential Revision: D62574948

fbshipit-source-id: 3efbfa64fa6c859eb2bc12df525a328e206e5efe
  • Loading branch information
GijsWeterings authored and facebook-github-bot committed Oct 2, 2024
1 parent 03724c0 commit b7a0790
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/metro-cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"exponential-backoff": "^3.1.1",
"flow-enums-runtime": "^0.0.6",
"https-proxy-agent": "^7.0.5",
"metro-core": "0.80.11"
},
"devDependencies": {
Expand Down
20 changes: 17 additions & 3 deletions packages/metro-cache/src/stores/HttpStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const NetworkError = require('./NetworkError');
const {backOff} = require('exponential-backoff');
const http = require('http');
const https = require('https');
const url = require('url');
// $FlowFixMe[untyped-import] https-proxy-agent is not flow typed
// $FlowFixMe[cannot-resolve-module] https-proxy-agent is not flow typed
const {HttpsProxyAgent} = require('https-proxy-agent');
const zlib = require('zlib');

export type Options =
Expand Down Expand Up @@ -46,6 +48,8 @@ type EndpointOptions = {
maxAttempts?: number,
retryNetworkErrors?: boolean,
retryStatuses?: $ReadOnlySet<number>,
socketPath?: string,
proxy?: string,
};

type Endpoint = {
Expand Down Expand Up @@ -115,19 +119,29 @@ class HttpStore<T> {
agentConfig.ca = options.ca;
}

const uri = url.parse(options.endpoint);
if (options.socketPath != null) {
// $FlowFixMe `socketPath` is missing in the Flow definition
agentConfig.socketPath = options.socketPath;
}

const uri = new URL(options.endpoint);
const module = uri.protocol === 'http:' ? http : https;

let agent = new module.Agent(agentConfig);
if (options.proxy != null) {
agent = new HttpsProxyAgent(options.proxy, agentConfig);
}

if (!uri.hostname || !uri.pathname) {
throw new TypeError('Invalid endpoint: ' + options.endpoint);
}

return {
agent,
headers: options.headers,
host: uri.hostname,
path: uri.pathname,
port: +uri.port,
agent: new module.Agent(agentConfig),
params: new URLSearchParams(options.params),
timeout: options.timeout || 5000,
module: uri.protocol === 'http:' ? http : https,
Expand Down
27 changes: 27 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,13 @@ acorn@^8.9.0:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.10.0.tgz#8be5b3907a67221a81ab23c7889c4c5526b62ec5"
integrity sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==

agent-base@^7.0.2:
version "7.1.1"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-7.1.1.tgz#bdbded7dfb096b751a2a087eeeb9664725b2e317"
integrity sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==
dependencies:
debug "^4.3.4"

ajv@^6.12.4:
version "6.12.6"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4"
Expand Down Expand Up @@ -2277,6 +2284,13 @@ [email protected], debug@^2.2.0, debug@^2.6.9:
dependencies:
ms "2.0.0"

debug@4:
version "4.3.7"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.7.tgz#87945b4151a011d76d95a198d7111c865c360a52"
integrity sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==
dependencies:
ms "^2.1.3"

debug@^3.2.7:
version "3.2.7"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.7.tgz#72580b7e9145fb39b6676f9c5e5fb100b934179a"
Expand Down Expand Up @@ -3255,6 +3269,14 @@ html-escaper@^2.0.0:
resolved "https://registry.yarnpkg.com/html-escaper/-/html-escaper-2.0.0.tgz#71e87f931de3fe09e56661ab9a29aadec707b491"
integrity sha512-a4u9BeERWGu/S8JiWEAQcdrg9v4QArtP9keViQjGMdff20fBdd8waotXaNmODqBe6uZ3Nafi7K/ho4gCQHV3Ig==

https-proxy-agent@^7.0.5:
version "7.0.5"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-7.0.5.tgz#9e8b5013873299e11fab6fd548405da2d6c602b2"
integrity sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw==
dependencies:
agent-base "^7.0.2"
debug "4"

human-signals@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
Expand Down Expand Up @@ -4488,6 +4510,11 @@ [email protected], ms@^2.1.1:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==

ms@^2.1.3:
version "2.1.3"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==

natural-compare@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
Expand Down

0 comments on commit b7a0790

Please sign in to comment.