@dignetwork/dig-sdk 0.0.1-alpha.149 → 0.0.1-alpha.150
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.
|
@@ -8,6 +8,15 @@ export declare class DigNetwork {
|
|
|
8
8
|
constructor(storeId: string);
|
|
9
9
|
static subscribeToStore(storeId: string): Promise<void>;
|
|
10
10
|
static getUdiContent(udi: string): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Find a peer that has the store key and root hash.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} storeId - The ID of the store.
|
|
15
|
+
* @param {string} rootHash - The root hash of the store.
|
|
16
|
+
* @param {string} [key] - Optional key to check for in the store.
|
|
17
|
+
* @param {string[]} [initialBlackList] - Initial list of blacklisted peer IPs.
|
|
18
|
+
* @returns {Promise<DigPeer | null>} - A valid peer or null if none found.
|
|
19
|
+
*/
|
|
11
20
|
static findPeerWithStoreKey(storeId: string, rootHash: string, key?: string, initialBlackList?: string[]): Promise<DigPeer | null>;
|
|
12
21
|
static unsubscribeFromStore(storeId: string): void;
|
|
13
22
|
static pingNetworkOfUpdate(storeId: string, rootHash: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DigNetwork.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/DigNetwork.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,qBAAa,UAAU;IACrB,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,aAAa,CAA2B;IAChD,OAAO,CAAC,MAAM,CAAC,cAAc,CAAmC;gBAEpD,OAAO,EAAE,MAAM;WAOP,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAQhD,aAAa,CAAC,GAAG,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"DigNetwork.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/DigNetwork.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,qBAAa,UAAU;IACrB,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,aAAa,CAA2B;IAChD,OAAO,CAAC,MAAM,CAAC,cAAc,CAAmC;gBAEpD,OAAO,EAAE,MAAM;WAOP,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAQhD,aAAa,CAAC,GAAG,EAAE,MAAM;IAI7C;;;;;;;;OAQG;WACiB,oBAAoB,CACtC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,GAAG,CAAC,EAAE,MAAM,EACZ,gBAAgB,GAAE,MAAM,EAAO,GAC9B,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;WA6EZ,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;WAOrC,mBAAmB,CACrC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC;IAcH,kBAAkB,CAC7B,eAAe,CAAC,EAAE,OAAO,EACzB,iBAAiB,CAAC,EAAE,MAAM,GACzB,OAAO,CAAC,IAAI,CAAC;IAgHH,mBAAmB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAUvD"}
|
|
@@ -47,14 +47,22 @@ class DigNetwork {
|
|
|
47
47
|
static async getUdiContent(udi) {
|
|
48
48
|
// TODO: Implement this method
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Find a peer that has the store key and root hash.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} storeId - The ID of the store.
|
|
54
|
+
* @param {string} rootHash - The root hash of the store.
|
|
55
|
+
* @param {string} [key] - Optional key to check for in the store.
|
|
56
|
+
* @param {string[]} [initialBlackList] - Initial list of blacklisted peer IPs.
|
|
57
|
+
* @returns {Promise<DigPeer | null>} - A valid peer or null if none found.
|
|
58
|
+
*/
|
|
50
59
|
static async findPeerWithStoreKey(storeId, rootHash, key, initialBlackList = []) {
|
|
51
|
-
const peerBlackList = initialBlackList;
|
|
60
|
+
const peerBlackList = new Set(initialBlackList);
|
|
52
61
|
const serverCoin = new blockchain_1.ServerCoin(storeId);
|
|
53
|
-
const allPeers = await serverCoin.getActiveEpochPeers();
|
|
54
62
|
while (true) {
|
|
55
63
|
try {
|
|
56
|
-
// Sample 10 peers from the current epoch
|
|
57
|
-
const digPeers = await serverCoin.sampleCurrentEpoch(10, peerBlackList);
|
|
64
|
+
// Sample 10 peers from the current epoch excluding blacklisted peers
|
|
65
|
+
const digPeers = await serverCoin.sampleCurrentEpoch(10, Array.from(peerBlackList));
|
|
58
66
|
// If no peers are returned, break out of the loop
|
|
59
67
|
if (digPeers.length === 0) {
|
|
60
68
|
console.log("No more peers found.");
|
|
@@ -94,7 +102,7 @@ class DigNetwork {
|
|
|
94
102
|
return firstValidPeer;
|
|
95
103
|
}
|
|
96
104
|
// If none of the peers were valid, add them to the blacklist
|
|
97
|
-
digPeers.forEach((peerIp) => peerBlackList.
|
|
105
|
+
digPeers.forEach((peerIp) => peerBlackList.add(peerIp));
|
|
98
106
|
// Retry with the next set of peers
|
|
99
107
|
console.log("No valid peers found, retrying with new peers...");
|
|
100
108
|
}
|