From 8dee1bb3f2a64015cbd585aea55ecfe68bcd4879 Mon Sep 17 00:00:00 2001 From: Radkesvat <134321679+radkesvat@users.noreply.github.com> Date: Wed, 3 Apr 2024 22:19:03 +0300 Subject: [PATCH] refactor --- core/static_tunnels.c | 6 ++ tunnels/adapters/connector/tcp.c | 2 +- .../adapters/tcp_connector/tcp_connector.c | 2 +- tunnels/server/header/header_server.c | 65 ++++++++++--------- 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/core/static_tunnels.c b/core/static_tunnels.c index 458e8e4b..d60b482f 100644 --- a/core/static_tunnels.c +++ b/core/static_tunnels.c @@ -87,6 +87,9 @@ #include "tunnels/client/preconnect/preconnect_client.h" #endif +#ifdef INCLUDE_PRECONNECT_SERVER +#include "tunnels/server/preconnect/preconnect_server.h" +#endif void loadStaticTunnelsIntoCore() @@ -167,5 +170,8 @@ void loadStaticTunnelsIntoCore() USING(PreConnectClient); #endif +#ifdef INCLUDE_PRECONNECT_SERVER + USING(PreConnectServer); +#endif } \ No newline at end of file diff --git a/tunnels/adapters/connector/tcp.c b/tunnels/adapters/connector/tcp.c index 31118294..5f65b389 100644 --- a/tunnels/adapters/connector/tcp.c +++ b/tunnels/adapters/connector/tcp.c @@ -2,7 +2,7 @@ #include "utils/sockutils.h" #include "loggers/network_logger.h" -static void cleanup(tcp_listener_con_state_t *cstate) +static void cleanup(connector_con_state_t *cstate) { hio_t *last_resumed_io = NULL; diff --git a/tunnels/adapters/tcp_connector/tcp_connector.c b/tunnels/adapters/tcp_connector/tcp_connector.c index 4a6c0245..dcba0654 100644 --- a/tunnels/adapters/tcp_connector/tcp_connector.c +++ b/tunnels/adapters/tcp_connector/tcp_connector.c @@ -3,7 +3,7 @@ #include "utils/sockutils.h" #include "loggers/network_logger.h" -static void cleanup(tcp_listener_con_state_t *cstate) +static void cleanup(tcp_connector_con_state_t *cstate) { hio_t *last_resumed_io = NULL; diff --git a/tunnels/server/header/header_server.c b/tunnels/server/header/header_server.c index 01c2abe0..0ff01825 100644 --- a/tunnels/server/header/header_server.c +++ b/tunnels/server/header/header_server.c @@ -33,40 +33,43 @@ static void upStream(tunnel_t *self, context_t *c) { header_server_state_t *state = STATE(self); - if (c->payload != NULL && c->first) + if (c->payload != NULL) { - - shift_buffer_t *buf = c->payload; - if (bufLen(buf) < 2) - { - DISCARD_CONTEXT(c); - self->up->upStream(self->up, newFinContext(c->line)); - self->dw->downStream(self->dw, newFinContext(c->line)); - destroyContext(c); - return; - } - - uint16_t port = 0; - switch ((enum header_dynamic_value_status)state->data.status) + if (c->first) { - case hdvs_dest_port: - readUI16(buf, &port); - sockaddr_set_port(&(c->line->dest_ctx.addr), port); - shiftr(c->payload, sizeof(uint16_t)); - break; - - default: - (void)(0); - break; - } - CSTATE(c)->init_sent = true; - self->up->upStream(self->up, newInitContext(c->line)); - if (!ISALIVE(c)) - { - DISCARD_CONTEXT(c); - destroyContext(c); - return; + shift_buffer_t *buf = c->payload; + if (bufLen(buf) < 2) + { + DISCARD_CONTEXT(c); + self->up->upStream(self->up, newFinContext(c->line)); + self->dw->downStream(self->dw, newFinContext(c->line)); + destroyContext(c); + return; + } + + uint16_t port = 0; + switch ((enum header_dynamic_value_status)state->data.status) + { + case hdvs_dest_port: + + readUI16(buf, &port); + sockaddr_set_port(&(c->line->dest_ctx.addr), port); + shiftr(c->payload, sizeof(uint16_t)); + break; + + default: + (void)(0); + break; + } + CSTATE(c)->init_sent = true; + self->up->upStream(self->up, newInitContext(c->line)); + if (!ISALIVE(c)) + { + DISCARD_CONTEXT(c); + destroyContext(c); + return; + } } } else if (c->init)