Fix P2P discovery and networking

This commit is contained in:
2025-08-31 14:12:01 -04:00
parent 1f92098d8e
commit b5d78b2bd9
2 changed files with 192 additions and 5 deletions

View File

@@ -109,6 +109,9 @@ public class P2PConsole
case "upnp":
await ShowUPnPStatusAsync();
break;
case "discovery":
await ShowDiscoveryInfoAsync();
break;
case "exit":
case "quit":
System.Console.WriteLine("Stopping P2P node...");
@@ -144,6 +147,7 @@ public class P2PConsole
System.Console.WriteLine(" migrate <vm-id> <node-id> - Migrate VM to different node");
System.Console.WriteLine(" forward <vm-id> <port> - Forward port for VM (master only)");
System.Console.WriteLine(" upnp - Show UPnP status");
System.Console.WriteLine(" discovery - Show network discovery information");
System.Console.WriteLine(" help - Show this help");
System.Console.WriteLine(" exit/quit - Exit the application");
}
@@ -518,4 +522,51 @@ public class P2PConsole
var input = System.Console.ReadLine()?.Trim();
return string.IsNullOrEmpty(input) ? defaultValue : input;
}
private async Task ShowDiscoveryInfoAsync()
{
System.Console.WriteLine("=== Network Discovery Information ===");
System.Console.WriteLine($"Current Node ID: {_p2pNode.CurrentNode.NodeId}");
System.Console.WriteLine($"Current Node IP: {_p2pNode.CurrentNode.IpAddress}");
System.Console.WriteLine($"Current Node Port: {_p2pNode.CurrentNode.Port}");
System.Console.WriteLine($"Current Role: {_p2pNode.CurrentNode.Role}");
System.Console.WriteLine($"Is Master: {_p2pNode.IsMaster}");
System.Console.WriteLine();
// Get cluster state to show known nodes
var cluster = _p2pNode.ClusterState;
System.Console.WriteLine($"Known Nodes: {cluster.Nodes.Count}");
if (cluster.Nodes.Count > 0)
{
System.Console.WriteLine();
System.Console.WriteLine("=== Known Nodes ===");
System.Console.WriteLine($"{"Node ID",-20} {"IP Address",-15} {"Port",-8} {"Role",-10} {"Last Seen"}");
System.Console.WriteLine(new string('-', 80));
foreach (var node in cluster.Nodes.Values)
{
var lastSeen = node.LastSeen.ToString("HH:mm:ss");
System.Console.WriteLine($"{node.NodeId,-20} {node.IpAddress,-15} {node.Port,-8} {node.Role,-10} {lastSeen}");
}
}
else
{
System.Console.WriteLine("No other nodes discovered yet.");
System.Console.WriteLine();
System.Console.WriteLine("Discovery troubleshooting:");
System.Console.WriteLine("1. Make sure other nodes are running on the same network");
System.Console.WriteLine("2. Check if firewall is blocking UDP port 8080");
System.Console.WriteLine("3. Try running multiple instances on different machines");
System.Console.WriteLine("4. Check network connectivity between nodes");
}
System.Console.WriteLine();
System.Console.WriteLine("=== Network Configuration ===");
System.Console.WriteLine("UDP Discovery: Enabled (port 8080)");
System.Console.WriteLine("TCP Communication: Enabled (port 8081)");
System.Console.WriteLine("Heartbeat Interval: 5 seconds");
System.Console.WriteLine("Discovery Interval: 30 seconds");
System.Console.WriteLine("Node Timeout: 30 seconds");
}
}