feat: new cluster forming protocoll

This commit is contained in:
2025-10-19 12:51:31 +02:00
parent b6b55c0a6f
commit d166b0b634
3 changed files with 149 additions and 139 deletions

View File

@@ -49,7 +49,7 @@ The backend now includes automatic UDP discovery for SPORE nodes on the network.
### 🚀 How It Works
1. **UDP Server**: The backend listens on port 4210 for UDP messages
2. **Discovery Message**: Nodes send `CLUSTER_DISCOVERY` messages to broadcast address `255.255.255.255:4210`
2. **Heartbeat Message**: Nodes send `CLUSTER_HEARTBEAT` messages to broadcast address `255.255.255.255:4210`
3. **Auto Configuration**: When a discovery message is received, the source IP is automatically used to configure the SporeApiClient
4. **Dynamic Updates**: The system automatically switches to the most recently seen node as the primary connection
5. **Health Monitoring**: Continuous monitoring of node availability with automatic failover
@@ -57,7 +57,7 @@ The backend now includes automatic UDP discovery for SPORE nodes on the network.
### 📡 Discovery Protocol
- **Port**: 4210 (configurable via `UDP_PORT` constant)
- **Message**: `CLUSTER_DISCOVERY` (configurable via `DISCOVERY_MESSAGE` constant)
- **Message**: `CLUSTER_HEARTBEAT` (configurable via `HEARTBEAT_MESSAGE` constant)
- **Broadcast**: `255.255.255.255:4210`
- **Protocol**: UDP broadcast listening
- **Auto-binding**: Automatically binds to the specified port on startup
@@ -72,27 +72,27 @@ npm start
# The server will automatically:
# - Start HTTP server on port 3001
# - Start UDP discovery server on port 4210
# - Wait for CLUSTER_DISCOVERY messages
# - Wait for CLUSTER_HEARTBEAT messages
```
#### Node Configuration
SPORE nodes should send discovery messages periodically:
SPORE nodes should send heartbeat messages periodically:
```bash
# Recommended: Send every 30-60 seconds
# Message format: "CLUSTER_DISCOVERY"
# Message format: "CLUSTER_HEARTBEAT:hostname"
# Target: 255.255.255.255:4210
```
### 🌐 Discovery Endpoints
### 🌐 Cluster Endpoints
#### Discovery Management
- `GET /api/discovery/nodes` - View all discovered nodes and current status
- `POST /api/discovery/refresh` - Manually trigger discovery refresh
#### Cluster Management
- `GET /api/discovery/nodes` - View all cluster nodes and current status
- `POST /api/discovery/refresh` - Manually trigger cluster refresh
- `POST /api/discovery/primary/:ip` - Manually set a specific node as primary
- `POST /api/discovery/random-primary` - Randomly select a new primary node
#### Health Monitoring
- `GET /api/health` - Comprehensive health check including discovery status
- `GET /api/health` - Comprehensive health check including cluster status
### 🧪 Testing & Development