Use createHTTPSAgent for all requests
This commit is contained in:
parent
15e1d6e441
commit
f8c4e392fe
3 changed files with 47 additions and 42 deletions
|
@ -1367,13 +1367,17 @@ export function initialize({
|
||||||
log.warn(`${logId}: Done`);
|
log.warn(`${logId}: Done`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let fetchForLinkPreviews: linkPreviewFetch.FetchFn;
|
let fetchAgent: Agent;
|
||||||
if (proxyUrl) {
|
if (proxyUrl) {
|
||||||
const agent = createProxyAgent(proxyUrl);
|
fetchAgent = createProxyAgent(proxyUrl);
|
||||||
fetchForLinkPreviews = (href, init) => fetch(href, { ...init, agent });
|
|
||||||
} else {
|
} else {
|
||||||
fetchForLinkPreviews = fetch;
|
fetchAgent = createHTTPSAgent({
|
||||||
|
keepAlive: false,
|
||||||
|
maxCachedSessions: 0,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
const fetchForLinkPreviews: linkPreviewFetch.FetchFn = (href, init) =>
|
||||||
|
fetch(href, { ...init, agent: fetchAgent });
|
||||||
|
|
||||||
// Thanks, function hoisting!
|
// Thanks, function hoisting!
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -33,6 +33,28 @@ const CONNECT_TIMEOUT_MS = 10 * SECOND;
|
||||||
|
|
||||||
const electronLookup = promisify(electronLookupWithCb);
|
const electronLookup = promisify(electronLookupWithCb);
|
||||||
|
|
||||||
|
const HOST_LOG_ALLOWLIST = new Set([
|
||||||
|
// Production
|
||||||
|
'chat.signal.org',
|
||||||
|
'storage.signal.org',
|
||||||
|
'cdsi.signal.org',
|
||||||
|
'cdn.signal.org',
|
||||||
|
'cdn2.signal.org',
|
||||||
|
'create.signal.art',
|
||||||
|
|
||||||
|
// Staging
|
||||||
|
'chat.staging.signal.org',
|
||||||
|
'storage-staging.signal.org',
|
||||||
|
'cdsi.staging.signal.org',
|
||||||
|
'cdn-staging.signal.org',
|
||||||
|
'cdn2-staging.signal.org',
|
||||||
|
'create.staging.signal.art',
|
||||||
|
|
||||||
|
// Common
|
||||||
|
'updates2.signal.org',
|
||||||
|
'sfu.voip.signal.org',
|
||||||
|
]);
|
||||||
|
|
||||||
export class Agent extends HTTPSAgent {
|
export class Agent extends HTTPSAgent {
|
||||||
constructor(options: AgentOptions = {}) {
|
constructor(options: AgentOptions = {}) {
|
||||||
super({
|
super({
|
||||||
|
@ -65,16 +87,18 @@ export class Agent extends HTTPSAgent {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const duration = Date.now() - start;
|
if (HOST_LOG_ALLOWLIST.has(host)) {
|
||||||
const logLine =
|
const duration = Date.now() - start;
|
||||||
`createHTTPSAgent.createConnection(${host}): connected to ` +
|
const logLine =
|
||||||
`IPv${address.family} addr after ${duration}ms ` +
|
`createHTTPSAgent.createConnection(${host}): connected to ` +
|
||||||
`(attempts v4=${v4Attempts} v6=${v6Attempts})`;
|
`IPv${address.family} addr after ${duration}ms ` +
|
||||||
|
`(attempts v4=${v4Attempts} v6=${v6Attempts})`;
|
||||||
|
|
||||||
if (v4Attempts + v6Attempts > 1 || duration > CONNECT_THRESHOLD_MS) {
|
if (v4Attempts + v6Attempts > 1 || duration > CONNECT_THRESHOLD_MS) {
|
||||||
log.warn(logLine);
|
log.warn(logLine);
|
||||||
} else {
|
} else {
|
||||||
log.info(logLine);
|
log.info(logLine);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return socket;
|
return socket;
|
||||||
|
|
|
@ -1,36 +1,18 @@
|
||||||
// Copyright 2023 Signal Messenger, LLC
|
// Copyright 2023 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import type { LookupOneOptions, LookupAllOptions, LookupAddress } from 'dns';
|
import type {
|
||||||
import { lookup as nodeLookup } from 'dns';
|
LookupOneOptions,
|
||||||
|
LookupAllOptions,
|
||||||
|
LookupAddress,
|
||||||
|
lookup as nodeLookup,
|
||||||
|
} from 'dns';
|
||||||
import { ipcRenderer, net } from 'electron';
|
import { ipcRenderer, net } from 'electron';
|
||||||
import type { ResolvedHost } from 'electron';
|
import type { ResolvedHost } from 'electron';
|
||||||
|
|
||||||
import { strictAssert } from './assert';
|
import { strictAssert } from './assert';
|
||||||
import { drop } from './drop';
|
import { drop } from './drop';
|
||||||
|
|
||||||
const HOST_ALLOWLIST = new Set([
|
|
||||||
// Production
|
|
||||||
'chat.signal.org',
|
|
||||||
'storage.signal.org',
|
|
||||||
'cdsi.signal.org',
|
|
||||||
'cdn.signal.org',
|
|
||||||
'cdn2.signal.org',
|
|
||||||
'create.signal.art',
|
|
||||||
|
|
||||||
// Staging
|
|
||||||
'chat.staging.signal.org',
|
|
||||||
'storage-staging.signal.org',
|
|
||||||
'cdsi.staging.signal.org',
|
|
||||||
'cdn-staging.signal.org',
|
|
||||||
'cdn2-staging.signal.org',
|
|
||||||
'create.staging.signal.art',
|
|
||||||
|
|
||||||
// Common
|
|
||||||
'updates2.signal.org',
|
|
||||||
'sfu.voip.signal.org',
|
|
||||||
]);
|
|
||||||
|
|
||||||
function lookupAll(
|
function lookupAll(
|
||||||
hostname: string,
|
hostname: string,
|
||||||
opts: LookupOneOptions | LookupAllOptions,
|
opts: LookupOneOptions | LookupAllOptions,
|
||||||
|
@ -40,11 +22,6 @@ function lookupAll(
|
||||||
family?: number
|
family?: number
|
||||||
) => void
|
) => void
|
||||||
): void {
|
): void {
|
||||||
if (!HOST_ALLOWLIST.has(hostname)) {
|
|
||||||
nodeLookup(hostname, opts, callback);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Node.js support various signatures, but we only support one.
|
// Node.js support various signatures, but we only support one.
|
||||||
strictAssert(typeof opts === 'object', 'missing options');
|
strictAssert(typeof opts === 'object', 'missing options');
|
||||||
strictAssert(typeof callback === 'function', 'missing callback');
|
strictAssert(typeof callback === 'function', 'missing callback');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue