@hive-p2p/server 1.0.66 → 1.0.68

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.
Files changed (2) hide show
  1. package/core/unicast.mjs +9 -2
  2. package/package.json +1 -1
package/core/unicast.mjs CHANGED
@@ -83,6 +83,8 @@ export class UnicastMessager {
83
83
  if (!builtResult.success) return false;
84
84
 
85
85
  // Caution: re-routing usage who can involve insane results
86
+ const destinations = [];
87
+ const createdMessagePromises = [];
86
88
  const finalSpread = builtResult.success === 'blind' ? 1 : spread; // Spread only if re-routing is false
87
89
  for (let i = 0; i < Math.min(finalSpread, builtResult.routes.length); i++) {
88
90
  const route = builtResult.routes[i].path;
@@ -90,9 +92,14 @@ export class UnicastMessager {
90
92
  if (this.verbose > 1) console.warn(`Cannot send unicast message to ${remoteId} as route exceeds maxHops (${UNICAST.MAX_HOPS}). BFS incurred.`);
91
93
  continue; // too long route
92
94
  }
93
- const message = await this.cryptoCodex.createUnicastMessage(type, data, route, this.peerStore.neighborsList);
94
- this.#sendMessageToPeer(route[1], message); // send to next peer
95
+
96
+ destinations.push(route[1]); // send to next peer
97
+ createdMessagePromises.push(this.cryptoCodex.createUnicastMessage(type, data, route, this.peerStore.neighborsList));
95
98
  }
99
+
100
+ const createdMessages = await Promise.all(createdMessagePromises);
101
+ for (let i = 0; i < createdMessages.length; i++)
102
+ this.#sendMessageToPeer(destinations[i], createdMessages[i]);
96
103
  return true;
97
104
  }
98
105
  /** @param {string} targetId @param {Uint8Array} serialized */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hive-p2p/server",
3
- "version": "1.0.66",
3
+ "version": "1.0.68",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },