- u_async.c: process immediate_queue BEFORE epoll_wait in uasync_poll - stcp_link.c: defensive NULL etcp_conn/etcp_link in stcp_link_close - utun_instance.c: move stcp_server_list_destroy_all to Phase J (before ETCP), add deferred drain in both Phase J and L - stcp.h/c: STCP_HS_ENC_CLIENT 6→38, STCP_HS_ENC_SERVER 7→39, exchange ed25519_pubkey in both handshake directions - etcp_connections.c: copy peer_ed25519 from STCP to ETCP_CONN in etcp_link_enter_ready_tcp; guard link->etcp in tcp_link_close_cb - chat_sync.c: fix lk->conn NULL dereference for TCP links - test_stcp.c: update stcp_server_create/stcp_client_connect callsites - tools/chat_tcp_test: change transport udp→tcp
128 lines
3.7 KiB
C
128 lines
3.7 KiB
C
/*
|
|
* control_server.h - Control Socket Server for ETCP Monitoring
|
|
*
|
|
* Provides TCP control interface for ETCP connection monitoring
|
|
*/
|
|
|
|
#ifndef CONTROL_SERVER_H
|
|
#define CONTROL_SERVER_H
|
|
|
|
#include "../tools/etcpmon/etcpmon_protocol.h"
|
|
#include "../lib/socket_compat.h"
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* Forward declarations */
|
|
struct UTUN_INSTANCE;
|
|
struct UASYNC;
|
|
struct TOPO_GROUP_NODE;
|
|
struct ll_queue;
|
|
|
|
/* Forward declaration */
|
|
struct control_server;
|
|
|
|
/* Client connection state */
|
|
struct control_client {
|
|
struct control_client* next; /* Linked list */
|
|
struct control_server* server; /* Back pointer to server */
|
|
socket_t fd; /* Client socket */
|
|
void* socket_id; /* uasync socket ID */
|
|
|
|
/* Receive buffer */
|
|
uint8_t recv_buffer[ETCPMON_MAX_MSG_SIZE];
|
|
uint16_t recv_len; /* Bytes received so far */
|
|
|
|
/* Selected connection */
|
|
uint64_t selected_peer_id; /* 0 = none selected */
|
|
|
|
struct ll_queue* output_queue; /* Output queue for async sends */
|
|
void* idle_timer; /* Client idle timeout */
|
|
uint8_t subscribed_nodes; /* 1 = subscribed to node updates */
|
|
uint8_t write_registered; /* 1 = write events registered in uasync */
|
|
};
|
|
|
|
/* Control server state */
|
|
struct control_server {
|
|
struct UTUN_INSTANCE* instance; /* Parent instance */
|
|
struct UASYNC* ua; /* Async context */
|
|
|
|
/* Listening socket */
|
|
socket_t listen_fd;
|
|
void* listen_socket_id; /* uasync socket ID */
|
|
struct sockaddr_storage bind_addr; /* Bound address */
|
|
|
|
/* Client connections */
|
|
struct control_client* clients; /* Linked list of clients */
|
|
uint32_t client_count; /* Number of connected clients */
|
|
uint32_t max_clients; /* Maximum allowed clients */
|
|
|
|
/* Log file */
|
|
FILE* log_file;
|
|
};
|
|
|
|
/* ============================================================================
|
|
* Public API
|
|
* ============================================================================ */
|
|
|
|
/* Initialize control server
|
|
*
|
|
* Creates listening socket and registers with uasync
|
|
*
|
|
* Parameters:
|
|
* server - Server state structure to initialize
|
|
* ua - uasync context for event handling
|
|
* instance - Parent utun instance
|
|
* bind_addr - Address to bind (from config control_sock)
|
|
* max_clients - Maximum concurrent client connections
|
|
*
|
|
* Returns:
|
|
* 0 on success, -1 on error
|
|
*/
|
|
int control_server_init(struct control_server* server,
|
|
struct UASYNC* ua,
|
|
struct UTUN_INSTANCE* instance,
|
|
struct sockaddr_storage* bind_addr,
|
|
uint32_t max_clients);
|
|
|
|
/* Shutdown control server
|
|
*
|
|
* Closes all client connections and listening socket
|
|
*
|
|
* Parameters:
|
|
* server - Server state to shutdown
|
|
*/
|
|
void control_server_shutdown(struct control_server* server);
|
|
|
|
/* Process periodic updates
|
|
*
|
|
* Should be called periodically (e.g., from main loop) to send
|
|
* metrics updates to clients that have selected connections
|
|
*
|
|
* Parameters:
|
|
* server - Server state
|
|
*/
|
|
void control_server_process_updates(struct control_server* server);
|
|
|
|
/* Get number of connected clients
|
|
*
|
|
* Parameters:
|
|
* server - Server state
|
|
*
|
|
* Returns:
|
|
* Number of connected clients
|
|
*/
|
|
uint32_t control_server_get_client_count(const struct control_server* server);
|
|
|
|
void control_server_notify_node_change(struct control_server* server, struct TOPO_GROUP_NODE* node);
|
|
void control_server_notify_node_removed(struct control_server* server, uint64_t node_id);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* CONTROL_SERVER_H */
|