From 74060878375cff4c1c27d71087beff96b89ef047 Mon Sep 17 00:00:00 2001 From: Radkesvat <134321679+radkesvat@users.noreply.github.com> Date: Sat, 6 Apr 2024 04:47:27 +0300 Subject: [PATCH] reformat --- tunnels/adapters/connector/resolve.c | 2 +- tunnels/client/reverse/reverse_client.c | 2 +- tunnels/logger/CMakeLists.txt | 8 ++------ tunnels/server/trojan/auth/trojan_auth_server.c | 4 ++-- tunnels/server/trojan/socks/trojan_socks_server.c | 10 +++++++--- ww/CMakeLists.txt | 10 ++++++++-- ww/api.h | 2 +- ww/shiftbuffer.c | 8 ++++---- ww/shiftbuffer.h | 2 +- 9 files changed, 27 insertions(+), 21 deletions(-) diff --git a/tunnels/adapters/connector/resolve.c b/tunnels/adapters/connector/resolve.c index 0eea9729..5adff767 100644 --- a/tunnels/adapters/connector/resolve.c +++ b/tunnels/adapters/connector/resolve.c @@ -8,7 +8,7 @@ bool connectorResolvedomain(socket_context_t *dest) struct timeval tv1, tv2; gettimeofday(&tv1, NULL); #endif - assert( dest->domain != NULL); + assert(dest->domain != NULL); /* resolve domain */ { if (sockaddr_set_ipport(&(dest->addr), dest->domain, old_port) != 0) diff --git a/tunnels/client/reverse/reverse_client.c b/tunnels/client/reverse/reverse_client.c index 3eeef148..2ffbaed3 100644 --- a/tunnels/client/reverse/reverse_client.c +++ b/tunnels/client/reverse/reverse_client.c @@ -164,7 +164,7 @@ tunnel_t *newReverseClient(node_instance_context_t *instance_info) // int total = max(16, state->cons_forward); // int total = max(1, state->cons_forward); state->min_unused_cons = min(max(threads_count * 2, state->min_unused_cons), 128); - state->connection_per_thread = state->min_unused_cons / threads_count; + state->connection_per_thread = min(4,state->min_unused_cons / threads_count); // we are always the first line creator so its easy to get the positon independent index here line_t *l = newLine(0); diff --git a/tunnels/logger/CMakeLists.txt b/tunnels/logger/CMakeLists.txt index 95a89616..0bd659a3 100644 --- a/tunnels/logger/CMakeLists.txt +++ b/tunnels/logger/CMakeLists.txt @@ -32,10 +32,6 @@ endif() target_compile_definitions(LoggerTunnel PRIVATE STC_STATIC=1 LoggerTunnel_VERSION=0.1) -if(NOT CMAKE_BUILD_TYPE STREQUAL "RELEASE") +if(CMAKE_BUILD_TYPE STREQUAL "Debug") target_compile_definitions(LoggerTunnel PRIVATE DEBUG=1) - -else() -target_compile_definitions(LoggerTunnel PRIVATE NDEBUG=1) - -endif() \ No newline at end of file +endif() diff --git a/tunnels/server/trojan/auth/trojan_auth_server.c b/tunnels/server/trojan/auth/trojan_auth_server.c index f14161cb..233a34da 100644 --- a/tunnels/server/trojan/auth/trojan_auth_server.c +++ b/tunnels/server/trojan/auth/trojan_auth_server.c @@ -273,11 +273,11 @@ static void parse(tunnel_t *t, cJSON *settings, size_t chain_index) memset(tuser, 0, sizeof(trojan_user_t)); tuser->user = *user; free(user); - sha224(tuser->user.uid, strlen(tuser->user.uid), &(tuser->hash_user[0])); + sha224((uint8_t*)tuser->user.uid, strlen(tuser->user.uid), &(tuser->hash_user[0])); for (int i = 0; i < sizeof(sha224_t); i++) { - sprintf(&(tuser->hash_hexed_user[i * 2]), "%02x", (unsigned char)(tuser->hash_user[i])); + sprintf((char*)&(tuser->hash_hexed_user[i * 2]), "%02x", (unsigned char)(tuser->hash_user[i])); } // 640f8fd293ea546e483060cce622d7f9ab96026d6af84a4333f486f9 LOGD("TrojanAuthServer: user \"%s\" parsed, sha224: %.12s...", tuser->user.name, tuser->hash_hexed_user); diff --git a/tunnels/server/trojan/socks/trojan_socks_server.c b/tunnels/server/trojan/socks/trojan_socks_server.c index 37ce3c28..56003239 100644 --- a/tunnels/server/trojan/socks/trojan_socks_server.c +++ b/tunnels/server/trojan/socks/trojan_socks_server.c @@ -46,7 +46,7 @@ static void makeUdpPacketAddress(context_t *c) assert(plen < 8192); shiftl(c->payload, CRLF_LEN); - writeRaw(c->payload, "\r\n", 2); + writeRaw(c->payload, (unsigned char*)"\r\n", 2); plen = (plen << 8) | (plen >> 8); shiftl(c->payload, 2); // LEN @@ -390,13 +390,18 @@ static bool processUdp(tunnel_t *self, trojan_socks_server_con_state_t *cstate, if (!ISALIVE(c)) { LOGW("TrojanSocksServer: next node instantly closed the init with fin"); - return false; + return true; } cstate->init_sent = true; } self->up->packetUpStream(self->up, c); + // line is alvie because caller is holding a context, but still fin could received + // and state is gone + if(line->chains_state[self->chain_index] == NULL){ + return true; + } return processUdp(self, cstate, line, src_io); } @@ -560,7 +565,6 @@ static inline void upStream(tunnel_t *self, context_t *c) } } } - return; } static inline void downStream(tunnel_t *self, context_t *c) diff --git a/ww/CMakeLists.txt b/ww/CMakeLists.txt index 6f43a424..25932933 100644 --- a/ww/CMakeLists.txt +++ b/ww/CMakeLists.txt @@ -57,7 +57,7 @@ CPMAddPackage( if(stc_ADDED) target_include_directories(ww PUBLIC ${stc_SOURCE_DIR}/include) - target_sources(ww PUBLIC ${stc_SOURCE_DIR}/src/libstc.c) + target_sources(ww PRIVATE ${stc_SOURCE_DIR}/src/libstc.c) endif() @@ -74,7 +74,7 @@ CPMAddPackage( ) if(cjson_ADDED) target_include_directories(ww PUBLIC ${cjson_SOURCE_DIR}) - target_sources(ww PUBLIC ${cjson_SOURCE_DIR}/cJSON.c) + target_sources(ww PRIVATE ${cjson_SOURCE_DIR}/cJSON.c) endif() @@ -105,6 +105,12 @@ CPMAddPackage( ) # target_compile_options(hv_static PRIVATE -fPIC) +# message( FATAL_ERROR "Y" ) + +if(ENABLE_ASAN AND CMAKE_BUILD_TYPE STREQUAL "Debug") + target_compile_options(ww PUBLIC -fsanitize=address) + target_link_options(ww PUBLIC -fsanitize=address) +endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_compile_options(ww PRIVATE -ftrack-macro-expansion=0) diff --git a/ww/api.h b/ww/api.h index 4349473a..ca1592e8 100644 --- a/ww/api.h +++ b/ww/api.h @@ -4,7 +4,7 @@ #include "basic_types.h" #include "utils/hashutils.h" #include "node.h" -#include "shiftbuffer.h" +#include "buffer_pool.h" #include "context_queue.h" #include "tunnel.h" #include "config_file.h" diff --git a/ww/shiftbuffer.c b/ww/shiftbuffer.c index 6e82cccb..1f7bc701 100644 --- a/ww/shiftbuffer.c +++ b/ww/shiftbuffer.c @@ -109,22 +109,22 @@ void writeI32(shift_buffer_t *self, int32_t data) void writeUI32(shift_buffer_t *self, uint32_t data) { - writeRaw(self, (char *)&data, sizeof(uint32_t)); + writeRaw(self, (unsigned char *)&data, sizeof(uint32_t)); } void writeI16(shift_buffer_t *self, int16_t data) { - writeRaw(self, (char *)&data, sizeof(int16_t)); + writeRaw(self, (unsigned char *)&data, sizeof(int16_t)); } void writeUI16(shift_buffer_t *self, uint16_t data) { - writeRaw(self, (char *)&data, sizeof(uint16_t)); + writeRaw(self, (unsigned char *)&data, sizeof(uint16_t)); } void writeUI8(shift_buffer_t *self, uint8_t data) { - writeRaw(self, (char *)&data, sizeof(uint8_t)); + writeRaw(self, (unsigned char *)&data, sizeof(uint8_t)); } void readUI8(shift_buffer_t *self, uint8_t *dest) diff --git a/ww/shiftbuffer.h b/ww/shiftbuffer.h index 457decc5..bd3d876c 100644 --- a/ww/shiftbuffer.h +++ b/ww/shiftbuffer.h @@ -69,7 +69,7 @@ inline unsigned char *rawBuf(shift_buffer_t *self) {return (unsigned char *)&( -void writeRaw(shift_buffer_t *self, unsigned char* buffer, size_t len); +void writeRaw(shift_buffer_t *self, unsigned char* buffer, size_t len); void writeI32(shift_buffer_t *self, int32_t data); void writeUI32(shift_buffer_t *self, uint32_t data);