@dignetwork/dig-sdk 0.0.1-alpha.155 → 0.0.1-alpha.158
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/dist/DigNetwork/ContentServer.d.ts +12 -0
- package/dist/DigNetwork/ContentServer.d.ts.map +1 -1
- package/dist/DigNetwork/ContentServer.js +86 -22
- package/dist/DigNetwork/PropagationServer.d.ts +6 -1
- package/dist/DigNetwork/PropagationServer.d.ts.map +1 -1
- package/dist/DigNetwork/PropagationServer.js +36 -4
- package/dist/blockchain/DataStore.d.ts.map +1 -1
- package/dist/blockchain/DataStore.js +1 -0
- package/dist/utils/PeerRanker.d.ts.map +1 -1
- package/dist/utils/PeerRanker.js +0 -1
- package/package.json +1 -1
|
@@ -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;
|
|
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;AAQlC,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,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,CAAC;IAeL,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAS3D,iBAAiB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAcxD;;;;OAIG;IACU,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC;IA6B5B,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAQ9B,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAM9B,YAAY,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAqB7C,OAAO,CAClB,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAA;KAAE,CAAC;IAqBvD,SAAS,CAAC,OAAO,CAAC,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QACjE,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC;KACpC,CAAC;IAmBF;;;;;;OAMG;IACU,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA0BrD,SAAS,CAAC,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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
|
96
|
-
|
|
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
|
|
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) {
|
|
@@ -28,6 +28,7 @@ export declare class PropagationServer {
|
|
|
28
28
|
getMyPublicIp(rootHash: string): Promise<void>;
|
|
29
29
|
/**
|
|
30
30
|
* Ping the current peer about an update to the store, passing rootHash.
|
|
31
|
+
* If the combination of ipAddress-storeId-rootHash is cached as "successfully synced", skip the request.
|
|
31
32
|
* @param rootHash - The root hash for the store update.
|
|
32
33
|
*/
|
|
33
34
|
pingUpdate(rootHash: string): Promise<void>;
|
|
@@ -36,7 +37,11 @@ export declare class PropagationServer {
|
|
|
36
37
|
*/
|
|
37
38
|
addInactivityTimeout(stream: PassThrough, timeoutMs: number): PassThrough;
|
|
38
39
|
/**
|
|
39
|
-
*
|
|
40
|
+
* Checks if the store exists and optionally if a specific rootHash exists.
|
|
41
|
+
* Utilizes caching to improve performance.
|
|
42
|
+
*
|
|
43
|
+
* @param rootHash - (Optional) The root hash to check.
|
|
44
|
+
* @returns A promise that resolves to an object containing store existence and root hash existence.
|
|
40
45
|
*/
|
|
41
46
|
checkStoreExists(rootHash?: string): Promise<{
|
|
42
47
|
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;
|
|
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;AAuBrC,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;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,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,10 @@ 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 });
|
|
54
|
+
const pingUpdatecache = new node_cache_1.default({ stdTTL: 86400 });
|
|
51
55
|
// Helper function to trim long filenames with ellipsis and ensure consistent padding
|
|
52
56
|
function formatFilename(filename, maxLength = 30) {
|
|
53
57
|
if (!filename) {
|
|
@@ -117,9 +121,15 @@ class PropagationServer {
|
|
|
117
121
|
}
|
|
118
122
|
/**
|
|
119
123
|
* Ping the current peer about an update to the store, passing rootHash.
|
|
124
|
+
* If the combination of ipAddress-storeId-rootHash is cached as "successfully synced", skip the request.
|
|
120
125
|
* @param rootHash - The root hash for the store update.
|
|
121
126
|
*/
|
|
122
127
|
async pingUpdate(rootHash) {
|
|
128
|
+
const cacheKey = `${this.ipAddress}-${this.storeId}-${rootHash}`;
|
|
129
|
+
// Check if response for this combination is already cached
|
|
130
|
+
if (pingUpdatecache.get(cacheKey) === "successfully synced") {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
123
133
|
try {
|
|
124
134
|
const httpsAgent = this.createHttpsAgent();
|
|
125
135
|
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/update`;
|
|
@@ -129,7 +139,6 @@ class PropagationServer {
|
|
|
129
139
|
"Content-Type": "application/json",
|
|
130
140
|
},
|
|
131
141
|
};
|
|
132
|
-
// Data to send in the request (storeId and rootHash)
|
|
133
142
|
const data = {
|
|
134
143
|
storeId: this.storeId,
|
|
135
144
|
rootHash: rootHash,
|
|
@@ -137,7 +146,11 @@ class PropagationServer {
|
|
|
137
146
|
};
|
|
138
147
|
try {
|
|
139
148
|
const response = await axios_1.default.post(url, data, config);
|
|
140
|
-
console.log((0, colorette_1.green)(`✔ Successfully pinged peer: ${this.ipAddress}`));
|
|
149
|
+
console.log((0, colorette_1.green)(`✔ Successfully pinged peer: ${this.ipAddress}`), response.data);
|
|
150
|
+
if (response.data.message === "Already Synced") {
|
|
151
|
+
// Cache the response as "successfully synced" to avoid redundant requests
|
|
152
|
+
pingUpdatecache.set(cacheKey, "successfully synced");
|
|
153
|
+
}
|
|
141
154
|
return response.data;
|
|
142
155
|
}
|
|
143
156
|
catch (error) {
|
|
@@ -171,9 +184,23 @@ class PropagationServer {
|
|
|
171
184
|
return stream;
|
|
172
185
|
}
|
|
173
186
|
/**
|
|
174
|
-
*
|
|
187
|
+
* Checks if the store exists and optionally if a specific rootHash exists.
|
|
188
|
+
* Utilizes caching to improve performance.
|
|
189
|
+
*
|
|
190
|
+
* @param rootHash - (Optional) The root hash to check.
|
|
191
|
+
* @returns A promise that resolves to an object containing store existence and root hash existence.
|
|
175
192
|
*/
|
|
176
193
|
async checkStoreExists(rootHash) {
|
|
194
|
+
// Construct the cache key
|
|
195
|
+
const cacheKey = rootHash
|
|
196
|
+
? `${this.storeId}-${rootHash}`
|
|
197
|
+
: `${this.storeId}-nohash`;
|
|
198
|
+
// Check if the result is already cached
|
|
199
|
+
const cachedResult = storeExistsCache.get(cacheKey);
|
|
200
|
+
if (cachedResult !== undefined) {
|
|
201
|
+
return cachedResult;
|
|
202
|
+
}
|
|
203
|
+
// If not cached, proceed with the HTTP request
|
|
177
204
|
const spinner = (0, nanospinner_1.createSpinner)(`Checking if store ${this.storeId} exists...`).start();
|
|
178
205
|
try {
|
|
179
206
|
const config = {
|
|
@@ -197,7 +224,9 @@ class PropagationServer {
|
|
|
197
224
|
text: (0, colorette_1.yellow)(`Store ${this.storeId} does not exist on ${this.ipAddress}. Credentials will be required to push.`),
|
|
198
225
|
});
|
|
199
226
|
}
|
|
200
|
-
|
|
227
|
+
const result = { storeExists, rootHashExists };
|
|
228
|
+
storeExistsCache.set(cacheKey, result);
|
|
229
|
+
return result;
|
|
201
230
|
}
|
|
202
231
|
catch (error) {
|
|
203
232
|
spinner.error({ text: (0, colorette_1.red)("Error checking if store exists:") });
|
|
@@ -482,6 +511,7 @@ class PropagationServer {
|
|
|
482
511
|
return Buffer.concat(dataBuffers);
|
|
483
512
|
}
|
|
484
513
|
catch (error) {
|
|
514
|
+
storeExistsCache.del(`${this.storeId}-nohash`);
|
|
485
515
|
throw error;
|
|
486
516
|
}
|
|
487
517
|
finally {
|
|
@@ -584,6 +614,8 @@ class PropagationServer {
|
|
|
584
614
|
}
|
|
585
615
|
}
|
|
586
616
|
catch (error) {
|
|
617
|
+
storeExistsCache.del(`${this.storeId}-nohash`);
|
|
618
|
+
storeExistsCache.del(`${this.storeId}-${rootHash}`);
|
|
587
619
|
throw error;
|
|
588
620
|
}
|
|
589
621
|
finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataStore.d.ts","sourceRoot":"","sources":["../../src/blockchain/DataStore.ts"],"names":[],"mappings":"AAEA,OAAO,EAOL,SAAS,IAAI,eAAe,EAE5B,iBAAiB,EAIlB,MAAM,8BAA8B,CAAC;AAWtC,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG3C,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE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C;QAC7B,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IAkCW,wBAAwB,IAAI,OAAO,CAAC;QAC/C,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;IAiBW,iBAAiB,IAAI,OAAO,CAAC;QACxC,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;YA0BY,iBAAiB;IAYlB,cAAc,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IA4C/D,oBAAoB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAexD,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAKzC,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAM5B,uBAAuB,CAClC,kBAAkB,CAAC,EAAE,MAAM,GAC1B,OAAO,CAAC,OAAO,CAAC;IAkBN,cAAc,CACzB,QAAQ,EAAE,iBAAiB,GAC1B,OAAO,CAAC,eAAe,CAAC;IAgD3B;;;;;OAKG;IACU,qBAAqB,CAChC,QAAQ,EAAE,MAAM,EAChB,kBAAkB,GAAE,OAAe,GAClC,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CA6C7C"}
|
|
@@ -23,6 +23,7 @@ const config_2 = require("../utils/config");
|
|
|
23
23
|
const StoreMonitorRegistry_1 = require("./StoreMonitorRegistry");
|
|
24
24
|
// Initialize the cache with a TTL of 180 seconds (3 minutes)
|
|
25
25
|
const rootHistoryCache = new node_cache_1.default({ stdTTL: 180 });
|
|
26
|
+
const allStoresCache = new node_cache_1.default({ stdTTL: 15 });
|
|
26
27
|
const stat = (0, util_1.promisify)(fs_1.default.stat);
|
|
27
28
|
const readdir = (0, util_1.promisify)(fs_1.default.readdir);
|
|
28
29
|
class DataStore {
|
|
@@ -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;IACrB,OAAO,CAAC,WAAW,CAAW;IAC9B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAS;IAChC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAS;IAC/B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAS;IAG/B,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,YAAY,CAAa;IAEjC;;;OAGG;gBACS,WAAW,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,MAAa,EAAE,cAAc,GAAE,MAAoB;IAW/F;;;;;;OAMG;YACW,cAAc;IAkD5B;;;;;OAKG;YACW,gBAAgB;
|
|
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;IACrB,OAAO,CAAC,WAAW,CAAW;IAC9B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAS;IAChC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAS;IAC/B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAS;IAG/B,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,YAAY,CAAa;IAEjC;;;OAGG;gBACS,WAAW,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,MAAa,EAAE,cAAc,GAAE,MAAoB;IAW/F;;;;;;OAMG;YACW,cAAc;IAkD5B;;;;;OAKG;YACW,gBAAgB;IA2C9B;;;;;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"}
|
package/dist/utils/PeerRanker.js
CHANGED
|
@@ -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`;
|