querysub 0.128.0 → 0.129.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.128.0",
3
+ "version": "0.129.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",
@@ -303,6 +303,17 @@ async function edgeNodeFunction(config: {
303
303
 
304
304
  // I guess... only allow private nodes, if they specify the exact host (which would match above).
305
305
  edgeNodes = edgeNodes.filter(x => x.public);
306
+ if (edgeNodes.length === 0) {
307
+ throw new Error(`No public nodes found`);
308
+ }
309
+
310
+ let liveNodes = edgeNodes.filter(x => x.gitHash === edgeIndex.liveHash);
311
+ if (liveNodes.length === 0) {
312
+ let latestHash = edgeNodes[0].gitHash;
313
+ console.warn(`Could not find any live nodes (${edgeIndex.liveHash}), falling back to latest hash: ${latestHash}`);
314
+ liveNodes = edgeNodes.filter(x => x.gitHash === latestHash);
315
+ }
316
+ edgeNodes = liveNodes;
306
317
 
307
318
  // TODO: Instead of randomly shuffling, use the node's current load when picking a node.
308
319
  // All our future traffic (such as syncing) goes through the edge node we use, so it preferrable
@@ -49,14 +49,19 @@ function getNodeIdFromPath(path: string) {
49
49
  const getEdgeNodesIndex = lazy(async (): Promise<EdgeNodesIndex> => {
50
50
  await startUpdateLoop();
51
51
  let edgeNodesIndex = await edgeNodeStorage.get("edgeNodesIndex.json");
52
+ let liveHash = await Querysub.commitSynced(() => {
53
+ return deploySchema()[getDomain()].deploy.live.hash;
54
+ });
52
55
  if (!edgeNodesIndex) return {
53
56
  edgeNodes: [],
57
+ liveHash,
54
58
  };
55
59
  return JSON.parse(edgeNodesIndex.toString());
56
60
  });
57
61
 
58
62
  export type EdgeNodesIndex = {
59
63
  edgeNodes: EdgeNodeConfig[];
64
+ liveHash: string;
60
65
  };
61
66
 
62
67
 
@@ -91,21 +96,12 @@ export async function registerEdgeNode(config: {
91
96
 
92
97
  await waitForFirstTimeSync();
93
98
 
94
- let gitHash = getGitRef();
95
-
96
99
  if (!isLocal()) {
97
- gitHash = await Querysub.commitSynced(() => {
98
- return deploySchema()[getDomain()].deploy.live.hash;
99
- });
100
100
  let loadedHash = "";
101
101
  Querysub.createWatcher(() => {
102
102
  let hash = deploySchema()[getDomain()].deploy.live.hash;
103
103
  if (hash === loadedHash || !Querysub.isAllSynced()) return;
104
104
 
105
- // todonext
106
- // Remove this line, it is just to verify our preloading works
107
- if (loadedHash) return;
108
-
109
105
  loadedHash = hash;
110
106
  void Promise.resolve().then(async () => {
111
107
  await loadEntryPointsByHash({
@@ -116,6 +112,7 @@ export async function registerEdgeNode(config: {
116
112
  });
117
113
  });
118
114
  } else {
115
+ let gitHash = getGitRef();
119
116
 
120
117
  let nodeId = getOwnNodeId();
121
118
  let machineId = getOwnMachineId();
@@ -180,6 +177,8 @@ const loadEntryPointsByHash = runInSerial(async function loadEntryPointsByHash(c
180
177
 
181
178
  SocketFunction.expose(EdgeNodeController);
182
179
 
180
+ await updateEdgeNodesFile();
181
+
183
182
  onEdgeNodesChanged();
184
183
  });
185
184
 
@@ -221,8 +220,12 @@ async function runEdgeNodesAliveCheck() {
221
220
  }
222
221
  async function updateEdgeNodesFile() {
223
222
  let prevEdgeNodeFile = await edgeNodeStorage.get("edgeNodesIndex.json");
223
+ let liveHash = await Querysub.commitSynced(() => {
224
+ return deploySchema()[getDomain()].deploy.live.hash;
225
+ });
224
226
  let prevEdgeNodeIndex: EdgeNodesIndex = {
225
227
  edgeNodes: [],
228
+ liveHash: "",
226
229
  };
227
230
  try {
228
231
  if (prevEdgeNodeFile) {
@@ -242,12 +245,16 @@ async function updateEdgeNodesFile() {
242
245
  }
243
246
 
244
247
  let diff = !!compareArray(edgeNodeNodeIds.sort(), prevEdgeNodeIndex.edgeNodes.map(x => x.nodeId).sort());
248
+ if (liveHash !== prevEdgeNodeIndex.liveHash) {
249
+ diff = true;
250
+ }
245
251
  if (!diff) return;
246
252
 
247
- console.log("Detected edgeNodes changed. Updating edgeNodesIndex.json", { edgeNodeNodeIds });
253
+ console.log("Detected edgeNodes changed. Updating edgeNodesIndex.json", { edgeNodeNodeIds, liveHash });
248
254
 
249
255
  let newEdgeNodeIndex: EdgeNodesIndex = {
250
256
  edgeNodes: [],
257
+ liveHash,
251
258
  };
252
259
  for (let nodeFile of edgeNodeFiles) {
253
260
  let edgeNodeConfig = await getEdgeNodeConfig(nodeFile);
@@ -315,16 +322,6 @@ const EdgeNodeController = SocketFunction.register(
315
322
  // - I think it isn't? But maybe we just need to do-update again
316
323
 
317
324
 
318
- // 3) Dynamically watch the live hash, and load new hashes (deploying their services)
319
- // - PUSH and making sure we serve the old UI (when not running --local)
320
- // - Turning off the preloading in deploy, and ensuring it updates
321
- // - ALSO, when the live hash changes, invalidate getCachedConfig?
322
-
323
-
324
- // 5) Write the live hash to the index, and have the client prefer this hash
325
- // - And if it can't be found, fallback to the the hash with the highest bootTime
326
- // (picking from that pool, not just that single node)
327
-
328
325
  // 7) Client live hash watch code + notify + refresh + flag to ignore the baked in live hash + edge node
329
326
  // - Test by pushing, deploying, and then we should immediately see a notify to refresh
330
327