@dignetwork/dig-sdk 0.0.1-alpha.154 → 0.0.1-alpha.156

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.
@@ -10,6 +10,11 @@ export declare class ContentServer {
10
10
  getKey(key: string, rootHash: string, challengeHex?: string): Promise<string>;
11
11
  getKeyChunk(key: string, rootHash: string): Promise<Buffer>;
12
12
  getPaymentAddress(): Promise<string | null>;
13
+ /**
14
+ * Fetches and caches the .well-known information for the store's IP address.
15
+ *
16
+ * @returns A promise that resolves to the .well-known JSON data.
17
+ */
13
18
  getWellKnown(): Promise<any>;
14
19
  getKnownStores(): Promise<any>;
15
20
  getStoresIndex(): Promise<any>;
@@ -24,6 +29,13 @@ export declare class ContentServer {
24
29
  success: boolean;
25
30
  headers?: http.IncomingHttpHeaders;
26
31
  }>;
32
+ /**
33
+ * Checks if the store has the specified rootHash.
34
+ * Utilizes caching to improve performance.
35
+ *
36
+ * @param rootHash - The root hash to check.
37
+ * @returns A promise that resolves to true if the root hash exists, otherwise false.
38
+ */
27
39
  hasRootHash(rootHash: string): Promise<boolean>;
28
40
  streamKey(key: string, rootHash?: string): Promise<Readable>;
29
41
  private head;
@@ -1 +1 @@
1
- {"version":3,"file":"ContentServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/ContentServer.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAIlC,qBAAa,aAAa;IACxB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAS;IAChC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAS;IAC/B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAQ;gBAExB,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAYjC,MAAM,CACjB,GAAG,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GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;YAmDrD,IAAI;YA0EJ,SAAS;YAMT,gBAAgB;YAiChB,KAAK;YA+GL,eAAe;CA4G9B"}
@@ -9,6 +9,9 @@ const http_1 = __importDefault(require("http"));
9
9
  const url_1 = require("url");
10
10
  const ssl_1 = require("../utils/ssl");
11
11
  const network_1 = require("../utils/network");
12
+ const node_cache_1 = __importDefault(require("node-cache"));
13
+ const hasRootHashCache = new node_cache_1.default({ stdTTL: 86400 });
14
+ const wellKnownCache = new node_cache_1.default({ stdTTL: 86400 });
12
15
  class ContentServer {
13
16
  constructor(ipAddress, storeId) {
14
17
  this.ipAddress = ipAddress;
@@ -47,10 +50,30 @@ class ContentServer {
47
50
  return null;
48
51
  }
49
52
  }
50
- // Method to get the .well-known information
53
+ /**
54
+ * Fetches and caches the .well-known information for the store's IP address.
55
+ *
56
+ * @returns A promise that resolves to the .well-known JSON data.
57
+ */
51
58
  async getWellKnown() {
59
+ // Construct the cache key based on ipAddress
60
+ const cacheKey = `${this.ipAddress}-wellknown`;
61
+ // Check if the result is already cached
62
+ const cachedResult = wellKnownCache.get(cacheKey);
63
+ if (cachedResult !== undefined) {
64
+ return cachedResult;
65
+ }
66
+ // If not cached, proceed to fetch the .well-known information
52
67
  const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/.well-known`;
53
- return this.fetchJson(url);
68
+ try {
69
+ const data = await this.fetchJson(url);
70
+ wellKnownCache.set(cacheKey, data);
71
+ return data;
72
+ }
73
+ catch (error) {
74
+ console.error(`Error fetching .well-known information for ${this.ipAddress}:`, error.message);
75
+ throw error; // Propagate the error after logging
76
+ }
54
77
  }
55
78
  // Method to get the list of known stores
56
79
  async getKnownStores() {
@@ -64,38 +87,80 @@ class ContentServer {
64
87
  }
65
88
  // Method to get the index of keys in a store
66
89
  async getKeysIndex(rootHash) {
67
- let udi = `chia.${this.storeId}`;
68
- if (rootHash) {
69
- udi += `.${rootHash}`;
90
+ try {
91
+ let udi = `chia.${this.storeId}`;
92
+ if (rootHash) {
93
+ udi += `.${rootHash}`;
94
+ }
95
+ const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi}`;
96
+ return this.fetchJson(url);
97
+ }
98
+ catch (error) {
99
+ if (rootHash) {
100
+ hasRootHashCache.del(`${this.storeId}-${rootHash}`);
101
+ }
102
+ throw error;
70
103
  }
71
- const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi}`;
72
- return this.fetchJson(url);
73
104
  }
74
105
  // Method to check if a specific key exists (HEAD request)
75
106
  async headKey(key, rootHash) {
76
- let udi = `chia.${this.storeId}`;
77
- if (rootHash) {
78
- udi += `.${rootHash}`;
107
+ try {
108
+ let udi = `chia.${this.storeId}`;
109
+ if (rootHash) {
110
+ udi += `.${rootHash}`;
111
+ }
112
+ const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi}/${key}`;
113
+ return this.head(url);
114
+ }
115
+ catch (error) {
116
+ if (rootHash) {
117
+ hasRootHashCache.del(`${this.storeId}-${rootHash}`);
118
+ }
119
+ throw error;
79
120
  }
