feat: implement automatic ring positioning
- Remove manual --position parameter from CLI - Add automatic optimal position calculation based on gap analysis - Implement dynamic ring topology management - Add position tracking and synchronization across nodes - Add topology command for visual ring structure inspection - Clean up unused variables and dead code - Simplify node setup with automatic positioning
Este commit está contenido en:
32
node.js
32
node.js
@@ -19,9 +19,6 @@ for (let i = 0; i < args.length; i++) {
|
||||
case '--bootstrap':
|
||||
options.bootstrap = args[++i];
|
||||
break;
|
||||
case '--position':
|
||||
options.ringPosition = parseInt(args[++i]);
|
||||
break;
|
||||
case '--ice-servers':
|
||||
try {
|
||||
options.iceServers = JSON.parse(args[++i]);
|
||||
@@ -52,7 +49,6 @@ Options:
|
||||
--port <port> Port to listen on (default: random)
|
||||
--id <id> Node ID (default: auto-generated)
|
||||
--bootstrap <addr> Bootstrap node address (host:port)
|
||||
--position <pos> Initial ring position (default: 0)
|
||||
--ice-servers <json> ICE servers configuration (JSON array)
|
||||
--config <file> Load configuration from JSON file
|
||||
--help Show this help message
|
||||
@@ -62,6 +58,8 @@ Examples:
|
||||
node node.js --port 8081 --bootstrap localhost:8080
|
||||
node node.js --id mynode --port 8082 --bootstrap localhost:8080
|
||||
node node.js --config config/ice-servers-with-turn.json --port 8080
|
||||
|
||||
Note: Ring positions are now assigned automatically for optimal network topology.
|
||||
|
||||
ICE Servers Example:
|
||||
--ice-servers '[{"urls":"stun:stun.l.google.com:19302"},{"urls":"turn:turn.example.com:3478","username":"user","credential":"pass"}]'
|
||||
@@ -175,6 +173,31 @@ function handleCommand(command) {
|
||||
}
|
||||
break;
|
||||
|
||||
case 'topology':
|
||||
const topology = node.getRingTopology();
|
||||
console.log(chalk.blue('\n🔄 Ring Topology:'));
|
||||
console.log(` Ring Size: ${topology.ringSize}`);
|
||||
console.log(` Total Nodes: ${topology.totalNodes}`);
|
||||
console.log(` My Position: ${node.ringPosition}`);
|
||||
|
||||
if (topology.nodes.length > 0) {
|
||||
console.log(chalk.yellow('\n📍 Node Positions:'));
|
||||
topology.nodes.forEach(nodeInfo => {
|
||||
const indicators = [];
|
||||
if (nodeInfo.isThisNode) indicators.push(chalk.green('ME'));
|
||||
if (nodeInfo.isOracle) indicators.push(chalk.yellow('🔮'));
|
||||
if (nodeInfo.isConnected) indicators.push(chalk.green('✓'));
|
||||
|
||||
const indicatorStr = indicators.length > 0 ? ` [${indicators.join(' ')}]` : '';
|
||||
console.log(` ${nodeInfo.position.toString().padStart(4)}: ${nodeInfo.nodeId}...${indicatorStr}`);
|
||||
});
|
||||
|
||||
console.log(chalk.cyan('\n🔄 Ring Connections:'));
|
||||
console.log(` Inner Ring: ${topology.innerRing.left}... ← ME → ${topology.innerRing.right}...`);
|
||||
console.log(` Outer Ring: ${topology.outerRing.left}... ← ME → ${topology.outerRing.right}...`);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'help':
|
||||
console.log(chalk.blue(`
|
||||
📚 Available Commands:
|
||||
@@ -182,6 +205,7 @@ function handleCommand(command) {
|
||||
info - Show network information
|
||||
peers - List connected peers
|
||||
connections - Show persistent connection status
|
||||
topology - Show ring topology and positions
|
||||
help - Show this help
|
||||
quit - Exit the node
|
||||
`));
|
||||
|
||||
Referencia en una nueva incidencia
Block a user