@dignetwork/dig-sdk 0.0.1-alpha.43 → 0.0.1-alpha.45
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.
|
@@ -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,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;WA6BrC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAQhD,oBAAoB,CACtC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,GAAG,CAAC,EAAE,MAAM,EACZ,eAAe,GAAE,MAAM,EAAO,GAC7B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;WAuCX,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAQ5C,aAAa,CACxB,aAAa,GAAE,OAAe,EAC9B,iBAAiB,GAAE,OAAc,EACjC,QAAQ,GAAE,OAAe,GACxB,OAAO,CAAC,IAAI,CAAC;
|
|
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,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;WA6BrC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAQhD,oBAAoB,CACtC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,GAAG,CAAC,EAAE,MAAM,EACZ,eAAe,GAAE,MAAM,EAAO,GAC7B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;WAuCX,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAQ5C,aAAa,CACxB,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"}
|
|
@@ -135,7 +135,7 @@ class DigNetwork {
|
|
|
135
135
|
break;
|
|
136
136
|
const peerIp = digPeers[0];
|
|
137
137
|
const digPeer = new DigPeer_1.DigPeer(peerIp, storeId);
|
|
138
|
-
const storeResponse = await digPeer.
|
|
138
|
+
const storeResponse = await digPeer.contentServer.headStore({
|
|
139
139
|
hasRootHash: rootHash,
|
|
140
140
|
});
|
|
141
141
|
console.log(peerIp, storeResponse.headers);
|
|
@@ -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() {
|