querysub 0.53.0 → 0.55.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "querysub",
3
- "version": "0.53.0",
3
+ "version": "0.55.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
@@ -24,7 +24,7 @@
24
24
  "node-forge": "https://github.com/sliftist/forge#e618181b469b07bdc70b968b0391beb8ef5fecd6",
25
25
  "pako": "^2.1.0",
26
26
  "preact": "^10.11.3",
27
- "socket-function": "^0.47.0",
27
+ "socket-function": "^0.50.0",
28
28
  "terser": "^5.31.0",
29
29
  "typesafecss": "^0.6.3",
30
30
  "yaml": "^2.5.0",
@@ -1,7 +1,7 @@
1
1
  import { SocketFunction } from "socket-function/SocketFunction";
2
2
  import { getArchives } from "../-a-archives/archives";
3
3
  import { getDomain, isDevDebugbreak, isNoNetwork } from "../config";
4
- import { measureWrap } from "socket-function/src/profiling/measure";
4
+ import { measureBlock, measureWrap } from "socket-function/src/profiling/measure";
5
5
  import { isNode, sha256Hash, throttleFunction, timeInMinute, timeInSecond } from "socket-function/src/misc";
6
6
  import { errorToUndefined, errorToUndefinedSilent, ignoreErrors, logErrors, timeoutToUndefined, timeoutToUndefinedSilent } from "../errors";
7
7
  import { requiresNetworkTrustHook } from "../-d-trust/NetworkTrust2";
@@ -261,7 +261,7 @@ async function syncArchives() {
261
261
  }
262
262
 
