- tcp_io.h/c: push_fin/push_close через очередь отправки Кодирование: dgram=NULL→close, len=0+dgram!=NULL→FIN (sentinel) FIN: shutdown(SHUT_WR), стоп чтения, on_fin_sent CLOSE: close сокета, on_closed read_cb: отбрасывание входящих после fin_sent guard wq_fetch: error||closed (не fin) - tcp_proxy_server: адаптация handle_fin→push_fin, handle_close→push_close read_queue_drain_cb: discard при fin_sent DEBUG_INFO на всех точках закрытия - tcp_proxy_client: send_fin, handle_fin — DEBUG_INFO - test_tcp_io: +6 тестов (push_fin, push_close, ordering, double-push, fin+close)
68 lines
2.5 KiB
C
68 lines
2.5 KiB
C
// tcp_proxy_server.h — TCP прокси-сервер (exit node)
|
|
#ifndef TCP_PROXY_SERVER_H
|
|
#define TCP_PROXY_SERVER_H
|
|
|
|
#include <stdint.h>
|
|
#include "../lib/socket_compat.h"
|
|
#include "../lib/ll_queue.h"
|
|
#include "../lib/tcp_io.h"
|
|
|
|
struct UTUN_INSTANCE;
|
|
struct UASYNC;
|
|
struct ll_entry;
|
|
struct ETCP_CONN;
|
|
|
|
#define TCP_PROXY_SUBCMD_CONNECT 0x01
|
|
#define TCP_PROXY_SUBCMD_DATA 0x03
|
|
#define TCP_PROXY_SUBCMD_CLOSE 0x04
|
|
#define TCP_PROXY_SUBCMD_ERROR 0x05
|
|
#define TCP_PROXY_SUBCMD_FIN 0x06
|
|
|
|
#define TCP_PROXY_HDR_SIZE 6 // svc_id(1)+subcmd(1)+stream_id(4)
|
|
#define TCP_PROXY_CONNECT_HDR_SIZE 12 // HDR_SIZE + dest_ip(4)+dest_port(2)
|
|
|
|
struct tcp_proxy_server_conn {
|
|
struct tcp_proxy_server_conn* next;
|
|
struct tcp_proxy_server* ctx;
|
|
struct tcp_conn* tc;
|
|
uint32_t stream_id;
|
|
uint64_t peer_node_id;
|
|
uint8_t dest_ip[4];
|
|
uint16_t dest_port;
|
|
|
|
uint8_t cli_closed; // client sent CLOSE
|
|
uint8_t close_pending; // CLOSE/ERROR не доставлен, ретрай
|
|
|
|
void* close_timer; // таймер повтора CLOSE/ERROR
|
|
int close_backoff; // backoff: 50..5000 tb (5ms..500ms)
|
|
void* diag_timer; // 1-секундный таймер диагностики
|
|
uint8_t freed; // 1 = уже освобождён, защита от double-free
|
|
|
|
struct queue_waiter_handle pause_waiter;
|
|
struct UASYNC* ua;
|
|
};
|
|
|
|
struct tcp_proxy_server {
|
|
int enabled;
|
|
int conn_count;
|
|
struct tcp_proxy_server_conn* conns;
|
|
struct UTUN_INSTANCE* inst;
|
|
};
|
|
|
|
int tcp_proxy_server_init(struct UTUN_INSTANCE* inst);
|
|
void tcp_proxy_server_destroy(struct UTUN_INSTANCE* inst);
|
|
|
|
struct tcp_proxy_server_conn* tcp_proxy_server_find_conn(struct tcp_proxy_server* ctx, uint32_t stream_id);
|
|
void tcp_proxy_server_conn_free(struct tcp_proxy_server_conn* rc);
|
|
|
|
void tcp_proxy_server_recv_cb(struct ETCP_CONN* conn, struct ll_entry* entry);
|
|
|
|
int tcp_proxy_server_handle_connect(struct UTUN_INSTANCE* inst, struct ll_entry* entry,
|
|
uint32_t stream_id, uint64_t src_node_id);
|
|
int tcp_proxy_server_handle_data(struct UTUN_INSTANCE* inst, struct ETCP_CONN* conn, struct ll_entry* entry, uint32_t stream_id);
|
|
void tcp_proxy_server_handle_close(struct UTUN_INSTANCE* inst, uint32_t stream_id);
|
|
void tcp_proxy_server_handle_error(struct UTUN_INSTANCE* inst, uint32_t stream_id);
|
|
void tcp_proxy_server_handle_fin(struct UTUN_INSTANCE* inst, uint32_t stream_id);
|
|
|
|
#endif
|