diff --git a/CMakeLists.txt b/CMakeLists.txt index 33361b1f..421db79d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -341,10 +341,6 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") target_compile_definitions(Waterwall PRIVATE DEBUG=1) endif() -add_compile_options( - $<$:/W4 /WX> - $<$>:-Wall -Wextra -Wpedantic -Werror> -) if(ENABLE_ASAN AND CMAKE_BUILD_TYPE STREQUAL "Debug") diff --git a/tunnels/adapters/connector/tcp/tcp_connector.c b/tunnels/adapters/connector/tcp/tcp_connector.c index 79cb1536..59033348 100644 --- a/tunnels/adapters/connector/tcp/tcp_connector.c +++ b/tunnels/adapters/connector/tcp/tcp_connector.c @@ -32,7 +32,7 @@ static void cleanup(tcp_connector_con_state_t *cstate, bool write_queue) } destroyContext(cw); } - + resumeLineDownSide(cstate->line); destroyContextQueue(cstate->data_queue); doneLineUpSide(cstate->line); free(cstate); @@ -44,10 +44,10 @@ static bool resumeWriteQueue(tcp_connector_con_state_t *cstate) hio_t *io = cstate->io; while (contextQueueLen(data_queue) > 0) { - context_t *cw = contextQueuePop(data_queue); - unsigned int bytes = bufLen(cw->payload); - int nwrite = hio_write(io, cw->payload); - cw->payload = NULL; + context_t *cw = contextQueuePop(data_queue); + int bytes = (int) bufLen(cw->payload); + int nwrite = hio_write(io, cw->payload); + cw->payload = NULL; destroyContext(cw); if (nwrite >= 0 && nwrite < bytes) { @@ -168,9 +168,9 @@ static void upStream(tunnel_t *self, context_t *c) } else { - unsigned int bytes = bufLen(c->payload); - int nwrite = hio_write(cstate->io, c->payload); - c->payload = NULL; + int bytes = (int) bufLen(c->payload); + int nwrite = hio_write(cstate->io, c->payload); + c->payload = NULL; if (nwrite >= 0 && nwrite < bytes) { @@ -179,7 +179,6 @@ static void upStream(tunnel_t *self, context_t *c) hio_setcb_write(cstate->io, onWriteComplete); } destroyContext(c); - } } else @@ -277,7 +276,6 @@ static void upStream(tunnel_t *self, context_t *c) } else if (c->fin) { - hio_t *io = cstate->io; CSTATE_MUT(c) = NULL; cleanup(cstate, true); destroyContext(c); diff --git a/tunnels/adapters/connector/udp/udp_connector.c b/tunnels/adapters/connector/udp/udp_connector.c index 0be67921..1d5e575e 100644 --- a/tunnels/adapters/connector/udp/udp_connector.c +++ b/tunnels/adapters/connector/udp/udp_connector.c @@ -6,7 +6,6 @@ static void cleanup(udp_connector_con_state_t *cstate) { - udp_connector_state_t *state = STATE(cstate->tunnel); free(cstate); } static void onRecvFrom(hio_t *io, shift_buffer_t *buf) @@ -20,17 +19,6 @@ static void onRecvFrom(hio_t *io, shift_buffer_t *buf) shift_buffer_t *payload = buf; tunnel_t *self = (cstate)->tunnel; line_t *line = (cstate)->line; - struct sockaddr *destaddr = hio_peeraddr(io); - enum socket_address_type address_type; - - if (destaddr->sa_family == AF_INET6) - { - address_type = kSatIPV6; - } - else - { - address_type = kSatIPV4; - } if (! cstate->established) { @@ -56,7 +44,6 @@ static void upStream(tunnel_t *self, context_t *c) if (c->payload != NULL) { - unsigned int bytes = bufLen(c->payload); if (hio_is_closed(cstate->io)) { @@ -68,7 +55,7 @@ static void upStream(tunnel_t *self, context_t *c) size_t nwrite = hio_write(cstate->io, c->payload); c->payload = NULL; - + (void)nwrite; // assert(nwrite <= 0 || nwrite == bytes); destroyContext(c); } diff --git a/tunnels/adapters/listener/tcp/tcp_listener.c b/tunnels/adapters/listener/tcp/tcp_listener.c index d4492bd9..fee22171 100644 --- a/tunnels/adapters/listener/tcp/tcp_listener.c +++ b/tunnels/adapters/listener/tcp/tcp_listener.c @@ -14,7 +14,7 @@ // #define PROFILE 1 enum { - kDefaultKeepAliveTimeOutMs = 75*1000 // same as NGINX + kDefaultKeepAliveTimeOutMs = 75 * 1000 // same as NGINX }; typedef struct tcp_listener_state_s @@ -69,6 +69,7 @@ static void cleanup(tcp_listener_con_state_t *cstate, bool write_queue) destroyContext(cw); } + resumeLineUpSide(cstate->line); destroyContextQueue(cstate->data_queue); doneLineDownSide(cstate->line); destroyLine(cstate->line); @@ -81,10 +82,10 @@ static bool resumeWriteQueue(tcp_listener_con_state_t *cstate) hio_t *io = cstate->io; while (contextQueueLen(data_queue) > 0) { - context_t *cw = contextQueuePop(data_queue); - unsigned int bytes = bufLen(cw->payload); - int nwrite = hio_write(io, cw->payload); - cw->payload = NULL; + context_t *cw = contextQueuePop(data_queue); + int bytes = (int) bufLen(cw->payload); + int nwrite = hio_write(io, cw->payload); + cw->payload = NULL; destroyContext(cw); if (nwrite >= 0 && nwrite < bytes) { @@ -173,9 +174,9 @@ static void downStream(tunnel_t *self, context_t *c) } else { - unsigned int bytes = bufLen(c->payload); - int nwrite = hio_write(cstate->io, c->payload); - c->payload = NULL; + int bytes = (int) bufLen(c->payload); + int nwrite = hio_write(cstate->io, c->payload); + c->payload = NULL; if (nwrite >= 0 && nwrite < bytes) { @@ -199,7 +200,6 @@ static void downStream(tunnel_t *self, context_t *c) } if (c->fin) { - hio_t *io = cstate->io; cleanup(cstate, true); CSTATE_MUT(c) = NULL; destroyContext(c); @@ -410,7 +410,6 @@ tunnel_t *newTcpListener(node_instance_context_t *instance_info) const cJSON *list_item = NULL; cJSON_ArrayForEach(list_item, wlist) { - unsigned int list_item_len = 0; if (! getStringFromJson(&(list[i]), list_item) || ! verifyIpCdir(list[i], getNetworkLogger())) { LOGF("JSON Error: TcpListener->settings->whitelist (array of strings field) index %d : The data " diff --git a/tunnels/adapters/listener/udp/udp_listener.c b/tunnels/adapters/listener/udp/udp_listener.c index 25ead03a..364c96af 100644 --- a/tunnels/adapters/listener/udp/udp_listener.c +++ b/tunnels/adapters/listener/udp/udp_listener.c @@ -117,7 +117,6 @@ static void downStream(tunnel_t *self, context_t *c) } if (c->fin) { - hio_t *io = cstate->io; CSTATE_MUT(c) = NULL; cleanup(cstate); destroyLine(c->line); @@ -320,7 +319,6 @@ tunnel_t *newUdpListener(node_instance_context_t *instance_info) const cJSON *list_item = NULL; cJSON_ArrayForEach(list_item, wlist) { - unsigned int list_item_len = 0; if (! getStringFromJson(&(list[i]), list_item) || ! verifyIpCdir(list[i], getNetworkLogger())) { LOGF("JSON Error: UdpListener->settings->whitelist (array of strings field) index %d : The data " diff --git a/tunnels/client/http2/http2_client.c b/tunnels/client/http2/http2_client.c index 9ca771b0..3165505e 100644 --- a/tunnels/client/http2/http2_client.c +++ b/tunnels/client/http2/http2_client.c @@ -53,7 +53,6 @@ static bool trySendRequest(tunnel_t *self, http2_client_con_state_t *con, size_t return true; } - assert(len >= 0); if (buf == NULL || bufLen(buf) <= 0) { @@ -130,11 +129,13 @@ static void flushWriteQueue(http2_client_con_state_t *con) destroyContext(g); } -static int onHeaderCallback(nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *_name, size_t namelen, - const uint8_t *_value, size_t valuelen, uint8_t flags, void *userdata) +static int onHeaderCallback(nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *name, size_t namelen, + const uint8_t *value, size_t valuelen, uint8_t flags, void *userdata) { + (void) name; (void) session; (void) namelen; + (void) value; (void) valuelen; (void) flags; if (userdata == NULL) @@ -144,12 +145,12 @@ static int onHeaderCallback(nghttp2_session *session, const nghttp2_frame *frame // LOGD("onHeaderCallback\n"); printFrameHd(&frame->hd); - const char *name = (const char *) _name; - const char *value = (const char *) _value; + // const char *name = (const char *) _name; + // const char *value = (const char *) _value; // LOGD("%s: %s\n", name, value); - http2_client_con_state_t *con = (http2_client_con_state_t *) userdata; - tunnel_t *self = con->tunnel; + // http2_client_con_state_t *con = (http2_client_con_state_t *) userdata; + // tunnel_t *self = con->tunnel; // Todo (http headers) should be saved somewhere // if (*name == ':') @@ -183,8 +184,7 @@ static int onDataChunkRecvCallback(nghttp2_session *session, uint8_t flags, int3 { return 0; } - http2_client_con_state_t *con = (http2_client_con_state_t *) userdata; - tunnel_t *self = con->tunnel; + http2_client_con_state_t *con = (http2_client_con_state_t *) userdata; http2_client_child_con_state_t *stream = nghttp2_session_get_stream_user_data(session, stream_id); if (! stream) @@ -495,7 +495,9 @@ tunnel_t *newHttp2Client(node_instance_context_t *instance_info) free(content_type_buf); } - getIntFromJsonObjectOrDefault(&(state->concurrency), settings, "concurrency", kDefaultConcurrency); + int int_concurrency; + getIntFromJsonObjectOrDefault(&(int_concurrency), settings, "concurrency", kDefaultConcurrency); + state->concurrency = int_concurrency; nghttp2_option_new(&(state->ngoptions)); nghttp2_option_set_peer_max_concurrent_streams(state->ngoptions, 0xffffffffU); diff --git a/tunnels/client/http2/types.h b/tunnels/client/http2/types.h index 87e6f42f..a1e7d783 100644 --- a/tunnels/client/http2/types.h +++ b/tunnels/client/http2/types.h @@ -28,37 +28,37 @@ typedef struct http2_client_child_con_state_s { struct http2_client_child_con_state_s *prev, *next; int32_t stream_id; - nghttp2_stream * ng_stream; - buffer_stream_t * chunkbs; // used for grpc + nghttp2_stream *ng_stream; + buffer_stream_t *chunkbs; // used for grpc size_t bytes_needed; - tunnel_t * tunnel; - line_t * parent; - line_t * line; + tunnel_t *tunnel; + line_t *parent; + line_t *line; } http2_client_child_con_state_t; typedef struct http2_client_con_state_s { - nghttp2_session * session; + nghttp2_session *session; http2_session_state state; - context_queue_t * queue; + context_queue_t *queue; size_t childs_added; int error; int frame_type_when_stream_closed; bool handshake_completed; enum http_method method; enum http_content_type content_type; - const char * path; - const char * host; // authority + const char *path; + const char *host; // authority int host_port; - const char * scheme; + const char *scheme; bool init_sent; bool first_sent; bool no_ping_ack; - htimer_t * ping_timer; - tunnel_t * tunnel; - line_t * line; + htimer_t *ping_timer; + tunnel_t *tunnel; + line_t *line; http2_client_child_con_state_t root; } http2_client_con_state_t; @@ -78,12 +78,12 @@ typedef struct http2_client_state_s { nghttp2_session_callbacks *cbs; enum http_content_type content_type; - int concurrency; - char * path; - char * host; // authority + size_t concurrency; + char *path; + char *host; // authority int host_port; - char * scheme; + char *scheme; int last_iid; - nghttp2_option * ngoptions; + nghttp2_option *ngoptions; thread_connection_pool_t thread_cpool[]; } http2_client_state_t; diff --git a/tunnels/client/preconnect/helpers.h b/tunnels/client/preconnect/helpers.h index 403f63ce..c5884555 100644 --- a/tunnels/client/preconnect/helpers.h +++ b/tunnels/client/preconnect/helpers.h @@ -47,7 +47,6 @@ static void destroyCstate(preconnect_client_con_state_t *cstate) static void doConnect(struct connect_arg *cg) { tunnel_t *self = cg->t; - preconnect_client_state_t *state = STATE(self); preconnect_client_con_state_t *cstate = createCstate(cg->tid); free(cg); (cstate->u->chains_state)[self->chain_index] = cstate; diff --git a/tunnels/client/preconnect/preconnect_client.c b/tunnels/client/preconnect/preconnect_client.c index cb517e68..daa1d767 100644 --- a/tunnels/client/preconnect/preconnect_client.c +++ b/tunnels/client/preconnect/preconnect_client.c @@ -112,6 +112,7 @@ static void downStream(tunnel_t *self, context_t *c) case kNotconnected: LOGE("PreConnectClient: this node is not purposed to handle downstream data before pairing"); + //fallthrough default: LOGF("PreConnectClient: invalid value of connection state (memory error?)"); exit(1); @@ -193,7 +194,7 @@ static void startPreconnect(htimer_t *timer) tunnel_t *self = hevent_userdata(timer); preconnect_client_state_t *state = STATE(self); - for (int i = 0; i < workers_count; i++) + for (unsigned int i = 0; i < workers_count; i++) { const size_t cpt = state->connection_per_thread; for (size_t ci = 0; ci < cpt; ci++) @@ -213,9 +214,9 @@ tunnel_t *newPreConnectClient(node_instance_context_t *instance_info) memset(state, 0, sizeof(preconnect_client_state_t) + (workers_count * sizeof(thread_box_t))); const cJSON *settings = instance_info->node_settings_json; - getIntFromJsonObject(&(state->min_unused_cons), settings, "minimum-unused"); + getIntFromJsonObject((int*)&(state->min_unused_cons), settings, "minimum-unused"); - state->min_unused_cons = min(max(workers_count * 4, state->min_unused_cons), 128); + state->min_unused_cons = (unsigned int)min(max((ssize_t)(workers_count * 4), (ssize_t)state->min_unused_cons), 128); state->connection_per_thread = min(4, state->min_unused_cons / workers_count); tunnel_t *t = newTunnel(); diff --git a/tunnels/client/preconnect/types.h b/tunnels/client/preconnect/types.h index 5e9a0ac8..8e524e3f 100644 --- a/tunnels/client/preconnect/types.h +++ b/tunnels/client/preconnect/types.h @@ -7,7 +7,7 @@ struct connect_arg { uint8_t tid; unsigned int delay; - tunnel_t * t; + tunnel_t *t; }; typedef enum { @@ -19,8 +19,8 @@ typedef enum typedef struct preconnect_client_con_state_s { struct preconnect_client_con_state_s *prev, *next; - line_t * u; - line_t * d; + line_t *u; + line_t *d; connection_state mode; } preconnect_client_con_state_t; @@ -38,7 +38,7 @@ typedef struct preconnect_client_state_s atomic_uint unused_cons; atomic_uint round_index; size_t connection_per_thread; - int min_unused_cons; + unsigned int min_unused_cons; thread_box_t workers[]; } preconnect_client_state_t; diff --git a/tunnels/client/reality/reality_client.c b/tunnels/client/reality/reality_client.c index dce7a1dc..3b404a20 100644 --- a/tunnels/client/reality/reality_client.c +++ b/tunnels/client/reality/reality_client.c @@ -257,7 +257,7 @@ static void downStream(tunnel_t *self, context_t *c) { bufferStreamViewBytesAt(cstate->read_stream, 0, tls_header, kTLSHeaderlen); uint16_t length = *(uint16_t *) (tls_header + 3); - if (bufferStreamLen(cstate->read_stream) >= kTLSHeaderlen + length) + if ((int) bufferStreamLen(cstate->read_stream) >= kTLSHeaderlen + length) { shift_buffer_t *buf = bufferStreamRead(cstate->read_stream, kTLSHeaderlen + length); shiftr(buf, kTLSHeaderlen); @@ -374,7 +374,6 @@ static void downStream(tunnel_t *self, context_t *c) if (SSL_is_init_finished(cstate->ssl)) { LOGD("RealityClient: Tls handshake complete"); - reality_client_state_t *state = STATE(self); cstate->handshake_completed = true; cstate->read_stream = newBufferStream(getContextBufferPool(c)); @@ -474,7 +473,7 @@ tunnel_t *newRealityClient(node_instance_context_t *instance_info) uint64_t *p64 = (uint64_t *) state->hashes; p64[0] = CALC_HASH_BYTES(state->password, strlen(state->password)); - for (int i = 1; i < EVP_MAX_MD_SIZE / sizeof(uint64_t); i++) + for (int i = 1; i < (int)(EVP_MAX_MD_SIZE / sizeof(uint64_t)); i++) { p64[i] = p64[i - 1]; } diff --git a/tunnels/server/http2/http2_server.c b/tunnels/server/http2/http2_server.c index d1272eea..7c6212b1 100644 --- a/tunnels/server/http2/http2_server.c +++ b/tunnels/server/http2/http2_server.c @@ -25,7 +25,6 @@ static int onHeaderCallback(nghttp2_session *session, const nghttp2_frame *frame // LOGD("%s: %s\n", name, value); http2_server_con_state_t *con = (http2_server_con_state_t *) userdata; - tunnel_t * self = con->tunnel; if (*name == ':') { @@ -68,7 +67,6 @@ static int onDataChunkRecvCallback(nghttp2_session *session, uint8_t flags, int3 return 0; } http2_server_con_state_t *con = (http2_server_con_state_t *) userdata; - tunnel_t * self = con->tunnel; http2_server_child_con_state_t *stream = nghttp2_session_get_stream_user_data(session, stream_id); if (! stream) @@ -302,7 +300,6 @@ static bool trySendResponse(tunnel_t *self, http2_server_con_state_t *con, size_ static void upStream(tunnel_t *self, context_t *c) { - http2_server_state_t *state = STATE(self); if (c->payload != NULL) { http2_server_con_state_t *con = CSTATE(c); @@ -420,9 +417,9 @@ static void downStream(tunnel_t *self, context_t *c) tunnel_t *newHttp2Server(node_instance_context_t *instance_info) { + (void)instance_info; http2_server_state_t *state = malloc(sizeof(http2_server_state_t)); memset(state, 0, sizeof(http2_server_state_t)); - cJSON *settings = instance_info->node_settings_json; nghttp2_session_callbacks_new(&(state->cbs)); nghttp2_session_callbacks_set_on_header_callback(state->cbs, onHeaderCallback); diff --git a/tunnels/server/openssl/openssl_server.c b/tunnels/server/openssl/openssl_server.c index 22f929d8..b4e777c7 100644 --- a/tunnels/server/openssl/openssl_server.c +++ b/tunnels/server/openssl/openssl_server.c @@ -58,7 +58,7 @@ static int onAlpnSelect(SSL *ssl, const unsigned char **out, unsigned char *outl while (offset < inlen) { // LOGD("client ALPN -> %.*s", in[offset], &(in[1 + offset])); - for (int i = 0; i < state->alpns_length; i++) + for (int i = 0; i < (int)state->alpns_length; i++) { if (0 == strncmp((const char *) &(in[1 + offset]), state->alpns[i].name, state->alpns[i].name_length < in[offset] ? state->alpns[i].name_length : in[offset])) diff --git a/tunnels/server/reality/reality_server.c b/tunnels/server/reality/reality_server.c index 1b3a5c5f..da7c18f9 100644 --- a/tunnels/server/reality/reality_server.c +++ b/tunnels/server/reality/reality_server.c @@ -109,7 +109,7 @@ static void upStream(tunnel_t *self, context_t *c) { bufferStreamViewBytesAt(cstate->read_stream, 0, tls_header, kTLSHeaderlen); uint16_t length = *(uint16_t *) (tls_header + 3); - if (bufferStreamLen(cstate->read_stream) >= kTLSHeaderlen + length) + if ((int) bufferStreamLen(cstate->read_stream) >= kTLSHeaderlen + length) { shift_buffer_t *buf = bufferStreamRead(cstate->read_stream, kTLSHeaderlen + length); shiftr(buf, kTLSHeaderlen); @@ -154,7 +154,6 @@ static void upStream(tunnel_t *self, context_t *c) } } } - cstate->giveup_counter -= 0; if (cstate->giveup_counter == 0) { @@ -162,6 +161,7 @@ static void upStream(tunnel_t *self, context_t *c) cstate->auth_state = kConUnAuthorized; } } + // fallthrough case kConUnAuthorized: state->dest->upStream(state->dest, c); @@ -176,7 +176,7 @@ static void upStream(tunnel_t *self, context_t *c) { bufferStreamViewBytesAt(cstate->read_stream, 0, tls_header, kTLSHeaderlen); uint16_t length = *(uint16_t *) (tls_header + 3); - if (bufferStreamLen(cstate->read_stream) >= kTLSHeaderlen + length) + if ((int) bufferStreamLen(cstate->read_stream) >= kTLSHeaderlen + length) { shift_buffer_t *buf = bufferStreamRead(cstate->read_stream, kTLSHeaderlen + length); shiftr(buf, kTLSHeaderlen); @@ -270,7 +270,7 @@ static void downStream(tunnel_t *self, context_t *c) case kConAuthorized:; shift_buffer_t *buf = c->payload; c->payload = NULL; - const int chunk_size = ((1 << 16) - (kSignLen + (2 * kEncryptionBlockSize) + kIVlen)); + const unsigned int chunk_size = ((1 << 16) - (kSignLen + (2 * kEncryptionBlockSize) + kIVlen)); if (bufLen(buf) < chunk_size) { @@ -305,11 +305,12 @@ static void downStream(tunnel_t *self, context_t *c) } else { - if (c->est ) + if (c->est) { - if(cstate->auth_state == kConAuthorized){ + if (cstate->auth_state == kConAuthorized) + { destroyContext(c); - return; + return; } self->dw->downStream(self->dw, c); return; @@ -357,7 +358,7 @@ tunnel_t *newRealityServer(node_instance_context_t *instance_info) } uint64_t *p64 = (uint64_t *) state->hashes; p64[0] = CALC_HASH_BYTES(state->password, strlen(state->password)); - for (int i = 1; i < EVP_MAX_MD_SIZE / sizeof(uint64_t); i++) + for (int i = 1; i < (int) (EVP_MAX_MD_SIZE / sizeof(uint64_t)); i++) { p64[i] = p64[i - 1]; } diff --git a/tunnels/server/socks/5/socks5_server.c b/tunnels/server/socks/5/socks5_server.c index 3313194a..663b59e3 100644 --- a/tunnels/server/socks/5/socks5_server.c +++ b/tunnels/server/socks/5/socks5_server.c @@ -94,11 +94,7 @@ static void cleanup(socks5_server_con_state_t *cstate, buffer_pool_t *reusepool) static void encapsulateUdpPacket(context_t* c) { shift_buffer_t* packet = c->payload; - uint16_t packet_len = bufLen(c->payload); - // packet_len = (packet_len << 8) | (packet_len >> 8); - // shiftl(packet, 2); // LEN - // writeUI16(packet, packet_len); uint16_t port = sockaddr_port(&(c->line->dest_ctx.address)); port = (port << 8) | (port >> 8); @@ -112,6 +108,7 @@ static void encapsulateUdpPacket(context_t* c) writeRaw(packet, &(c->line->dest_ctx.address.sin6.sin6_addr), 16); shiftl(packet, 1); writeUI8(packet, kIPv6Addr); + break; case kSatIPV4: default: @@ -130,7 +127,7 @@ static void encapsulateUdpPacket(context_t* c) #define ATLEAST(x) \ do \ { \ - if (bufLen(c->payload) < (x)) \ + if ((int)bufLen(c->payload) < (x)) \ { \ reuseContextBuffer(c); \ goto disconnect; \ @@ -253,7 +250,6 @@ disconnect:; } static void upStream(tunnel_t *self, context_t *c) { - socks5_server_state_t *state = STATE(self); socks5_server_con_state_t *cstate = CSTATE(c); if (c->payload != NULL) @@ -303,6 +299,7 @@ static void upStream(tunnel_t *self, context_t *c) { case kSBegin: cstate->state = kSAuthMethodsCount; + //fallthrough case kSAuthMethodsCount: { assert(cstate->need == 2); uint8_t version = 0; @@ -324,7 +321,7 @@ static void upStream(tunnel_t *self, context_t *c) break; case kSAuthMethods: { // TODO(root): check auth methods - uint8_t authmethod = kNoAuth; + // uint8_t authmethod = kNoAuth; // send auth mothod shift_buffer_t *resp = popBuffer(getContextBufferPool(c)); shiftl(resp, 1); @@ -364,7 +361,7 @@ static void upStream(tunnel_t *self, context_t *c) readUI8(bytes, &cmd); shiftr(bytes, 1); - if (version != SOCKS5_VERSION || cmd != kConnectCommand && cmd != kAssociateCommand) + if (version != SOCKS5_VERSION || (cmd != kConnectCommand && cmd != kAssociateCommand)) { LOGE("Socks5Server: Unsupprted command: %d", (int) cmd); reuseContextBuffer(c); @@ -526,7 +523,6 @@ static void upStream(tunnel_t *self, context_t *c) reuseContextBuffer(c); //todo (ip filter) socks5 standard says this should whitelist the caller ip // socks5 outbound accepted, udp relay will connect - socks5_server_con_state_t *cstate = CSTATE(c); shift_buffer_t *respbuf = popBuffer(getContextBufferPool(c)); setLen(respbuf, 32); uint8_t *resp = rawBufMut(respbuf); @@ -635,7 +631,6 @@ static void downStream(tunnel_t *self, context_t *c) { cstate->init_sent = false; // socks5 outbound failed - socks5_server_con_state_t *cstate = CSTATE(c); shift_buffer_t *respbuf = popBuffer(getContextBufferPool(c)); setLen(respbuf, 32); uint8_t *resp = rawBufMut(respbuf); diff --git a/tunnels/server/trojan/auth/trojan_auth_server.c b/tunnels/server/trojan/auth/trojan_auth_server.c index db11551a..81b664b7 100644 --- a/tunnels/server/trojan/auth/trojan_auth_server.c +++ b/tunnels/server/trojan/auth/trojan_auth_server.c @@ -186,7 +186,7 @@ failed:; goto fallback; } -disconnect:; +// disconnect:; reuseContextBuffer(c); free(CSTATE(c)); CSTATE_MUT(c) = NULL; diff --git a/tunnels/server/trojan/socks/trojan_socks_server.c b/tunnels/server/trojan/socks/trojan_socks_server.c index e93f1a02..386ec34a 100644 --- a/tunnels/server/trojan/socks/trojan_socks_server.c +++ b/tunnels/server/trojan/socks/trojan_socks_server.c @@ -25,7 +25,7 @@ enum trojan_atyp typedef struct trojan_socks_server_state_s { - void*_; + void *_; } trojan_socks_server_state_t; @@ -69,6 +69,7 @@ static void encapsulateUdpPacket(context_t *c) writeRaw(c->payload, &(c->line->dest_ctx.address.sin6.sin6_addr), 16); shiftl(c->payload, 1); writeUI8(c->payload, kTrojanatypIpV6); + break; case kSatIPV4: default: @@ -245,7 +246,7 @@ static bool processUdp(tunnel_t *self, trojan_socks_server_con_state_t *cstate, } domain_len = bufferStreamViewByteAt(bstream, 1); - if (bufferStreamLen(bstream) < 1 + 1 + domain_len + 2 + 2 + 2) + if ((int) bufferStreamLen(bstream) < 1 + 1 + domain_len + 2 + 2 + 2) { return true; } @@ -532,7 +533,6 @@ static void upStream(tunnel_t *self, context_t *c) { CSTATE_MUT(c) = malloc(sizeof(trojan_socks_server_con_state_t)); memset(CSTATE(c), 0, sizeof(trojan_socks_server_con_state_t)); - trojan_socks_server_con_state_t *cstate = CSTATE(c); destroyContext(c); } else if (c->fin) diff --git a/tunnels/server/wolfssl/wolfssl_server.c b/tunnels/server/wolfssl/wolfssl_server.c index e8867490..492c54f2 100644 --- a/tunnels/server/wolfssl/wolfssl_server.c +++ b/tunnels/server/wolfssl/wolfssl_server.c @@ -58,7 +58,7 @@ static int onAlpnSelect(SSL *ssl, const unsigned char **out, unsigned char *outl while (offset < inlen) { LOGD("client ALPN -> %.*s", in[offset], &(in[1 + offset])); - for (int i = 0; i < state->alpns_length; i++) + for (int i = 0; i < (int) state->alpns_length; i++) { if (0 == strncmp((const char *) &(in[1 + offset]), state->alpns[i].name, state->alpns[i].name_length < in[offset] ? state->alpns[i].name_length : in[offset])) @@ -134,8 +134,8 @@ static void fallbackWrite(tunnel_t *self, context_t *c) { cstate->fallback_init_sent = true; - cstate->init_sent = true; - state->fallback->upStream(state->fallback, newInitContext(c->line)); + cstate->init_sent = true; + state->fallback->upStream(state->fallback, newInitContext(c->line)); if (! isAlive(c->line)) { destroyContext(c); @@ -179,7 +179,7 @@ static void upStream(tunnel_t *self, context_t *c) } enum sslstatus status; int n; - size_t len = bufLen(c->payload); + int len = (int) bufLen(c->payload); while (len > 0) { @@ -205,7 +205,7 @@ static void upStream(tunnel_t *self, context_t *c) do { shift_buffer_t *buf = popBuffer(getContextBufferPool(c)); - size_t avail = rCap(buf); + int avail = (int) rCap(buf); n = BIO_read(cstate->wbio, rawBufMut(buf), avail); // assert(-1 == BIO_read(cstate->wbio, rawBuf(buf), avail)); if (n > 0) @@ -278,8 +278,8 @@ static void upStream(tunnel_t *self, context_t *c) shift_buffer_t *buf = popBuffer(getContextBufferPool(c)); shiftl(buf, 8192 / 2); setLen(buf, 0); - size_t avail = rCap(buf); - n = SSL_read(cstate->ssl, rawBufMut(buf), avail); + int avail = (int) rCap(buf); + n = SSL_read(cstate->ssl, rawBufMut(buf), avail); if (n > 0) { @@ -315,7 +315,7 @@ static void upStream(tunnel_t *self, context_t *c) do { shift_buffer_t *buf = popBuffer(getContextBufferPool(c)); - size_t avail = rCap(buf); + int avail = (int) rCap(buf); n = BIO_read(cstate->wbio, rawBufMut(buf), avail); if (n > 0) @@ -423,7 +423,6 @@ disconnect:; static void downStream(tunnel_t *self, context_t *c) { - wssl_server_state_t *state = STATE(self); wssl_server_con_state_t *cstate = CSTATE(c); if (c->payload != NULL) @@ -447,7 +446,7 @@ static void downStream(tunnel_t *self, context_t *c) LOGF("How it is possible to receive data before sending init to upstream?"); exit(1); } - size_t len = bufLen(c->payload); + int len = (int) bufLen(c->payload); while (len) { int n = SSL_write(cstate->ssl, rawBuf(c->payload), len); @@ -463,7 +462,7 @@ static void downStream(tunnel_t *self, context_t *c) { shift_buffer_t *buf = popBuffer(getContextBufferPool(c)); - size_t avail = rCap(buf); + int avail = (int) rCap(buf); n = BIO_read(cstate->wbio, rawBufMut(buf), avail); if (n > 0) { diff --git a/tunnels/shared/openssl/openssl_globals.h b/tunnels/shared/openssl/openssl_globals.h index 1c565321..54b18950 100644 --- a/tunnels/shared/openssl/openssl_globals.h +++ b/tunnels/shared/openssl/openssl_globals.h @@ -127,6 +127,7 @@ static ssl_ctx_t sslCtxNew(ssl_ctx_opt_t *param) BIO *bio = BIO_new(BIO_s_mem()); int n = BIO_write(bio, cacert_bytes, (int) cacert_len); assert(n == (int) cacert_len); + (void) n; X509 *x = NULL; while (true) { diff --git a/tunnels/shared/reality/reality_helpers.h b/tunnels/shared/reality/reality_helpers.h index 646eed06..8d3064a6 100644 --- a/tunnels/shared/reality/reality_helpers.h +++ b/tunnels/shared/reality/reality_helpers.h @@ -119,7 +119,7 @@ static shift_buffer_t *genericEncrypt(shift_buffer_t *in, EVP_CIPHER_CTX *encryp int input_length = (int) bufLen(in); uint8_t iv[kIVlen]; - for (int i = 0; i < kIVlen / sizeof(uint32_t); i++) + for (int i = 0; i < (int)(kIVlen / sizeof(uint32_t)); i++) { ((uint32_t *) iv)[i] = fastRand(); } diff --git a/tunnels/shared/trojan/sha2.c b/tunnels/shared/trojan/sha2.c index b506535a..45014fef 100644 --- a/tunnels/shared/trojan/sha2.c +++ b/tunnels/shared/trojan/sha2.c @@ -29,9 +29,8 @@ * SUCH DAMAGE. */ -#if 1 + #define UNROLL_LOOPS /* Enable loops unrolling */ -#endif #include @@ -117,8 +116,8 @@ static const uint32 kSha224H0[8] = {0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4}; -static const uint32 kSha256H0[8] = {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, - 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; +// static const uint32 kSha256H0[8] = {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, +// 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; static const uint64 kSha384H0[8] = {0xcbbb9d5dc1059ed8ULL, 0x629a292a367cd507ULL, 0x9159015a3070dd17ULL, 0x152fecd8f70e5939ULL, 0x67332667ffc00b31ULL, 0x8eb44a8768581511ULL, diff --git a/tunnels/shared/wolfssl/wolfssl_globals.h b/tunnels/shared/wolfssl/wolfssl_globals.h index 4b1e8587..b12e3cc7 100644 --- a/tunnels/shared/wolfssl/wolfssl_globals.h +++ b/tunnels/shared/wolfssl/wolfssl_globals.h @@ -127,6 +127,7 @@ static ssl_ctx_t sslCtxNew(ssl_ctx_opt_t *param) BIO *bio = BIO_new(BIO_s_mem()); int n = BIO_write(bio, cacert_bytes, (int)cacert_len); assert(n == (int)cacert_len); + (void)n; X509 *x = NULL; while (true) { diff --git a/ww/CMakeLists.txt b/ww/CMakeLists.txt index 74ce0fda..ea8e97e0 100644 --- a/ww/CMakeLists.txt +++ b/ww/CMakeLists.txt @@ -117,11 +117,19 @@ endif() # endif() # todo (:<) -target_compile_options(ww PUBLIC -Wno-gnu-zero-variadic-macro-arguments) target_compile_definitions(ww PUBLIC STC_STATIC=1 WW_VERSION=0.1) -target_compile_options(ww PUBLIC -pedantic) +target_compile_options(ww PUBLIC + $<$:/W4 /WX> + $<$>:-Wall -Wextra -Werror> +) + +target_compile_options(ww PUBLIC -Wno-gnu-zero-variadic-macro-arguments -Wno-unused-function) + +target_compile_options(ww PUBLIC -pedantic -pedantic-errors) + + if(CMAKE_BUILD_TYPE STREQUAL "Debug") target_compile_definitions(ww PRIVATE DEBUG=1) diff --git a/ww/config_file.c b/ww/config_file.c index 3b73a290..b30ab4ad 100644 --- a/ww/config_file.c +++ b/ww/config_file.c @@ -45,7 +45,7 @@ void unsafeCommitChanges(config_file_t *state) char *string = cJSON_PrintBuffered(state->root, (int) ((state->file_prebuffer_size) * 2), true); size_t len = strlen(string); const int max_retries = 3; - for (size_t i = 0; i < max_retries; i++) + for (int i = 0; i < max_retries; i++) { if (writeFile(state->file_path, string, len)) { diff --git a/ww/eventloop/base/array.h b/ww/eventloop/base/array.h index 4370d5b3..a46e9546 100644 --- a/ww/eventloop/base/array.h +++ b/ww/eventloop/base/array.h @@ -49,7 +49,7 @@ static inline type* atype##_at(atype* p, int pos) {\ if (pos < 0) {\ pos += p->size;\ }\ - assert(pos >= 0 && pos < p->size);\ + assert(pos >= 0 && (size_t) pos < p->size);\ return p->ptr + pos;\ }\ \ @@ -104,11 +104,11 @@ static inline void atype##_add(atype* p, type* elem, int pos) {\ if (pos < 0) {\ pos += p->size;\ }\ - assert(pos >= 0 && pos <= p->size);\ + assert(pos >= 0 && (size_t)pos <= p->size);\ if (p->size == p->maxsize) {\ atype##_double_resize(p);\ }\ - if (pos < p->size) {\ + if ((size_t)pos < p->size) {\ memmove(p->ptr + pos+1, p->ptr + pos, sizeof(type) * (p->size - pos));\ }\ p->ptr[pos] = *elem;\ @@ -119,9 +119,9 @@ static inline void atype##_del(atype* p, int pos) {\ if (pos < 0) {\ pos += p->size;\ }\ - assert(pos >= 0 && pos < p->size);\ + assert(pos >= 0 && (size_t)pos < p->size);\ p->size--;\ - if (pos < p->size) {\ + if ((size_t)pos < p->size) {\ memmove(p->ptr + pos, p->ptr + pos+1, sizeof(type) * (p->size - pos));\ }\ }\ @@ -130,9 +130,9 @@ static inline void atype##_del_nomove(atype* p, int pos) {\ if (pos < 0) {\ pos += p->size;\ }\ - assert(pos >= 0 && pos < p->size);\ + assert(pos >= 0 && (size_t) pos < p->size);\ p->size--;\ - if (pos < p->size) {\ + if ((size_t)pos < p->size) {\ p->ptr[pos] = p->ptr[p->size];\ }\ }\ diff --git a/ww/eventloop/base/hlog.c b/ww/eventloop/base/hlog.c index 7350b80a..7db6270b 100644 --- a/ww/eventloop/base/hlog.c +++ b/ww/eventloop/base/hlog.c @@ -121,7 +121,7 @@ void logger_set_level_by_str(logger_t* logger, const char* szLoglevel) { } int logger_will_write_level(logger_t* logger, log_level_e level) { - return (logger->level) <= level; + return (logger->level) <= (int)level; } logger_handler logger_handle(logger_t* logger){ return logger->handler; @@ -259,7 +259,7 @@ static FILE* logfile_shift(logger_t* logger) { // NOTE: estimate can_write_cnt to avoid frequent fseek/ftell if (logger->fp_ && --logger->can_write_cnt < 0) { fseek(logger->fp_, 0, SEEK_END); - long filesize = ftell(logger->fp_); + unsigned long long filesize = ftell(logger->fp_); if (filesize > logger->max_filesize) { fclose(logger->fp_); logger->fp_ = NULL; @@ -454,13 +454,16 @@ void hv_destroy_default_logger(void) { } void stdout_logger(int loglevel, const char* buf, int len) { + (void)loglevel; fprintf(stdout, "%.*s", len, buf); } void stderr_logger(int loglevel, const char* buf, int len) { + (void)loglevel; fprintf(stderr, "%.*s", len, buf); } void file_logger(int loglevel, const char* buf, int len) { + (void)loglevel; logfile_write(hv_default_logger(), buf, len); } diff --git a/ww/eventloop/base/hmain.c b/ww/eventloop/base/hmain.c index b7160b63..f2086368 100644 --- a/ww/eventloop/base/hmain.c +++ b/ww/eventloop/base/hmain.c @@ -396,6 +396,7 @@ pid_t getpid_from_pidfile(void) { } int pid = -1; int _ = fscanf(fp, "%d", &pid); + (void)_; fclose(fp); return pid; } @@ -600,6 +601,7 @@ void signal_handle(const char* signal) { // master-workers processes static HTHREAD_ROUTINE(worker_thread) { + (void)userdata; hlogi("worker_thread pid=%ld tid=%ld", hv_getpid(), hv_gettid()); if (g_main_ctx.worker_fn) { g_main_ctx.worker_fn(g_main_ctx.worker_userdata); @@ -608,6 +610,7 @@ static HTHREAD_ROUTINE(worker_thread) { } static void worker_init(void* userdata) { + (void)userdata; #ifdef OS_UNIX setproctitle("%s: worker process", g_main_ctx.program_name); signal(SIGNAL_RELOAD, signal_handler); @@ -615,6 +618,7 @@ static void worker_init(void* userdata) { } static void worker_proc(void* userdata) { + (void)userdata; for (int i = 1; i < g_main_ctx.worker_threads; ++i) { hthread_create(worker_thread, NULL); } diff --git a/ww/eventloop/event/epoll.c b/ww/eventloop/event/epoll.c index 3456de73..07e37109 100644 --- a/ww/eventloop/event/epoll.c +++ b/ww/eventloop/event/epoll.c @@ -121,7 +121,7 @@ int iowatcher_poll_events(hloop_t* loop, int timeout) { } if (nepoll == 0) return 0; int nevents = 0; - for (int i = 0; i < epoll_ctx->events.size; ++i) { + for (size_t i = 0; i < epoll_ctx->events.size; ++i) { struct epoll_event* ee = epoll_ctx->events.ptr + i; int fd = ee->data.fd; uint32_t revents = ee->events; diff --git a/ww/eventloop/event/hevent.c b/ww/eventloop/event/hevent.c index 8d4a1d9f..a04b0562 100644 --- a/ww/eventloop/event/hevent.c +++ b/ww/eventloop/event/hevent.c @@ -57,6 +57,7 @@ static void hio_socket_init(hio_t* io) { } socklen_t addrlen = sizeof(sockaddr_u); int ret = getsockname(io->fd, io->localaddr, &addrlen); + (void)ret; printd("getsockname fd=%d ret=%d errno=%d\n", io->fd, ret, socket_errno()); // NOTE: udp peeraddr set by recvfrom/sendto if (io->io_type & HIO_TYPE_SOCK_STREAM) { @@ -81,6 +82,7 @@ void hio_init(hio_t* io) { // write_queue_init(&io->write_queue, 4); // hrecursive_mutex_init(&io->write_mutex); + (void)io; } void hio_ready(hio_t* io) { @@ -131,10 +133,6 @@ void hio_ready(hio_t* io) { #ifdef EVENT_IOCP io->hovlp = NULL; - - - - #endif // io_type @@ -142,8 +140,6 @@ void hio_ready(hio_t* io) { if (io->io_type & HIO_TYPE_SOCKET) { hio_socket_init(io); } - - } void hio_done(hio_t* io) { @@ -152,11 +148,9 @@ void hio_done(hio_t* io) { hio_del(io, HV_RDWR); - - // write_queue shift_buffer_t* buf = NULL; - // + // while (!write_queue_empty(&io->write_queue)) { buf = *write_queue_front(&io->write_queue); reuseBuffer(io->loop->bufpool, buf); @@ -164,8 +158,6 @@ void hio_done(hio_t* io) { } write_queue_cleanup(&io->write_queue); io->write_queue.ptr = NULL; - - } void hio_free(hio_t* io) { @@ -295,7 +287,7 @@ void hio_connect_cb(hio_t* io) { } } -void hio_handle_read(hio_t* io,shift_buffer_t* buf) { +void hio_handle_read(hio_t* io, shift_buffer_t* buf) { // hio_read hio_read_cb(io, buf); } @@ -409,7 +401,7 @@ void hio_set_close_timeout(hio_t* io, int timeout_ms) { static void __read_timeout_cb(htimer_t* timer) { hio_t* io = (hio_t*)timer->privdata; uint64_t inactive_ms = (io->loop->cur_hrtime - io->last_read_hrtime) / 1000; - if (inactive_ms + 100 < io->read_timeout) { + if (inactive_ms + 100 < (uint64_t)io->read_timeout) { htimer_reset(io->read_timer, io->read_timeout - inactive_ms); } else { @@ -445,7 +437,7 @@ void hio_set_read_timeout(hio_t* io, int timeout_ms) { static void __write_timeout_cb(htimer_t* timer) { hio_t* io = (hio_t*)timer->privdata; uint64_t inactive_ms = (io->loop->cur_hrtime - io->last_write_hrtime) / 1000; - if (inactive_ms + 100 < io->write_timeout) { + if (inactive_ms + 100 < (uint64_t)io->write_timeout) { htimer_reset(io->write_timer, io->write_timeout - inactive_ms); } else { @@ -482,7 +474,7 @@ static void __keepalive_timeout_cb(htimer_t* timer) { hio_t* io = (hio_t*)timer->privdata; uint64_t last_rw_hrtime = MAX(io->last_read_hrtime, io->last_write_hrtime); uint64_t inactive_ms = (io->loop->cur_hrtime - last_rw_hrtime) / 1000; - if (inactive_ms + 100 < io->keepalive_timeout) { + if (inactive_ms + 100 < (uint64_t)io->keepalive_timeout) { htimer_reset(io->keepalive_timer, io->keepalive_timeout - inactive_ms); } else { @@ -544,8 +536,6 @@ void hio_set_heartbeat(hio_t* io, int interval_ms, hio_send_heartbeat_fn fn) { //-----------------iobuf--------------------------------------------- - - void hio_set_max_write_bufsize(hio_t* io, uint32_t size) { io->max_write_bufsize = size; } diff --git a/ww/eventloop/event/hloop.c b/ww/eventloop/event/hloop.c index 0e1bdca4..a9d98a64 100644 --- a/ww/eventloop/event/hloop.c +++ b/ww/eventloop/event/hloop.c @@ -183,9 +183,10 @@ int hloop_process_events(hloop_t* loop, int timeout_ms) { } } int ncbs = hloop_process_pendings(loop); - // printd("blocktime=%d nios=%d/%u ntimers=%d/%u nidles=%d/%u nactives=%d npendings=%d ncbs=%d\n", - // blocktime, nios, loop->nios, ntimers, loop->ntimers, nidles, loop->nidles, - // loop->nactives, npendings, ncbs); + printd("blocktime=%d nios=%d/%u ntimers=%d/%u nidles=%d/%u nactives=%d npendings=%d ncbs=%d\n", + blocktime, nios, loop->nios, ntimers, loop->ntimers, nidles, loop->nidles, + loop->nactives, npendings, ncbs); + (void)nios; return ncbs; } @@ -354,7 +355,7 @@ static void hloop_cleanup(hloop_t* loop) { // ios printd("cleanup ios...\n"); - for (int i = 0; i < loop->ios.maxsize; ++i) { + for (size_t i = 0; i < loop->ios.maxsize; ++i) { hio_t* io = loop->ios.ptr[i]; if (io) { hio_free(io); @@ -511,7 +512,7 @@ hloop_status_e hloop_status(hloop_t* loop) { void hloop_update_time(hloop_t* loop) { loop->cur_hrtime = gethrtime_us(); - if (hloop_now(loop) != time(NULL)) { + if ((time_t)hloop_now(loop) != time(NULL)) { // systemtime changed, we adjust start_ms loop->start_ms = gettimeofday_ms() - (loop->cur_hrtime - loop->start_hrtime) / 1000; } @@ -713,7 +714,7 @@ const char* hio_engine(void) { } static inline hio_t* __hio_get(hloop_t* loop, int fd) { - if (fd >= loop->ios.maxsize) { + if (fd >= (int)loop->ios.maxsize) { int newsize = ceil2e(fd); newsize = MAX(newsize, IO_ARRAY_INIT_SIZE); io_array_resize(&loop->ios, newsize > fd ? newsize : 2 * fd); @@ -742,7 +743,7 @@ hio_t* hio_get(hloop_t* loop, int fd) { void hio_detach(hio_t* io) { hloop_t* loop = io->loop; int fd = io->fd; - assert(loop != NULL && fd < loop->ios.maxsize); + assert(loop != NULL && fd < (int)loop->ios.maxsize); loop->ios.ptr[fd] = NULL; } @@ -761,7 +762,7 @@ void hio_attach(hloop_t* loop, hio_t* io) { } bool hio_exists(hloop_t* loop, int fd) { - if (fd >= loop->ios.maxsize) { + if (fd >= (int)loop->ios.maxsize) { return false; } return loop->ios.ptr[fd] != NULL; diff --git a/ww/eventloop/event/nio.c b/ww/eventloop/event/nio.c index d08f1e51..c46be19f 100644 --- a/ww/eventloop/event/nio.c +++ b/ww/eventloop/event/nio.c @@ -186,7 +186,8 @@ static int __nio_write(hio_t* io, const void* buf, int len) { static void nio_read(hio_t* io) { // printd("nio_read fd=%d\n", io->fd); int nread = 0, err = 0; -read:; +// read:; + // #if defined(OS_LINUX) && defined(HAVE_PIPE) // if(io->pfd_w){ // len = (1U << 20); // 1 MB @@ -251,10 +252,10 @@ read:; static void nio_write(hio_t* io) { // printd("nio_write fd=%d\n", io->fd); int nwrite = 0, err = 0; - // + // write: if (write_queue_empty(&io->write_queue)) { - + if (io->close) { io->close = 0; hio_close(io); @@ -262,14 +263,14 @@ static void nio_write(hio_t* io) { return; } shift_buffer_t* buf = *write_queue_front(&io->write_queue); - unsigned int len = bufLen(buf); + int len = (int)bufLen(buf); // char* base = pbuf->base; nwrite = __nio_write(io, rawBufMut(buf), len); // printd("write retval=%d\n", nwrite); if (nwrite < 0) { err = socket_errno(); if (err == EAGAIN || err == EINTR) { - + return; } else { @@ -299,16 +300,15 @@ static void nio_write(hio_t* io) { // write continue goto write; } - }else{ + } + else { __write_cb(io); - } - return; write_error: disconnect: - + if (io->io_type & HIO_TYPE_SOCK_STREAM) { hio_close(io); } @@ -326,11 +326,11 @@ static void hio_handle_events(hio_t* io) { if ((io->events & HV_WRITE) && (io->revents & HV_WRITE)) { // NOTE: del HV_WRITE, if write_queue empty - // + // if (write_queue_empty(&io->write_queue)) { hio_del(io, HV_WRITE); } - + if (io->connect) { // NOTE: connect just do once // ONESHOT @@ -392,10 +392,10 @@ int hio_write(hio_t* io, shift_buffer_t* buf) { return -1; } int nwrite = 0, err = 0; - // - unsigned int len = bufLen(buf); + // + int len = (int)bufLen(buf); if (write_queue_empty(&io->write_queue)) { - try_write: + // try_write: nwrite = __nio_write(io, rawBufMut(buf), len); // printd("write retval=%d\n", nwrite); if (nwrite < 0) { @@ -457,7 +457,7 @@ int hio_write(hio_t* io, shift_buffer_t* buf) { } write_done: - + if (nwrite > 0) { if (nwrite == len) { reuseBuffer(io->loop->bufpool, buf); @@ -467,7 +467,7 @@ int hio_write(hio_t* io, shift_buffer_t* buf) { return nwrite; write_error: disconnect: - + /* NOTE: * We usually free resources in hclose_cb, * if hio_close_sync, we have to be very careful to avoid using freed resources. @@ -486,14 +486,14 @@ int hio_close(hio_t* io) { return hio_close_async(io); } - // + // if (io->closed) { - + return 0; } if (!write_queue_empty(&io->write_queue) && io->error == 0 && io->close == 0 && io->destroy == 0) { io->close = 1; - + hlogd("write_queue not empty, close later."); int timeout_ms = io->close_timeout ? io->close_timeout : HIO_DEFAULT_CLOSE_TIMEOUT; io->close_timer = htimer_add(io->loop, __close_timeout_cb, timeout_ms, 1); @@ -501,7 +501,6 @@ int hio_close(hio_t* io) { return 0; } io->closed = 1; - hio_done(io); __close_cb(io); diff --git a/ww/idle_table.c b/ww/idle_table.c index 26ddb581..a3630149 100644 --- a/ww/idle_table.c +++ b/ww/idle_table.c @@ -151,7 +151,6 @@ bool removeIdleItemByHash(idle_table_t *self, hash_t key) static void beforeCloseCallBack(hevent_t *ev) { idle_item_t *item = hevent_userdata(ev); - const uint64_t oldex = item->expire_at_ms; item->cb(item); free(item); } diff --git a/ww/managers/node_manager.c b/ww/managers/node_manager.c index e1acbdd1..6189b3aa 100644 --- a/ww/managers/node_manager.c +++ b/ww/managers/node_manager.c @@ -257,15 +257,15 @@ static void startParsingFiles(void) runNodes(); } -static tunnel_t *getTunnel(hash_t hash_node_name) -{ - map_node_t_iter iter = map_node_t_find(&(state->node_map), hash_node_name); - if (iter.ref == map_node_t_end(&(state->node_map)).ref) - { - return NULL; - } - return (iter.ref->second)->instance; -} +// static tunnel_t *getTunnel(hash_t hash_node_name) +// { +// map_node_t_iter iter = map_node_t_find(&(state->node_map), hash_node_name); +// if (iter.ref == map_node_t_end(&(state->node_map)).ref) +// { +// return NULL; +// } +// return (iter.ref->second)->instance; +// } struct node_manager_s *getNodeManager(void) { diff --git a/ww/managers/socket_manager.c b/ww/managers/socket_manager.c index 633cd05f..d104dffc 100644 --- a/ww/managers/socket_manager.c +++ b/ww/managers/socket_manager.c @@ -72,6 +72,7 @@ static bool redirectPortRangeUdp(unsigned int pmin, unsigned int pmax, unsigned sprintf(b, "iptables -t nat -A PREROUTING -p UDP --dport %u:%u -j REDIRECT --to-port %u", pmin, pmax, to); return execCmd(b).exit_code == 0; } + static bool redirectPortTcp(unsigned int port, unsigned int to) { char b[300]; @@ -220,7 +221,7 @@ int parseIPWithSubnetMask(struct in6_addr *base_addr, const char *input, struct prefix_length -= bits; } // struct in6_addr mask_addr; - memcpy(&(subnet_mask->s6_addr), subnet_mask, 16); + // memcpy(&(subnet_mask->s6_addr), subnet_mask, 16); // inet_ntop(AF_INET6, &mask_addr, subnet_mask, INET6_ADDRSTRLEN); } else @@ -638,9 +639,9 @@ static void listenUdpSinglePort(hloop_t *loop, socket_filter_t *filter, char *ho LOGF("SocketManager: stopping due to null socket handle"); exit(1); } - udpsock_t* socket = malloc(sizeof(udpsock_t)); - *socket = (udpsock_t){.io = filter->listen_io,.table = newIdleTable(loop)}; - hevent_set_userdata(filter->listen_io,socket); + udpsock_t *socket = malloc(sizeof(udpsock_t)); + *socket = (udpsock_t){.io = filter->listen_io, .table = newIdleTable(loop)}; + hevent_set_userdata(filter->listen_io, socket); hio_setcb_read(filter->listen_io, onRecvFrom); hio_read(filter->listen_io); } @@ -699,12 +700,14 @@ void writeUdpThisLoop(hevent_t *ev) { struct udp_sb *ub = hevent_userdata(ev); size_t nwrite = hio_write(ub->socket_io, ub->buf); + (void) nwrite; + free(ub); } void postUdpWrite(hio_t *socket_io, shift_buffer_t *buf) { struct udp_sb *ub = malloc(sizeof(struct udp_sb)); - *ub = (struct udp_sb){.socket_io = socket_io, buf = buf}; + *ub = (struct udp_sb){.socket_io = socket_io, buf}; hevent_t ev = (hevent_t){.loop = hevent_loop(socket_io), .cb = writeUdpThisLoop}; ev.userdata = ub; @@ -713,6 +716,7 @@ void postUdpWrite(hio_t *socket_io, shift_buffer_t *buf) static HTHREAD_ROUTINE(accept_thread) // NOLINT { + (void) userdata; hloop_t *loop = hloop_new(HLOOP_FLAG_AUTO_FREE, createSmallBufferPool()); hhybridmutex_lock(&(state->mutex)); @@ -748,7 +752,7 @@ void startSocketManager(void) { assert(state != NULL); // accept_thread(accept_thread_loop); - state->accept_thread = hthread_create(accept_thread,NULL); + state->accept_thread = hthread_create(accept_thread, NULL); } socket_manager_state_t *createSocketManager(void) diff --git a/ww/shiftbuffer.c b/ww/shiftbuffer.c index f49b68b3..be8a8e28 100644 --- a/ww/shiftbuffer.c +++ b/ww/shiftbuffer.c @@ -41,7 +41,6 @@ void destroyShiftBuffer(shift_buffer_t *self) shift_buffer_t *newShiftBuffer(unsigned int pre_cap) { - assert(pre_cap >= 0); unsigned int real_cap = pre_cap * 2; shift_buffer_t *self = malloc(sizeof(shift_buffer_t)); @@ -109,7 +108,6 @@ void unShallow(shift_buffer_t *self) void expand(shift_buffer_t *self, unsigned int increase) { - const bool keep = self->curpos != self->lenpos; if (isShallow(self)) { const unsigned int old_realcap = self->full_cap; diff --git a/ww/utils/utils.c b/ww/utils/utils.c index cd2218f4..b2ff5b25 100644 --- a/ww/utils/utils.c +++ b/ww/utils/utils.c @@ -74,7 +74,7 @@ void toUpperCase(char *str) int i = 0; while (str[i] != 0x0) { - str[i] = (char)toupper(str[i]); + str[i] = (char) toupper(str[i]); i++; } } @@ -83,14 +83,11 @@ void toLowerCase(char *str) int i = 0; while (str[i] != 0x0) { - str[i] = (char)tolower(str[i]); + str[i] = (char) tolower(str[i]); i++; } } - - - bool getBoolFromJsonObject(bool *dest, const cJSON *json_obj, const char *key) { assert(dest != NULL); @@ -533,7 +530,6 @@ cmdresult_t execCmd(const char *str) FILE *fp; cmdresult_t result = (cmdresult_t){{0}, -1}; char *buf = &(result.output[0]); - int i = 0; /* Open the command for reading. */ fp = popen(str, "r"); if (fp == NULL) @@ -542,7 +538,8 @@ cmdresult_t execCmd(const char *str) return (cmdresult_t){{0}, -1}; } - int read = fscanf(fp, "%2047s", buf); + int read = fscanf(fp, "%2047s", buf); + (void) read; result.exit_code = pclose(fp); return result; diff --git a/ww/ww.c b/ww/ww.c index 18378c13..59cc4e3b 100644 --- a/ww/ww.c +++ b/ww/ww.c @@ -144,7 +144,7 @@ void createWW(ww_construction_data_t init_data) ram_profile = init_data.ram_profile; buffer_pools = (struct buffer_pool_s **) malloc(sizeof(struct buffer_pool_s *) * workers_count); - for (int i = 0; i < workers_count; ++i) + for (unsigned int i = 0; i < workers_count; ++i) { buffer_pools[i] = createBufferPool(); } @@ -153,7 +153,7 @@ void createWW(ww_construction_data_t init_data) loops[0] = hloop_new(HLOOP_FLAG_AUTO_FREE, buffer_pools[0]); workers[0] = (hthread_t) NULL; - for (int i = 1; i < workers_count; ++i) + for (unsigned int i = 1; i < workers_count; ++i) { loops[i] = hloop_new(HLOOP_FLAG_AUTO_FREE, buffer_pools[i]); workers[i] = hthread_create(worker_thread, loops[i]);