querysub 0.280.0 → 0.282.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.280.0",
3
+ "version": "0.282.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",
@@ -403,8 +403,8 @@ export class ArchivesBackblaze {
403
403
  }
404
404
 
405
405
  let desiredCorsRules = this.config.public ? [{
406
- corsRuleName: "onlyCurrentOrigin",
407
- allowedOrigins: ["*"],
406
+ corsRuleName: "allowAll",
407
+ allowedOrigins: ["https"],
408
408
  allowedOperations: ["b2_download_file_by_id", "b2_download_file_by_name"],
409
409
  allowedHeaders: ["range"],
410
410
  exposeHeaders: ["x-bz-content-sha1"],
@@ -21,7 +21,7 @@ import { addRecord, deleteRecord, getRecords, hasDNSWritePermissions, setRecord
21
21
  import { SocketServerConfig } from "socket-function/src/webSocketServer";
22
22
  import debugbreak from "debugbreak";
23
23
  import { delay, runInfinitePoll, runInfinitePollCallAtStart } from "socket-function/src/batching";
24
- import { getDomain, isNoNetwork, isPublic } from "../config";
24
+ import { getDomain, isBootstrapOnly, 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";
@@ -250,7 +250,7 @@ async function getHTTPSKeyCertInner(callerIP: string) {
250
250
  // with our A record public while we create our cert.
251
251
  runEdgeDomainAliveLoop();
252
252
  const edgeDomain = getDomain();
253
- if (callerIP) {
253
+ if (callerIP && !isBootstrapOnly()) {
254
254
  try {
255
255
  let promises: Promise<void>[] = [];
256
256
  let existingIPs = await getRecords("A", edgeDomain);
@@ -29,6 +29,18 @@ export function startEdgeNotifier() {
29
29
  }
30
30
  void notifyClients(liveHash, refreshThresholdTime);
31
31
  });
32
+ (async () => {
33
+ await delay(1);
34
+ let { watchOnRollingUpdate } = await import("../deployManager/machineController");
35
+ watchOnRollingUpdate({
36
+ callback: (time) => {
37
+ let duration = Date.now() - time;
38
+ // Refresh 10% earlier, as we don't want clients to refresh RIGHT when the server shutsdown...
39
+ time = Date.now() + duration * 0.9;
40
+ void notifyClients(lastHashServer, time);
41
+ }
42
+ });
43
+ })();
32
44
  }
33
45
 
34
46
  let watchingClientNodes = new Set<string>();
@@ -773,7 +773,7 @@ export class Querysub {
773
773
  }
774
774
  }
775
775
 
776
- await SocketFunction.mount({
776
+ let mountedNodeId = await SocketFunction.mount({
777
777
  public: isPublic(),
778
778
  port: config.port,
779
779
  autoForwardPort: true,
@@ -785,42 +785,15 @@ export class Querysub {
785
785
  },
786
786
  allowHostnames,
787
787
  });
788
+ let port = getNodeIdLocation(mountedNodeId)?.port;
788
789
 
789
790
  let { ip, ipDomain } = await publishMachineARecords();
790
791
 
791
792
  if (!isBootstrapOnly()) {
792
793
  await registerEdgeNode({
793
- host: ipDomain + ":" + config.port,
794
+ host: ipDomain + ":" + port,
794
795
  entryPaths,
795
796
  });
796
- } else {
797
- // bootstraponly mode. Setup cloudflare proxy. If they are developing (localhost), we can't proxy, so don't (but still setup domain). Using the cloudflare proxy should prevent the site from entirely breaking if the bootstrapper goes down.
798
- let ip = await getHostedIP();
799
- let existingRecords = await getRecords("A", getDomain());
800
- if (ip !== "127.0.0.1") {
801
- let validRecords: string[] = [];
802
- // Ignore ourself, we want OTHER records.
803
- existingRecords = existingRecords.filter(x => x !== ip);
804
- await Promise.all(existingRecords.map(async (record) => {
805
- let isListening = await timeoutToUndefined(timeInSecond * 10, testTCPIsListening(record, 443));
806
- if (isListening) {
807
- validRecords.push(record);
808
- }
809
- }));
810
- // It's hard to manage multiple bootstrappers, so... just don't.
811
- if (validRecords.length > 0) {
812
- console.error(`Found existing bootstrapper at ${JSON.stringify(validRecords)}, so why are we even running? Terminating shortly`);
813
- // Give logs time to write
814
- await shutdown();
815
- }
816
- await setRecord("A", getDomain(), ip, "proxied");
817
- } else {
818
- if (existingRecords.length === 0) {
819
- await setRecord("A", ip, getDomain());
820
- } else {
821
- console.log(`Not clobbering existing A record for ${getDomain()} of ${JSON.stringify(existingRecords)}`);
822
- }
823
- }
824
797
  }
825
798
  }
826
799
  private static async addSourceMapCheck(config: {
@@ -1319,4 +1292,5 @@ import { blue } from "socket-function/src/formatting/logColors";
1319
1292
  import { MachineController } from "../deployManager/machineController";
1320
1293
  import { getRecords, setRecord } from "../-b-authorities/dnsAuthority";
1321
1294
  import { testTCPIsListening } from "socket-function/src/networking";
1295
+ import { getNodeId, getNodeIdLocation } from "socket-function/src/nodeCache";
1322
1296
 
@@ -12,6 +12,7 @@ import { getGitURLLive, setGitRef } from "../4-deploy/git";
12
12
  import os from "os";
13
13
  import { runPromise } from "../functional/runCommand";
14
14
  import { getSyncedController } from "../library-components/SyncedController";
15
+ import { logErrors } from "../errors";
15
16
 
16
17
  const POLL_INTERVAL = timeInMinute * 15;
17
18
 
@@ -35,16 +36,35 @@ export function onServiceConfigChange(callback: () => Promise<void>): () => void
35
36
  serviceConfigChangeWatchers.delete(callback);
36
37
  };
37
38
  }
39
+
40
+
41
+ let rollingUpdateWatchers = new Set<(time: number) => void>();
42
+ export function watchOnRollingUpdate(config: {
43
+ callback: (time: number) => void;
44
+ }) {
45
+ rollingUpdateWatchers.add(config.callback);
46
+ }
38
47
  class OnServiceChangeBase {
39
48
  public async onServiceConfigChange() {
40
49
  await triggerServiceConfigChangeCallbacks();
41
50
  }
51
+
52
+ public async onRollingUpdate(time: number) {
53
+ for (let callback of rollingUpdateWatchers) {
54
+ try {
55
+ callback(time);
56
+ } catch (e) {
57
+ logErrors(e);
58
+ }
59
+ }
60
+ }
42
61
  }
43
62
  export const OnServiceChange = SocketFunction.register(
44
63
  "on-service-change-aa6b4aaa-c325-4112-b2a8-f81c180016a0",
45
64
  () => new OnServiceChangeBase(),
46
65
  () => ({
47
66
  onServiceConfigChange: {},
67
+ onRollingUpdate: {},
48
68
  }),
49
69
  () => ({
50
70
  hooks: [requiresNetworkTrustHook],
@@ -52,6 +72,8 @@ export const OnServiceChange = SocketFunction.register(
52
72
  );
53
73
 
54
74
 
75
+
76
+
55
77
  class MachineControllerBase {
56
78
  // NOTE: We don't need to worry about escaping commands here. YES, the user CAN inject code into the key. But this system is literally for running arbitrary commands, so they could just write a serviceConfig and run anything they want, on all the machines...
57
79
  public async streamScreenOutput(config: {
@@ -1,3 +1,9 @@
1
+ OH! the bootstrap root index file has CORS issues
2
+ - We didn't notice this before because the cached value always worked?
3
+
4
+ The actual http registration isn't working? And our edgeNode file is so messy it's hard to see if it's there or not... ugh...
5
+
6
+
1
7
  8) Use a special service for the HTTP bootstrapper, and then have 2 others that are on other ports
2
8
  --bootstraponly is added, and should work?
3
9
 
@@ -17,8 +23,9 @@
17
23
  - Tracked per serviceId
18
24
  - Update the rolling time, so if we remove the rolling window we kill the old service immediately
19
25
  - Notify when servers are outdated
20
- - In HTTP server, notify users, in the same way we notify for hash updates, that they will need to switch servers
26
+ - After min(5 minute, 10% of rolling window size)
21
27
  - Use the node registration to know the nodeId to talk to, and allow servers to register to get told when they are outdated (and how long before they are shutdown).
28
+ - In HTTP server, notify users, in the same way we notify for hash updates, that they will need to switch servers
22
29
  - Verify this update works with a relatively low rolling update window, ensuring it force refreshes before the server actually restarts.
23
30
 
24
31
  10) Add RAM total, ram % used, cpu count, CPU %, disk size, disk % used to machine info