|
|
|
@ -100,23 +100,9 @@ static void send_error(struct tcp_proxy_server_conn* rc) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ====================================================================
|
|
|
|
// ====================================================================
|
|
|
|
// Коллбэки tcp_io + очередь
|
|
|
|
// Коллбэки tcp_io
|
|
|
|
// ====================================================================
|
|
|
|
// ====================================================================
|
|
|
|
|
|
|
|
|
|
|
|
static void write_on_get_cb(struct ll_queue* q, void* arg) { |
|
|
|
|
|
|
|
struct tcp_proxy_server_conn* rc = (struct tcp_proxy_server_conn*)arg; |
|
|
|
|
|
|
|
struct UTUN_INSTANCE* inst = rc->ctx ? rc->ctx->inst : NULL; |
|
|
|
|
|
|
|
if (!inst) return; |
|
|
|
|
|
|
|
rc->ack_batch++; |
|
|
|
|
|
|
|
if (rc->ack_batch >= 8) { |
|
|
|
|
|
|
|
rc->ack_batch = 0; |
|
|
|
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_SOCKET, "SOCK:ACK fd=%d sid=%08x write_q=%d", |
|
|
|
|
|
|
|
rc->tc ? (int)rc->tc->sock : -1, rc->stream_id, |
|
|
|
|
|
|
|
queue_entry_count(q)); |
|
|
|
|
|
|
|
etcp_router_consumer_ack(inst, rc->peer_node_id, ETCP_ID_TCP_PROXY); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void on_fin_cb(struct tcp_conn* tc, void* arg) { |
|
|
|
static void on_fin_cb(struct tcp_conn* tc, void* arg) { |
|
|
|
struct tcp_proxy_server_conn* rc = (struct tcp_proxy_server_conn*)arg; |
|
|
|
struct tcp_proxy_server_conn* rc = (struct tcp_proxy_server_conn*)arg; |
|
|
|
if (write_pending(tc)) |
|
|
|
if (write_pending(tc)) |
|
|
|
@ -147,15 +133,6 @@ static void diag_timer_cb(void* arg) { |
|
|
|
int ent_f = tc->entry_pool->free_count; |
|
|
|
int ent_f = tc->entry_pool->free_count; |
|
|
|
int dat_f = tc->data_pool->free_count; |
|
|
|
int dat_f = tc->data_pool->free_count; |
|
|
|
|
|
|
|
|
|
|
|
int sq = 0; |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
struct UTUN_INSTANCE* inst = rc->ctx ? rc->ctx->inst : NULL; |
|
|
|
|
|
|
|
if (inst) { |
|
|
|
|
|
|
|
struct ETCP_ROUTER_CONN* rconn = etcp_router_conn_get(inst, rc->peer_node_id, ETCP_ID_TCP_PROXY); |
|
|
|
|
|
|
|
if (rconn && rconn->send_q) sq = queue_entry_count(rconn->send_q); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int rcv_buf = 0, snd_buf = 0; |
|
|
|
int rcv_buf = 0, snd_buf = 0; |
|
|
|
socklen_t optlen = sizeof(int); |
|
|
|
socklen_t optlen = sizeof(int); |
|
|
|
getsockopt(tc->sock, SOL_SOCKET, SO_RCVBUF, &rcv_buf, &optlen); |
|
|
|
getsockopt(tc->sock, SOL_SOCKET, SO_RCVBUF, &rcv_buf, &optlen); |
|
|
|
@ -163,12 +140,11 @@ static void diag_timer_cb(void* arg) { |
|
|
|
|
|
|
|
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_SOCKET, |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_SOCKET, |
|
|
|
"SOCK:DIAG fd=%d sid=%08x conn=%d fin=%d " |
|
|
|
"SOCK:DIAG fd=%d sid=%08x conn=%d fin=%d " |
|
|
|
"rq=%d(%zub) wq=%d(%zub) send_q=%d wbuf=%s " |
|
|
|
"rq=%d(%zub) wq=%d(%zub) wbuf=%s " |
|
|
|
"ent_f=%d dat_f=%d tcp_rb=%zu tcp_sb=%zu", |
|
|
|
"ent_f=%d dat_f=%d tcp_rb=%zu tcp_sb=%zu", |
|
|
|
(int)tc->sock, rc->stream_id, tc->connected, tc->fin, |
|
|
|
(int)tc->sock, rc->stream_id, tc->connected, tc->fin, |
|
|
|
tc->read_queue->count, queue_total_bytes(tc->read_queue), |
|
|
|
tc->read_queue->count, queue_total_bytes(tc->read_queue), |
|
|
|
tc->write_queue->count, queue_total_bytes(tc->write_queue), |
|
|
|
tc->write_queue->count, queue_total_bytes(tc->write_queue), |
|
|
|
sq, |
|
|
|
|
|
|
|
tc->write_buf ? "y" : "n", |
|
|
|
tc->write_buf ? "y" : "n", |
|
|
|
ent_f, dat_f, |
|
|
|
ent_f, dat_f, |
|
|
|
(size_t)rcv_buf, (size_t)snd_buf); |
|
|
|
(size_t)rcv_buf, (size_t)snd_buf); |
|
|
|
@ -193,13 +169,10 @@ static void read_queue_drain_cb(struct ll_queue* q, void* arg) { |
|
|
|
if (ret == 0) { |
|
|
|
if (ret == 0) { |
|
|
|
queue_resume_callback(q); |
|
|
|
queue_resume_callback(q); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
struct ETCP_ROUTER_CONN* rconn = etcp_router_conn_get(inst, rc->peer_node_id, ETCP_ID_TCP_PROXY); |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "SOCK:BACKPRESSURE fd=%d sid=%08x — pausing drain", |
|
|
|
if (rconn && rconn->send_q) { |
|
|
|
(int)rc->tc->sock, rc->stream_id); |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "SOCK:BACKPRESSURE fd=%d sid=%08x send_q=%d — pausing drain", |
|
|
|
etcp_router_on_send_ready(inst, rc->peer_node_id, ETCP_ID_TCP_PROXY, |
|
|
|
(int)rc->tc->sock, rc->stream_id, queue_entry_count(rconn->send_q)); |
|
|
|
&rc->pause_waiter, pause_resume_cb, rc); |
|
|
|
queue_waiter_wait(rconn->send_q, &rc->pause_waiter, pause_resume_cb, rc); |
|
|
|
|
|
|
|
} else |
|
|
|
|
|
|
|
etcp_router_waiter_register(inst, rc->peer_node_id, &rc->pause_waiter, pause_resume_cb, rc); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -230,15 +203,6 @@ void tcp_proxy_server_conn_free(struct tcp_proxy_server_conn* rc) { |
|
|
|
struct tcp_proxy_server_conn** prev = &rc->ctx->conns; |
|
|
|
struct tcp_proxy_server_conn** prev = &rc->ctx->conns; |
|
|
|
while (*prev) { if (*prev == rc) { *prev = rc->next; rc->ctx->conn_count--; break; } prev = &(*prev)->next; } |
|
|
|
while (*prev) { if (*prev == rc) { *prev = rc->next; rc->ctx->conn_count--; break; } prev = &(*prev)->next; } |
|
|
|
} |
|
|
|
} |
|
|
|
if (rc->tc) { tcp_conn_destroy(rc->tc); rc->tc = NULL; } |
|
|
|
|
|
|
|
if (rc->close_timer) { uasync_cancel_timeout(rc->ua, rc->close_timer); rc->close_timer = NULL; } |
|
|
|
|
|
|
|
if (rc->diag_timer) { uasync_cancel_timeout(rc->ua, rc->diag_timer); rc->diag_timer = NULL; } |
|
|
|
|
|
|
|
if (rc->ctx && rc->ctx->inst) { |
|
|
|
|
|
|
|
struct ETCP_ROUTER_CONN* rconn = etcp_router_conn_get(rc->ctx->inst, rc->peer_node_id, ETCP_ID_TCP_PROXY); |
|
|
|
|
|
|
|
if (rconn && rconn->send_q) queue_waiter_cancel(rconn->send_q, &rc->pause_waiter); |
|
|
|
|
|
|
|
else etcp_router_waiter_cancel(rc->ctx->inst, rc->peer_node_id, &rc->pause_waiter); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (rc->tc) queue_set_on_get(rc->tc->write_queue, NULL, NULL); |
|
|
|
|
|
|
|
u_free(rc); |
|
|
|
u_free(rc); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -291,15 +255,6 @@ int tcp_proxy_server_handle_connect(struct UTUN_INSTANCE* inst, struct ll_entry* |
|
|
|
rc->next = ctx->conns; ctx->conns = rc; |
|
|
|
rc->next = ctx->conns; ctx->conns = rc; |
|
|
|
rc->diag_timer = uasync_set_timeout(rc->ua, 10000, rc, diag_timer_cb, "tps_diag"); |
|
|
|
rc->diag_timer = uasync_set_timeout(rc->ua, 10000, rc, diag_timer_cb, "tps_diag"); |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
struct ETCP_ROUTER_CONN* rconn = etcp_router_conn_get(inst, src_node_id, ETCP_ID_TCP_PROXY); |
|
|
|
|
|
|
|
if (rconn) { |
|
|
|
|
|
|
|
rconn->consumer_ack = 1; |
|
|
|
|
|
|
|
etcp_router_consumer_ack(inst, src_node_id, ETCP_ID_TCP_PROXY); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
queue_set_on_get(rc->tc->write_queue, write_on_get_cb, rc); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
queue_dgram_free(entry); queue_entry_free(entry); |
|
|
|
queue_dgram_free(entry); queue_entry_free(entry); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|