// remote_proxy.h — Удаленный TCP прокси (exit node) #ifndef REMOTE_PROXY_H #define REMOTE_PROXY_H #include #include "../lib/socket_compat.h" struct UTUN_INSTANCE; struct UASYNC; struct ll_entry; struct ETCP_CONN; struct remote_proxy_ctx; #define TCP_PROXY_SUBCMD_CONNECT 0x01 #define TCP_PROXY_SUBCMD_CONNECTED 0x02 #define TCP_PROXY_SUBCMD_DATA 0x03 #define TCP_PROXY_SUBCMD_CLOSE 0x04 #define TCP_PROXY_SUBCMD_ERROR 0x05 #define TCP_PROXY_CONNECTED_OK 0 #define TCP_PROXY_CONNECTED_REFUSED 1 #define TCP_PROXY_HDR_SIZE 8 // svc_id(1)+subcmd(1)+stream_id(4)+seq(2) #define TCP_PROXY_CONNECT_HDR_SIZE 14 // HDR_SIZE + dest_ip(4)+dest_port(2) #define TCP_PROXY_CONNECTED_HDR_SIZE 11 // HDR_SIZE + local_port(2)+status(1) struct remote_proxy_conn { struct remote_proxy_conn* next; struct remote_proxy_ctx* ctx; uint32_t stream_id; uint64_t peer_node_id; socket_t sock; void* read_id; struct UASYNC* ua; uint8_t dest_ip[4]; uint16_t dest_port; uint16_t send_seq; // 16-bit circular uint16_t recv_last_seq; uint8_t recv_init; uint8_t cli_closed; // client sent CLOSE uint8_t sock_closed; // socket EOF received uint8_t error; uint8_t connected; // connect() completed successfully }; struct remote_proxy_ctx { int enabled; int conn_count; struct remote_proxy_conn* conns; struct UTUN_INSTANCE* inst; }; int remote_proxy_init(struct UTUN_INSTANCE* inst); void remote_proxy_destroy(struct UTUN_INSTANCE* inst); struct remote_proxy_conn* remote_proxy_find_conn(struct remote_proxy_ctx* ctx, uint32_t stream_id); void rp_conn_free(struct remote_proxy_conn* rc); int remote_proxy_handle_connect(struct UTUN_INSTANCE* inst, struct ll_entry* entry, uint32_t stream_id, uint64_t src_node_id); int remote_proxy_handle_data(struct UTUN_INSTANCE* inst, struct ETCP_CONN* conn, struct ll_entry* entry, uint32_t stream_id); void remote_proxy_handle_close(struct UTUN_INSTANCE* inst, uint32_t stream_id); #endif