From 7d49af822a7c38e0e4f5098014ba224695342aeb Mon Sep 17 00:00:00 2001 From: Essem Date: Tue, 15 Aug 2023 03:44:06 +0000 Subject: [PATCH] Add address bind config option --- .config/example.yml | 3 +++ packages/backend/src/config/types.ts | 1 + packages/backend/src/misc/fetch.ts | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/.config/example.yml b/.config/example.yml index e28a20a3c..c4c634007 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -161,6 +161,9 @@ reservedUsernames: [ # deliverJobMaxAttempts: 12 # inboxJobMaxAttempts: 8 +# Local address used for outgoing requests +#outgoingAddress: 127.0.0.1 + # IP address family used for outgoing request (ipv4, ipv6 or dual) #outgoingAddressFamily: ipv4 diff --git a/packages/backend/src/config/types.ts b/packages/backend/src/config/types.ts index 7ead804a6..52854db5a 100644 --- a/packages/backend/src/config/types.ts +++ b/packages/backend/src/config/types.ts @@ -78,6 +78,7 @@ export type Source = { fingerprint?: string; }; + outgoingAddress?: string; outgoingAddressFamily?: "ipv4" | "ipv6" | "dual"; deliverJobConcurrency?: number; diff --git a/packages/backend/src/misc/fetch.ts b/packages/backend/src/misc/fetch.ts index 0e673ba3a..e47ef0d47 100644 --- a/packages/backend/src/misc/fetch.ts +++ b/packages/backend/src/misc/fetch.ts @@ -99,6 +99,7 @@ const _http = new http.Agent({ keepAlive: true, keepAliveMsecs: 30 * 1000, lookup: cache.lookup, + localAddress: config.outgoingAddress, } as http.AgentOptions); /** @@ -108,6 +109,7 @@ const _https = new https.Agent({ keepAlive: true, keepAliveMsecs: 30 * 1000, lookup: cache.lookup, + localAddress: config.outgoingAddress, } as https.AgentOptions); const maxSockets = Math.max(256, config.deliverJobConcurrency || 128); @@ -123,6 +125,7 @@ export const httpAgent = config.proxy maxFreeSockets: 256, scheduling: "lifo", proxy: config.proxy, + localAddress: config.outgoingAddress, }) : _http; @@ -137,6 +140,7 @@ export const httpsAgent = config.proxy maxFreeSockets: 256, scheduling: "lifo", proxy: config.proxy, + localAddress: config.outgoingAddress, }) : _https;