Skip to content

Commit

Permalink
format / hide some debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Apr 24, 2024
1 parent e2c6715 commit 5d98b92
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 25 deletions.
22 changes: 12 additions & 10 deletions core/core_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

static struct core_settings_s *settings = NULL;



static void parseLogPartOfJsonNoCheck(const cJSON *log_obj)
{
getStringFromJsonObjectOrDefault(&(settings->log_path), log_obj, "path", DEFAULT_LOG_PATH);
Expand Down Expand Up @@ -149,25 +147,29 @@ static void parseConfigPartOfJson(const cJSON *config_array)

static void parseMiscPartOfJson(cJSON *misc_obj)
{

// todo (remove deprection check) this should be removed in 0.7+
if (NULL != cJSON_GetObjectItemCaseSensitive(misc_obj, "threads"))
{
fprintf(stderr, "Deprectaed Error: core.json->misc->thraeds is replaced with \"workers\" since Waterwall 0.6\
, please update your json file");
exit(1);
}

if (cJSON_IsObject(misc_obj) && (misc_obj->child != NULL))
{
getStringFromJsonObjectOrDefault(&(settings->libs_path), misc_obj, "libs-path", DEFAULT_LIBS_PATH);
if (! getIntFromJsonObject(&(settings->workers_count), misc_obj, "workers"))
{
settings->workers_count = 0;
printf("workers_count unspecified in json (misc), fallback to cpu cores: %d\n", settings->workers_count);
}
if (settings->workers_count <= 0)
if (! getIntFromJsonObjectOrDefault(&(settings->workers_count), misc_obj, "workers", get_ncpu()))
{
settings->workers_count = get_ncpu();
printf("workers unspecified in json (misc), fallback to cpu cores: %d\n", settings->workers_count);
}
}
else
{
settings->libs_path = malloc(strlen(DEFAULT_LIBS_PATH) + 1);
strcpy(settings->libs_path, DEFAULT_LIBS_PATH);
settings->workers_count = get_ncpu();
printf("workers_count unspecified in json (misc), fallback to cpu cores: %d\n", settings->workers_count);
printf("misc block unspecified in json, using defaults. cpu cores: %d\n", settings->workers_count);
}
}
void parseCoreSettings(char *data_json)
Expand Down
2 changes: 1 addition & 1 deletion tunnels/adapters/listener/tcp/tcp_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void onInboundConnected(hevent_t *ev)
line_t * line = newLine(tid);
tcp_listener_con_state_t *cstate = malloc(sizeof(tcp_listener_con_state_t));
cstate->line = line;
cstate->buffer_pool = buffer_pools[tid];
cstate->buffer_pool = getThreadBufferPool(tid);
cstate->finished_queue = newContextQueue(cstate->buffer_pool);
cstate->data_queue = newContextQueue(cstate->buffer_pool);
cstate->io = io;
Expand Down
8 changes: 4 additions & 4 deletions tunnels/client/http2/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ static nghttp2_nv makeNV2(const char *name, const char *value, int namelen, int
static void printFrameHd(const nghttp2_frame_hd *hd)
{
(void) hd;
LOGD("[frame] length=%d type=%x flags=%x stream_id=%d\n", (int) hd->length, (int) hd->type, (int) hd->flags,
hd->stream_id);
// LOGD("[frame] length=%d type=%x flags=%x stream_id=%d\n", (int) hd->length, (int) hd->type, (int) hd->flags,
// hd->stream_id);
}

static void addStraem(http2_client_con_state_t *con, http2_client_child_con_state_t *stream)
Expand Down Expand Up @@ -123,9 +123,9 @@ static http2_client_con_state_t *createHttp2Connection(tunnel_t *self, int tid,
{
http2_client_state_t * state = STATE(self);
http2_client_con_state_t *con = malloc(sizeof(http2_client_con_state_t));

memset(con, 0, sizeof(http2_client_con_state_t));
con->queue = newContextQueue(buffer_pools[tid]);

con->queue = newContextQueue(getThreadBufferPool(tid));
con->content_type = state->content_type;
con->path = state->path;
con->host = state->host;
Expand Down
4 changes: 2 additions & 2 deletions tunnels/client/http2/http2_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
static void sendGrpcFinalData(tunnel_t *self, line_t *line, size_t stream_id)
{
http2_frame_hd framehd;
shift_buffer_t *buf = popBuffer(buffer_pools[line->tid]);
shift_buffer_t *buf = popBuffer(getLineBufferPool(line));
setLen(buf, HTTP2_FRAME_HDLEN);

framehd.length = 0;
Expand All @@ -34,7 +34,7 @@ static bool trySendRequest(tunnel_t *self, http2_client_con_state_t *con, size_t
// LOGD("nghttp2_session_mem_send %d\n", len);
if (len > 0)
{
shift_buffer_t *send_buf = popBuffer(buffer_pools[line->tid]);
shift_buffer_t *send_buf = popBuffer(getLineBufferPool(line));
shiftl(send_buf, lCap(send_buf) / 2); // use some unused space
setLen(send_buf, len);
writeRaw(send_buf, data, len);
Expand Down
7 changes: 4 additions & 3 deletions tunnels/server/http2/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ static nghttp2_nv makeNv2(const char *name, const char *value, int namelen, int
static void printFrameHd(const nghttp2_frame_hd *hd)
{
(void) hd;
LOGD("[frame] length=%d type=%x flags=%x stream_id=%d\n", (int) hd->length, (int) hd->type, (int) hd->flags,
hd->stream_id);
// LOGD("[frame] length=%d type=%x flags=%x stream_id=%d\n", (int) hd->length, (int) hd->type, (int) hd->flags,
// hd->stream_id);
}

static void addStream(http2_server_con_state_t *con, http2_server_child_con_state_t *stream)
Expand Down Expand Up @@ -57,8 +57,9 @@ http2_server_child_con_state_t *createHttp2Stream(http2_server_con_state_t *con,
http2_server_child_con_state_t *stream;
stream = malloc(sizeof(http2_server_child_con_state_t));
memset(stream, 0, sizeof(http2_server_child_con_state_t));

stream->stream_id = stream_id;
stream->chunkbs = newBufferStream(buffer_pools[this_line->tid]);
stream->chunkbs = newBufferStream(getLineBufferPool(this_line));
stream->parent = this_line;
stream->line = newLine(this_line->tid);
stream->line->chains_state[target_tun->chain_index - 1] = stream;
Expand Down
2 changes: 1 addition & 1 deletion tunnels/server/http2/http2_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static bool trySendResponse(tunnel_t *self, http2_server_con_state_t *con, size_
// LOGD("nghttp2_session_mem_send %d\n", len);
if (len > 0)
{
shift_buffer_t *send_buf = popBuffer(buffer_pools[line->tid]);
shift_buffer_t *send_buf = popBuffer(getLineBufferPool(line));
shiftl(send_buf, lCap(send_buf) / 2); // use some unused space
setLen(send_buf, len);
writeRaw(send_buf, data, len);
Expand Down
2 changes: 1 addition & 1 deletion tunnels/server/reverse/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static reverse_server_con_state_t *createCstate(bool isup, line_t *line)
if (isup)
{
cstate->u = line;
cstate->uqueue = newContextQueue(buffer_pools[line->tid]);
cstate->uqueue = newContextQueue(getLineBufferPool(line));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion tunnels/server/reverse/reverse_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static inline void downStream(tunnel_t *self, context_t *c)
}

dcstate->signal_sent = true;
shift_buffer_t *buf = popBuffer(buffer_pools[dcstate->d->tid]);
shift_buffer_t *buf = popBuffer(getLineBufferPool(dcstate->d));
shiftl(buf, 1);
writeUI8(buf, 0xFF);
context_t *c = newContext(dcstate->d);
Expand Down
2 changes: 1 addition & 1 deletion ww/tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extern context_t * newEstContext(line_t *line);
extern context_t * newFinContext(line_t *line);
extern context_t * newInitContext(line_t *line);
extern context_t * switchLine(context_t *c, line_t *line);
extern buffer_pool_t *geBufferPool(uint8_t tid);
extern buffer_pool_t *getThreadBufferPool(uint8_t tid);
extern buffer_pool_t *getLineBufferPool(line_t *l);
extern buffer_pool_t *getContextBufferPool(context_t *c);

Expand Down
2 changes: 1 addition & 1 deletion ww/tunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ inline bool isFullyAuthenticated(line_t *line)
}


inline buffer_pool_t *geBufferPool(uint8_t tid)
inline buffer_pool_t *getThreadBufferPool(uint8_t tid)
{
return buffer_pools[tid];
}
Expand Down

0 comments on commit 5d98b92

Please sign in to comment.