@hive-p2p/server 1.0.86 → 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 +4 -4
- package/package.json +1 -1
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
|
|
111
|
+
for (const peerId of this.peerStore.neighborsList) this.broadcastToPeer(peerId, serializedMessage);
|
|
112
112
|
}
|
|
113
113
|
/** @param {string} targetId @param {any} serializedMessage */
|
|
114
|
-
|
|
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
|
|
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
|
|
159
|
+
else this.broadcastToPeer(peerId, serializedToTransmit);
|
|
160
160
|
}
|
|
161
161
|
}
|