querysub 0.76.0 → 0.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -185,7 +185,7 @@ const runEdgeDomainAliveLoop = lazy(() => {
|
|
|
185
185
|
// NOTE: Our DNS TTL is 1 minute, which means no matter how fast we poll,
|
|
186
186
|
// we can't get below that. Of course the worst case is that + our poll rate,
|
|
187
187
|
// but still, this means there is less and less benefit the lower this value is.
|
|
188
|
-
runInfinitePoll(
|
|
188
|
+
runInfinitePoll(timeInMinute, checkEdgeDomainsAlive);
|
|
189
189
|
});
|
|
190
190
|
async function checkEdgeDomainsAlive() {
|
|
191
191
|
if (isNoNetwork()) return;
|
|
@@ -200,7 +200,12 @@ async function checkEdgeDomainsAlive() {
|
|
|
200
200
|
ips = ips.filter(ip => ip !== "127.0.0.1");
|
|
201
201
|
|
|
202
202
|
let results = await Promise.all(ips.map(async ip => {
|
|
203
|
-
|
|
203
|
+
// It must be not listening for 3 times in a row
|
|
204
|
+
for (let i = 0; i < 3; i++) {
|
|
205
|
+
let isListening = await testTCPIsListening(ip, publicPort);
|
|
206
|
+
if (isListening) return true;
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
204
209
|
}));
|
|
205
210
|
|
|
206
211
|
let deadIPs = ips.filter((ip, i) => !results[i]);
|
|
@@ -213,6 +218,25 @@ async function checkEdgeDomainsAlive() {
|
|
|
213
218
|
}
|
|
214
219
|
|
|
215
220
|
async function getHTTPSKeyCertInner(callerIP: string) {
|
|
221
|
+
let cert = await getBaseCert();
|
|
222
|
+
// If the cert is 50% expired generate a new one
|
|
223
|
+
let certObj = parseCert(cert.cert);
|
|
224
|
+
|
|
225
|
+
// Get expiration date
|
|
226
|
+
let expirationTime = +new Date(certObj.validity.notAfter);
|
|
227
|
+
let createTime = +new Date(certObj.validity.notBefore);
|
|
228
|
+
|
|
229
|
+
// If 50% of the lifetime has passed, renew the cert
|
|
230
|
+
let renewDate = createTime + (expirationTime - createTime) * 0.5;
|
|
231
|
+
if (renewDate < Date.now()) {
|
|
232
|
+
console.log(`HTTPS certificate is looking too old, forcefully renewing`);
|
|
233
|
+
getHTTPSKeyCert.clear(getDomain());
|
|
234
|
+
getBaseCert = createGetBaseCert();
|
|
235
|
+
cert = await getBaseCert();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// IMPORTANT! We have to set our A record AFTER we create our cert, otherwise we might wait a while
|
|
239
|
+
// with our A record public while we create our cert.
|
|
216
240
|
runEdgeDomainAliveLoop();
|
|
217
241
|
const edgeDomain = getDomain();
|
|
218
242
|
if (callerIP) {
|
|
@@ -262,23 +286,6 @@ async function getHTTPSKeyCertInner(callerIP: string) {
|
|
|
262
286
|
}
|
|
263
287
|
}
|
|
264
288
|
|
|
265
|
-
let cert = await getBaseCert();
|
|
266
|
-
// If the cert is 50% expired generate a new one
|
|
267
|
-
let certObj = parseCert(cert.cert);
|
|
268
|
-
|
|
269
|
-
// Get expiration date
|
|
270
|
-
let expirationTime = +new Date(certObj.validity.notAfter);
|
|
271
|
-
let createTime = +new Date(certObj.validity.notBefore);
|
|
272
|
-
|
|
273
|
-
// If 50% of the lifetime has passed, renew the cert
|
|
274
|
-
let renewDate = createTime + (expirationTime - createTime) * 0.5;
|
|
275
|
-
if (renewDate < Date.now()) {
|
|
276
|
-
console.log(`HTTPS certificate is looking too old, forcefully renewing`);
|
|
277
|
-
getHTTPSKeyCert.clear(getDomain());
|
|
278
|
-
getBaseCert = createGetBaseCert();
|
|
279
|
-
cert = await getBaseCert();
|
|
280
|
-
}
|
|
281
|
-
|
|
282
289
|
return cert;
|
|
283
290
|
}
|
|
284
291
|
|