/* Прямой stream-протокол: канонический big-endian заголовок, пути и подписанный END. * IDs ETCP определены только в etcp_api.h. Указатели parser заимствованы до освобождения кодограммы. */ #ifndef STREAM_WIRE_H #define STREAM_WIRE_H #include "stream_proto.h" #include "stream_metrics.h" #ifdef __cplusplus extern "C" { #endif #define STREAM_WIRE_VERSION 4 #define STREAM_WIRE_HEADER 52 #define STREAM_PATH_MAX 32 #define STREAM_END_SIZE 106 #define STREAM_METRIC_WIRE_SIZE 49 #define STREAM_INFO_METRIC_OFF 36 #define STREAM_INFO_OFFER_OFF (STREAM_INFO_METRIC_OFF + STREAM_METRIC_WIRE_SIZE) #define STREAM_INFO_PATH_OFF (STREAM_INFO_OFFER_OFF + 25) #define STREAM_INFO_SIZE (STREAM_INFO_PATH_OFF + 1) /* probe:8, границы/FEC:28, метрики:49, предложение:25, count:1 */ #define STREAM_OVERLOAD_MAX 64 #define STREAM_OVERLOAD_HEADER 18 enum stream_command { STREAM_CMD_INFO_REQ = 1, STREAM_CMD_INFO_RESP, STREAM_CMD_SUBSCRIBE, STREAM_CMD_ACCEPT, STREAM_CMD_REJECT, STREAM_CMD_RENEW, STREAM_CMD_UNSUBSCRIBE, STREAM_CMD_CLOSED, STREAM_CMD_DATA, STREAM_CMD_GAP, STREAM_CMD_END, STREAM_CMD_REVERSE_REQ, STREAM_CMD_OVERLOAD, STREAM_CMD_OVERLOAD_SELECT, STREAM_CMD_RELAY_REQUEST, STREAM_CMD_RELAY_STATUS, STREAM_CMD_RELAY_CANCEL }; /* Routed помощь: handle — nonce запроса; эпохи запроса/сервиса независимы от raw ETCP-сессии. */ enum stream_relay_status { STREAM_RELAY_STARTING = 1, STREAM_RELAY_READY, STREAM_RELAY_BOUND, STREAM_RELAY_REJECTED, STREAM_RELAY_ENDED, STREAM_RELAY_CANCELLED }; enum stream_reject { STREAM_REASON_STOPPED = 1, STREAM_REASON_POSITION, STREAM_REASON_EXPIRED, STREAM_REASON_STALE, STREAM_REASON_CONFLICT, STREAM_REASON_LIMIT, STREAM_REASON_LOOP, STREAM_REASON_TRANSPORT, STREAM_REASON_LEASE, STREAM_REASON_MEMBER, STREAM_REASON_PROTOCOL, STREAM_REASON_OVERLOAD }; struct stream_path { uint64_t nodes[STREAM_PATH_MAX]; uint8_t count; }; struct stream_message { struct stream_descriptor descriptor; uint64_t sender_epoch, receiver_epoch, handle; uint8_t command, subblock; const uint8_t *payload; size_t length; }; /* Проверяет размер, версию, ненулевые ключи/epoch и известный command; payload разбирает диспетчер. */ int stream_wire_parse(const uint8_t *wire, size_t length, struct stream_message *message); void stream_wire_header(uint8_t *wire, const struct stream_message *message); /* Путь без нулей/повторов, начинается источником и заканчивается отправителем; forbidden не входит в него. */ int stream_path_validate(const struct stream_path *path, uint64_t source, uint64_t sender, uint64_t forbidden); int stream_path_parse(const uint8_t *wire, size_t length, struct stream_path *path, size_t *used); size_t stream_path_write(uint8_t *wire, const struct stream_path *path); void stream_metric_write(uint8_t *wire, const struct stream_metric_snapshot *snapshot, int valid); int stream_metric_read(const uint8_t *wire, struct stream_metric_snapshot *snapshot, int *valid); int stream_end_sign(const struct stream_descriptor *descriptor, uint64_t last, const uint8_t key[32], uint8_t wire[STREAM_END_SIZE]); int stream_end_verify(const struct stream_descriptor *descriptor, const uint8_t key[32], const uint8_t *wire, size_t length, uint64_t *last); #ifdef __cplusplus } #endif #endif