querysub 0.33.0 → 0.35.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.33.0",
3
+ "version": "0.35.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",
@@ -174,7 +174,7 @@ const IdentityController = SocketFunction.register(
174
174
  })
175
175
  );
176
176
 
177
- const changeIdentityOnce = cache(measureWrap(async function changeIdentityOnce(connectionId: { nodeId: string }) {
177
+ const changeIdentityOnce = cache(async function changeIdentityOnce(connectionId: { nodeId: string }) {
178
178
  let nodeId = connectionId.nodeId;
179
179
  let threadKeyCert = getThreadKeyCert();
180
180
  let issuer = getIdentityCA();
@@ -191,7 +191,7 @@ const changeIdentityOnce = cache(measureWrap(async function changeIdentityOnce(c
191
191
  IdentityController.nodes[nodeId].changeIdentity(signature, payload),
192
192
  () => new Error(`Timeout calling changeIdentity for ${nodeId}`)
193
193
  );
194
- }));
194
+ });
195
195
  SocketFunction.addGlobalClientHook(async function identityHook(context) {
196
196
  if (context.call.classGuid === IdentityController._classGuid) return;
197
197
  // If we are talking to a client they should already know who we are (they established the connection!)
@@ -228,6 +228,14 @@ export function getBrowserUrlNode() {
228
228
  return rootLocation;
229
229
  }
230
230
 
231
+ export async function triggerNodeChange() {
232
+ await syncNodesNow();
233
+ await Promise.allSettled(Array.from(allNodeIds2).map(async nodeId => {
234
+ if (isOwnNodeId(nodeId)) return;
235
+ await timeoutToUndefinedSilent(timeInSecond * 5, errorToUndefinedSilent(NodeDiscoveryController.nodes[nodeId].addNode(getOwnNodeId())));
236
+ }));
237
+ }
238
+
231
239
  let seenNodesForEvilDNS = new Set<string>();
232
240
  async function syncArchives() {
233
241
  if (isServer()) {
@@ -267,8 +275,10 @@ async function runHeartbeatAuditLoop() {
267
275
  // We spent the money checking the node list, so we might as well update it
268
276
  setNodeIds(nodeIds);
269
277
 
278
+ let pendingDeadCount = 0;
279
+
270
280
  let removedNodeIds: string[] = [];
271
- for (let nodeId of nodeIds) {
281
+ await Promise.all(nodeIds.map(async nodeId => {
272
282
  let lastTime = Number((await archives().get(nodeId))?.toString()) || 0;
273
283
  if (lastTime < deadTime) {
274
284
  // Increment the dead count
@@ -282,14 +292,20 @@ async function runHeartbeatAuditLoop() {
282
292
  deadCount.delete(nodeId);
283
293
  } else {
284
294
  console.log(yellow(`Node ${nodeId} was found to be dead, last heartbeat at ${formatDateTime(lastTime)} < dead threshold at ${formatDateTime(deadTime)}, dead count ${count}/${DEAD_CHECK_COUNT}. Total nodes seen ${nodeIds.length}`));
295
+ pendingDeadCount++;
285
296
  }
286
297
  } else {
287
298
  deadCount.delete(nodeId);
288
299
  diskLog("Read node heartbeat", { nodeId, lastTime });
289
300
  }
301
+ }));
302
+ if (pendingDeadCount) {
303
+ console.log(blue(`Pending dead nodes ${pendingDeadCount}/${nodeIds.length}`));
290
304
  }
291
305
 
292
306
  if (removedNodeIds.length > 0) {
307
+ console.log(blue(`Removed ${removedNodeIds.length}/${nodeIds.length} nodes from node list`), { removedNodeIds });
308
+ await syncArchives();
293
309
  void tellEveryoneNodesChanges();
294
310
  }
295
311
  });
@@ -2,7 +2,7 @@ import { SocketFunction } from "socket-function/SocketFunction";
2
2
  import { measureFnc, measureWrap } from "socket-function/src/profiling/measure";
3
3
  import { errorToUndefined, errorToUndefinedSilent, ignoreErrors, logErrors, timeoutToUndefined, timeoutToUndefinedSilent } from "../errors";
4
4
  import { PromiseObj } from "../promise";
5
- import { getAllNodeIds, getBrowserUrlNode, getOwnNodeId, isNodeDiscoveryLogging, isOwnNodeId, onNodeDiscoveryReady, watchDeltaNodeIds, watchNodeIds } from "../-f-node-discovery/NodeDiscovery";
5
+ import { getAllNodeIds, getBrowserUrlNode, getOwnNodeId, isNodeDiscoveryLogging, isOwnNodeId, onNodeDiscoveryReady, triggerNodeChange, watchDeltaNodeIds, watchNodeIds } from "../-f-node-discovery/NodeDiscovery";
6
6
  import { PathValueController } from "./PathValueController";
7
7
  import { MAX_ACCEPTED_AUTHORITY_STARTUP_TIME, PathValueSnapshot, STARTUP_CUTOFF_TIME, authorityStorage, matchesParentRangeFilterPart } from "./pathValueCore";
8
8
  import { pathValueArchives } from "./pathValueArchives";
@@ -453,6 +453,8 @@ class NodePathAuthorities {
453
453
  for (let nodeId of await getAllNodeIds()) {
454
454
  ignoreErrors(PathController.nodes[nodeId].broadcastReadReady(readyTime));
455
455
  }
456
+ // Tell all nodes we exist, in case we started at the same time.
457
+ await triggerNodeChange();
456
458
 
457
459
  if (this.getSelfAuthorities().length > 0) {
458
460
  console.log(green(`Became an authority for:`));