80
- const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi}/${key}`;
81
- return this.head(url);
82
121
  }
83
122
  // Method to check if a specific store exists (HEAD request)
84
123
  async headStore(options) {
85
- let url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/chia.${this.storeId}`;
86
- if (options?.hasRootHash) {
87
- url += `?hasRootHash=${options.hasRootHash}`;
124
+ try {
125
+ let url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/chia.${this.storeId}`;
126
+ if (options?.hasRootHash) {
127
+ url += `?hasRootHash=${options.hasRootHash}`;
128
+ }
129
+ return this.head(url);
130
+ }
131
+ catch (error) {
132
+ if (options?.hasRootHash) {
133
+ hasRootHashCache.del(`${this.storeId}-${options.hasRootHash}`);
134
+ }
135
+ throw error;
88
136
  }
89
- return this.head(url);
90
137
  }
138
+ /**
139
+ * Checks if the store has the specified rootHash.
140
+ * Utilizes caching to improve performance.
141
+ *
142
+ * @param rootHash - The root hash to check.
143
+ * @returns A promise that resolves to true if the root hash exists, otherwise false.
144
+ */
91
145
  async hasRootHash(rootHash) {
146
+ // Construct the cache key using storeId and rootHash
147
+ const cacheKey = `${this.storeId}-${rootHash}`;
148
+ // Check if the result is already cached
149
+ const cachedResult = hasRootHashCache.get(cacheKey);
150
+ if (cachedResult !== undefined) {
151
+ return cachedResult;
152
+ }
153
+ // If not cached, perform the headStore request
92
154
  const { success, headers } = await this.headStore({
93
155
  hasRootHash: rootHash,
94
156
  });
95
- if (success) {
96
- return headers?.["x-has-root-hash"] === "true";
157
+ // Determine if the store has the root hash
158
+ const hasHash = success && headers?.["x-has-root-hash"] === "true";
159
+ // Only cache the result if the store has the root hash
160
+ if (hasHash) {
161
+ hasRootHashCache.set(cacheKey, true);
97
162
  }
98
- return false;
163
+ return hasHash;
99
164
  }
100
165
  streamKey(key, rootHash) {
101
166
  let udi = `chia.${this.storeId}`;
@@ -126,6 +191,7 @@ class ContentServer {
126
191
  }
127
192
  }
128
193
  else {
194
+ hasRootHashCache.del(`${this.storeId}-${rootHash}`);
129
195
  reject(new Error(`Failed to retrieve data from ${url}. Status code: ${response.statusCode}`));
130
196
  }
131
197
  });
@@ -365,9 +431,7 @@ class ContentServer {
365
431
  if (timeout) {
366
432
  clearTimeout(timeout);
367
433
  }
368
- this.fetchFirstChunk(redirectUrl)
369
- .then(resolve)
370
- .catch(reject);
434
+ this.fetchFirstChunk(redirectUrl).then(resolve).catch(reject);
371
435
  }
372
436
  else {
373
437
  if (timeout) {
@@ -36,7 +36,11 @@ export declare class PropagationServer {
36
36
  */
37
37
  addInactivityTimeout(stream: PassThrough, timeoutMs: number): PassThrough;
38
38
  /**
39
- * Check if the store and optional root hash exist by making a HEAD request.
39
+ * Checks if the store exists and optionally if a specific rootHash exists.
40
+ * Utilizes caching to improve performance.
41
+ *
42
+ * @param rootHash - (Optional) The root hash to check.
43
+ * @returns A promise that resolves to an object containing store existence and root hash existence.
40
44
  */
41
45
  checkStoreExists(rootHash?: string): Promise<{
42
46
  storeExists: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"PropagationServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/PropagationServer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,OAAO,CAAC;AAY1B,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAkBrC,qBAAa,iBAAiB;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAE7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAQ;IACpC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAQ;gBAErC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAY9C;;OAEG;IACG,gBAAgB;IAOtB;;OAEG;IACH,gBAAgB;IAQhB;;;OAGG;IACG,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BpD;;;OAGG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmCjD;;OAEG;IACH,oBAAoB,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM;IAyB3D;;OAEG;IACG,gBAAgB,CACpB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QA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,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;IA0DnB;;;OAGG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAmFlD;;OAEG;IACG,cAAc,CAClB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IA4B7C;;;OAGG;IACG,YAAY,CAChB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM;IA4GjB;;OAEG;WACU,aAAa,CACxB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;CA2FpB"}
@@ -48,6 +48,9 @@ const credentialsUtils_1 = require("../utils/credentialsUtils");
48
48
  const config_1 = require("../utils/config");
49
49
  const blockchain_1 = require("../blockchain");
50
50
  const network_1 = require("../utils/network");
51
+ const node_cache_1 = __importDefault(require("node-cache"));
52
+ // Initialize cache with a TTL of 1 week (604800 seconds)
53
+ const storeExistsCache = new node_cache_1.default({ stdTTL: 86400 });
51
54
  // Helper function to trim long filenames with ellipsis and ensure consistent padding
52
55
  function formatFilename(filename, maxLength = 30) {
53
56
  if (!filename) {
@@ -137,7 +140,7 @@ class PropagationServer {
137
140
  };
138
141
  try {
139
142
  const response = await axios_1.default.post(url, data, config);
140
- console.log((0, colorette_1.green)(`✔ Successfully pinged peer: ${this.ipAddress}`));
143
+ console.log((0, colorette_1.green)(`✔ Successfully pinged peer: ${this.ipAddress}`), response);
141
144
  return response.data;
142
145
  }
143
146
  catch (error) {
@@ -171,9 +174,23 @@ class PropagationServer {
171
174
  return stream;
172
175
  }
173
176
  /**
174
- * Check if the store and optional root hash exist by making a HEAD request.
177
+ * Checks if the store exists and optionally if a specific rootHash exists.
178
+ * Utilizes caching to improve performance.
179
+ *
180
+ * @param rootHash - (Optional) The root hash to check.
181
+ * @returns A promise that resolves to an object containing store existence and root hash existence.
175
182
  */
176
183
  async checkStoreExists(rootHash) {
184
+ // Construct the cache key
185
+ const cacheKey = rootHash
186
+ ? `${this.storeId}-${rootHash}`
187
+ : `${this.storeId}-nohash`;
188
+ // Check if the result is already cached
189
+ const cachedResult = storeExistsCache.get(cacheKey);
190
+ if (cachedResult !== undefined) {
191
+ return cachedResult;
192
+ }
193
+ // If not cached, proceed with the HTTP request
177
194
  const spinner = (0, nanospinner_1.createSpinner)(`Checking if store ${this.storeId} exists...`).start();
178
195
  try {
179
196
  const config = {
@@ -197,7 +214,9 @@ class PropagationServer {
197
214
  text: (0, colorette_1.yellow)(`Store ${this.storeId} does not exist on ${this.ipAddress}. Credentials will be required to push.`),
198
215
  });
199
216
  }
200
- return { storeExists, rootHashExists };
217
+ const result = { storeExists, rootHashExists };
218
+ storeExistsCache.set(cacheKey, result);
219
+ return result;
201
220
  }
202
221
  catch (error) {
203
222
  spinner.error({ text: (0, colorette_1.red)("Error checking if store exists:") });
@@ -482,6 +501,7 @@ class PropagationServer {
482
501
  return Buffer.concat(dataBuffers);
483
502
  }
484
503
  catch (error) {
504
+ storeExistsCache.del(`${this.storeId}-nohash`);
485
505
  throw error;
486
506
  }
487
507
  finally {
@@ -584,6 +604,8 @@ class PropagationServer {
584
604
  }
585
605
  }
586
606
  catch (error) {
607
+ storeExistsCache.del(`${this.storeId}-nohash`);
608
+ storeExistsCache.del(`${this.storeId}-${rootHash}`);
587
609
  throw error;
588
610
  }
589
611
  finally {
@@ -1 +1 @@
1
- {"version":3,"file":"PeerRanker.d.ts","sourceRoot":"","sources":["../../src/utils/PeerRanker.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,UAAU;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;OAKG;IACU,SAAS,CAAC,QAAQ,GAAE,MAAY,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAmCtE;;;;OAIG;IACI,eAAe,IAAI,WAAW,GAAG,IAAI;IAW5C;;OAEG;IACI,aAAa,IAAI,IAAI;CAG7B"}
@@ -94,7 +94,6 @@ class PeerRanker {
94
94
  async measureBandwidth(ip) {
95
95
  const cachedMetrics = peerCache.get(ip);
96
96
  if (cachedMetrics && cachedMetrics.bandwidth) {
97
- console.log(`Bandwidth for IP ${ip} retrieved from cache.`);
98
97
  return cachedMetrics.bandwidth;
99
98
  }
100
99
  const url = `https://${ip}:4159/diagnostics/bandwidth`;
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.formatHost = exports.getPublicHost = void 0;
7
7
  const superagent_1 = __importDefault(require("superagent"));
8
- const Environment_1 = require("./Environment");
9
8
  const MAX_RETRIES = 5;
10
9
  const RETRY_DELAY = 2000; // in milliseconds
11
10
  // Regular expression for validating both IPv4 and IPv6 addresses
@@ -18,7 +17,7 @@ const isValidHost = (host) => {
18
17
  return ipv4Regex.test(host) || ipv6Regex.test(host) || hostnameRegex.test(host);
19
18
  };
20
19
  const getPublicHost = async () => {
21
- const publicHost = Environment_1.Environment.PUBLIC_IP;
20
+ const publicHost = process.env.PUBLIC_IP;
22
21
  if (publicHost) {
23
22
  console.log("Public IP/Hostname from env:", publicHost);
24
23
  if (isValidHost(publicHost)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/dig-sdk",
3
- "version": "0.0.1-alpha.154",
3
+ "version": "0.0.1-alpha.156",
4
4
  "description": "",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",