diff --git a/backend/mempool-config.sample.json b/backend/mempool-config.sample.json index 19758c0ed..625886f13 100644 --- a/backend/mempool-config.sample.json +++ b/backend/mempool-config.sample.json @@ -18,6 +18,7 @@ "EXTERNAL_ASSETS": [], "EXTERNAL_MAX_RETRY": 10, "EXTERNAL_RETRY_INTERVAL": 60, + "USER_AGENT": "mempool", "STDOUT_LOG_MIN_PRIORITY": "debug" }, "CORE_RPC": { diff --git a/backend/src/api/bisq/bisq.ts b/backend/src/api/bisq/bisq.ts index 332dd5e81..dcde77b06 100644 --- a/backend/src/api/bisq/bisq.ts +++ b/backend/src/api/bisq/bisq.ts @@ -8,6 +8,7 @@ import { BisqBlocks, BisqBlock, BisqTransaction, BisqStats, BisqTrade } from './ import { Common } from '../common'; import { BlockExtended } from '../../mempool.interfaces'; import { StaticPool } from 'node-worker-threads-pool'; +import backendInfo from '../backend-info'; import logger from '../../logger'; class Bisq { @@ -148,13 +149,22 @@ class Bisq { } private async updatePrice() { type axiosOptions = { + headers: { + 'User-Agent': string + }; + timeout: number; httpAgent?: http.Agent; httpsAgent?: https.Agent; } const setDelay = (secs: number = 1): Promise => new Promise(resolve => setTimeout(() => resolve(), secs * 1000)); const BISQ_URL = (config.SOCKS5PROXY.ENABLED === true) && (config.SOCKS5PROXY.USE_ONION === true) ? config.PRICE_DATA_SERVER.BISQ_ONION : config.PRICE_DATA_SERVER.BISQ_URL; const isHTTP = (new URL(BISQ_URL).protocol.split(':')[0] === 'http') ? true : false; - const axiosOptions: axiosOptions = {}; + const axiosOptions: axiosOptions = { + headers: { + 'User-Agent': (config.MEMPOOL.USER_AGENT === 'mempool') ? `mempool/v${backendInfo.getBackendInfo().version}` : `${config.MEMPOOL.USER_AGENT}` + }, + timeout: config.SOCKS5PROXY.ENABLED ? 30000 : 10000 + }; let retry = 0; if (config.SOCKS5PROXY.ENABLED) { diff --git a/backend/src/api/fiat-conversion.ts b/backend/src/api/fiat-conversion.ts index 5bc664099..fb8717d78 100644 --- a/backend/src/api/fiat-conversion.ts +++ b/backend/src/api/fiat-conversion.ts @@ -55,7 +55,7 @@ class FiatConversion { const isHTTP = (new URL(fiatConversionUrl).protocol.split(':')[0] === 'http') ? true : false; const axiosOptions: axiosOptions = { headers: { - 'User-Agent': `mempool/v${backendInfo.getBackendInfo().version}` + 'User-Agent': (config.MEMPOOL.USER_AGENT === 'mempool') ? `mempool/v${backendInfo.getBackendInfo().version}` : `${config.MEMPOOL.USER_AGENT}` }, timeout: config.SOCKS5PROXY.ENABLED ? 30000 : 10000 }; diff --git a/backend/src/config.ts b/backend/src/config.ts index 8295faeaa..c3d3a45a7 100644 --- a/backend/src/config.ts +++ b/backend/src/config.ts @@ -20,6 +20,7 @@ interface IConfig { EXTERNAL_ASSETS: string[]; EXTERNAL_MAX_RETRY: number; EXTERNAL_RETRY_INTERVAL: number; + USER_AGENT: string; STDOUT_LOG_MIN_PRIORITY: 'emerg' | 'alert' | 'crit' | 'err' | 'warn' | 'notice' | 'info' | 'debug'; }; ESPLORA: { @@ -108,6 +109,7 @@ const defaults: IConfig = { 'EXTERNAL_ASSETS': [], 'EXTERNAL_MAX_RETRY': 10, 'EXTERNAL_RETRY_INTERVAL': 60, + 'USER_AGENT': 'mempool', 'STDOUT_LOG_MIN_PRIORITY': 'debug', }, 'ESPLORA': { diff --git a/backend/src/sync-assets.ts b/backend/src/sync-assets.ts index 74d15e901..f4cc1f266 100644 --- a/backend/src/sync-assets.ts +++ b/backend/src/sync-assets.ts @@ -1,6 +1,7 @@ import axios, { AxiosResponse } from 'axios'; import * as fs from 'fs'; import config from './config'; +import backendInfo from './api/backend-info'; import logger from './logger'; import { SocksProxyAgent } from 'socks-proxy-agent'; @@ -42,6 +43,9 @@ class SyncAssets { logger.info(`Downloading external asset ${fileName} over the Tor network...`); return axios.get(url, { + headers: { + 'User-Agent': (config.MEMPOOL.USER_AGENT === 'mempool') ? `mempool/v${backendInfo.getBackendInfo().version}` : `${config.MEMPOOL.USER_AGENT}` + }, httpAgent: agent, httpsAgent: agent, responseType: 'stream', @@ -57,6 +61,9 @@ class SyncAssets { } else { logger.info(`Downloading external asset ${fileName} over clearnet...`); return axios.get(url, { + headers: { + 'User-Agent': (config.MEMPOOL.USER_AGENT === 'mempool') ? `mempool/v${backendInfo.getBackendInfo().version}` : `${config.MEMPOOL.USER_AGENT}` + }, responseType: 'stream', timeout: 30000 }).then(function (response) { diff --git a/backend/src/tasks/pools-updater.ts b/backend/src/tasks/pools-updater.ts index 6ff56548d..6140c3ed3 100644 --- a/backend/src/tasks/pools-updater.ts +++ b/backend/src/tasks/pools-updater.ts @@ -2,6 +2,7 @@ import axios, { AxiosResponse } from 'axios'; import poolsParser from '../api/pools-parser'; import config from '../config'; import DB from '../database'; +import backendInfo from '../api/backend-info'; import logger from '../logger'; import { SocksProxyAgent } from 'socks-proxy-agent'; import * as https from 'https'; @@ -113,10 +114,19 @@ class PoolsUpdater { */ private async query(path): Promise { type axiosOptions = { + headers: { + 'User-Agent': string + }; + timeout: number; httpsAgent?: https.Agent; } const setDelay = (secs: number = 1): Promise => new Promise(resolve => setTimeout(() => resolve(), secs * 1000)); - const axiosOptions: axiosOptions = {}; + const axiosOptions: axiosOptions = { + headers: { + 'User-Agent': (config.MEMPOOL.USER_AGENT === 'mempool') ? `mempool/v${backendInfo.getBackendInfo().version}` : `${config.MEMPOOL.USER_AGENT}` + }, + timeout: config.SOCKS5PROXY.ENABLED ? 30000 : 10000 + }; let retry = 0; if (config.SOCKS5PROXY.ENABLED) {