From 40bfc6bff3c8fef0dc9a1f13f02b9a137f82c7ec Mon Sep 17 00:00:00 2001 From: Ayanami Date: Mon, 23 May 2022 20:05:32 +0900 Subject: [PATCH] Include SocksProxyAgent inside while loop To address error Socks5 proxy rejected connection - Failure --- backend/src/api/bisq/bisq.ts | 44 +++++++++++++++--------------- backend/src/api/fiat-conversion.ts | 44 +++++++++++++++--------------- backend/src/tasks/pools-updater.ts | 34 +++++++++++------------ 3 files changed, 61 insertions(+), 61 deletions(-) diff --git a/backend/src/api/bisq/bisq.ts b/backend/src/api/bisq/bisq.ts index 10b011b37..4e2eb5fdd 100644 --- a/backend/src/api/bisq/bisq.ts +++ b/backend/src/api/bisq/bisq.ts @@ -167,30 +167,30 @@ class Bisq { }; let retry = 0; - if (config.SOCKS5PROXY.ENABLED) { - const socksOptions: any = { - agentOptions: { - keepAlive: true, - }, - hostname: config.SOCKS5PROXY.HOST, - port: config.SOCKS5PROXY.PORT - }; - - if (config.SOCKS5PROXY.USERNAME && config.SOCKS5PROXY.PASSWORD) { - socksOptions.username = config.SOCKS5PROXY.USERNAME; - socksOptions.password = config.SOCKS5PROXY.PASSWORD; - } - - // Handle proxy agent for onion addresses - if (isHTTP) { - axiosOptions.httpAgent = new SocksProxyAgent(socksOptions); - } else { - axiosOptions.httpsAgent = new SocksProxyAgent(socksOptions); - } - } - while(retry < config.MEMPOOL.EXTERNAL_MAX_RETRY) { try { + if (config.SOCKS5PROXY.ENABLED) { + const socksOptions: any = { + agentOptions: { + keepAlive: true, + }, + hostname: config.SOCKS5PROXY.HOST, + port: config.SOCKS5PROXY.PORT + }; + + if (config.SOCKS5PROXY.USERNAME && config.SOCKS5PROXY.PASSWORD) { + socksOptions.username = config.SOCKS5PROXY.USERNAME; + socksOptions.password = config.SOCKS5PROXY.PASSWORD; + } + + // Handle proxy agent for onion addresses + if (isHTTP) { + axiosOptions.httpAgent = new SocksProxyAgent(socksOptions); + } else { + axiosOptions.httpsAgent = new SocksProxyAgent(socksOptions); + } + } + const data: AxiosResponse = await axios.get(`${BISQ_URL}/trades/?market=bsq_btc`, axiosOptions); if (data.statusText === 'error' || !data.data) { throw new Error(`Could not fetch data from Bisq market, Error: ${data.status}`); diff --git a/backend/src/api/fiat-conversion.ts b/backend/src/api/fiat-conversion.ts index fb8717d78..e8a504eb7 100644 --- a/backend/src/api/fiat-conversion.ts +++ b/backend/src/api/fiat-conversion.ts @@ -62,30 +62,30 @@ class FiatConversion { let retry = 0; - if (config.SOCKS5PROXY.ENABLED) { - let socksOptions: any = { - agentOptions: { - keepAlive: true, - }, - hostname: config.SOCKS5PROXY.HOST, - port: config.SOCKS5PROXY.PORT - }; - - if (config.SOCKS5PROXY.USERNAME && config.SOCKS5PROXY.PASSWORD) { - socksOptions.username = config.SOCKS5PROXY.USERNAME; - socksOptions.password = config.SOCKS5PROXY.PASSWORD; - } - - // Handle proxy agent for onion addresses - if (isHTTP) { - axiosOptions.httpAgent = new SocksProxyAgent(socksOptions); - } else { - axiosOptions.httpsAgent = new SocksProxyAgent(socksOptions); - } - } - while(retry < config.MEMPOOL.EXTERNAL_MAX_RETRY) { try { + if (config.SOCKS5PROXY.ENABLED) { + let socksOptions: any = { + agentOptions: { + keepAlive: true, + }, + hostname: config.SOCKS5PROXY.HOST, + port: config.SOCKS5PROXY.PORT + }; + + if (config.SOCKS5PROXY.USERNAME && config.SOCKS5PROXY.PASSWORD) { + socksOptions.username = config.SOCKS5PROXY.USERNAME; + socksOptions.password = config.SOCKS5PROXY.PASSWORD; + } + + // Handle proxy agent for onion addresses + if (isHTTP) { + axiosOptions.httpAgent = new SocksProxyAgent(socksOptions); + } else { + axiosOptions.httpsAgent = new SocksProxyAgent(socksOptions); + } + } + logger.debug('Querying currency rates service...'); const response: AxiosResponse = await axios.get(`${fiatConversionUrl}`, axiosOptions); diff --git a/backend/src/tasks/pools-updater.ts b/backend/src/tasks/pools-updater.ts index 6140c3ed3..0211948d6 100644 --- a/backend/src/tasks/pools-updater.ts +++ b/backend/src/tasks/pools-updater.ts @@ -129,25 +129,25 @@ class PoolsUpdater { }; let retry = 0; - if (config.SOCKS5PROXY.ENABLED) { - const socksOptions: any = { - agentOptions: { - keepAlive: true, - }, - hostname: config.SOCKS5PROXY.HOST, - port: config.SOCKS5PROXY.PORT - }; - - if (config.SOCKS5PROXY.USERNAME && config.SOCKS5PROXY.PASSWORD) { - socksOptions.username = config.SOCKS5PROXY.USERNAME; - socksOptions.password = config.SOCKS5PROXY.PASSWORD; - } - - axiosOptions.httpsAgent = new SocksProxyAgent(socksOptions); - } - while(retry < config.MEMPOOL.EXTERNAL_MAX_RETRY) { try { + if (config.SOCKS5PROXY.ENABLED) { + const socksOptions: any = { + agentOptions: { + keepAlive: true, + }, + hostname: config.SOCKS5PROXY.HOST, + port: config.SOCKS5PROXY.PORT + }; + + if (config.SOCKS5PROXY.USERNAME && config.SOCKS5PROXY.PASSWORD) { + socksOptions.username = config.SOCKS5PROXY.USERNAME; + socksOptions.password = config.SOCKS5PROXY.PASSWORD; + } + + axiosOptions.httpsAgent = new SocksProxyAgent(socksOptions); + } + const data: AxiosResponse = await axios.get(path, axiosOptions); if (data.statusText === 'error' || !data.data) { throw new Error(`Could not fetch data from Github, Error: ${data.status}`);