105 lines
2.9 KiB
C
105 lines
2.9 KiB
C
#ifndef DEPLOYD_PROTO_H_
|
|
#define DEPLOYD_PROTO_H_
|
|
|
|
#include "conf.h"
|
|
|
|
#include "def.h"
|
|
#include "log.h"
|
|
|
|
#include <sqlite3.h>
|
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#define DP_DOMAIN_LEN 64
|
|
#define DP_PACKET_SIZE 1024
|
|
#define DP_VERSION "1.0.0"
|
|
|
|
#define DP_PROTO_LOG "proto"
|
|
|
|
typedef enum {
|
|
/* Deploy packets: 0x0N */
|
|
dp_PacketType_command = (uint8_t)0x00,
|
|
|
|
/* Status packets: 0x1N */
|
|
dp_PacketType_ping = (uint8_t)0x10,
|
|
dp_PacketType_ping_reply = (uint8_t)0x11,
|
|
dp_PacketType_allowed = (uint8_t)0x12,
|
|
dp_PacketType_ready = (uint8_t)0x13,
|
|
|
|
/* Log packets: 0x2N */
|
|
dp_PacketType_log = (uint8_t)0x20,
|
|
dp_PacketType_logs_end = (uint8_t)0x21,
|
|
|
|
/* Flow packets: 0x3N */
|
|
dp_PacketType_exit = (uint8_t)0x30,
|
|
|
|
/* Error packet: 0xff */
|
|
dp_PacketType_error = (uint8_t)0xff,
|
|
} dp_PacketType;
|
|
|
|
typedef enum {
|
|
dp_DeployCommand_trigger = (uint8_t)0x00,
|
|
dp_DeployCommand_teardown = (uint8_t)0x01,
|
|
dp_DeployCommand_deploy = (uint8_t)0x02,
|
|
dp_DeployCommand_rollback = (uint8_t)0x03,
|
|
dp_DeployCommand_cleanup = (uint8_t)0x04,
|
|
dp_DeployCommand_restart = (uint8_t)0x05,
|
|
dp_DeployCommand_sysadmin = (uint8_t)0x06,
|
|
dp_DeployCommand_logs = (uint8_t)0x07,
|
|
} dp_DeployCommand;
|
|
|
|
typedef enum {
|
|
/* 0x00NN: Internal errors */
|
|
dp_PacketError_internal = 0x0000,
|
|
dp_PacketError_type = 0x0001,
|
|
dp_PacketError_status = 0x0002,
|
|
|
|
/* 0x10NN: Authentication errors */
|
|
dp_PacketError_auth_token = 0x1000,
|
|
dp_PacketError_auth_key = 0x1001,
|
|
|
|
/* 0x20NN: Protocol errors */
|
|
dp_PacketError_proto_packet_too_short = 0x2000,
|
|
dp_PacketError_proto_domain_invalid = 0x2001,
|
|
dp_PacketError_proto_packet_too_long = 0x2002,
|
|
dp_PacketError_proto_domain_not_found = 0x2003,
|
|
dp_PacketError_proto_packet_invalid = 0x2004,
|
|
|
|
/* 0x30NN: Proof-of-work (PoW) errors */
|
|
dp_PacketError_pow_too_many_pings = 0x3000,
|
|
dp_PacketError_pow_bad_solution = 0x3001,
|
|
|
|
/* 0x40NN: Deployment errors */
|
|
dp_PacketError_deploy_error = 0x4000,
|
|
dp_PacketError_invalid_command = 0x4001,
|
|
} dp_PacketError;
|
|
|
|
const char *dp_PacketError_to_str(dp_PacketError code);
|
|
|
|
bool dp_proto_command(SSL *ssl,
|
|
const uint8_t *packet,
|
|
int bytes,
|
|
sqlite3 *database,
|
|
dp_Logger *logger);
|
|
|
|
bool dp_proto_error(SSL *ssl,
|
|
dp_PacketError code,
|
|
const char *msg,
|
|
dp_Logger *logger);
|
|
|
|
bool dp_proto_log_chunker(SSL *ssl,
|
|
const char *chunk,
|
|
size_t chunk_size,
|
|
dp_Logger *logger);
|
|
|
|
bool dp_proto_log_end(SSL *ssl, dp_Logger *logger);
|
|
|
|
bool dp_proto_exit(SSL *ssl);
|
|
|
|
bool dp_proto_ping(SSL *ssl);
|
|
bool dp_proto_ping_reply(SSL *ssl);
|
|
bool dp_proto_ready(SSL *ssl);
|
|
|
|
bool dp_proto_skip(SSL *ssl, dp_PacketType type);
|
|
|
|
#endif /* DEPLOYD_PROTO_H_ */
|