263
263
  async function runHeartbeatAuditLoop() {
264
- await onNodeDiscoveryReady();
264
+ await getAllNodeIds();
265
265
  let deadCount = new Map<string, number>();
266
266
  // 90% of the normal interval, so we don't run at the same tmie as the other audit
267
267
  await runInfinitePollCallAtStart(CHECK_INTERVAL * 0.9, async () => {
@@ -349,7 +349,7 @@ async function fastMemorySync() {
349
349
  }
350
350
 
351
351
  async function runMemoryAuditLoop() {
352
- await onNodeDiscoveryReady();
352
+ await getAllNodeIds();
353
353
  runInfinitePoll(DISK_AUDIT_RATE, syncArchives);
354
354
  runInfinitePoll(API_AUDIT_RATE, fastMemorySync);
355
355
  }
@@ -416,18 +416,14 @@ async function runMainSyncLoops(discoveryReady: PromiseObj<void>) {
416
416
  });
417
417
  }
418
418
 
419
+ let discoveryReady = new PromiseObj<void>();
420
+ beforeGetNodeAllId = async () => {
421
+ await discoveryReady.promise;
422
+ };
419
423
  export async function onNodeDiscoveryReady() {
420
- // NOTE: This isn't really early enough, especially in the browser, because a lot of calls are created
421
- // immediately on render. But... it should be good enough for now.
422
- await waitForFirstTimeSync();
423
- await getAllNodeIds();
424
+ await beforeGetNodeAllId();
424
425
  }
425
-
426
426
  if (isServer()) {
427
- let discoveryReady = new PromiseObj<void>();
428
- beforeGetNodeAllId = async () => {
429
- await discoveryReady.promise;
430
- };
431
427
  setImmediate(() => {
432
428
  logErrors(runHeartbeatAuditLoop());
433
429
  logErrors(runMemoryAuditLoop());
@@ -437,28 +433,25 @@ if (isServer()) {
437
433
  discoveryReady.reject(e);
438
434
  logErrors(Promise.reject(e));
439
435
  });
440
- // // Wait until we mount
441
- // void SocketFunction.mountPromise.finally(async () => {
442
-
443
- // });
444
436
  });
445
437
  } else {
446
- setImmediate(() => {
447
- if (isNode()) {
448
- // Just get the archives, syncing again if we haven't synced in a while
449
- let lastGetTime = 0;
450
- beforeGetNodeAllId = async () => {
451
- let lastGetThreshold = lastGetTime + CLIENTSIDE_POLL_RATE;
452
- if (Date.now() > lastGetThreshold) {
453
- lastGetTime = Date.now();
454
- await syncArchives();
455
- }
456
- };
457
- } else {
458
- let discoveryReady = new PromiseObj<void>();
438
+
439
+ if (isNode()) {
440
+ discoveryReady.resolve();
441
+ // Just get the archives, syncing again if we haven't synced in a while
442
+ let lastGetTime = 0;
443
+ beforeGetNodeAllId = async () => {
444
+ let lastGetThreshold = lastGetTime + CLIENTSIDE_POLL_RATE;
445
+ if (Date.now() > lastGetThreshold) {
446
+ lastGetTime = Date.now();
447
+ await syncArchives();
448
+ }
449
+ };
450
+ } else {
451
+ setImmediate(() => {
459
452
  let browserNodeId = getBrowserUrlNode();
460
453
  let nodes = [getBrowserUrlNode()];
461
- logErrors((async function checkForLocalHost() {
454
+ logErrors(measureWrap((async function checkForLocalHost() {
462
455
  // If there is a server at the localhost domain, AND, it's the same as the current server...
463
456
  // use that domain instead. This is just an optimization, but makes a big difference
464
457
  // when using management tools to scan the DB (otherwise the entire DB has to go through
@@ -482,12 +475,8 @@ if (isServer()) {
482
475
 
483
476
  allNodeIds2 = new Set(nodes);
484
477
  discoveryReady.resolve();
485
- })());
478
+ }))());
486
479
 
487
- // Block until we finish checking for local host
488
- beforeGetNodeAllId = async () => {
489
- await discoveryReady.promise;
490
- };
491
480
 
492
481
  // NOTE: We run into TLS issues (as in, our servers use self signed certs), if we try to talk to just
493
482
  // any node, so... we better just talk to the edge node
@@ -495,8 +484,8 @@ if (isServer()) {
495
484
  // certs (I think we can only wildcard a single depth anyways), and A records for the machines too...
496
485
  // but... having all traffic route through an edge node is probably better anyways...
497
486
  nodeOverrides = nodes;
498
- }
499
- });
487
+ });
488
+ }
500
489
  }
501
490
 
502
491
 
@@ -199,9 +199,14 @@ class NodePathAuthorities {
199
199
 
200
200
  private previouslyNotAvailableNodes = new Set<string>();
201
201
 
202
+
203
+ private BOOT_TIME = Date.now();
204
+ private d = (type: string) => console.log(`TEST | ${type} at ${formatTime(Date.now() - this.BOOT_TIME)}`);
202
205
  @measureFnc
203
206
  private async watchAuthorityPaths() {
207
+ this.d("watchAuthorityPaths");
204
208
  await onNodeDiscoveryReady();
209
+ this.d("after onNodeDiscoveryReady");
205
210
 
206
211
  onReadReady = (nodeId, time) => {
207
212
  let obj = this.authorities.get(nodeId);
@@ -219,6 +224,7 @@ class NodePathAuthorities {
219
224
  logErrors(firstPromise.promise);
220
225
 
221
226
  const ingestNewNodeIds = (newNodeIds: string[], removedNodeIds: string[]) => {
227
+ this.d("ingestNewNodeIds");
222
228
  for (let nodeId of removedNodeIds) {
223
229
  this.authorities.delete(nodeId);
224
230
  }
@@ -308,6 +314,8 @@ class NodePathAuthorities {
308
314
  watchDeltaNodeIds(obj => ingestNewNodeIds(obj.newNodeIds, obj.removedNodeIds));
309
315
  await firstPromise.promise;
310
316
 
317
+ this.d("after firstPromise");
318
+
311
319
  let recoveryIndex = 0;
312
320
  runInfinitePoll(INITIAL_RECOVERY_POLL_INTERVAL, async () => {
313
321
  // Wait longer the more times we loop. This allows us to reconnect quickly on startup
@@ -39,7 +39,7 @@ import { minify_sync } from "terser";
39
39
  import { isClient } from "../config2";
40
40
  import { remoteWatcher } from "../1-path-client/RemoteWatcher";
41
41
  import { waitForFirstTimeSync } from "socket-function/time/trueTimeShim";
42
- import { measureFnc } from "socket-function/src/profiling/measure";
42
+ import { measureBlock, measureFnc } from "socket-function/src/profiling/measure";
43
43
  import { delay } from "socket-function/src/batching";
44
44
  import { MaybePromise } from "socket-function/src/types";
45
45
  import { devDebugbreak, getDomain, isDevDebugbreak, isNoNetwork, isPublic } from "../config";
@@ -200,7 +200,9 @@ export class Querysub {
200
200
  */
201
201
  @measureFnc
202
202
  public static async optionalStartupWait() {
203
- await waitForFirstTimeSync();
203
+ await measureBlock(async () => {
204
+ await waitForFirstTimeSync();
205
+ }, "waitForFirstTimeSync");
204
206
  await nodePathAuthority.waitUntilRoutingIsReady();
205
207
  }
206
208