8cca891b9a
CI / lint (pull_request) Failing after 30s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (undefined) (pull_request) Has been skipped
CI / fuzz-build (pull_request) Has been skipped
CI / coverage (pull_request) Has been skipped
CI / valgrind (pull_request) Has been skipped
89 lines
3.1 KiB
C
89 lines
3.1 KiB
C
#ifndef PROTOCOL_H
|
|
#define PROTOCOL_H
|
|
|
|
#include "data.h"
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
|
|
/* Maximum allowed string size for receive_str (64 KB) */
|
|
#define MAX_STRING_SIZE (64 * 1024)
|
|
|
|
/* Maximum allowed data payload size for receive_data (100 MB) */
|
|
#define MAX_DATA_PAYLOAD_SIZE (100ULL * 1024 * 1024)
|
|
|
|
/* Maximum chunk size (64 MB) — prevents unbounded allocation from the wire */
|
|
#define MAX_CHUNK_SIZE (64ULL * 1024 * 1024)
|
|
#define MAX_MANIFEST_ENTRIES (1024 * 1024)
|
|
/* Aggregate bytes retained by one received deletion manifest. */
|
|
#define MAX_MANIFEST_BYTES (16ULL * 1024 * 1024)
|
|
|
|
typedef struct ssl_st SSL;
|
|
|
|
/*
|
|
* Explicit owner of protocol I/O. A session does not own the descriptors or
|
|
* SSL object; it only describes the transport used by a transfer. This makes
|
|
* it safe to pass the transport to a worker without relying on inherited
|
|
* thread-local state.
|
|
*/
|
|
typedef struct ProtocolSession {
|
|
int read_fd;
|
|
int write_fd;
|
|
SSL* ssl;
|
|
unsigned long long bwlimit;
|
|
long long bw_tokens;
|
|
long long bw_last_refill_sec;
|
|
long bw_last_refill_nsec;
|
|
unsigned long long total_allocated_bytes;
|
|
} ProtocolSession;
|
|
|
|
typedef int Status;
|
|
enum NET_STATUS {
|
|
STATUS_OK,
|
|
STATUS_ERROR,
|
|
STATUS_FINISHED,
|
|
STATUS_NEXT,
|
|
STATUS_CHUNK,
|
|
STATUS_MANIFEST,
|
|
STATUS_CHECK,
|
|
STATUS_DELTA_SIGNATURE,
|
|
STATUS_DELTA_DATA,
|
|
STATUS_KEEPALIVE,
|
|
STATUS_ABORT,
|
|
STATUS_CHECK_BATCH
|
|
};
|
|
|
|
void io_set_fds(int read_fd, int write_fd);
|
|
void io_set_bwlimit(unsigned long long bytes_per_sec);
|
|
void io_set_ssl(SSL* ssl);
|
|
SSL* io_get_ssl(void);
|
|
|
|
void protocol_session_init(ProtocolSession* session, int read_fd, int write_fd);
|
|
/* Transitional bridge for helpers whose signatures still carry only an fd. */
|
|
void protocol_session_bind(ProtocolSession* session);
|
|
void protocol_session_unbind(void);
|
|
void protocol_session_set_ssl(ProtocolSession* session, SSL* ssl);
|
|
void protocol_session_set_bwlimit(ProtocolSession* session, unsigned long long bytes_per_sec);
|
|
bool protocol_send_n_data(ProtocolSession* session, const void* data, size_t data_size);
|
|
bool protocol_receive_n_data(ProtocolSession* session, void* data, size_t data_size);
|
|
bool protocol_send_str(ProtocolSession* session, const char* data);
|
|
char* protocol_receive_str(ProtocolSession* session);
|
|
bool protocol_send_data(ProtocolSession* session, const Data* data);
|
|
Data* protocol_receive_data(ProtocolSession* session);
|
|
bool protocol_send_int(ProtocolSession* session, int data);
|
|
bool protocol_receive_int(ProtocolSession* session, int* data);
|
|
bool protocol_send_status(ProtocolSession* session, Status status);
|
|
bool protocol_receive_status(ProtocolSession* session, Status* status);
|
|
bool send_n_data(int file_descriptor, const void* data, size_t data_size);
|
|
bool receive_n_data(int file_descriptor, void* data, size_t data_size);
|
|
|
|
bool send_str(int file_descriptor, const char* data);
|
|
char* receive_str(int file_descriptor);
|
|
bool send_data(int file_descriptor, const Data* data);
|
|
Data* receive_data(int file_descriptor);
|
|
bool send_int(int file_descriptor, int data);
|
|
bool receive_int(int file_descriptor, int* data);
|
|
bool send_status(int file_descriptor, Status status);
|
|
bool receive_status(int file_descriptor, Status* status);
|
|
|
|
#endif
|