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';