diff --git a/core/core_settings.c b/core/core_settings.c index a9cd3109..21de01ca 100644 --- a/core/core_settings.c +++ b/core/core_settings.c @@ -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); @@ -149,17 +147,21 @@ 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 @@ -167,7 +169,7 @@ static void parseMiscPartOfJson(cJSON *misc_obj) 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) diff --git a/tunnels/adapters/listener/tcp/tcp_listener.c b/tunnels/adapters/listener/tcp/tcp_listener.c index d22f0d71..c1374acf 100644 --- a/tunnels/adapters/listener/tcp/tcp_listener.c +++ b/tunnels/adapters/listener/tcp/tcp_listener.c @@ -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; diff --git a/tunnels/client/http2/helpers.h b/tunnels/client/http2/helpers.h index d2a0ab03..ad12ddac 100644 --- a/tunnels/client/http2/helpers.h +++ b/tunnels/client/http2/helpers.h @@ -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) @@ -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; diff --git a/tunnels/client/http2/http2_client.c b/tunnels/client/http2/http2_client.c index 2d00ce98..98e4d636 100644 --- a/tunnels/client/http2/http2_client.c +++ b/tunnels/client/http2/http2_client.c @@ -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; @@ -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); diff --git a/tunnels/server/http2/helpers.h b/tunnels/server/http2/helpers.h index 98030cf9..d1f5b069 100644 --- a/tunnels/server/http2/helpers.h +++ b/tunnels/server/http2/helpers.h @@ -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) @@ -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; diff --git a/tunnels/server/http2/http2_server.c b/tunnels/server/http2/http2_server.c index 92032af2..d93da3d0 100644 --- a/tunnels/server/http2/http2_server.c +++ b/tunnels/server/http2/http2_server.c @@ -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); diff --git a/tunnels/server/reverse/helpers.h b/tunnels/server/reverse/helpers.h index f246671f..f15c7a5c 100644 --- a/tunnels/server/reverse/helpers.h +++ b/tunnels/server/reverse/helpers.h @@ -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 { diff --git a/tunnels/server/reverse/reverse_server.c b/tunnels/server/reverse/reverse_server.c index 8c26ab49..644b0898 100644 --- a/tunnels/server/reverse/reverse_server.c +++ b/tunnels/server/reverse/reverse_server.c @@ -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); diff --git a/ww/tunnel.c b/ww/tunnel.c index e1639888..1747e0d3 100644 --- a/ww/tunnel.c +++ b/ww/tunnel.c @@ -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); diff --git a/ww/tunnel.h b/ww/tunnel.h index 45dc9f87..160cf361 100644 --- a/ww/tunnel.h +++ b/ww/tunnel.h @@ -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]; }