querysub 0.74.0 → 0.76.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.74.0",
3
+ "version": "0.76.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",
@@ -25,6 +25,9 @@ import { getDomain, isNoNetwork, isPublic } from "../config";
25
25
  import { requiresNetworkTrustHook } from "../-d-trust/NetworkTrust2";
26
26
  import { getExternalIP, testTCPIsListening } from "../misc/networking";
27
27
  import { magenta, yellow } from "socket-function/src/formatting/logColors";
28
+ import { timeInMinute, timeInSecond } from "socket-function/src/misc";
29
+ import { nodeDiscoveryShutdown } from "../-f-node-discovery/NodeDiscovery";
30
+ import { shutdown } from "../diagnostics/periodic";
28
31
 
29
32
  let publicPort = -1;
30
33
 
@@ -187,6 +190,9 @@ const runEdgeDomainAliveLoop = lazy(() => {
187
190
  async function checkEdgeDomainsAlive() {
188
191
  if (isNoNetwork()) return;
189
192
  if (publicPort === -1) return;
193
+ // Only check once we are actually running on real sites (not just developer sites, which
194
+ // use non-port 443)
195
+ if (publicPort !== 443) return;
190
196
  const edgeDomain = getDomain();
191
197
  let ips = await getRecords("A", edgeDomain);
192
198
  // Don't check 127.0.0.1, if we are in development this will still be set,
@@ -199,7 +205,7 @@ async function checkEdgeDomainsAlive() {
199
205
 
200
206
  let deadIPs = ips.filter((ip, i) => !results[i]);
201
207
  if (deadIPs.length > 0) {
202
- console.log(`Found dead IPs for ${edgeDomain}:${publicPort}, removing their A records: ${JSON.stringify(deadIPs)}`);
208
+ console.error(`Found dead IPs for ${edgeDomain}:${publicPort}, removing their A records: ${JSON.stringify(deadIPs)}`);
203
209
  }
204
210
  for (let deadIP of deadIPs) {
205
211
  await deleteRecord("A", edgeDomain, deadIP);
@@ -239,6 +245,13 @@ async function getHTTPSKeyCertInner(callerIP: string) {
239
245
  promises.push(deleteRecord("A", edgeDomain, "127.0.0.1"));
240
246
  }
241
247
  promises.push(addRecord("A", edgeDomain, callerIP));
248
+ runInfinitePoll(timeInMinute * 5, async () => {
249
+ let ips = await getRecords("A", edgeDomain);
250
+ if (!ips.includes(callerIP)) {
251
+ console.error(`Our A record for ${edgeDomain} is no longer pointing to our ip (${callerIP}, as it is now pointing to ${JSON.stringify(ips)}). Terminating, hopefully when we restart we will fix it. This SHOULDN'T happen often!`);
252
+ await shutdown();
253
+ }
254
+ });
242
255
  }
243
256
  promises.push(addRecord("A", "noproxy." + edgeDomain, "127.0.0.1"));
244
257
  promises.push(addRecord("A", "127-0-0-1." + edgeDomain, "127.0.0.1"));
@@ -96,6 +96,9 @@ class NodePathAuthorities {
96
96
  public getAuthorityPaths(nodeId: string) {
97
97
  return this.authorities.get(nodeId)?.authorityPaths;
98
98
  }
99
+ public debug_getAllAuthorities() {
100
+ return Array.from(this.authorities.values());
101
+ }
99
102
 
100
103
  public readonly createTime = Date.now();
101
104
  constructor() {
@@ -163,6 +163,8 @@ export class RemoteWatcher {
163
163
  let newDisconnectParents = 0;
164
164
  let foundPaths = 0;
165
165
  let foundParentPaths = 0;
166
+
167
+ let totalMissingPaths = 0;
166
168
  measureBlock(() => {
167
169
  for (let path of config.paths) {
168
170
  // IMPORTANT! We have to await, otherwise we might see the paths are watched, skip them
@@ -177,6 +179,11 @@ export class RemoteWatcher {
177
179
 
178
180
  let authorityId = pathValueAuthority2.getSingleReadNodeSync(path);
179
181
  if (!authorityId) {
182
+ if (totalMissingPaths === 0) {
183
+ let authorities = pathValueAuthority2.debug_getAllAuthorities();
184
+ console.warn(`Missing authority for path ${path}`, { authorities });
185
+ }
186
+ totalMissingPaths++;
180
187
  if (!this.disconnectedPaths.has(path)) {
181
188
  newDisconnectPaths++;
182
189
  this.disconnectedPaths.add(path);
@@ -294,7 +301,7 @@ export class RemoteWatcher {
294
301
  }, `watchLatest|getSingleReadNode`);
295
302
 
296
303
  if (newDisconnectPaths > 0 || newDisconnectParents > 0) {
297
- console.log(yellow(`Some paths have no authority. We will search for an authority periodically until we find an authority. New missing ${newDisconnectPaths} paths and ${newDisconnectParents} parent paths, total missing ${this.disconnectedPaths.size} paths and ${this.disconnectedParents.size} parent paths.`));
304
+ console.warn(`Some paths have no authority. We will search for an authority periodically until we find an authority. New missing ${newDisconnectPaths} paths and ${newDisconnectParents} parent paths, total missing ${this.disconnectedPaths.size} paths and ${this.disconnectedParents.size} parent paths.`);
298
305
  let first10 = Array.from(this.disconnectedPaths).slice(0, 10);
299
306
  for (let path of first10) {
300
307
  console.log(`\t${path}`);
@@ -32,7 +32,7 @@ import { pathValueCommitter } from "../0-path-value-core/PathValueCommitter";
32
32
  import debugbreak from "debugbreak";
33
33
  import { extractPublicKey, verifyED25519 } from "../-a-auth/ed25519";
34
34
  import { registerDynamicResource, registerResource } from "../diagnostics/trackResources";
35
- import { registerPeriodic } from "../diagnostics/periodic";
35
+ import { registerPeriodic, shutdown } from "../diagnostics/periodic";
36
36
  import { sha256 } from "js-sha256";
37
37
  import { green, red } from "socket-function/src/formatting/logColors";
38
38
  import { minify_sync } from "terser";
@@ -78,6 +78,7 @@ export class Querysub {
78
78
  public static createElement = qreact.createElement;
79
79
  public static Fragment = qreact.Fragment;
80
80
  public static t = t;
81
+ public static shutdown = () => shutdown();
81
82
  /**
82
83
  IMPORTANT! New schemas must be deployed by calling `yarn deploy`
83
84
 
@@ -24,7 +24,7 @@ function logAll() {
24
24
 
25
25
  logErrors(runInfinitePollCallAtStart(timeInMinute * 5, logAll));
26
26
 
27
- async function shutdown() {
27
+ export async function shutdown() {
28
28
  const { authorityStorage } = await import("../0-path-value-core/pathValueCore");
29
29
  try {
30
30
  await authorityStorage.onShutdown();
@@ -66,7 +66,7 @@ function getBufferUsage() {
66
66
 
67
67
  registerDynamicResource("Heap", getUsedHeapSize);
68
68
  registerDynamicResource("Buffers", getBufferUsage);
69
- registerDynamicResource("All Memory", getHeapSize);
69
+ registerDynamicResource("Used Memory", getHeapSize);
70
70
 
71
71
  function logResourcesNow() {
72
72
  let resourcesWithCounts = resources.map(resource => ({ ...resource, count: resource.getCount() }));