mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2024-11-23 18:03:44 +03:00
Add retries (not tested)
This commit is contained in:
parent
da7701393e
commit
699bef6fea
|
@ -60,7 +60,38 @@
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const tryPromiseSeveralTimesAsync = (createPromise, timeoutsInSec) =>
|
||||||
|
createPromise().then(
|
||||||
|
(res) => Promise.resolve(res),
|
||||||
|
(err) => {
|
||||||
|
console.log('Promise failed, are there any retries?');
|
||||||
|
const outSec = timeoutsInSec.shift();
|
||||||
|
if (outSec === undefined) {
|
||||||
|
console.log('No retries left.');
|
||||||
|
return Promise.reject(err);
|
||||||
|
}
|
||||||
|
console.log('Retrying in', outSec, 'sec');
|
||||||
|
/*
|
||||||
|
const alarmName = 'try-promise=several-times-async';
|
||||||
|
const res = new Promise((resolve) => {
|
||||||
|
chrome.alarms.onAlarm.addListener((alarmInfo) => {
|
||||||
|
if (alarmInfo.name === alarmName) {
|
||||||
|
console.log('Time to retry.');
|
||||||
|
resolve(tryPromiseSeveralTimesAsync(createPromise, timeoutsInSec));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
chrome.alarms.create(alarmName, { delayInMinutes: outSec/60 });
|
||||||
|
return res;
|
||||||
|
*/
|
||||||
|
return new Promise((resolve) =>
|
||||||
|
window.setTimeout(() => resolve(tryPromiseSeveralTimesAsync(createPromise, timeoutsInSec)), outSec*1000),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const doWithoutProxyAsync = (createPromise) => new Promise((resolve, reject) => {
|
const doWithoutProxyAsync = (createPromise) => new Promise((resolve, reject) => {
|
||||||
|
console.log('Doing without proxy...');
|
||||||
chrome.proxy.settings.get({}, chromified((getErr, settings) => {
|
chrome.proxy.settings.get({}, chromified((getErr, settings) => {
|
||||||
if (getErr) {
|
if (getErr) {
|
||||||
reject(getErr);
|
reject(getErr);
|
||||||
|
@ -147,7 +178,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const setPacScriptFromProviderAsync = function setPacScriptFromProviderAsync(
|
const setPacScriptFromProviderAsync = function setPacScriptFromProviderAsync(
|
||||||
provider, lastModifiedStr = mandatory(), cb = throwIfError,
|
provider, lastModifiedStr, ifUnattended = mandatory(), cb = throwIfError,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const pacUrl = provider.pacUrls[0];
|
const pacUrl = provider.pacUrls[0];
|
||||||
|
@ -182,11 +213,10 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Doing without proxy...');
|
doWithoutProxyAsync(
|
||||||
const pacDataPromise = doWithoutProxyAsync(
|
|
||||||
// Employ all urls, the latter are fallbacks for the former.
|
// Employ all urls, the latter are fallbacks for the former.
|
||||||
() =>
|
() => {
|
||||||
provider.pacUrls.reduce(
|
const tryAllUrlsAsync = () => provider.pacUrls.reduce(
|
||||||
(promise, url) => promise.catch(
|
(promise, url) => promise.catch(
|
||||||
() => new Promise(
|
() => new Promise(
|
||||||
(resolve, reject) => httpLib.get(
|
(resolve, reject) => httpLib.get(
|
||||||
|
@ -197,13 +227,18 @@
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Promise.reject(),
|
Promise.reject(),
|
||||||
|
);
|
||||||
|
return (ifUnattended
|
||||||
|
? tryPromiseSeveralTimesAsync(tryAllUrlsAsync, [10, 20, 30])
|
||||||
|
: tryAllUrlsAsync()
|
||||||
).catch(
|
).catch(
|
||||||
(err) => Promise.reject(clarify(
|
(err) => Promise.reject(clarify(
|
||||||
err,
|
err,
|
||||||
chrome.i18n.getMessage('FailedToDownloadPacScriptFromAddresses') + ': [ '
|
chrome.i18n.getMessage('FailedToDownloadPacScriptFromAddresses') + ': [ '
|
||||||
+ provider.pacUrls.join(' , ') + ' ].',
|
+ provider.pacUrls.join(' , ') + ' ].',
|
||||||
)),
|
)),
|
||||||
),
|
);
|
||||||
|
},
|
||||||
).then(
|
).then(
|
||||||
(pacData) => {
|
(pacData) => {
|
||||||
setPacAsync(
|
setPacAsync(
|
||||||
|
@ -240,7 +275,7 @@
|
||||||
<br/> <a href="https://rebrand.ly/ac-pacs">Comparison of PAC-scripts (ru)</a>.
|
<br/> <a href="https://rebrand.ly/ac-pacs">Comparison of PAC-scripts (ru)</a>.
|
||||||
\`,
|
\`,
|
||||||
order: 0,
|
order: 0,
|
||||||
pacUrls: ['https://antizapret.prostovpn.org/proxy.pac'],
|
pacUrls: ['https://AAAAAAAAAantizapret.prostovpn.org/proxy.pac'],
|
||||||
},
|
},
|
||||||
Антицензорити: {
|
Антицензорити: {
|
||||||
distinctKey: 'Anticensority',
|
distinctKey: 'Anticensority',
|
||||||
|
@ -390,12 +425,13 @@
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
syncWithPacProviderAsync(
|
syncWithPacProviderAsync(opts = {}, cb = throwIfError) {
|
||||||
key = this.currentPacProvierKey, cb = throwIfError) {
|
const optsDefaults = Object.freeze({ key: this.getCurrentPacProviderKey(), ifUnattended: false });
|
||||||
if( typeof(key) === 'function' ) {
|
if( typeof(opts) === 'function' ) {
|
||||||
cb = key;
|
cb = opts;
|
||||||
key = this.getCurrentPacProviderKey();
|
opts = {};
|
||||||
}
|
}
|
||||||
|
let { key, ifUnattended } = { ...optsDefaults, ...opts };
|
||||||
cb = asyncLogGroup('Syncing with PAC provider ' + key + '...', cb);
|
cb = asyncLogGroup('Syncing with PAC provider ' + key + '...', cb);
|
||||||
|
|
||||||
if (key === null) {
|
if (key === null) {
|
||||||
|
@ -405,10 +441,13 @@
|
||||||
|
|
||||||
const pacProvider = this.getPacProvider(key);
|
const pacProvider = this.getPacProvider(key);
|
||||||
|
|
||||||
|
ifUnattended = true; // TODO:
|
||||||
|
|
||||||
const pacSetPromise = new Promise(
|
const pacSetPromise = new Promise(
|
||||||
(resolve, reject) => setPacScriptFromProviderAsync(
|
(resolve, reject) => setPacScriptFromProviderAsync(
|
||||||
pacProvider,
|
pacProvider,
|
||||||
this.getLastModifiedForKey(key),
|
this.getLastModifiedForKey(key),
|
||||||
|
ifUnattended,
|
||||||
(err, res, ...warns) => {
|
(err, res, ...warns) => {
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
|
@ -425,12 +464,16 @@
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const ipsErrorPromise = new Promise(
|
const updateIpsAsync = () => new Promise(
|
||||||
(resolve, reject) => updatePacProxyIps(
|
(resolve, reject) => updatePacProxyIps(
|
||||||
resolve,
|
resolve,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const ipsErrorPromise = !ifUnattended
|
||||||
|
? updateIpsAsync()
|
||||||
|
: tryPromiseSeveralTimesAsync(updateIpsAsync, [10, 20, 30]);
|
||||||
|
|
||||||
Promise.all([pacSetPromise, ipsErrorPromise]).then(
|
Promise.all([pacSetPromise, ipsErrorPromise]).then(
|
||||||
([[pacErr, pacRes, ...pacWarns], ipsErr]) => {
|
([[pacErr, pacRes, ...pacWarns], ipsErr]) => {
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@
|
||||||
const promises = types.map(
|
const promises = types.map(
|
||||||
(type) => new Promise((resolve) =>
|
(type) => new Promise((resolve) =>
|
||||||
httpLib.get(
|
httpLib.get(
|
||||||
`https://dns.google.com/resolve?type=${type}&name=${host}&random_padding=${generateRandomHexString(30,500)}`,
|
`https://AAAAAAAAAdns.google.com/resolve?type=${type}&name=${host}&random_padding=${generateRandomHexString(30,500)}`,
|
||||||
(err, res) => {
|
(err, res) => {
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user