@dignetwork/dig-sdk 0.0.1-alpha.127 → 0.0.1-alpha.128

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.
@@ -9,7 +9,8 @@ export declare class DigNetwork {
9
9
  static getUdiContent(udi: string): Promise<void>;
10
10
  static findPeerWithStoreKey(storeId: string, rootHash: string, key?: string, intialBlackList?: string[]): Promise<DigPeer | null>;
11
11
  static unsubscribeFromStore(storeId: string): void;
12
- syncStoreFromPeers(maxRootsToProcess?: number): Promise<void>;
12
+ static pingNetworkOfUpdate(storeId: string, rootHash: string): Promise<void>;
13
+ syncStoreFromPeers(prioritizedPeer?: DigPeer, maxRootsToProcess?: number): Promise<void>;
13
14
  fetchAvailablePeers(): Promise<DigPeer[]>;
14
15
  }
15
16
  //# sourceMappingURL=DigNetwork.d.ts.map
@@ -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;AASpC,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;WAOP,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAQhD,aAAa,CAAC,GAAG,EAAE,MAAM;WAIzB,oBAAoB,CACtC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,GAAG,CAAC,EAAE,MAAM,EACZ,eAAe,GAAE,MAAM,EAAO,GAC7B,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;WA2DZ,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAO5C,kBAAkB,CAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiG7D,mBAAmB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAUvD"}
1
+ {"version":3,"file":"DigNetwork.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/DigNetwork.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,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;WAOP,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAQhD,aAAa,CAAC,GAAG,EAAE,MAAM;WAIzB,oBAAoB,CACtC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,GAAG,CAAC,EAAE,MAAM,EACZ,eAAe,GAAE,MAAM,EAAO,GAC7B,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;WA2DZ,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;WAOrC,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU5E,kBAAkB,CAC7B,eAAe,CAAC,EAAE,OAAO,EACzB,iBAAiB,CAAC,EAAE,MAAM,GACzB,OAAO,CAAC,IAAI,CAAC;IAqGH,mBAAmB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAUvD"}
@@ -99,7 +99,16 @@ class DigNetwork {
99
99
  });
100
100
  fs.unlinkSync(path.join(config_1.DIG_FOLDER_PATH, "stores", storeId + ".json"));
101
101
  }
102
- async syncStoreFromPeers(maxRootsToProcess) {
102
+ static async pingNetworkOfUpdate(storeId, rootHash) {
103
+ const serverCoin = new blockchain_1.ServerCoin(storeId);
104
+ // When an update is made, ping 10 network peers to pull updates from this store
105
+ const digPeers = await serverCoin.sampleCurrentEpoch(10);
106
+ for (const peer of digPeers) {
107
+ const digPeer = new DigPeer_1.DigPeer(peer, storeId);
108
+ await digPeer.propagationServer.pingUpdate(rootHash);
109
+ }
110
+ }
111
+ async syncStoreFromPeers(prioritizedPeer, maxRootsToProcess) {
103
112
  console.log("Starting file download process...");
104
113
  let peerBlackList = [];
105
114
  try {
@@ -126,7 +135,12 @@ class DigNetwork {
126
135
  while (true) {
127
136
  try {
128
137
  // Find a peer with the store and root hash
129
- selectedPeer = await DigNetwork.findPeerWithStoreKey(this.dataStore.StoreId, rootInfo.root_hash, undefined, peerBlackList);
138
+ if (prioritizedPeer) {
139
+ selectedPeer = prioritizedPeer;
140
+ }
141
+ else {
142
+ selectedPeer = await DigNetwork.findPeerWithStoreKey(this.dataStore.StoreId, rootInfo.root_hash, undefined, peerBlackList);
143
+ }
130
144
  if (!selectedPeer) {
131
145
  console.error(`No peer found with root hash ${rootInfo.root_hash}. Moving to next root.`);
132
146
  break; // Exit the while loop to proceed to the next rootInfo
@@ -21,6 +21,11 @@ export declare class PropagationServer {
21
21
  * Create an Axios HTTPS Agent with self-signed certificate allowance.
22
22
  */
23
23
  createHttpsAgent(): https.Agent;
24
+ /**
25
+ * Ping the current peer about an update to the store, passing rootHash.
26
+ * @param rootHash - The root hash for the store update.
27
+ */
28
+ pingUpdate(rootHash: string): Promise<void>;
24
29
  /**
25
30
  * Adds a custom inactivity timeout for large file transfers.
26
31
  */
@@ -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,E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QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,CAAC;IA4C7D;;OAEG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM;IAyDzC;;OAEG;IACG,YAAY,CAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,OAAO,CAAA;KAAE,CAAC;IA2BlD;;;OAGG;IACG,UAAU,CACd,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,UAAU,GAAE,OAAe;IAsH7B;;OAEG;IACG,mBAAmB;IAkCzB;;OAEG;WACU,WAAW,CACtB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;IA0DnB;;;OAGG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAkFlD;;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;IA0GjB;;OAEG;WACU,aAAa,CACxB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;CA2FpB"}
@@ -86,6 +86,46 @@ class PropagationServer {
86
86
  rejectUnauthorized: false,
87
87
  });
88
88
  }
89
+ /**
90
+ * Ping the current peer about an update to the store, passing rootHash.
91
+ * @param rootHash - The root hash for the store update.
92
+ */
93
+ async pingUpdate(rootHash) {
94
+ const spinner = (0, nanospinner_1.createSpinner)(`Pinging peer ${this.ipAddress}...`).start();
95
+ try {
96
+ const httpsAgent = this.createHttpsAgent();
97
+ const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/update`;
98
+ const config = {
99
+ httpsAgent,
100
+ headers: {
101
+ "Content-Type": "application/json",
102
+ },
103
+ };
104
+ // Data to send in the request (storeId and rootHash)
105
+ const data = {
106
+ storeId: this.storeId,
107
+ rootHash: rootHash,
108
+ updateTime: new Date().toISOString(),
109
+ };
110
+ try {
111
+ const response = await axios_1.default.post(url, data, config);
112
+ console.log((0, colorette_1.green)(`✔ Successfully pinged peer: ${this.ipAddress}`));
113
+ spinner.success({
114
+ text: (0, colorette_1.green)(`✔ Successfully pinged peer ${this.ipAddress} with rootHash ${rootHash}`),
115
+ });
116
+ return response.data;
117
+ }
118
+ catch (error) {
119
+ console.error((0, colorette_1.red)(`✖ Failed to ping peer: ${this.ipAddress}`));
120
+ console.error((0, colorette_1.red)(error.message));
121
+ throw error;
122
+ }
123
+ }
124
+ catch (error) {
125
+ spinner.error({ text: (0, colorette_1.red)("✖ Error pinging network peer.") });
126
+ console.error((0, colorette_1.red)(error.message));
127
+ }
128
+ }
89
129
  /**
90
130
  * Adds a custom inactivity timeout for large file transfers.
91
131
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/dig-sdk",
3
- "version": "0.0.1-alpha.127",
3
+ "version": "0.0.1-alpha.128",
4
4
  "description": "",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",