@hive-p2p/server 1.0.85 → 1.0.87

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.
package/core/gossip.mjs CHANGED
@@ -108,10 +108,10 @@ export class Gossip {
108
108
  const serializedMessage = this.cryptoCodex.createGossipMessage(topic, data, hops, this.peerStore.neighborsList);
109
109
  if (!this.bloomFilter.addMessage(serializedMessage)) return; // avoid sending duplicate messages
110
110
  if (this.verbose > 3) console.log(`(${this.id}) Gossip ${topic}, to ${JSON.stringify(this.peerStore.neighborsList)}: ${data}`);
111
- for (const peerId of this.peerStore.neighborsList) this.#broadcastToPeer(peerId, serializedMessage);
111
+ for (const peerId of this.peerStore.neighborsList) this.broadcastToPeer(peerId, serializedMessage);
112
112
  }
113
113
  /** @param {string} targetId @param {any} serializedMessage */
114
- #broadcastToPeer(targetId, serializedMessage) {
114
+ broadcastToPeer(targetId, serializedMessage) {
115
115
  if (targetId === this.id) throw new Error(`Refusing to send a gossip message to self (${this.id}).`);
116
116
  const transportInstance = this.peerStore.connected[targetId]?.transportInstance;
117
117
  if (!transportInstance) return { success: false, reason: `Transport instance is not available for peer ${targetId}.` };
@@ -120,7 +120,7 @@ export class Gossip {
120
120
  }
121
121
  sendGossipHistoryToPeer(peerId) {
122
122
  const gossipHistory = this.bloomFilter.getGossipHistoryByTime('asc');
123
- for (const entry of gossipHistory) this.#broadcastToPeer(peerId, entry.data);
123
+ for (const entry of gossipHistory) this.broadcastToPeer(peerId, entry.data);
124
124
  }
125
125
  /** @param {string} from @param {Uint8Array} serialized @returns {void} */
126
126
  async handleGossipMessage(from, serialized) {
@@ -156,6 +156,6 @@ export class Gossip {
156
156
  for (const peerId of this.peerStore.neighborsList)
157
157
  if (peerId === from) continue; // avoid sending back to sender
158
158
  else if (!avoidTransmissionRate && Math.random() > transmissionRate) continue; // apply gossip transmission rate
159
- else this.#broadcastToPeer(peerId, serializedToTransmit);
159
+ else this.broadcastToPeer(peerId, serializedToTransmit);
160
160
  }
161
161
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hive-p2p/server",
3
- "version": "1.0.85",
3
+ "version": "1.0.87",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -112,16 +112,13 @@ export class Clock {
112
112
 
113
113
  try {
114
114
  const startTime = Date.now();
115
- const response = await fetch(this.proxyUrl, { method: 'HEAD', signal: controller.signal });
115
+ const response = await fetch(this.proxyUrl, { signal: controller.signal });
116
116
  const networkLatency = (Date.now() - startTime) / 2;
117
- if (!response.ok) throw new Error(`HTTP ${response.status}`);
118
-
119
- const serverTime = new Date(response.headers.get('date')).getTime();
120
- if (isNaN(serverTime)) throw new Error('Invalid date header');
117
+ const data = await response.json();
121
118
 
122
119
  return {
123
120
  source: 'proxy',
124
- serverTime: serverTime + networkLatency,
121
+ serverTime: data.time + networkLatency,
125
122
  localTime: Date.now(),
126
123
  latency: networkLatency * 2
127
124
  };