@dignetwork/dig-sdk 0.0.1-alpha.43 → 0.0.1-alpha.46
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.
|
@@ -21,7 +21,7 @@ class ContentServer {
|
|
|
21
21
|
// Method to get the content of a specified key from the peer, with optional challenge query
|
|
22
22
|
async getKey(key, rootHash, challengeHex) {
|
|
23
23
|
// Construct the base URL
|
|
24
|
-
let url = `http://${this.ipAddress}/chia.${this.storeId}.${rootHash}/${key}`;
|
|
24
|
+
let url = `http://${this.ipAddress}:${ContentServer.port}/chia.${this.storeId}.${rootHash}/${key}`;
|
|
25
25
|
// If a challenge is provided, append it as a query parameter
|
|
26
26
|
if (challengeHex) {
|
|
27
27
|
url += `?challenge=${challengeHex}`;
|
|
@@ -42,32 +42,32 @@ class ContentServer {
|
|
|
42
42
|
}
|
|
43
43
|
// Method to get the .well-known information
|
|
44
44
|
async getWellKnown() {
|
|
45
|
-
const url = `http://${this.ipAddress}/.well-known`;
|
|
45
|
+
const url = `http://${this.ipAddress}:${ContentServer.port}/.well-known`;
|
|
46
46
|
return this.fetchJson(url);
|
|
47
47
|
}
|
|
48
48
|
// Method to get the list of known stores
|
|
49
49
|
async getKnownStores() {
|
|
50
|
-
const url = `http://${this.ipAddress}/.well-known/stores`;
|
|
50
|
+
const url = `http://${this.ipAddress}:${ContentServer.port}/.well-known/stores`;
|
|
51
51
|
return this.fetchJson(url);
|
|
52
52
|
}
|
|
53
53
|
// Method to get the index of all stores
|
|
54
54
|
async getStoresIndex() {
|
|
55
|
-
const url = `http://${this.ipAddress}/`;
|
|
55
|
+
const url = `http://${this.ipAddress}:${ContentServer.port}/`;
|
|
56
56
|
return this.fetchJson(url);
|
|
57
57
|
}
|
|
58
58
|
// Method to get the index of keys in a store
|
|
59
59
|
async getKeysIndex() {
|
|
60
|
-
const url = `http://${this.ipAddress}/${this.storeId}`;
|
|
60
|
+
const url = `http://${this.ipAddress}:${ContentServer.port}/${this.storeId}`;
|
|
61
61
|
return this.fetchJson(url);
|
|
62
62
|
}
|
|
63
63
|
// Method to check if a specific key exists (HEAD request)
|
|
64
64
|
async headKey(key) {
|
|
65
|
-
const url = `http://${this.ipAddress}/${this.storeId}/${key}`;
|
|
65
|
+
const url = `http://${this.ipAddress}:${ContentServer.port}/${this.storeId}/${key}`;
|
|
66
66
|
return this.head(url);
|
|
67
67
|
}
|
|
68
68
|
// Method to check if a specific store exists (HEAD request)
|
|
69
69
|
async headStore(options) {
|
|
70
|
-
let url = `http://${this.ipAddress}/${this.storeId}`;
|
|
70
|
+
let url = `http://${this.ipAddress}:${ContentServer.port}/${this.storeId}`;
|
|
71
71
|
if (options?.hasRootHash) {
|
|
72
72
|
url += `?hasRootHash=${options.hasRootHash}`;
|
|
73
73
|
}
|
|
@@ -75,7 +75,7 @@ class ContentServer {
|
|
|
75
75
|
}
|
|
76
76
|
streamKey(key) {
|
|
77
77
|
return new Promise((resolve, reject) => {
|
|
78
|
-
const url = `http://${this.ipAddress}/${this.storeId}/${key}`;
|
|
78
|
+
const url = `http://${this.ipAddress}:${ContentServer.port}/${this.storeId}/${key}`;
|
|
79
79
|
const urlObj = new url_1.URL(url);
|
|
80
80
|
const requestOptions = {
|
|
81
81
|
hostname: urlObj.hostname,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DigNetwork.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/DigNetwork.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWpC,qBAAa,UAAU;IACrB,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,aAAa,CAA2B;gBAEpC,OAAO,EAAE,MAAM;YAOb,eAAe;IA8ChB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAsDhD,WAAW,CAAC,OA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aAAa,GAAE,OAAe,EAC9B,iBAAiB,GAAE,OAAc,EACjC,QAAQ,GAAE,OAAe,GACxB,OAAO,CAAC,IAAI,CAAC;YAsFF,mBAAmB;YAWnB,kBAAkB;YASlB,oBAAoB;YASpB,qBAAqB;YAsFrB,cAAc;CAoB7B"}
|
|
@@ -188,14 +188,14 @@ class DigNetwork {
|
|
|
188
188
|
fs.writeFileSync(`${this.storeDir}/${rootInfo.root_hash}.dat`, rootResponse);
|
|
189
189
|
const root = JSON.parse(rootResponse);
|
|
190
190
|
if (!skipData) {
|
|
191
|
-
//
|
|
192
|
-
|
|
191
|
+
// Sequential file download
|
|
192
|
+
for (const [storeKey, file] of Object.entries(root.files)) {
|
|
193
193
|
const filePath = (0, hashUtils_1.getFilePathFromSha256)(file.sha256, `${this.storeDir}/data`);
|
|
194
194
|
if (!fs.existsSync(filePath) || forceDownload) {
|
|
195
195
|
console.log(`Downloading file with sha256: ${file.sha256}...`);
|
|
196
196
|
await this.downloadFileFromPeers(`data/${file.sha256.match(/.{1,2}/g).join("/")}`, filePath, forceDownload);
|
|
197
197
|
}
|
|
198
|
-
}
|
|
198
|
+
}
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
await this.downloadManifestFile(true);
|
|
@@ -231,6 +231,10 @@ class DigNetwork {
|
|
|
231
231
|
for (const digPeer of digPeers) {
|
|
232
232
|
if (blacklist.has(digPeer.IpAddress))
|
|
233
233
|
continue;
|
|
234
|
+
const response = await digPeer.propagationServer.headStore();
|
|
235
|
+
if (!response.success) {
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
234
238
|
try {
|
|
235
239
|
// Create directory if it doesn't exist
|
|
236
240
|
const directory = path.dirname(tempFilePath);
|
|
@@ -244,13 +248,13 @@ class DigNetwork {
|
|
|
244
248
|
// Pipe the peer stream to the temp file
|
|
245
249
|
await new Promise((resolve, reject) => {
|
|
246
250
|
peerStream.pipe(fileStream);
|
|
247
|
-
peerStream.on(
|
|
248
|
-
peerStream.on(
|
|
249
|
-
fileStream.on(
|
|
251
|
+
peerStream.on("end", resolve);
|
|
252
|
+
peerStream.on("error", reject);
|
|
253
|
+
fileStream.on("error", reject);
|
|
250
254
|
});
|
|
251
255
|
// Rename the temp file to the final file path after successful download
|
|
252
256
|
await rename(tempFilePath, filePath);
|
|
253
|
-
if (process.env.DIG_DEBUG ===
|
|
257
|
+
if (process.env.DIG_DEBUG === "1") {
|
|
254
258
|
console.log(`Downloaded ${dataPath} from ${digPeer.IpAddress}`);
|
|
255
259
|
}
|
|
256
260
|
return; // Exit the method if download succeeds
|
|
@@ -266,7 +270,7 @@ class DigNetwork {
|
|
|
266
270
|
}
|
|
267
271
|
this.peerBlacklist.set(dataPath, blacklist);
|
|
268
272
|
if (blacklist.size >= digPeers.length) {
|
|
269
|
-
if (process.env.DIG_DEBUG ===
|
|
273
|
+
if (process.env.DIG_DEBUG === "1") {
|
|
270
274
|
console.warn(`All peers blacklisted for ${dataPath}. Refreshing peers...`);
|
|
271
275
|
}
|
|
272
276
|
digPeers = await this.fetchAvailablePeers();
|
|
@@ -215,7 +215,7 @@ class FullNodePeer {
|
|
|
215
215
|
}
|
|
216
216
|
const bestPeer = peers[bestPeerIndex];
|
|
217
217
|
FullNodePeer.cachedPeer = { peer: bestPeer, timestamp: now };
|
|
218
|
-
console.log(`Using Peer: ${peerIPs[bestPeerIndex]}`);
|
|
218
|
+
console.log(`Using Fullnode Peer: ${peerIPs[bestPeerIndex]}`);
|
|
219
219
|
return bestPeer;
|
|
220
220
|
}
|
|
221
221
|
getPeer() {
|