From f6298af4c4222a12b3c90e2916af2d0f0b654932 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Fri, 16 Nov 2018 17:28:01 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=8E=20Switch=20to=20master=20source=20?= =?UTF-8?q?if=20CDN=20too=20slow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cdn/downloadWrapper.ts | 9 ++++++--- src/cdn/heartbeatDns.ts | 3 ++- src/interfaces/PatchMasterSource.ts | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 src/interfaces/PatchMasterSource.ts diff --git a/src/cdn/downloadWrapper.ts b/src/cdn/downloadWrapper.ts index b1854b8..cd2b658 100644 --- a/src/cdn/downloadWrapper.ts +++ b/src/cdn/downloadWrapper.ts @@ -1,5 +1,6 @@ import * as os from 'os'; import * as nodePath from 'path'; +import patchMasterSource from '../interfaces/PatchMasterSource'; import downloadWithCurl from './downloadWithCurl'; import checkLocalCache from './funcs/checkLocalCache'; import createDirRecursively from './funcs/createDirRecursively'; @@ -21,10 +22,12 @@ export default async function downloadWrapper({ host, path, size }: {host: strin } //Download via curl - //Try up to ten times - for (let i = 0; i < 10; i += 1) { + //Try up to 15 times + for (let i = 0; i < 15; i += 1) { try { - const downloadResult = await downloadWithCurl({ host, path, tempFileName }); + //After five tries from CDN, switch to master source + const currentHost = (host === 'cdn-patch.swtor.com' && i >= 5 ? patchMasterSource : host); + const downloadResult = await downloadWithCurl({ host: currentHost, path, tempFileName }); return downloadResult; } catch (err) { console.error(err); diff --git a/src/cdn/heartbeatDns.ts b/src/cdn/heartbeatDns.ts index e9185e2..7529ee0 100644 --- a/src/cdn/heartbeatDns.ts +++ b/src/cdn/heartbeatDns.ts @@ -1,4 +1,5 @@ import { IServerEntry } from '../interfaces/IDnsResult'; +import patchMasterSource from '../interfaces/PatchMasterSource'; import resolveDns from './funcs/resolveDns'; /** Time when this script started, for delta time calculations */ @@ -8,7 +9,7 @@ let lastUpdate = 0; /** List of servers, sorted by reliability */ let servers: IServerEntry[] = []; //the master source is included by default -servers.push({ ip: '159.153.92.51', type: 'master', lastSeen: Infinity, weight: Infinity }); +servers.push({ ip: patchMasterSource, type: 'master', lastSeen: Infinity, weight: Infinity }); /** Updates the list of servers based on current DNS data */ async function heartbeatDns(domain: string) { diff --git a/src/interfaces/PatchMasterSource.ts b/src/interfaces/PatchMasterSource.ts new file mode 100644 index 0000000..9342b37 --- /dev/null +++ b/src/interfaces/PatchMasterSource.ts @@ -0,0 +1,2 @@ +/** The master server hosting the patch files. */ +export default '159.153.92.51';