2026-04-18 04:42:13 -05:00
|
|
|
#ifndef H_SERVICES
|
|
|
|
|
#define H_SERVICES
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <netdb.h>
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
|
|
#include "../deps/vector/vector.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
2026-04-20 19:21:03 -05:00
|
|
|
enum State { NONE, DOWN, PARTIAL, UP };
|
2026-04-18 04:42:13 -05:00
|
|
|
struct StatusPeroid;
|
|
|
|
|
struct ServerStatus;
|
|
|
|
|
struct EndpointStatus;
|
|
|
|
|
struct Endpoint;
|
|
|
|
|
struct Service;
|
|
|
|
|
|
|
|
|
|
void report();
|
|
|
|
|
void* run_endpoint(void* endpoint);
|
|
|
|
|
void queue_report(struct EndpointStatus status);
|
|
|
|
|
void load_service(struct Service** self);
|
|
|
|
|
uint8_t add_endpoint(struct Service* self, const char* uri);
|
|
|
|
|
enum State get_state(struct Service** self);
|
|
|
|
|
struct ServerStatus* update_server_status(struct Service** self);
|
|
|
|
|
const char* state_text(enum State state);
|
|
|
|
|
|
|
|
|
|
struct StatusPeroid {
|
|
|
|
|
unsigned long time;
|
|
|
|
|
Vector server_statuses; // of ServerStatus*
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ServerStatus {
|
|
|
|
|
struct Service* service;
|
|
|
|
|
Vector endpoint_statuses; // of EndpointStatus*
|
|
|
|
|
enum State state;
|
|
|
|
|
double ping;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct EndpointStatus {
|
|
|
|
|
struct Endpoint* endpoint;
|
|
|
|
|
enum State state;
|
|
|
|
|
double ping;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Endpoint {
|
|
|
|
|
struct Service* service;
|
|
|
|
|
uint8_t enabled;
|
|
|
|
|
uint8_t running;
|
|
|
|
|
char* scheme;
|
|
|
|
|
char* target;
|
|
|
|
|
uint16_t port;
|
|
|
|
|
uint32_t backoff;
|
|
|
|
|
time_t last_check;
|
|
|
|
|
enum State last_state;
|
|
|
|
|
double last_ping;
|
|
|
|
|
Vector status_history;
|
|
|
|
|
pthread_t thread;
|
2026-04-20 19:21:03 -05:00
|
|
|
struct addrinfo* addr;
|
2026-04-18 04:42:13 -05:00
|
|
|
int sockfd;
|
|
|
|
|
int last_errno;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Service {
|
|
|
|
|
char* id;
|
|
|
|
|
char* name;
|
|
|
|
|
char* text;
|
|
|
|
|
Vector endpoints;
|
|
|
|
|
enum State last_state;
|
|
|
|
|
double average_ping;
|
|
|
|
|
uint32_t backoff;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|