You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.5 KiB
101 lines
3.5 KiB
// tcp_proxy_client.h — TCP прокси-клиент: стек lwIP TCP → ETCP → удалённый exit узел |
|
#ifndef TCP_PROXY_CLIENT_H |
|
#define TCP_PROXY_CLIENT_H |
|
|
|
#ifdef __cplusplus |
|
extern "C" { |
|
#endif |
|
|
|
|
|
#include <stdint.h> |
|
#include <stddef.h> |
|
#include "../lib/socket_compat.h" |
|
#include "../lib/ll_queue.h" |
|
|
|
struct UASYNC; |
|
struct UTUN_INSTANCE; |
|
struct ETCP_CONN; |
|
struct tun_if; |
|
struct ll_queue; |
|
struct ll_entry; |
|
struct memory_pool; |
|
struct tcp_proxy_client_mapping_config; |
|
struct tcp_proxy_server; |
|
struct lwip_tcp_ctx; |
|
struct socks_proxy_conn; |
|
struct listen_ctx; |
|
|
|
struct tcp_pcb; |
|
|
|
struct tcp_proxy_client_conn { |
|
struct tcp_proxy_client_conn* next; |
|
struct tcp_proxy_client* proxy; |
|
struct tcp_pcb* pcb; |
|
|
|
uint32_t stream_id; |
|
|
|
struct ll_queue* to_lwip; // DATA от exit → lwIP (управление потоком) |
|
|
|
uint8_t fin_local; // локальная сторона отправила FIN (lwIP) |
|
uint8_t fin_remote; // exit отправил FIN (назначение закрылось) |
|
uint8_t fin_deferred; // FIN от exit пришёл, но отложен до дренажа to_lwip |
|
uint8_t rem_closed; // exit отправил CLOSE |
|
uint8_t error; // ошибка, немедленная очистка |
|
uint8_t close_sent; // отправили CLOSE/ERROR в exit |
|
uint8_t close_pending; // CLOSE/ERROR не доставлен, ждём повтора |
|
|
|
struct ll_queue* tx_queue; // буфер lwIP→ETCP при backpressure (аналог server read_queue) |
|
struct queue_waiter_handle tx_waiter; // waiter на send_q (etcp_router_on_send_ready) |
|
void* tx_retry_timer; // retry safety-net (force=1), аналог server retry_timer |
|
|
|
uint32_t bytes_to_exit; // байт отправлено в exit (из lwIP/TUN) |
|
uint32_t bytes_from_exit; // байт получено от exit (в lwIP/TUN) |
|
uint32_t bp_count; // счётчик backpressure (send fail) |
|
|
|
void* diag_timer; // периодический снимок состояния (DEBUG-категория) |
|
|
|
uint8_t dest_ip[4]; |
|
uint16_t dest_port; |
|
}; |
|
|
|
struct tcp_proxy_client { |
|
struct UTUN_INSTANCE* inst; |
|
struct UASYNC* ua; |
|
struct tun_if* tun; |
|
struct tcp_proxy_client_conn* conns; |
|
int conn_count; |
|
struct memory_pool* entry_pool; |
|
uint32_t next_stream_id; |
|
uint64_t via_node_id; |
|
struct lwip_tcp_ctx* lwip; |
|
|
|
struct tcp_proxy_client_mapping_config* mappings; // указатель на конфиг |
|
int mapping_count; |
|
|
|
// SOCKS proxy |
|
int socks_enabled; |
|
struct socks_proxy_conn* socks_conns; |
|
int socks_conn_count; |
|
struct listen_ctx* socks_listen; |
|
|
|
// HTTP CONNECT proxy |
|
int http_proxy_enabled; |
|
struct socks_proxy_conn* http_conns; |
|
int http_conn_count; |
|
struct listen_ctx* http_listen; |
|
}; |
|
|
|
struct tcp_proxy_client* tcp_proxy_client_create(struct UTUN_INSTANCE* inst, struct UASYNC* ua, |
|
const char* tun_name, const char* tun_ip, int mtu, int test_mode, |
|
struct tcp_proxy_client_mapping_config* mappings, int mapping_count, |
|
uint64_t via_node_id, |
|
int socks_enabled, const char* socks_addr, |
|
int http_proxy_enabled, const char* http_proxy_addr); |
|
void tcp_proxy_client_destroy(struct tcp_proxy_client* p); |
|
void tcp_proxy_client_router_recv_cb(struct ETCP_CONN* conn, struct ll_entry* entry); |
|
|
|
|
|
#ifdef __cplusplus |
|
} |
|
#endif |
|
#endif // TCP_PROXY_CLIENT_H
|
|
|