querysub 0.34.0 → 0.36.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.34.0",
3
+ "version": "0.36.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!)
@@ -267,6 +267,7 @@ async function runHeartbeatAuditLoop() {
267
267
  await runInfinitePollCallAtStart(CHECK_INTERVAL * 0.9, async () => {
268
268
  if (shutdown) return;
269
269
  // Wait a bit longer, to try to prevent all nodes from synchronizing their audit times.
270
+ console.log(magenta(`Auditing node list`));
270
271
  await delay(CHECK_INTERVAL * Math.random() * 0.1);
271
272
  //console.log(magenta(`Auditing node list`));
272
273
 
@@ -275,8 +276,10 @@ async function runHeartbeatAuditLoop() {
275
276
  // We spent the money checking the node list, so we might as well update it
276
277
  setNodeIds(nodeIds);
277
278
 
279
+ let pendingDeadCount = 0;
280
+
278
281
  let removedNodeIds: string[] = [];
279
- for (let nodeId of nodeIds) {
282
+ await Promise.all(nodeIds.map(async nodeId => {
280
283
  let lastTime = Number((await archives().get(nodeId))?.toString()) || 0;
281
284
  if (lastTime < deadTime) {
282
285
  // Increment the dead count
@@ -290,15 +293,21 @@ async function runHeartbeatAuditLoop() {
290
293
  deadCount.delete(nodeId);
291
294
  } else {
292
295
  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}`));
296
+ pendingDeadCount++;
293
297
  }
294
298
  } else {
295
299
  deadCount.delete(nodeId);
296
300
  diskLog("Read node heartbeat", { nodeId, lastTime });
297
301
  }
302
+ }));
303
+ if (pendingDeadCount) {
304
+ console.log(blue(`Pending dead nodes ${pendingDeadCount}/${nodeIds.length}`));
298
305
  }
299
306
 
300
307
  if (removedNodeIds.length > 0) {
301
- void tellEveryoneNodesChanges();
308
+ console.log(blue(`Removed ${removedNodeIds.length}/${nodeIds.length} nodes from node list`), { removedNodeIds });
309
+ await syncArchives();
310
+ await tellEveryoneNodesChanges();
302
311
  }
303
312
  });
304
313
  }