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:
ale
2025-06-17 00:15:09 +02:00
padre e238b4b307
commit 303b3fa9f7
Se han modificado 7 ficheros con 299 adiciones y 87 borrados

Ver fichero

@@ -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
@@ -63,6 +59,8 @@ Examples:
node oracle.js --id oracle1 --port 8082 --bootstrap localhost:8080
node oracle.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"}]'
@@ -240,6 +238,31 @@ async function handleCommand(command) {
}
break;
case 'topology':
const topology = oracle.getRingTopology();
console.log(chalk.blue('\n🔄 Ring Topology:'));
console.log(` Ring Size: ${topology.ringSize}`);
console.log(` Total Nodes: ${topology.totalNodes}`);
console.log(` My Position: ${oracle.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.yellow(`
🔮 Oracle Commands:
@@ -253,6 +276,7 @@ async function handleCommand(command) {
get <key> - Retrieve data from storage
propose <text> - Create a consensus proposal
vote <id> <yes|no> - Vote on a proposal
topology - Show ring topology and positions
help - Show this help
quit - Exit the oracle
`));