Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Apr 6, 2024
1 parent c85a914 commit 7406087
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion tunnels/adapters/connector/resolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tunnels/client/reverse/reverse_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 2 additions & 6 deletions tunnels/logger/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
endif()
4 changes: 2 additions & 2 deletions tunnels/server/trojan/auth/trojan_auth_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 7 additions & 3 deletions tunnels/server/trojan/socks/trojan_socks_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions ww/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ww/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions ww/shiftbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ww/shiftbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7406087

Please sign in to comment.