mirror of
https://github.com/lklynet/hypermind.git
synced 2026-05-03 09:30:36 +00:00
feat(p2p): increase max relay hops and improve gossip algorithm
Increase MAX_RELAY_HOPS from 2 to 5 for better message propagation. Update gossip algorithm to scale with connection count, using a minimum of 6 or 25% of eligible peers.
This commit is contained in:
@@ -101,7 +101,7 @@ Tune the network parameters to fit your system resources. The defaults are safe
|
||||
|----------|---------|-------------|
|
||||
| `MAX_PEERS` | `50000` | Maximum number of peers to track in memory. |
|
||||
| `MAX_MESSAGE_SIZE` | `2048` | Maximum size of a single message in bytes. |
|
||||
| `MAX_RELAY_HOPS` | `2` | Maximum number of times a message is relayed. |
|
||||
| `MAX_RELAY_HOPS` | `5` | Maximum number of times a message is relayed. |
|
||||
| `MAX_CONNECTIONS` | `15` | Maximum number of active P2P connections. |
|
||||
| `HEARTBEAT_INTERVAL` | `30000` | How often (ms) to send heartbeat messages. |
|
||||
| `CONNECTION_ROTATION_INTERVAL` | `300000` | How often (ms) to rotate connections. |
|
||||
|
||||
+1
-1
@@ -19,6 +19,6 @@ services:
|
||||
# - CONNECTION_ROTATION_INTERVAL=300000 # Connection rotation frequency (ms)
|
||||
# - PEER_TIMEOUT=45000 # Time before peer is considered offline (ms)
|
||||
# - MAX_MESSAGE_SIZE=2048 # Max message size (bytes)
|
||||
# - MAX_RELAY_HOPS=2 # Max message relay hops
|
||||
# - MAX_RELAY_HOPS=5 # Max message relay hops
|
||||
# - CHAT_RATE_LIMIT=5000 # Chat rate limit window (ms)
|
||||
# - VISUAL_LIMIT=500 # Max particles on dashboard
|
||||
|
||||
@@ -18,7 +18,7 @@ const VERIFICATION_POW_PREFIX = "0000";
|
||||
|
||||
const MAX_PEERS = parseInt(process.env.MAX_PEERS) || 50000;
|
||||
const MAX_MESSAGE_SIZE = parseInt(process.env.MAX_MESSAGE_SIZE) || 2048;
|
||||
const MAX_RELAY_HOPS = parseInt(process.env.MAX_RELAY_HOPS) || 2;
|
||||
const MAX_RELAY_HOPS = parseInt(process.env.MAX_RELAY_HOPS) || 5;
|
||||
const MAX_CONNECTIONS = parseInt(process.env.MAX_CONNECTIONS) || 15;
|
||||
|
||||
const HEARTBEAT_INTERVAL = parseInt(process.env.HEARTBEAT_INTERVAL) || 30000;
|
||||
|
||||
+7
-5
@@ -2,13 +2,15 @@ const relayMessage = (msg, sourceSocket, swarm, diagnostics) => {
|
||||
const data = JSON.stringify(msg) + "\n";
|
||||
|
||||
// Gossip Subsampling:
|
||||
// Instead of flooding everyone (which causes massive bandwidth usage with 50 connections),
|
||||
// we relay to a random subset of peers (e.g., 6).
|
||||
// This maintains "Epidemic" reach (O(log N)) while capping bandwidth.
|
||||
|
||||
const TARGET_GOSSIP_COUNT = 6;
|
||||
// We relay to a subset of peers to prevent flooding, but scale with connection count.
|
||||
// We use a minimum of 6 or 25% of eligible peers, whichever is larger.
|
||||
|
||||
const allSockets = Array.from(swarm.connections);
|
||||
const eligible = allSockets.filter((s) => s !== sourceSocket);
|
||||
|
||||
const MIN_GOSSIP_COUNT = 6;
|
||||
const GOSSIP_FACTOR = 0.25; // Relay to 25% of peers
|
||||
const TARGET_GOSSIP_COUNT = Math.max(MIN_GOSSIP_COUNT, Math.ceil(eligible.length * GOSSIP_FACTOR));
|
||||
|
||||
let targets = eligible;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user