#ifndef MAZE32_GATEWAY_H #define MAZE32_GATEWAY_H #include #include #include "esp_err.h" #include "esp_http_server.h" #include "esp_timer.h" #include "maze32_lobby.h" #ifdef __cplusplus extern "C" { #endif #define MAZE32_GATEWAY_CONNECTION_LIMIT MAZE32_SESSION_LIMIT #define MAZE32_GATEWAY_QUEUE_LIMIT 12U #define MAZE32_GATEWAY_OUTGOING_LIMIT 768U #define MAZE32_GATEWAY_RATE_LIMIT_PER_SECOND 20U typedef struct { int active; int socket_fd; uint32_t last_client_sequence; uint64_t rate_window_started_ms; unsigned int messages_in_window; } maze32_gateway_connection_t; typedef struct { int socket_fd; size_t length; char payload[MAZE32_GATEWAY_OUTGOING_LIMIT]; } maze32_gateway_outgoing_t; typedef struct { httpd_handle_t server; maze32_lobby_t lobby; maze32_gateway_connection_t connections[MAZE32_GATEWAY_CONNECTION_LIMIT]; maze32_gateway_outgoing_t outgoing[MAZE32_GATEWAY_QUEUE_LIMIT]; size_t outgoing_head; size_t outgoing_count; uint32_t server_sequence; unsigned int suggestion_index; esp_timer_handle_t countdown_timer; } maze32_gateway_t; esp_err_t maze32_gateway_init(maze32_gateway_t* gateway); void maze32_gateway_set_server(maze32_gateway_t* gateway, httpd_handle_t server); esp_err_t maze32_gateway_register(httpd_handle_t server, maze32_gateway_t* gateway); void maze32_gateway_close_socket(httpd_handle_t server, int socket_fd); int maze32_gateway_can_reconfigure(const maze32_gateway_t* gateway); #ifdef __cplusplus } #endif #endif