|
#ifndef RPROXY_TYPES_H
|
|
#define RPROXY_TYPES_H
|
|
|
|
#ifndef _GNU_SOURCE
|
|
#define _GNU_SOURCE
|
|
#endif
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <time.h>
|
|
#include <openssl/ssl.h>
|
|
#include <sqlite3.h>
|
|
|
|
#define MAX_EVENTS 4096
|
|
#define MAX_FDS 65536
|
|
#define CHUNK_SIZE 65536
|
|
#define HISTORY_SECONDS 300
|
|
#define MAX_HEADER_SIZE 8192
|
|
#define MAX_REQUEST_LINE_SIZE 4096
|
|
#define MAX_URI_SIZE 2048
|
|
#define CONNECTION_TIMEOUT 300
|
|
|
|
typedef enum {
|
|
CONN_TYPE_UNUSED,
|
|
CONN_TYPE_LISTENER,
|
|
CONN_TYPE_CLIENT,
|
|
CONN_TYPE_UPSTREAM
|
|
} conn_type_t;
|
|
|
|
typedef enum {
|
|
CLIENT_STATE_READING_HEADERS,
|
|
CLIENT_STATE_FORWARDING,
|
|
CLIENT_STATE_SERVING_INTERNAL,
|
|
CLIENT_STATE_ERROR,
|
|
CLIENT_STATE_CLOSING
|
|
} client_state_t;
|
|
|
|
typedef struct {
|
|
char *data;
|
|
size_t capacity;
|
|
size_t head;
|
|
size_t tail;
|
|
} buffer_t;
|
|
|
|
typedef struct {
|
|
char method[32];
|
|
char uri[MAX_URI_SIZE];
|
|
char version[16];
|
|
char host[256];
|
|
long content_length;
|
|
int is_websocket;
|
|
int keep_alive;
|
|
int connection_close;
|
|
bool is_chunked;
|
|
} http_request_t;
|
|
|
|
struct connection_s;
|
|
struct vhost_stats_s;
|
|
|
|
typedef struct connection_s {
|
|
conn_type_t type;
|
|
client_state_t state;
|
|
int fd;
|
|
struct connection_s *pair;
|
|
struct vhost_stats_s *vhost_stats;
|
|
buffer_t read_buf;
|
|
buffer_t write_buf;
|
|
SSL *ssl;
|
|
int ssl_handshake_done;
|
|
http_request_t request;
|
|
double request_start_time;
|
|
time_t last_activity;
|
|
int half_closed;
|
|
int write_shutdown;
|
|
} connection_t;
|
|
|
|
typedef struct {
|
|
char hostname[256];
|
|
char upstream_host[256];
|
|
int upstream_port;
|
|
int use_ssl;
|
|
int rewrite_host;
|
|
} route_config_t;
|
|
|
|
typedef struct {
|
|
int port;
|
|
route_config_t *routes;
|
|
int route_count;
|
|
} app_config_t;
|
|
|
|
typedef struct {
|
|
double time;
|
|
double value;
|
|
} history_point_t;
|
|
|
|
typedef struct {
|
|
history_point_t *points;
|
|
int capacity;
|
|
int head;
|
|
int count;
|
|
} history_deque_t;
|
|
|
|
typedef struct {
|
|
double time;
|
|
double rx_kbps;
|
|
double tx_kbps;
|
|
} network_history_point_t;
|
|
|
|
typedef struct {
|
|
network_history_point_t *points;
|
|
int capacity;
|
|
int head;
|
|
int count;
|
|
} network_history_deque_t;
|
|
|
|
typedef struct {
|
|
double time;
|
|
double read_mbps;
|
|
double write_mbps;
|
|
} disk_history_point_t;
|
|
|
|
typedef struct {
|
|
disk_history_point_t *points;
|
|
int capacity;
|
|
int head;
|
|
int count;
|
|
} disk_history_deque_t;
|
|
|
|
typedef struct {
|
|
double *times;
|
|
int capacity;
|
|
int head;
|
|
int count;
|
|
} request_time_deque_t;
|
|
|
|
typedef struct vhost_stats_s {
|
|
char vhost_name[256];
|
|
long long http_requests;
|
|
long long websocket_requests;
|
|
long long total_requests;
|
|
long long bytes_sent;
|
|
long long bytes_recv;
|
|
double avg_request_time_ms;
|
|
long long last_bytes_sent;
|
|
long long last_bytes_recv;
|
|
double last_update;
|
|
history_deque_t throughput_history;
|
|
request_time_deque_t request_times;
|
|
struct vhost_stats_s *next;
|
|
} vhost_stats_t;
|
|
|
|
typedef struct {
|
|
time_t start_time;
|
|
int active_connections;
|
|
history_deque_t cpu_history;
|
|
history_deque_t memory_history;
|
|
network_history_deque_t network_history;
|
|
disk_history_deque_t disk_history;
|
|
history_deque_t throughput_history;
|
|
history_deque_t load1_history;
|
|
history_deque_t load5_history;
|
|
history_deque_t load15_history;
|
|
long long last_net_sent;
|
|
long long last_net_recv;
|
|
long long last_disk_read;
|
|
long long last_disk_write;
|
|
double last_net_update_time;
|
|
double last_disk_update_time;
|
|
vhost_stats_t *vhost_stats_head;
|
|
sqlite3 *db;
|
|
} system_monitor_t;
|
|
|
|
#endif
|