From 36adfe5cb3f87a455856f97cf317ba3a2115ddf1 Mon Sep 17 00:00:00 2001 From: Radkesvat <134321679+radkesvat@users.noreply.github.com> Date: Wed, 15 May 2024 01:57:58 +0000 Subject: [PATCH] reformat in order to support old compilers as well --- core/core_settings.c | 10 +- core/core_settings.h | 10 +- core/main.c | 2 +- core/os_helpers.h | 6 +- core/static_tunnels.c | 4 +- core/static_tunnels.h | 2 +- tunnels/adapters/bridge/bridge.c | 6 +- tunnels/adapters/bridge/bridge.h | 2 +- tunnels/adapters/connector/connector.c | 6 +- tunnels/adapters/connector/connector.h | 2 +- .../adapters/connector/tcp/tcp_connector.c | 4 +- .../adapters/connector/tcp/tcp_connector.h | 2 +- .../adapters/connector/udp/udp_connector.c | 4 +- .../adapters/connector/udp/udp_connector.h | 2 +- tunnels/adapters/listener/listener.c | 6 +- tunnels/adapters/listener/listener.h | 2 +- tunnels/adapters/listener/tcp/tcp_listener.c | 4 +- tunnels/adapters/listener/tcp/tcp_listener.h | 2 +- tunnels/adapters/listener/udp/udp_listener.c | 6 +- tunnels/adapters/listener/udp/udp_listener.h | 2 +- tunnels/client/header/header_client.c | 6 +- tunnels/client/header/header_client.h | 2 +- tunnels/client/http2/helpers.h | 5 +- tunnels/client/http2/http2_client.c | 2 +- tunnels/client/http2/http2_client.h | 2 +- tunnels/client/openssl/openssl_client.c | 2 +- tunnels/client/openssl/openssl_client.h | 2 +- tunnels/client/preconnect/helpers.h | 17 +-- tunnels/client/preconnect/preconnect_client.c | 4 +- tunnels/client/preconnect/preconnect_client.h | 2 +- tunnels/client/protobuf/protobuf_client.c | 6 +- tunnels/client/protobuf/protobuf_client.h | 2 +- tunnels/client/reality/reality_client.c | 2 +- tunnels/client/reality/reality_client.h | 2 +- tunnels/client/reverse/helpers.h | 2 +- tunnels/client/reverse/reverse_client.c | 4 +- tunnels/client/reverse/reverse_client.h | 2 +- tunnels/client/wolfssl/wolfssl_client.c | 2 +- tunnels/client/wolfssl/wolfssl_client.h | 2 +- tunnels/logger/logger_tunnel.c | 7 +- tunnels/logger/logger_tunnel.h | 3 +- tunnels/server/header/header_server.c | 6 +- tunnels/server/header/header_server.h | 2 +- tunnels/server/http2/helpers.h | 5 +- tunnels/server/http2/http2_server.c | 2 +- tunnels/server/http2/http2_server.h | 2 +- tunnels/server/openssl/openssl_server.c | 2 +- tunnels/server/openssl/openssl_server.h | 2 +- tunnels/server/preconnect/preconnect_server.c | 16 ++- tunnels/server/preconnect/preconnect_server.h | 2 +- tunnels/server/protobuf/protobuf_server.c | 6 +- tunnels/server/protobuf/protobuf_server.h | 2 +- tunnels/server/reality/reality_server.c | 2 +- tunnels/server/reality/reality_server.h | 2 +- tunnels/server/reverse/reverse_server.c | 4 +- tunnels/server/reverse/reverse_server.h | 2 +- tunnels/server/socks/5/socks5_server.c | 4 +- tunnels/server/socks/5/socks5_server.h | 2 +- .../server/trojan/auth/trojan_auth_server.c | 2 +- .../server/trojan/auth/trojan_auth_server.h | 2 +- .../server/trojan/socks/trojan_socks_server.c | 3 +- .../server/trojan/socks/trojan_socks_server.h | 2 +- tunnels/server/wolfssl/wolfssl_server.c | 2 +- tunnels/server/wolfssl/wolfssl_server.h | 2 +- tunnels/shared/openssl/openssl_globals.h | 28 ++--- tunnels/shared/reality/reality_helpers.h | 17 +-- tunnels/shared/trojan/sha2.c | 2 +- tunnels/shared/trojan/sha2.h | 2 +- tunnels/shared/wolfssl/wolfssl_globals.h | 25 +++-- ww/CMakeLists.txt | 9 +- ww/api.h | 2 +- ww/buffer_pool.c | 4 +- ww/buffer_pool.h | 4 +- ww/buffer_stream.c | 2 +- ww/eventloop/base/hbase.c | 4 +- ww/eventloop/base/hbase.h | 4 +- ww/eventloop/base/hchan.c | 102 +++++++++--------- ww/eventloop/base/hlog.c | 4 +- ww/eventloop/base/hlog.h | 14 +-- ww/eventloop/base/hmain.c | 4 +- ww/eventloop/base/hmain.h | 4 +- ww/eventloop/base/hsocket.h | 2 +- ww/eventloop/base/hsysinfo.h | 2 +- ww/eventloop/base/htime.c | 8 +- ww/eventloop/base/htime.h | 12 +-- ww/eventloop/base/hversion.c | 2 +- ww/eventloop/base/hversion.h | 4 +- ww/eventloop/event/epoll.c | 2 +- ww/eventloop/event/hevent.c | 4 +- ww/eventloop/event/hevent.h | 11 +- ww/eventloop/event/hloop.c | 2 +- ww/eventloop/event/hloop.h | 2 +- ww/frand.c | 2 +- ww/http_def.c | 2 +- ww/idle_table.c | 4 +- ww/idle_table.h | 2 +- ww/library_loader.h | 2 +- ww/loggers/core_logger.c | 6 +- ww/loggers/core_logger.h | 4 +- ww/loggers/dns_logger.c | 2 +- ww/loggers/dns_logger.h | 2 +- ww/loggers/network_logger.c | 2 +- ww/loggers/network_logger.h | 2 +- ww/managers/node_manager.c | 14 +-- ww/managers/node_manager.h | 6 +- ww/managers/socket_manager.c | 16 +-- ww/managers/socket_manager.h | 6 +- ww/shiftbuffer.c | 6 +- ww/shiftbuffer.h | 1 + ww/sync_dns.c | 2 +- ww/tunnel.c | 2 +- ww/tunnel.h | 4 +- ww/utils/hashutils.h | 15 +++ ww/utils/userutils.h | 2 +- ww/ww.c | 4 +- ww/ww.h | 4 +- 116 files changed, 330 insertions(+), 302 deletions(-) diff --git a/core/core_settings.c b/core/core_settings.c index 34a33a51..a63bcdbf 100644 --- a/core/core_settings.c +++ b/core/core_settings.c @@ -273,25 +273,25 @@ void parseCoreSettings(char *data_json) // TODO (DNS) Implement dns settings and backend } -char *getCoreLoggerFullPath() +char *getCoreLoggerFullPath(void) { return concat(settings->log_path, settings->core_log_file); } -char *getNetworkLoggerFullPath() +char *getNetworkLoggerFullPath(void) { return concat(settings->log_path, settings->network_log_file); } -char *getDnsLoggerFullPath() +char *getDnsLoggerFullPath(void) { return concat(settings->log_path, settings->dns_log_file); } -struct core_settings_s *getCoreSettings() +struct core_settings_s *getCoreSettings(void) { return settings; } -void initCoreSettings() +void initCoreSettings(void) { assert(settings == NULL); // we can't use logs here, so just assert diff --git a/core/core_settings.h b/core/core_settings.h index ad3e2ab6..6b8638c9 100644 --- a/core/core_settings.h +++ b/core/core_settings.h @@ -30,9 +30,9 @@ struct core_settings_s void parseCoreSettings(char *data_json); -char *getCoreLoggerFullPath(); -char *getNetworkLoggerFullPath(); -char *getDnsLoggerFullPath(); +char *getCoreLoggerFullPath(void); +char *getNetworkLoggerFullPath(void); +char *getDnsLoggerFullPath(void); -struct core_settings_s *getCoreSettings(); -void initCoreSettings(); +struct core_settings_s *getCoreSettings(void); +void initCoreSettings(void); diff --git a/core/main.c b/core/main.c index e39b3edd..be0b23d9 100644 --- a/core/main.c +++ b/core/main.c @@ -79,4 +79,4 @@ int main(void) LOGD("Core: starting workers ..."); startSocketManager(); runMainThread(); -} \ No newline at end of file +} diff --git a/core/os_helpers.h b/core/os_helpers.h index 4c060877..ddaf2a8f 100644 --- a/core/os_helpers.h +++ b/core/os_helpers.h @@ -4,7 +4,7 @@ #ifdef OS_UNIX #include -static void increaseFileLimit() +static void increaseFileLimit(void) { struct rlimit rlim; @@ -36,8 +36,8 @@ static void increaseFileLimit() } } #else -static void increaseFileLimit() +static void increaseFileLimit(void) { (void) (0); } -#endif \ No newline at end of file +#endif diff --git a/core/static_tunnels.c b/core/static_tunnels.c index bca3642e..bb8ec6b0 100644 --- a/core/static_tunnels.c +++ b/core/static_tunnels.c @@ -124,7 +124,7 @@ #include "tunnels/client/reality/reality_client.h" #endif -void loadStaticTunnelsIntoCore() +void loadStaticTunnelsIntoCore(void) { #ifdef INCLUDE_TCP_LISTENER USING(TcpListener); @@ -233,4 +233,4 @@ void loadStaticTunnelsIntoCore() #ifdef INCLUDE_REALITY_CLIENT USING(RealityClient); #endif -} \ No newline at end of file +} diff --git a/core/static_tunnels.h b/core/static_tunnels.h index c90b2cfa..752fb38f 100644 --- a/core/static_tunnels.h +++ b/core/static_tunnels.h @@ -4,4 +4,4 @@ -void loadStaticTunnelsIntoCore(); +void loadStaticTunnelsIntoCore(void); diff --git a/tunnels/adapters/bridge/bridge.c b/tunnels/adapters/bridge/bridge.c index ab41757a..e06a4e6a 100644 --- a/tunnels/adapters/bridge/bridge.c +++ b/tunnels/adapters/bridge/bridge.c @@ -13,7 +13,7 @@ typedef struct bridge_state_s typedef struct bridge_con_state_s { - + void*_; } bridge_con_state_t; static void upStream(tunnel_t *self, context_t *c) @@ -119,7 +119,7 @@ tunnel_t *destroyBridge(tunnel_t *self) return NULL; } -tunnel_metadata_t getMetadataBridge() +tunnel_metadata_t getMetadataBridge(void) { return (tunnel_metadata_t){.version = 0001, .flags = kNodeFlagChainHead}; -} \ No newline at end of file +} diff --git a/tunnels/adapters/bridge/bridge.h b/tunnels/adapters/bridge/bridge.h index ce437648..4620de78 100644 --- a/tunnels/adapters/bridge/bridge.h +++ b/tunnels/adapters/bridge/bridge.h @@ -6,4 +6,4 @@ tunnel_t * newBridge(node_instance_context_t *instance_info); api_result_t apiBridge(tunnel_t *self, const char *msg); tunnel_t * destroyBridge(tunnel_t *self); -tunnel_metadata_t getMetadataBridge(); +tunnel_metadata_t getMetadataBridge(void); diff --git a/tunnels/adapters/connector/connector.c b/tunnels/adapters/connector/connector.c index e60ebc92..d3dc6e65 100644 --- a/tunnels/adapters/connector/connector.c +++ b/tunnels/adapters/connector/connector.c @@ -12,7 +12,7 @@ typedef struct connector_state_s typedef struct connector_con_state_s { - + void*_; } connector_con_state_t; static void upStream(tunnel_t *self, context_t *c) @@ -84,7 +84,7 @@ tunnel_t *destroyConnector(tunnel_t *self) (void) (self); return NULL; } -tunnel_metadata_t getMetadataConnector() +tunnel_metadata_t getMetadataConnector(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; -} \ No newline at end of file +} diff --git a/tunnels/adapters/connector/connector.h b/tunnels/adapters/connector/connector.h index 8388d813..384f0453 100644 --- a/tunnels/adapters/connector/connector.h +++ b/tunnels/adapters/connector/connector.h @@ -9,4 +9,4 @@ tunnel_t * newConnector(node_instance_context_t *instance_info); api_result_t apiConnector(tunnel_t *self, const char *msg); tunnel_t * destroyConnector(tunnel_t *self); -tunnel_metadata_t getMetadataConnector(); +tunnel_metadata_t getMetadataConnector(void); diff --git a/tunnels/adapters/connector/tcp/tcp_connector.c b/tunnels/adapters/connector/tcp/tcp_connector.c index e3101399..79cb1536 100644 --- a/tunnels/adapters/connector/tcp/tcp_connector.c +++ b/tunnels/adapters/connector/tcp/tcp_connector.c @@ -406,7 +406,7 @@ tunnel_t *destroyTcpConnector(tunnel_t *self) (void) (self); return NULL; } -tunnel_metadata_t getMetadataTcpConnector() +tunnel_metadata_t getMetadataTcpConnector(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; -} \ No newline at end of file +} diff --git a/tunnels/adapters/connector/tcp/tcp_connector.h b/tunnels/adapters/connector/tcp/tcp_connector.h index d7e0a1f6..62211c5b 100644 --- a/tunnels/adapters/connector/tcp/tcp_connector.h +++ b/tunnels/adapters/connector/tcp/tcp_connector.h @@ -9,4 +9,4 @@ tunnel_t * newTcpConnector(node_instance_context_t *instance_info); api_result_t apiTcpConnector(tunnel_t *self, const char *msg); tunnel_t * destroyTcpConnector(tunnel_t *self); -tunnel_metadata_t getMetadataTcpConnector(); +tunnel_metadata_t getMetadataTcpConnector(void); diff --git a/tunnels/adapters/connector/udp/udp_connector.c b/tunnels/adapters/connector/udp/udp_connector.c index 41794e6c..0be67921 100644 --- a/tunnels/adapters/connector/udp/udp_connector.c +++ b/tunnels/adapters/connector/udp/udp_connector.c @@ -257,7 +257,7 @@ tunnel_t *destroyUdpConnector(tunnel_t *self) (void) (self); return NULL; } -tunnel_metadata_t getMetadataUdpConnector() +tunnel_metadata_t getMetadataUdpConnector(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; -} \ No newline at end of file +} diff --git a/tunnels/adapters/connector/udp/udp_connector.h b/tunnels/adapters/connector/udp/udp_connector.h index 53f337e3..19cf3a1a 100644 --- a/tunnels/adapters/connector/udp/udp_connector.h +++ b/tunnels/adapters/connector/udp/udp_connector.h @@ -9,4 +9,4 @@ tunnel_t * newUdpConnector(node_instance_context_t *instance_info); api_result_t apiUdpConnector(tunnel_t *self, const char *msg); tunnel_t * destroyUdpConnector(tunnel_t *self); -tunnel_metadata_t getMetadataUdpConnector(); +tunnel_metadata_t getMetadataUdpConnector(void); diff --git a/tunnels/adapters/listener/listener.c b/tunnels/adapters/listener/listener.c index cef50a6e..46b323d1 100644 --- a/tunnels/adapters/listener/listener.c +++ b/tunnels/adapters/listener/listener.c @@ -16,7 +16,7 @@ typedef struct listener_state_s typedef struct listener_con_state_s { - + void*_; } listener_con_state_t; // set function pointers baby)) @@ -100,7 +100,7 @@ tunnel_t *destroyListener(tunnel_t *self) (void) (self); return NULL; } -tunnel_metadata_t getMetadataListener() +tunnel_metadata_t getMetadataListener(void) { return (tunnel_metadata_t){.version = 0001, .flags = kNodeFlagChainHead}; -} \ No newline at end of file +} diff --git a/tunnels/adapters/listener/listener.h b/tunnels/adapters/listener/listener.h index 92cb7822..51578066 100644 --- a/tunnels/adapters/listener/listener.h +++ b/tunnels/adapters/listener/listener.h @@ -9,4 +9,4 @@ tunnel_t * newListener(node_instance_context_t *instance_info); api_result_t apiListener(tunnel_t *self, const char *msg); tunnel_t * destroyListener(tunnel_t *self); -tunnel_metadata_t getMetadataListener(); +tunnel_metadata_t getMetadataListener(void); diff --git a/tunnels/adapters/listener/tcp/tcp_listener.c b/tunnels/adapters/listener/tcp/tcp_listener.c index e04b2962..d4492bd9 100644 --- a/tunnels/adapters/listener/tcp/tcp_listener.c +++ b/tunnels/adapters/listener/tcp/tcp_listener.c @@ -454,7 +454,7 @@ tunnel_t *destroyTcpListener(tunnel_t *self) (void) (self); return NULL; } -tunnel_metadata_t getMetadataTcpListener() +tunnel_metadata_t getMetadataTcpListener(void) { return (tunnel_metadata_t){.version = 0001, .flags = kNodeFlagChainHead}; -} \ No newline at end of file +} diff --git a/tunnels/adapters/listener/tcp/tcp_listener.h b/tunnels/adapters/listener/tcp/tcp_listener.h index d0278038..e7a7bc6a 100644 --- a/tunnels/adapters/listener/tcp/tcp_listener.h +++ b/tunnels/adapters/listener/tcp/tcp_listener.h @@ -9,4 +9,4 @@ tunnel_t *newTcpListener(node_instance_context_t *instance_info); api_result_t apiTcpListener(tunnel_t *self, const char *msg); tunnel_t *destroyTcpListener(tunnel_t *self); -tunnel_metadata_t getMetadataTcpListener(); +tunnel_metadata_t getMetadataTcpListener(void); diff --git a/tunnels/adapters/listener/udp/udp_listener.c b/tunnels/adapters/listener/udp/udp_listener.c index ce0b42f4..25ead03a 100644 --- a/tunnels/adapters/listener/udp/udp_listener.c +++ b/tunnels/adapters/listener/udp/udp_listener.c @@ -53,7 +53,7 @@ static void cleanup(udp_listener_con_state_t *cstate) // sounds impossible... LOGE("Checkpoint udp listener"); // this prevent double free - *cstate = (udp_listener_con_state_t){}; + *cstate = (udp_listener_con_state_t){0}; } } else @@ -364,7 +364,7 @@ tunnel_t *destroyUdpListener(tunnel_t *self) (void) (self); return NULL; } -tunnel_metadata_t getMetadataUdpListener() +tunnel_metadata_t getMetadataUdpListener(void) { return (tunnel_metadata_t){.version = 0001, .flags = kNodeFlagChainHead}; -} \ No newline at end of file +} diff --git a/tunnels/adapters/listener/udp/udp_listener.h b/tunnels/adapters/listener/udp/udp_listener.h index e78fa677..334a2456 100644 --- a/tunnels/adapters/listener/udp/udp_listener.h +++ b/tunnels/adapters/listener/udp/udp_listener.h @@ -10,4 +10,4 @@ tunnel_t * newUdpListener(node_instance_context_t *instance_info); api_result_t apiUdpListener(tunnel_t *self, const char *msg); tunnel_t * destroyUdpListener(tunnel_t *self); -tunnel_metadata_t getMetadataUdpListener(); +tunnel_metadata_t getMetadataUdpListener(void); diff --git a/tunnels/client/header/header_client.c b/tunnels/client/header/header_client.c index f3a0f000..d692ffbd 100644 --- a/tunnels/client/header/header_client.c +++ b/tunnels/client/header/header_client.c @@ -19,7 +19,7 @@ typedef struct header_client_state_s typedef struct header_client_con_state_s { - + void*_; } header_client_con_state_t; static void upStream(tunnel_t *self, context_t *c) @@ -81,7 +81,7 @@ tunnel_t *destroyHeaderClient(tunnel_t *self) (void) (self); return NULL; } -tunnel_metadata_t getMetadataHeaderClient() +tunnel_metadata_t getMetadataHeaderClient(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; -} \ No newline at end of file +} diff --git a/tunnels/client/header/header_client.h b/tunnels/client/header/header_client.h index cc0c4dbb..4416d0de 100644 --- a/tunnels/client/header/header_client.h +++ b/tunnels/client/header/header_client.h @@ -8,7 +8,7 @@ tunnel_t *newHeaderClient(node_instance_context_t *instance_info); api_result_t apiHeaderClient(tunnel_t *self, const char *msg); tunnel_t *destroyHeaderClient(tunnel_t *self); -tunnel_metadata_t getMetadataHeaderClient(); +tunnel_metadata_t getMetadataHeaderClient(void); diff --git a/tunnels/client/http2/helpers.h b/tunnels/client/http2/helpers.h index 28b0a2d9..d4b9bd79 100644 --- a/tunnels/client/http2/helpers.h +++ b/tunnels/client/http2/helpers.h @@ -3,10 +3,11 @@ #include "tunnel.h" #include "types.h" +#define kMaxConcurrentStreams 0xffffffffU // NOLINT + enum { - kMaxConcurrentStreams = 0xffffffffU, - kPingInterval = 5000 + kPingInterval = 5000 }; static void onPingTimer(htimer_t *timer); diff --git a/tunnels/client/http2/http2_client.c b/tunnels/client/http2/http2_client.c index f9998568..9ca771b0 100644 --- a/tunnels/client/http2/http2_client.c +++ b/tunnels/client/http2/http2_client.c @@ -524,7 +524,7 @@ tunnel_t *destroyHttp2Client(tunnel_t *self) return NULL; } -tunnel_metadata_t getMetadataHttp2Client() +tunnel_metadata_t getMetadataHttp2Client(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; } diff --git a/tunnels/client/http2/http2_client.h b/tunnels/client/http2/http2_client.h index 45b236e6..d15a51f2 100644 --- a/tunnels/client/http2/http2_client.h +++ b/tunnels/client/http2/http2_client.h @@ -8,4 +8,4 @@ tunnel_t * newHttp2Client(node_instance_context_t *instance_info); api_result_t apiHttp2Client(tunnel_t *self,const char *msg); tunnel_t * destroyHttp2Client(tunnel_t *self); -tunnel_metadata_t getMetadataHttp2Client(); +tunnel_metadata_t getMetadataHttp2Client(void); diff --git a/tunnels/client/openssl/openssl_client.c b/tunnels/client/openssl/openssl_client.c index 28f96b8e..7f87703b 100644 --- a/tunnels/client/openssl/openssl_client.c +++ b/tunnels/client/openssl/openssl_client.c @@ -492,7 +492,7 @@ tunnel_t *destroyOpenSSLClient(tunnel_t *self) return NULL; } -tunnel_metadata_t getMetadataOpenSSLClient() +tunnel_metadata_t getMetadataOpenSSLClient(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; } diff --git a/tunnels/client/openssl/openssl_client.h b/tunnels/client/openssl/openssl_client.h index 0304f3e2..b69cf717 100644 --- a/tunnels/client/openssl/openssl_client.h +++ b/tunnels/client/openssl/openssl_client.h @@ -8,4 +8,4 @@ tunnel_t * newOpenSSLClient(node_instance_context_t *instance_info); api_result_t apiOpenSSLClient(tunnel_t *self, const char *msg); tunnel_t * destroyOpenSSLClient(tunnel_t *self); -tunnel_metadata_t getMetadataOpenSSLClient(); +tunnel_metadata_t getMetadataOpenSSLClient(void); diff --git a/tunnels/client/preconnect/helpers.h b/tunnels/client/preconnect/helpers.h index 2f2e9b4c..403f63ce 100644 --- a/tunnels/client/preconnect/helpers.h +++ b/tunnels/client/preconnect/helpers.h @@ -3,8 +3,11 @@ #include "types.h" #include "utils/mathutils.h" -#define PRECONNECT_DELAY_SHORT 10 -#define PRECONNECT_DELAY_HIGH 750 +enum +{ + kPreconnectDelayShort = 10, + kPreconnectDelayHigh = 750 +}; static void addConnection(thread_box_t *box, preconnect_client_con_state_t *con) { @@ -43,8 +46,8 @@ 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); + 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; @@ -59,7 +62,7 @@ static void connectTimerFinished(htimer_t *timer) static void beforeConnect(hevent_t *ev) { struct connect_arg *cg = hevent_userdata(ev); - htimer_t * connect_timer = htimer_add(loops[cg->tid], connectTimerFinished, cg->delay, 1); + htimer_t *connect_timer = htimer_add(loops[cg->tid], connectTimerFinished, cg->delay, 1); if (connect_timer) { hevent_set_userdata(connect_timer, cg); @@ -100,8 +103,8 @@ static void initiateConnect(tunnel_t *self, bool delay) struct connect_arg *cg = malloc(sizeof(struct connect_arg)); cg->t = self; cg->tid = tid; - cg->delay = delay ? PRECONNECT_DELAY_HIGH : PRECONNECT_DELAY_SHORT; + cg->delay = delay ? kPreconnectDelayHigh : kPreconnectDelayShort; ev.userdata = cg; hloop_post_event(worker_loop, &ev); -} \ No newline at end of file +} diff --git a/tunnels/client/preconnect/preconnect_client.c b/tunnels/client/preconnect/preconnect_client.c index 7384f954..cb517e68 100644 --- a/tunnels/client/preconnect/preconnect_client.c +++ b/tunnels/client/preconnect/preconnect_client.c @@ -241,7 +241,7 @@ tunnel_t *destroyPreConnectClient(tunnel_t *self) (void) (self); return NULL; } -tunnel_metadata_t getMetadataPreConnectClient() +tunnel_metadata_t getMetadataPreConnectClient(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; -} \ No newline at end of file +} diff --git a/tunnels/client/preconnect/preconnect_client.h b/tunnels/client/preconnect/preconnect_client.h index e92d2dd0..f30f63e6 100644 --- a/tunnels/client/preconnect/preconnect_client.h +++ b/tunnels/client/preconnect/preconnect_client.h @@ -8,4 +8,4 @@ tunnel_t * newPreConnectClient(node_instance_context_t *instance_info); api_result_t apiPreConnectClient(tunnel_t *self, const char *msg); tunnel_t * destroyPreConnectClient(tunnel_t *self); -tunnel_metadata_t getMetadataPreConnectClient(); +tunnel_metadata_t getMetadataPreConnectClient(void); diff --git a/tunnels/client/protobuf/protobuf_client.c b/tunnels/client/protobuf/protobuf_client.c index b1c06cbf..22cb640e 100644 --- a/tunnels/client/protobuf/protobuf_client.c +++ b/tunnels/client/protobuf/protobuf_client.c @@ -21,7 +21,7 @@ enum typedef struct protobuf_client_state_s { - + void*_; } protobuf_client_state_t; typedef struct protobuf_client_con_state_s @@ -173,7 +173,7 @@ tunnel_t *destroyProtoBufClient(tunnel_t *self) (void) (self); return NULL; } -tunnel_metadata_t getMetadataProtoBufClient() +tunnel_metadata_t getMetadataProtoBufClient(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; -} \ No newline at end of file +} diff --git a/tunnels/client/protobuf/protobuf_client.h b/tunnels/client/protobuf/protobuf_client.h index 4e49bfa1..92843ebf 100644 --- a/tunnels/client/protobuf/protobuf_client.h +++ b/tunnels/client/protobuf/protobuf_client.h @@ -10,4 +10,4 @@ tunnel_t *newProtoBufClient(node_instance_context_t *instance_info); api_result_t apiProtoBufClient(tunnel_t *self, const char *msg); tunnel_t *destroyProtoBufClient(tunnel_t *self); -tunnel_metadata_t getMetadataProtoBufClient(); +tunnel_metadata_t getMetadataProtoBufClient(void); diff --git a/tunnels/client/reality/reality_client.c b/tunnels/client/reality/reality_client.c index a5705552..dce7a1dc 100644 --- a/tunnels/client/reality/reality_client.c +++ b/tunnels/client/reality/reality_client.c @@ -525,7 +525,7 @@ tunnel_t *destroyRealityClient(tunnel_t *self) return NULL; } -tunnel_metadata_t getMetadataRealityClient() +tunnel_metadata_t getMetadataRealityClient(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; } diff --git a/tunnels/client/reality/reality_client.h b/tunnels/client/reality/reality_client.h index 29fa59c9..f13e57ce 100644 --- a/tunnels/client/reality/reality_client.h +++ b/tunnels/client/reality/reality_client.h @@ -8,4 +8,4 @@ tunnel_t * newRealityClient(node_instance_context_t *instance_info); api_result_t apiRealityClient(tunnel_t *self, const char *msg); tunnel_t * destroyRealityClient(tunnel_t *self); -tunnel_metadata_t getMetadataRealityClient(); +tunnel_metadata_t getMetadataRealityClient(void); diff --git a/tunnels/client/reverse/helpers.h b/tunnels/client/reverse/helpers.h index 124a1f95..801f5271 100644 --- a/tunnels/client/reverse/helpers.h +++ b/tunnels/client/reverse/helpers.h @@ -133,4 +133,4 @@ static void initiateConnect(tunnel_t *self, uint8_t tid, bool delay) cg->delay = delay ? kPreconnectDelayHigh : kPreconnectDelayShort; ev.userdata = cg; hloop_post_event(worker_loop, &ev); -} \ No newline at end of file +} diff --git a/tunnels/client/reverse/reverse_client.c b/tunnels/client/reverse/reverse_client.c index c6f5d7f1..5deb9c96 100644 --- a/tunnels/client/reverse/reverse_client.c +++ b/tunnels/client/reverse/reverse_client.c @@ -219,7 +219,7 @@ tunnel_t *destroyReverseClient(tunnel_t *self) (void) (self); return NULL; } -tunnel_metadata_t getMetadataReverseClient() +tunnel_metadata_t getMetadataReverseClient(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; -} \ No newline at end of file +} diff --git a/tunnels/client/reverse/reverse_client.h b/tunnels/client/reverse/reverse_client.h index f3226e14..a96c8a47 100644 --- a/tunnels/client/reverse/reverse_client.h +++ b/tunnels/client/reverse/reverse_client.h @@ -6,4 +6,4 @@ tunnel_t * newReverseClient(node_instance_context_t *instance_info); api_result_t apiReverseClient(tunnel_t *self, const char *msg); tunnel_t * destroyReverseClient(tunnel_t *self); -tunnel_metadata_t getMetadataReverseClient(); +tunnel_metadata_t getMetadataReverseClient(void); diff --git a/tunnels/client/wolfssl/wolfssl_client.c b/tunnels/client/wolfssl/wolfssl_client.c index 7ba507a5..65a72ee1 100644 --- a/tunnels/client/wolfssl/wolfssl_client.c +++ b/tunnels/client/wolfssl/wolfssl_client.c @@ -493,7 +493,7 @@ tunnel_t *destroyWolfSSLClient(tunnel_t *self) return NULL; } -tunnel_metadata_t getMetadataWolfSSLClient() +tunnel_metadata_t getMetadataWolfSSLClient(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; } diff --git a/tunnels/client/wolfssl/wolfssl_client.h b/tunnels/client/wolfssl/wolfssl_client.h index be0c065d..15bbb78f 100644 --- a/tunnels/client/wolfssl/wolfssl_client.h +++ b/tunnels/client/wolfssl/wolfssl_client.h @@ -8,4 +8,4 @@ tunnel_t * newWolfSSLClient(node_instance_context_t *instance_info); api_result_t apiWolfSSLClient(tunnel_t *self,const char *msg); tunnel_t * destroyWolfSSLClient(tunnel_t *self); -tunnel_metadata_t getMetadataWolfSSLClient(); +tunnel_metadata_t getMetadataWolfSSLClient(void); diff --git a/tunnels/logger/logger_tunnel.c b/tunnels/logger/logger_tunnel.c index 4b3955ff..c02c73ce 100644 --- a/tunnels/logger/logger_tunnel.c +++ b/tunnels/logger/logger_tunnel.c @@ -11,11 +11,12 @@ static inline size_t min(size_t x, size_t y) typedef struct logger_tunnel_state_s { - + void*_; } logger_tunnel_state_t; typedef struct logger_tunnel_con_state_s { + void*_; } logger_tunnel_con_state_t; @@ -166,7 +167,7 @@ tunnel_t *destroyLoggerTunnel(tunnel_t *self) (void) (self); return NULL; } -tunnel_metadata_t getMetadataLoggerTunnel() +tunnel_metadata_t getMetadataLoggerTunnel(void) { return (tunnel_metadata_t){.version = 0001, .flags = kNodeFlagChainHead}; -} \ No newline at end of file +} diff --git a/tunnels/logger/logger_tunnel.h b/tunnels/logger/logger_tunnel.h index ce051f5c..0aa50101 100644 --- a/tunnels/logger/logger_tunnel.h +++ b/tunnels/logger/logger_tunnel.h @@ -4,9 +4,8 @@ // // dw <------> networklogger <------> up // -// tunnel_t * newLoggerTunnel(node_instance_context_t *instance_info); api_result_t apiLoggerTunnel(tunnel_t *self, const char *msg); tunnel_t * destroyLoggerTunnel(tunnel_t *self); -tunnel_metadata_t getMetadataLoggerTunnel(); +tunnel_metadata_t getMetadataLoggerTunnel(void); diff --git a/tunnels/server/header/header_server.c b/tunnels/server/header/header_server.c index b806d0eb..0e496132 100644 --- a/tunnels/server/header/header_server.c +++ b/tunnels/server/header/header_server.c @@ -94,7 +94,7 @@ static void upStream(tunnel_t *self, context_t *c) else if (c->init) { cstate = malloc(sizeof(header_server_con_state_t)); - *cstate = (header_server_con_state_t){}; + *cstate = (header_server_con_state_t){0}; CSTATE_MUT(c) = cstate; destroyContext(c); } @@ -164,7 +164,7 @@ tunnel_t *destroyHeaderServer(tunnel_t *self) (void) (self); return NULL; } -tunnel_metadata_t getMetadataHeaderServer() +tunnel_metadata_t getMetadataHeaderServer(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; -} \ No newline at end of file +} diff --git a/tunnels/server/header/header_server.h b/tunnels/server/header/header_server.h index 6ded0d5e..1197c819 100644 --- a/tunnels/server/header/header_server.h +++ b/tunnels/server/header/header_server.h @@ -8,4 +8,4 @@ tunnel_t * newHeaderServer(node_instance_context_t *instance_info); api_result_t apiHeaderServer(tunnel_t *self,const char *msg); tunnel_t * destroyHeaderServer(tunnel_t *self); -tunnel_metadata_t getMetadataHeaderServer(); +tunnel_metadata_t getMetadataHeaderServer(void); diff --git a/tunnels/server/http2/helpers.h b/tunnels/server/http2/helpers.h index 8070dc09..0764c371 100644 --- a/tunnels/server/http2/helpers.h +++ b/tunnels/server/http2/helpers.h @@ -3,10 +3,7 @@ #include "tunnel.h" #include "types.h" -enum -{ - kMaxConcurrentStreams = 0xffffffffU -}; +#define kMaxConcurrentStreams 0xffffffffU // NOLINT static nghttp2_nv makeNv(const char *name, const char *value) { diff --git a/tunnels/server/http2/http2_server.c b/tunnels/server/http2/http2_server.c index 06ffa620..d1272eea 100644 --- a/tunnels/server/http2/http2_server.c +++ b/tunnels/server/http2/http2_server.c @@ -456,7 +456,7 @@ tunnel_t *destroyHttp2Server(tunnel_t *self) return NULL; } -tunnel_metadata_t getMetadataHttp2Server() +tunnel_metadata_t getMetadataHttp2Server(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; } diff --git a/tunnels/server/http2/http2_server.h b/tunnels/server/http2/http2_server.h index db1054a2..7332b3fe 100644 --- a/tunnels/server/http2/http2_server.h +++ b/tunnels/server/http2/http2_server.h @@ -8,4 +8,4 @@ tunnel_t * newHttp2Server(node_instance_context_t *instance_info); api_result_t apiHttp2Server(tunnel_t *self, const char *msg); tunnel_t * destroyHttp2Server(tunnel_t *self); -tunnel_metadata_t getMetadataHttp2Server(); +tunnel_metadata_t getMetadataHttp2Server(void); diff --git a/tunnels/server/openssl/openssl_server.c b/tunnels/server/openssl/openssl_server.c index f878d912..22f929d8 100644 --- a/tunnels/server/openssl/openssl_server.c +++ b/tunnels/server/openssl/openssl_server.c @@ -678,7 +678,7 @@ tunnel_t *destroyOpenSSLServer(tunnel_t *self) return NULL; } -tunnel_metadata_t getMetadataOpenSSLServer() +tunnel_metadata_t getMetadataOpenSSLServer(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; } diff --git a/tunnels/server/openssl/openssl_server.h b/tunnels/server/openssl/openssl_server.h index 2bcae58e..13060f62 100644 --- a/tunnels/server/openssl/openssl_server.h +++ b/tunnels/server/openssl/openssl_server.h @@ -8,4 +8,4 @@ tunnel_t *newOpenSSLServer(node_instance_context_t *instance_info); api_result_t apiOpenSSLServer(tunnel_t *self, const char *msg); tunnel_t *destroyOpenSSLServer(tunnel_t *self); -tunnel_metadata_t getMetadataOpenSSLServer(); +tunnel_metadata_t getMetadataOpenSSLServer(void); diff --git a/tunnels/server/preconnect/preconnect_server.c b/tunnels/server/preconnect/preconnect_server.c index b0f25268..15dca541 100644 --- a/tunnels/server/preconnect/preconnect_server.c +++ b/tunnels/server/preconnect/preconnect_server.c @@ -5,7 +5,7 @@ typedef struct preconnect_server_state_s { - + void *_; } preconnect_server_state_t; typedef struct preconnect_server_con_state_s @@ -72,18 +72,16 @@ static void downStream(tunnel_t *self, context_t *c) self->dw->downStream(self->dw, c); } - - tunnel_t *newPreConnectServer(node_instance_context_t *instance_info) { (void) instance_info; preconnect_server_state_t *state = malloc(sizeof(preconnect_server_state_t)); memset(state, 0, sizeof(preconnect_server_state_t)); - tunnel_t *t = newTunnel(); - t->state = state; - t->upStream = &upStream; - t->downStream = &downStream; + tunnel_t *t = newTunnel(); + t->state = state; + t->upStream = &upStream; + t->downStream = &downStream; atomic_thread_fence(memory_order_release); return t; @@ -101,7 +99,7 @@ tunnel_t *destroyPreConnectServer(tunnel_t *self) (void) (self); return NULL; } -tunnel_metadata_t getMetadataPreConnectServer() +tunnel_metadata_t getMetadataPreConnectServer(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; -} \ No newline at end of file +} diff --git a/tunnels/server/preconnect/preconnect_server.h b/tunnels/server/preconnect/preconnect_server.h index baf0ffe6..4951fd06 100644 --- a/tunnels/server/preconnect/preconnect_server.h +++ b/tunnels/server/preconnect/preconnect_server.h @@ -9,4 +9,4 @@ tunnel_t * newPreConnectServer(node_instance_context_t *instance_info); api_result_t apiPreConnectServer(tunnel_t *self, const char *msg); tunnel_t * destroyPreConnectServer(tunnel_t *self); -tunnel_metadata_t getMetadataPreConnectServer(); +tunnel_metadata_t getMetadataPreConnectServer(void); diff --git a/tunnels/server/protobuf/protobuf_server.c b/tunnels/server/protobuf/protobuf_server.c index dfc83c3b..ba361682 100644 --- a/tunnels/server/protobuf/protobuf_server.c +++ b/tunnels/server/protobuf/protobuf_server.c @@ -21,7 +21,7 @@ enum typedef struct protobuf_server_state_s { - + void *_; } protobuf_server_state_t; typedef struct protobuf_server_con_state_s @@ -177,7 +177,7 @@ tunnel_t *destroyProtoBufServer(tunnel_t *self) (void) (self); return NULL; } -tunnel_metadata_t getMetadataProtoBufServer() +tunnel_metadata_t getMetadataProtoBufServer(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; -} \ No newline at end of file +} diff --git a/tunnels/server/protobuf/protobuf_server.h b/tunnels/server/protobuf/protobuf_server.h index 170e4c0a..bb2bbb2d 100644 --- a/tunnels/server/protobuf/protobuf_server.h +++ b/tunnels/server/protobuf/protobuf_server.h @@ -8,4 +8,4 @@ tunnel_t * newProtoBufServer(node_instance_context_t *instance_info); api_result_t apiProtoBufServer(tunnel_t *self, const char *msg); tunnel_t * destroyProtoBufServer(tunnel_t *self); -tunnel_metadata_t getMetadataProtoBufServer(); +tunnel_metadata_t getMetadataProtoBufServer(void); diff --git a/tunnels/server/reality/reality_server.c b/tunnels/server/reality/reality_server.c index cb23723f..1b3a5c5f 100644 --- a/tunnels/server/reality/reality_server.c +++ b/tunnels/server/reality/reality_server.c @@ -408,7 +408,7 @@ tunnel_t *destroyRealityServer(tunnel_t *self) return NULL; } -tunnel_metadata_t getMetadataRealityServer() +tunnel_metadata_t getMetadataRealityServer(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; } diff --git a/tunnels/server/reality/reality_server.h b/tunnels/server/reality/reality_server.h index 6e586f1d..cc8d657b 100644 --- a/tunnels/server/reality/reality_server.h +++ b/tunnels/server/reality/reality_server.h @@ -8,4 +8,4 @@ tunnel_t *newRealityServer(node_instance_context_t *instance_info); api_result_t apiRealityServer(tunnel_t *self, const char *msg); tunnel_t *destroyRealityServer(tunnel_t *self); -tunnel_metadata_t getMetadataRealityServer(); +tunnel_metadata_t getMetadataRealityServer(void); diff --git a/tunnels/server/reverse/reverse_server.c b/tunnels/server/reverse/reverse_server.c index 7c84f68c..f851f827 100644 --- a/tunnels/server/reverse/reverse_server.c +++ b/tunnels/server/reverse/reverse_server.c @@ -246,7 +246,7 @@ tunnel_t *destroyReverseServer(tunnel_t *self) (void) (self); return NULL; } -tunnel_metadata_t getMetadataReverseServer() +tunnel_metadata_t getMetadataReverseServer(void) { return (tunnel_metadata_t){.version = 0001, .flags = kNodeFlagChainHead}; -} \ No newline at end of file +} diff --git a/tunnels/server/reverse/reverse_server.h b/tunnels/server/reverse/reverse_server.h index 436f8e71..e6000db7 100644 --- a/tunnels/server/reverse/reverse_server.h +++ b/tunnels/server/reverse/reverse_server.h @@ -6,4 +6,4 @@ tunnel_t * newReverseServer(node_instance_context_t *instance_info); api_result_t apiReverseServer(tunnel_t *self, const char *msg); tunnel_t * destroyReverseServer(tunnel_t *self); -tunnel_metadata_t getMetadataReverseServer(); +tunnel_metadata_t getMetadataReverseServer(void); diff --git a/tunnels/server/socks/5/socks5_server.c b/tunnels/server/socks/5/socks5_server.c index ac95ff5e..3313194a 100644 --- a/tunnels/server/socks/5/socks5_server.c +++ b/tunnels/server/socks/5/socks5_server.c @@ -67,7 +67,7 @@ typedef enum typedef struct socks5_server_state_s { - + void*_; } socks5_server_state_t; typedef struct socks5_server_con_state_s @@ -749,7 +749,7 @@ tunnel_t *destroySocks5Server(tunnel_t *self) return NULL; } -tunnel_metadata_t getMetadataSocks5Server() +tunnel_metadata_t getMetadataSocks5Server(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; } diff --git a/tunnels/server/socks/5/socks5_server.h b/tunnels/server/socks/5/socks5_server.h index 90a6dac7..0cd8c743 100644 --- a/tunnels/server/socks/5/socks5_server.h +++ b/tunnels/server/socks/5/socks5_server.h @@ -8,4 +8,4 @@ tunnel_t * newSocks5Server(node_instance_context_t *instance_info); api_result_t apiSocks5Server(tunnel_t *self, const char *msg); tunnel_t * destroySocks5Server(tunnel_t *self); -tunnel_metadata_t getMetadataSocks5Server(); \ No newline at end of file +tunnel_metadata_t getMetadataSocks5Server(void); diff --git a/tunnels/server/trojan/auth/trojan_auth_server.c b/tunnels/server/trojan/auth/trojan_auth_server.c index cf3145b8..db11551a 100644 --- a/tunnels/server/trojan/auth/trojan_auth_server.c +++ b/tunnels/server/trojan/auth/trojan_auth_server.c @@ -352,7 +352,7 @@ tunnel_t *destroyTrojanAuthServer(tunnel_t *self) return NULL; } -tunnel_metadata_t getMetadataTrojanAuthServer() +tunnel_metadata_t getMetadataTrojanAuthServer(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; } diff --git a/tunnels/server/trojan/auth/trojan_auth_server.h b/tunnels/server/trojan/auth/trojan_auth_server.h index 9ee0625e..f066cd85 100644 --- a/tunnels/server/trojan/auth/trojan_auth_server.h +++ b/tunnels/server/trojan/auth/trojan_auth_server.h @@ -12,4 +12,4 @@ tunnel_t *newTrojanAuthServer(node_instance_context_t *instance_info); api_result_t apiTrojanAuthServer(tunnel_t *self, const char *msg); tunnel_t *destroyTrojanAuthServer(tunnel_t *self); -tunnel_metadata_t getMetadataTrojanAuthServer(); +tunnel_metadata_t getMetadataTrojanAuthServer(void); diff --git a/tunnels/server/trojan/socks/trojan_socks_server.c b/tunnels/server/trojan/socks/trojan_socks_server.c index f8cd88ca..e93f1a02 100644 --- a/tunnels/server/trojan/socks/trojan_socks_server.c +++ b/tunnels/server/trojan/socks/trojan_socks_server.c @@ -25,6 +25,7 @@ enum trojan_atyp typedef struct trojan_socks_server_state_s { + void*_; } trojan_socks_server_state_t; @@ -596,7 +597,7 @@ tunnel_t *destroyTrojanSocksServer(tunnel_t *self) return NULL; } -tunnel_metadata_t getMetadataTrojanSocksServer() +tunnel_metadata_t getMetadataTrojanSocksServer(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; } diff --git a/tunnels/server/trojan/socks/trojan_socks_server.h b/tunnels/server/trojan/socks/trojan_socks_server.h index 126a77a4..07589967 100644 --- a/tunnels/server/trojan/socks/trojan_socks_server.h +++ b/tunnels/server/trojan/socks/trojan_socks_server.h @@ -12,4 +12,4 @@ tunnel_t *newTrojanSocksServer(node_instance_context_t *instance_info); api_result_t apiTrojanSocksServer(tunnel_t *self, const char *msg); tunnel_t *destroyTrojanSocksServer(tunnel_t *self); -tunnel_metadata_t getMetadataTrojanSocksServer(); \ No newline at end of file +tunnel_metadata_t getMetadataTrojanSocksServer(void); diff --git a/tunnels/server/wolfssl/wolfssl_server.c b/tunnels/server/wolfssl/wolfssl_server.c index 7f0754b3..e8867490 100644 --- a/tunnels/server/wolfssl/wolfssl_server.c +++ b/tunnels/server/wolfssl/wolfssl_server.c @@ -675,7 +675,7 @@ tunnel_t *destroyWolfSSLServer(tunnel_t *self) return NULL; } -tunnel_metadata_t getMetadataWolfSSLServer() +tunnel_metadata_t getMetadataWolfSSLServer(void) { return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; } diff --git a/tunnels/server/wolfssl/wolfssl_server.h b/tunnels/server/wolfssl/wolfssl_server.h index 9b6f969a..59fb9fa2 100644 --- a/tunnels/server/wolfssl/wolfssl_server.h +++ b/tunnels/server/wolfssl/wolfssl_server.h @@ -8,4 +8,4 @@ tunnel_t * newWolfSSLServer(node_instance_context_t *instance_info); api_result_t apiWolfSSLServer(tunnel_t *self,const char *msg); tunnel_t * destroyWolfSSLServer(tunnel_t *self); -tunnel_metadata_t getMetadataWolfSSLServer(); +tunnel_metadata_t getMetadataWolfSSLServer(void); diff --git a/tunnels/shared/openssl/openssl_globals.h b/tunnels/shared/openssl/openssl_globals.h index 9323e8dc..1c565321 100644 --- a/tunnels/shared/openssl/openssl_globals.h +++ b/tunnels/shared/openssl/openssl_globals.h @@ -2,6 +2,7 @@ #include "loggers/network_logger.h" #include "cacert.h" +#include #include #include #include @@ -15,7 +16,7 @@ enum ssl_endpoint static int openssl_lib_initialized = false; -static void opensslGlobalInit() +static void opensslGlobalInit(void) { if (openssl_lib_initialized == 0) { @@ -39,12 +40,12 @@ static void opensslGlobalInit() typedef struct { - const char * crt_file; - const char * key_file; - const char * ca_file; - const char * ca_path; + const char *crt_file; + const char *key_file; + const char *ca_file; + const char *ca_path; short verify_peer; - enum ssl_endpoint endpoint; + enum ssl_endpoint endpoint; } ssl_ctx_opt_t; typedef void *ssl_ctx_t; ///> SSL_CTX @@ -59,7 +60,9 @@ static ssl_ctx_t sslCtxNew(ssl_ctx_opt_t *param) SSL_CTX *ctx = SSL_CTX_new(TLS_method()); #endif if (ctx == NULL) + { return NULL; + } int mode = SSL_VERIFY_NONE; const char *ca_file = NULL; const char *ca_path = NULL; @@ -122,14 +125,16 @@ static ssl_ctx_t sslCtxNew(ssl_ctx_opt_t *param) // SSL_CTX_set_default_verify_paths(ctx); // alternative: use the boundeled cacert.pem BIO *bio = BIO_new(BIO_s_mem()); - int n = BIO_write(bio, cacert_bytes, cacert_len); - assert(n == cacert_len); + int n = BIO_write(bio, cacert_bytes, (int) cacert_len); + assert(n == (int) cacert_len); X509 *x = NULL; while (true) { x = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL); if (x == NULL) + { break; + } X509_STORE_add_cert(SSL_CTX_get_cert_store(ctx), x); X509_free(x); x = NULL; @@ -157,11 +162,11 @@ static void printSSLState(const SSL *ssl) // NOLINT (ssl in unused problem) } // if you get compile error at this function , include the propper logger before this file -static void printSSLError() +static void printSSLError(void) { BIO *bio = BIO_new(BIO_s_mem()); ERR_print_errors(bio); - char * buf = NULL; + char *buf = NULL; size_t len = BIO_get_mem_data(bio, &buf); if (len > 0) { @@ -175,7 +180,7 @@ static _Noreturn void printSSLErrorAndAbort(void) // ERR_print_errors_fp(stderr); BIO *bio = BIO_new(BIO_s_mem()); ERR_print_errors(bio); - char * buf = NULL; + char *buf = NULL; size_t len = BIO_get_mem_data(bio, &buf); if (len > 0) { @@ -183,5 +188,4 @@ static _Noreturn void printSSLErrorAndAbort(void) } abort(); BIO_free(bio); - } diff --git a/tunnels/shared/reality/reality_helpers.h b/tunnels/shared/reality/reality_helpers.h index b693f15e..646eed06 100644 --- a/tunnels/shared/reality/reality_helpers.h +++ b/tunnels/shared/reality/reality_helpers.h @@ -80,13 +80,13 @@ static void signMessage(shift_buffer_t *buf, EVP_MD *msg_digest, EVP_MD_CTX *sig static shift_buffer_t *genericDecrypt(shift_buffer_t *in, EVP_CIPHER_CTX *decryption_context, char *password, buffer_pool_t *pool) { - shift_buffer_t *out = popBuffer(pool); - + shift_buffer_t *out = popBuffer(pool); - EVP_DecryptInit_ex(decryption_context, EVP_aes_128_cbc(), NULL, (const uint8_t *) password, (const uint8_t *) rawBuf(in)); + EVP_DecryptInit_ex(decryption_context, EVP_aes_128_cbc(), NULL, (const uint8_t *) password, + (const uint8_t *) rawBuf(in)); shiftr(in, kIVlen); - uint16_t input_length = bufLen(in); - reserveBufSpace(out, input_length ); + uint16_t input_length = bufLen(in); + reserveBufSpace(out, input_length); int out_len = 0; /* @@ -126,7 +126,7 @@ static shift_buffer_t *genericEncrypt(shift_buffer_t *in, EVP_CIPHER_CTX *encryp EVP_EncryptInit_ex(encryption_context, EVP_aes_128_cbc(), NULL, (const uint8_t *) password, (const uint8_t *) iv); - reserveBufSpace(out, input_length + kEncryptionBlockSize +(input_length % kEncryptionBlockSize)); + reserveBufSpace(out, input_length + kEncryptionBlockSize + (input_length % kEncryptionBlockSize)); int out_len = 0; /* @@ -174,5 +174,6 @@ static void appendTlsHeader(shift_buffer_t *buf) static bool isTlsData(shift_buffer_t *buf) { return bufLen(buf) >= kTLSHeaderlen && ((uint8_t *) rawBuf(buf))[0] == kTLS12ApplicationData && - *((uint16_t *) (rawBuf(buf) + 1)) == kTLSVersion12 && *((uint16_t *) (rawBuf(buf) + 1)) > 0x0; -} \ No newline at end of file + *((uint16_t *) &(((char *) rawBuf(buf))[1])) == kTLSVersion12 + && bufLen(buf) > 0; +} diff --git a/tunnels/shared/trojan/sha2.c b/tunnels/shared/trojan/sha2.c index 9138154c..b506535a 100644 --- a/tunnels/shared/trojan/sha2.c +++ b/tunnels/shared/trojan/sha2.c @@ -1195,4 +1195,4 @@ int main(void) return 0; } -#endif /* TEST_VECTORS */ \ No newline at end of file +#endif /* TEST_VECTORS */ diff --git a/tunnels/shared/trojan/sha2.h b/tunnels/shared/trojan/sha2.h index ddf8d087..bcfc118c 100644 --- a/tunnels/shared/trojan/sha2.h +++ b/tunnels/shared/trojan/sha2.h @@ -97,4 +97,4 @@ extern "C" } #endif -#endif /* !SHA2_H */ \ No newline at end of file +#endif /* !SHA2_H */ diff --git a/tunnels/shared/wolfssl/wolfssl_globals.h b/tunnels/shared/wolfssl/wolfssl_globals.h index 2fa2b2bf..4b1e8587 100644 --- a/tunnels/shared/wolfssl/wolfssl_globals.h +++ b/tunnels/shared/wolfssl/wolfssl_globals.h @@ -2,6 +2,7 @@ #include "loggers/network_logger.h" #include "cacert.h" +#include #include #include #include @@ -16,7 +17,7 @@ enum ssl_endpoint static int wolfssl_lib_initialized = false; -static void wolfSslGlobalInit() +static void wolfSslGlobalInit(void) { if (wolfssl_lib_initialized == 0) { @@ -40,10 +41,10 @@ static void wolfSslGlobalInit() typedef struct { - const char * crt_file; - const char * key_file; - const char * ca_file; - const char * ca_path; + const char *crt_file; + const char *key_file; + const char *ca_file; + const char *ca_path; short verify_peer; enum ssl_endpoint endpoint; } ssl_ctx_opt_t; @@ -59,7 +60,9 @@ static ssl_ctx_t sslCtxNew(ssl_ctx_opt_t *param) SSL_CTX *ctx = SSL_CTX_new(TLS_method()); #endif if (ctx == NULL) + { return NULL; + } int mode = SSL_VERIFY_NONE; const char *ca_file = NULL; const char *ca_path = NULL; @@ -122,14 +125,16 @@ static ssl_ctx_t sslCtxNew(ssl_ctx_opt_t *param) // SSL_CTX_set_default_verify_paths(ctx); // alternative: use the boundeled cacert.pem BIO *bio = BIO_new(BIO_s_mem()); - int n = BIO_write(bio, cacert_bytes, cacert_len); - assert(n == cacert_len); + int n = BIO_write(bio, cacert_bytes, (int)cacert_len); + assert(n == (int)cacert_len); X509 *x = NULL; while (true) { x = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL); if (x == NULL) + { break; + } X509_STORE_add_cert(SSL_CTX_get_cert_store(ctx), x); X509_free(x); x = NULL; @@ -158,15 +163,15 @@ static void printSSLState(const SSL *ssl) // NOLINT (ssl in unused problem) } // if you get compile error at this function , include the propper logger before this file -static void printSSLError() +static void printSSLError(void) { BIO *bio = BIO_new(BIO_s_mem()); ERR_print_errors(bio); - char * buf = NULL; + char *buf = NULL; size_t len = BIO_get_mem_data(bio, &buf); if (len > 0) { LOGE("%.*s", len, buf); } BIO_free(bio); -} \ No newline at end of file +} diff --git a/ww/CMakeLists.txt b/ww/CMakeLists.txt index 3f3740c2..eca53e3f 100644 --- a/ww/CMakeLists.txt +++ b/ww/CMakeLists.txt @@ -43,15 +43,13 @@ if(komihash_ADDED) target_include_directories(ww PUBLIC ${komihash_SOURCE_DIR}) endif() - CPMAddPackage( NAME stc - GIT_REPOSITORY https://github.com/stclib/STC - GIT_TAG 09790f024ad29fca6fe60528461eeb589d4a917b + GIT_REPOSITORY https://github.com/radkesvat/STC + GIT_TAG HEAD DOWNLOAD_ONLY True ) - if(stc_ADDED) target_include_directories(ww PUBLIC ${stc_SOURCE_DIR}/include) # target_sources(ww PRIVATE ${stc_SOURCE_DIR}/src/libstc.c) @@ -117,9 +115,12 @@ endif() # if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # target_compile_options(ww PUBLIC -ftrack-macro-expansion=0) # endif() +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) if(CMAKE_BUILD_TYPE STREQUAL "Debug") target_compile_definitions(ww PRIVATE DEBUG=1) diff --git a/ww/api.h b/ww/api.h index 2e7ac756..b3c8a058 100644 --- a/ww/api.h +++ b/ww/api.h @@ -7,4 +7,4 @@ #include "node.h" #include "tunnel.h" #include "utils/hashutils.h" -#include "ww.h" \ No newline at end of file +#include "ww.h" diff --git a/ww/buffer_pool.c b/ww/buffer_pool.c index 4ca0d1cb..31b0ebd0 100644 --- a/ww/buffer_pool.c +++ b/ww/buffer_pool.c @@ -133,12 +133,12 @@ static buffer_pool_t *allocBufferPool(unsigned long bufcount) return pool; } -buffer_pool_t *createBufferPool() +buffer_pool_t *createBufferPool(void) { return allocBufferPool(BUFFERPOOL_CONTAINER_LEN); } -buffer_pool_t *createSmallBufferPool() +buffer_pool_t *createSmallBufferPool(void) { return allocBufferPool(BUFFERPOOL_SMALL_CONTAINER_LEN); } diff --git a/ww/buffer_pool.h b/ww/buffer_pool.h index b7d8b68a..1c348964 100644 --- a/ww/buffer_pool.h +++ b/ww/buffer_pool.h @@ -37,8 +37,8 @@ struct buffer_pool_s typedef struct buffer_pool_s buffer_pool_t; -buffer_pool_t *createSmallBufferPool(); -buffer_pool_t *createBufferPool(); +buffer_pool_t *createSmallBufferPool(void); +buffer_pool_t *createBufferPool(void); shift_buffer_t *popBuffer(buffer_pool_t *pool); void reuseBuffer(buffer_pool_t *pool, shift_buffer_t *b); shift_buffer_t *appendBufferMerge(buffer_pool_t *pool, shift_buffer_t *restrict b1, shift_buffer_t *restrict b2); diff --git a/ww/buffer_stream.c b/ww/buffer_stream.c index 67877f7e..1e99be24 100644 --- a/ww/buffer_stream.c +++ b/ww/buffer_stream.c @@ -149,7 +149,7 @@ void bufferStreamViewBytesAt(buffer_stream_t *self, size_t at, uint8_t *buf, siz size_t blen = bufLen(b); if (len - buf_i <= blen - bufferstream_i) { - memcpy(buf + buf_i, rawBuf(b) + bufferstream_i, len - buf_i); + memcpy(buf + buf_i, ((char*)rawBuf(b))+bufferstream_i , len - buf_i); return; } while (bufferstream_i < blen) diff --git a/ww/eventloop/base/hbase.c b/ww/eventloop/base/hbase.c index a7d600da..5f992b44 100644 --- a/ww/eventloop/base/hbase.c +++ b/ww/eventloop/base/hbase.c @@ -13,11 +13,11 @@ static hatomic_t s_alloc_cnt = HATOMIC_VAR_INIT(0); static hatomic_t s_free_cnt = HATOMIC_VAR_INIT(0); -long hv_alloc_cnt() { +long hv_alloc_cnt(void) { return s_alloc_cnt; } -long hv_free_cnt() { +long hv_free_cnt(void) { return s_free_cnt; } diff --git a/ww/eventloop/base/hbase.h b/ww/eventloop/base/hbase.h index 1a9041af..7fd2ac7a 100644 --- a/ww/eventloop/base/hbase.h +++ b/ww/eventloop/base/hbase.h @@ -48,8 +48,8 @@ HV_EXPORT void hv_free(void* ptr); #define HV_STACK_ALLOC(ptr, size) STACK_OR_HEAP_ALLOC(ptr, size, HV_DEFAULT_STACKBUF_SIZE) #define HV_STACK_FREE(ptr) STACK_OR_HEAP_FREE(ptr) -HV_EXPORT long hv_alloc_cnt(); -HV_EXPORT long hv_free_cnt(); +HV_EXPORT long hv_alloc_cnt(void); +HV_EXPORT long hv_free_cnt(void); HV_INLINE void hv_memcheck(void) { printf("Memcheck => alloc:%ld free:%ld\n", hv_alloc_cnt(), hv_free_cnt()); } diff --git a/ww/eventloop/base/hchan.c b/ww/eventloop/base/hchan.c index c6dfb542..8c3a30d4 100644 --- a/ww/eventloop/base/hchan.c +++ b/ww/eventloop/base/hchan.c @@ -1,11 +1,9 @@ #include "hchan.h" #include "hmutex.h" -#define align2(n, w) \ - ({ \ - assert(((w) & ((w) - 1)) == 0); /* alignment w is not a power of two */ \ - ((n) + ((w) - 1)) & ~((w) - 1); \ - }) +#define MUSTALIGN2(n, w) assert(((w) & ((w) - 1)) == 0); /* alignment w is not a power of two */ + +#define align2(n, w) (((n) + ((w) - 1)) & ~((w) - 1)) // DEBUG_CHAN_LOG: define to enable debug logging of send and recv // #define DEBUG_CHAN_LOG @@ -60,44 +58,44 @@ static const char* tcolor() { return colors[thread_id() % countof(colors)]; } -// _dlog_chan writes a log message to stderr along with a globally unique "causality" +// _//dlog_chan writes a log message to stderr along with a globally unique "causality" // sequence number. It does not use libc FILEs as those use mutex locks which would alter // the behavior of multi-threaded channel operations. Instead it uses a buffer on the stack, // which of course is local per thread and then calls the write syscall with the one buffer. // This all means that log messages may be out of order; use the "causality" sequence number // to understand what other messages were produced according to the CPU. ATTR_FORMAT(printf, 2, 3) -static void _dlog_chan(const char* fname, const char* fmt, ...) { +static void _ // dlog_chan(const char* fname, const char* fmt, ...) { static atomic_uint32_t seqnext = ATOMIC_VAR_INIT(1); // start at 1 to map to line nubmers - uint32_t seq = atomic_fetch_add_explicitx(&seqnext, 1, memory_order_acquire); +uint32_t seq = atomic_fetch_add_explicitx(&seqnext, 1, memory_order_acquire); - char buf[256]; - const ssize_t bufcap = (ssize_t)sizeof(buf); - ssize_t buflen = 0; +char buf[256]; +const ssize_t bufcap = (ssize_t)sizeof(buf); +ssize_t buflen = 0; - buflen += (ssize_t)snprintf(&buf[buflen], bufcap - buflen, "%04u \x1b[1m%sT%02zu ", seq, tcolor(), thread_id()); +buflen += (ssize_t)snprintf(&buf[buflen], bufcap - buflen, "%04u \x1b[1m%sT%02zu ", seq, tcolor(), thread_id()); - va_list ap; - va_start(ap, fmt); - buflen += (ssize_t)vsnprintf(&buf[buflen], bufcap - buflen, fmt, ap); - va_end(ap); +va_list ap; +va_start(ap, fmt); +buflen += (ssize_t)vsnprintf(&buf[buflen], bufcap - buflen, fmt, ap); +va_end(ap); - if (buflen > 0) { - buflen += (ssize_t)snprintf(&buf[buflen], bufcap - buflen, "\x1b[0m (%s)\n", fname); - if (buflen >= bufcap) { - // truncated; make sure to end the line - buf[buflen - 1] = '\n'; - } +if (buflen > 0) { + buflen += (ssize_t)snprintf(&buf[buflen], bufcap - buflen, "\x1b[0m (%s)\n", fname); + if (buflen >= bufcap) { + // truncated; make sure to end the line + buf[buflen - 1] = '\n'; } +} #undef FMT - write(STDERR_FILENO, buf, buflen); +write(STDERR_FILENO, buf, buflen); } -#define dlog_chan(fmt, ...) _dlog_chan(__FUNCTION__, fmt, ##__VA_ARGS__) -#define dlog_send(fmt, ...) dlog_chan("send: " fmt, ##__VA_ARGS__) -#define dlog_recv(fmt, ...) dlog_chan("recv: " fmt, ##__VA_ARGS__) +#define dlog_chan(fmt, ...) _ // dlog_chan(__FUNCTION__, fmt, ##__VA_ARGS__) +#define dlog_send(fmt, ...) // dlog_chan("send: " fmt, ##__VA_ARGS__) +#define dlog_recv(fmt, ...) // dlog_chan("recv: " fmt, ##__VA_ARGS__) // #define dlog_send(fmt, ...) do{}while(0) // #define dlog_recv(fmt, ...) do{}while(0) #else @@ -219,7 +217,7 @@ static void thr_init(Thr* t) { LSemaInit(&t->sema, 0); // TODO: Semadestroy? } -inline static Thr* thr_current() { +inline static Thr* thr_current(void) { static _Thread_local Thr _thr = {0}; Thr* t = &_thr; @@ -232,7 +230,7 @@ inline static void thr_signal(Thr* t) { } inline static void thr_wait(Thr* t) { - dlog_chan("thr_wait ..."); + // dlog_chan("thr_wait ..."); LSemaWait(&t->sema); // sleep } @@ -269,7 +267,7 @@ static Thr* chan_park(hchan_t* c, WaitQ* wq, void* elemptr) { // caller must hold lock on channel that owns wq Thr* t = thr_current(); atomic_store_explicit(&t->elemptr, elemptr, memory_order_relaxed); - dlog_chan("park: elemptr %p", elemptr); + // dlog_chan("park: elemptr %p", elemptr); wq_enqueue(wq, t); chan_unlock(&c->lock); thr_wait(t); @@ -292,8 +290,8 @@ static bool chan_send_direct(hchan_t* c, void* srcelemptr, Thr* recvt) { void* dstelemptr = atomic_load_explicit(&recvt->elemptr, memory_order_acquire); assert(dstelemptr != NULL); - dlog_send("direct send of srcelemptr %p to [%zu] (dstelemptr %p)", srcelemptr, recvt->id, dstelemptr); - // store to address provided with chan_recv call + // dlog_send("direct send of srcelemptr %p to [%zu] (dstelemptr %p)", srcelemptr, recvt->id, dstelemptr); + // store to address provided with chan_recv call memcpy(dstelemptr, srcelemptr, c->elemsize); atomic_store_explicit(&recvt->elemptr, NULL, memory_order_relaxed); // clear pointer (TODO: is this really needed?) @@ -304,7 +302,7 @@ static bool chan_send_direct(hchan_t* c, void* srcelemptr, Thr* recvt) { inline static bool chan_send(hchan_t* c, void* srcelemptr, bool* closed) { bool block = closed == NULL; - dlog_send("srcelemptr %p", srcelemptr); + // dlog_send("srcelemptr %p", srcelemptr); // fast path for non-blocking send on full channel // @@ -355,7 +353,7 @@ inline static bool chan_send(hchan_t* c, void* srcelemptr, bool* closed) { // copy *srcelemptr -> *dstelemptr void* dstelemptr = chan_bufptr(c, i); memcpy(dstelemptr, srcelemptr, c->elemsize); - dlog_send("enqueue elemptr %p at buf[%u]", srcelemptr, i); + // dlog_send("enqueue elemptr %p at buf[%u]", srcelemptr, i); if (i == c->qcap - 1) atomic_store_explicit(&c->sendx, 0, memory_order_relaxed); atomic_fetch_add_explicit(&c->qlen, 1, memory_order_relaxed); chan_unlock(&c->lock); @@ -370,9 +368,9 @@ inline static bool chan_send(hchan_t* c, void* srcelemptr, bool* closed) { // park the calling thread. Some recv caller will wake us up. // Note that chan_park calls chan_unlock(&c->lock) - dlog_send("wait... (elemptr %p)", srcelemptr); + // dlog_send("wait... (elemptr %p)", srcelemptr); chan_park(c, &c->sendq, srcelemptr); - dlog_send("woke up -- sent elemptr %p", srcelemptr); + // dlog_send("woke up -- sent elemptr %p", srcelemptr); return true; } @@ -388,7 +386,7 @@ static bool chan_recv_direct(hchan_t* c, void* dstelemptr, Thr* st); inline static bool chan_recv(hchan_t* c, void* dstelemptr, bool* closed) { bool block = closed == NULL; // TODO: non-blocking path - dlog_recv("dstelemptr %p", dstelemptr); + // dlog_recv("dstelemptr %p", dstelemptr); // Fast path: check for failed non-blocking operation without acquiring the lock. if (!block && chan_empty(c)) { @@ -423,7 +421,7 @@ inline static bool chan_recv(hchan_t* c, void* dstelemptr, bool* closed) { if (atomic_load_explicit(&c->closed, memory_order_relaxed) && atomic_load_explicit(&c->qlen, memory_order_relaxed) == 0) { // channel is closed and the buffer queue is empty - dlog_recv("channel closed & empty queue"); + // dlog_recv("channel closed & empty queue"); chan_unlock(&c->lock); memset(dstelemptr, 0, c->elemsize); if (closed) *closed = true; @@ -454,7 +452,7 @@ inline static bool chan_recv(hchan_t* c, void* dstelemptr, bool* closed) { memset(srcelemptr, 0, c->elemsize); // zero buffer memory #endif - dlog_recv("dequeue elemptr %p from buf[%u]", srcelemptr, i); + // dlog_recv("dequeue elemptr %p from buf[%u]", srcelemptr, i); chan_unlock(&c->lock); return true; @@ -474,23 +472,23 @@ inline static bool chan_recv(hchan_t* c, void* dstelemptr, bool* closed) { // Block by parking the thread. Some send caller will wake us up. // Note that chan_park calls chan_unlock(&c->lock) - dlog_recv("wait... (elemptr %p)", dstelemptr); + // dlog_recv("wait... (elemptr %p)", dstelemptr); t = chan_park(c, &c->recvq, dstelemptr); // woken up by sender or close call if (atomic_load_explicit(&t->closed, memory_order_relaxed)) { // Note that we check "closed" on the Thr, not the hchan_t. // This is important since c->closed may be true even as we receive a message. - dlog_recv("woke up -- channel closed"); + // dlog_recv("woke up -- channel closed"); goto ret_closed; } // message was delivered by storing to elemptr by some sender - dlog_recv("woke up -- received to elemptr %p", dstelemptr); + // dlog_recv("woke up -- received to elemptr %p", dstelemptr); return true; ret_closed: - dlog_recv("channel closed"); + // dlog_recv("channel closed"); memset(dstelemptr, 0, c->elemsize); return false; } @@ -511,7 +509,7 @@ static bool chan_recv_direct(hchan_t* c, void* dstelemptr, Thr* sendert) { if (atomic_load_explicit(&c->qlen, memory_order_relaxed) == 0) { // Copy data from sender void* srcelemptr = atomic_load_explicit(&sendert->elemptr, memory_order_consume); - dlog_recv("direct recv of srcelemptr %p from [%zu] (dstelemptr %p, buffer empty)", srcelemptr, sendert->id, dstelemptr); + // dlog_recv("direct recv of srcelemptr %p from [%zu] (dstelemptr %p, buffer empty)", srcelemptr, sendert->id, dstelemptr); assert(srcelemptr != NULL); memcpy(dstelemptr, srcelemptr, c->elemsize); } @@ -519,7 +517,7 @@ static bool chan_recv_direct(hchan_t* c, void* dstelemptr, Thr* sendert) { // Queue is full. Take the item at the head of the queue. // Make the sender enqueue its item at the tail of the queue. // Since the queue is full, those are both the same slot. - dlog_recv("direct recv from [%zu] (dstelemptr %p, buffer full)", sendert->id, dstelemptr); + // dlog_recv("direct recv from [%zu] (dstelemptr %p, buffer full)", sendert->id, dstelemptr); // assert_debug(atomic_load_explicit(&c->qlen) == c->qcap); // queue is full // copy element from queue to receiver @@ -536,13 +534,13 @@ static bool chan_recv_direct(hchan_t* c, void* dstelemptr, Thr* sendert) { void* bufelemptr = chan_bufptr(c, i); assert(bufelemptr != NULL); memcpy(dstelemptr, bufelemptr, c->elemsize); - dlog_recv("dequeue srcelemptr %p from buf[%u]", bufelemptr, i); + // dlog_recv("dequeue srcelemptr %p from buf[%u]", bufelemptr, i); // copy *sendert->elemptr -> c->buf[i] void* srcelemptr = atomic_load_explicit(&sendert->elemptr, memory_order_consume); assert(srcelemptr != NULL); memcpy(bufelemptr, srcelemptr, c->elemsize); - dlog_recv("enqueue srcelemptr %p to buf[%u]", srcelemptr, i); + // dlog_recv("enqueue srcelemptr %p to buf[%u]", srcelemptr, i); } chan_unlock(&c->lock); @@ -554,6 +552,7 @@ hchan_t* hchan_Open(size_t elemsize, uint32_t bufcap) { int64_t memsize = (int64_t)sizeof(hchan_t) + ((int64_t)bufcap * (int64_t)elemsize); // ensure we have enough space to offset the allocation by line cache (for alignment) + MUSTALIGN2(memsize + ((LINE_CACHE_SIZE + 1) / 2), LINE_CACHE_SIZE); memsize = align2(memsize + ((LINE_CACHE_SIZE + 1) / 2), LINE_CACHE_SIZE); // check for overflow @@ -566,6 +565,7 @@ hchan_t* hchan_Open(size_t elemsize, uint32_t bufcap) { uintptr_t ptr = (uintptr_t)malloc(memsize); // align c to line cache boundary + MUSTALIGN2(ptr, LINE_CACHE_SIZE); hchan_t* c = (hchan_t*)align2(ptr, LINE_CACHE_SIZE); c->memptr = ptr; @@ -582,10 +582,10 @@ hchan_t* hchan_Open(size_t elemsize, uint32_t bufcap) { } void hchan_Close(hchan_t* c) { - dlog_chan("--- close ---"); + // dlog_chan("--- close ---"); chan_lock(&c->lock); - dlog_chan("close: channel locked"); + // dlog_chan("close: channel locked"); if (atomic_exchange_explicit(&c->closed, 1, memory_order_acquire) != 0) { fprintf(stderr, "close of closed channel"); @@ -595,7 +595,7 @@ void hchan_Close(hchan_t* c) { Thr* t = atomic_load_explicit(&c->recvq.first, memory_order_acquire); while (t) { - dlog_chan("close: wake recv [%zu]", t->id); + // dlog_chan("close: wake recv [%zu]", t->id); Thr* next = t->next; atomic_store_explicit(&t->closed, true, memory_order_relaxed); thr_signal(t); @@ -604,7 +604,7 @@ void hchan_Close(hchan_t* c) { t = atomic_load_explicit(&c->sendq.first, memory_order_acquire); while (t) { - dlog_chan("close: wake send [%zu]", t->id); + // dlog_chan("close: wake send [%zu]", t->id); Thr* next = t->next; atomic_store_explicit(&t->closed, true, memory_order_relaxed); thr_signal(t); @@ -612,7 +612,7 @@ void hchan_Close(hchan_t* c) { } chan_unlock(&c->lock); - dlog_chan("close: done"); + // dlog_chan("close: done"); } void hchan_Free(hchan_t* c) { diff --git a/ww/eventloop/base/hlog.c b/ww/eventloop/base/hlog.c index 003a9109..7350b80a 100644 --- a/ww/eventloop/base/hlog.c +++ b/ww/eventloop/base/hlog.c @@ -59,7 +59,7 @@ static void logger_init(logger_t* logger) { hhybridmutex_init(&logger->mutex_); } -logger_t* logger_create() { +logger_t* logger_create(void) { // init gmtoff here time_t ts = time(NULL); static _Thread_local struct tm local_tm; @@ -438,7 +438,7 @@ int logger_print(logger_t* logger, int level, const char* fmt, ...) { } static logger_t* s_logger = NULL; -logger_t* hv_default_logger() { +logger_t* hv_default_logger(void) { if (s_logger == NULL) { s_logger = logger_create(); atexit(hv_destroy_default_logger); diff --git a/ww/eventloop/base/hlog.h b/ww/eventloop/base/hlog.h index 73402b97..6c089f53 100644 --- a/ww/eventloop/base/hlog.h +++ b/ww/eventloop/base/hlog.h @@ -80,7 +80,7 @@ HV_EXPORT void file_logger(int loglevel, const char* buf, int len); // network_logger implement see event/nlog.h // HV_EXPORT void network_logger(int loglevel, const char* buf, int len); -HV_EXPORT logger_t* logger_create(); +HV_EXPORT logger_t* logger_create(void); HV_EXPORT void logger_destroy(logger_t* logger); HV_EXPORT void logger_set_handler(logger_t* logger, logger_handler fn); @@ -121,7 +121,7 @@ HV_EXPORT void logger_fsync(logger_t* logger); HV_EXPORT const char* logger_get_cur_file(logger_t* logger); // hlog: default logger instance -HV_EXPORT logger_t* hv_default_logger(); +HV_EXPORT logger_t* hv_default_logger(void); HV_EXPORT void hv_destroy_default_logger(void); // macro hlog* @@ -142,11 +142,11 @@ HV_EXPORT void hv_destroy_default_logger(void); #define hlog_get_cur_file() logger_get_cur_file(hlog) #define hlog_will_write(level) logger_will_write_level(hlog,level) -#define hlogd(fmt, ...) logger_print(hlog, LOG_LEVEL_DEBUG, fmt " [%s:%d:%s]", ## __VA_ARGS__, __FILENAME__, __LINE__, __FUNCTION__) -#define hlogi(fmt, ...) logger_print(hlog, LOG_LEVEL_INFO, fmt " [%s:%d:%s]", ## __VA_ARGS__, __FILENAME__, __LINE__, __FUNCTION__) -#define hlogw(fmt, ...) logger_print(hlog, LOG_LEVEL_WARN, fmt " [%s:%d:%s]", ## __VA_ARGS__, __FILENAME__, __LINE__, __FUNCTION__) -#define hloge(fmt, ...) logger_print(hlog, LOG_LEVEL_ERROR, fmt " [%s:%d:%s]", ## __VA_ARGS__, __FILENAME__, __LINE__, __FUNCTION__) -#define hlogf(fmt, ...) logger_print(hlog, LOG_LEVEL_FATAL, fmt " [%s:%d:%s]", ## __VA_ARGS__, __FILENAME__, __LINE__, __FUNCTION__) +#define hlogd(fmt, ...) logger_print(hlog, LOG_LEVEL_DEBUG, fmt , ## __VA_ARGS__) +#define hlogi(fmt, ...) logger_print(hlog, LOG_LEVEL_INFO, fmt , ## __VA_ARGS__) +#define hlogw(fmt, ...) logger_print(hlog, LOG_LEVEL_WARN, fmt , ## __VA_ARGS__) +#define hloge(fmt, ...) logger_print(hlog, LOG_LEVEL_ERROR, fmt , ## __VA_ARGS__) +#define hlogf(fmt, ...) logger_print(hlog, LOG_LEVEL_FATAL, fmt , ## __VA_ARGS__) // below for android #if defined(ANDROID) || defined(__ANDROID__) diff --git a/ww/eventloop/base/hmain.c b/ww/eventloop/base/hmain.c index d0a0faef..b7160b63 100644 --- a/ww/eventloop/base/hmain.c +++ b/ww/eventloop/base/hmain.c @@ -368,7 +368,7 @@ void setproctitle(const char* fmt, ...) { } #endif -int create_pidfile() { +int create_pidfile(void) { FILE* fp = fopen(g_main_ctx.pidfile, "w"); if (fp == NULL) { hloge("fopen('%s') error: %d", g_main_ctx.pidfile, errno); @@ -388,7 +388,7 @@ void delete_pidfile(void) { remove(g_main_ctx.pidfile); } -pid_t getpid_from_pidfile() { +pid_t getpid_from_pidfile(void) { FILE* fp = fopen(g_main_ctx.pidfile, "r"); if (fp == NULL) { // hloge("fopen('%s') error: %d", g_main_ctx.pidfile, errno); diff --git a/ww/eventloop/base/hmain.h b/ww/eventloop/base/hmain.h index 3fe65989..5b4c15c4 100644 --- a/ww/eventloop/base/hmain.h +++ b/ww/eventloop/base/hmain.h @@ -85,9 +85,9 @@ HV_EXPORT void setproctitle(const char* fmt, ...); #endif // pidfile -HV_EXPORT int create_pidfile(); +HV_EXPORT int create_pidfile(void); HV_EXPORT void delete_pidfile(void); -HV_EXPORT pid_t getpid_from_pidfile(); +HV_EXPORT pid_t getpid_from_pidfile(void); // signal=[start,stop,restart,status,reload] HV_EXPORT int signal_init(procedure_t reload_fn DEFAULT(NULL), void* reload_userdata DEFAULT(NULL)); diff --git a/ww/eventloop/base/hsocket.h b/ww/eventloop/base/hsocket.h index 8459a7b0..ddd4d9ae 100644 --- a/ww/eventloop/base/hsocket.h +++ b/ww/eventloop/base/hsocket.h @@ -21,7 +21,7 @@ BEGIN_EXTERN_C -HV_INLINE int socket_errno() { +HV_INLINE int socket_errno(void) { #ifdef OS_WIN return WSAGetLastError(); #else diff --git a/ww/eventloop/base/hsysinfo.h b/ww/eventloop/base/hsysinfo.h index 5366aa5a..c1e3e181 100644 --- a/ww/eventloop/base/hsysinfo.h +++ b/ww/eventloop/base/hsysinfo.h @@ -12,7 +12,7 @@ #include #endif -static inline int get_ncpu() { +static inline int get_ncpu(void) { #ifdef OS_WIN SYSTEM_INFO si; GetSystemInfo(&si); diff --git a/ww/eventloop/base/htime.c b/ww/eventloop/base/htime.c index 16d79108..d5371f28 100644 --- a/ww/eventloop/base/htime.c +++ b/ww/eventloop/base/htime.c @@ -10,7 +10,7 @@ static const uint8_t s_days[] = \ // 1 3 5 7 8 10 12 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; -unsigned int gettick_ms() { +unsigned int gettick_ms(void) { #ifdef OS_WIN return GetTickCount(); #elif HAVE_CLOCK_GETTIME @@ -24,7 +24,7 @@ unsigned int gettick_ms() { #endif } -unsigned long long gethrtime_us() { +unsigned long long gethrtime_us(void) { #ifdef OS_WIN static LONGLONG s_freq = 0; if (s_freq == 0) { @@ -51,7 +51,7 @@ unsigned long long gethrtime_us() { #endif } -datetime_t datetime_now() { +datetime_t datetime_now(void) { #ifdef OS_WIN SYSTEMTIME tm; GetLocalTime(&tm); @@ -211,7 +211,7 @@ const char* weekday_itoa(int weekday) { return s_weekdays[weekday]; } -datetime_t hv_compile_datetime() { +datetime_t hv_compile_datetime(void) { datetime_t dt; char month[32]; sscanf(__DATE__, "%s %d %d", month, &dt.day, &dt.year); diff --git a/ww/eventloop/base/htime.h b/ww/eventloop/base/htime.h index 4d6dd016..d228b1e9 100644 --- a/ww/eventloop/base/htime.h +++ b/ww/eventloop/base/htime.h @@ -53,20 +53,20 @@ HV_INLINE int gettimeofday(struct timeval *tv, struct timezone *tz) { } #endif -HV_EXPORT unsigned int gettick_ms(); -HV_INLINE unsigned long long gettimeofday_ms() { +HV_EXPORT unsigned int gettick_ms(void); +HV_INLINE unsigned long long gettimeofday_ms(void) { struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec * (unsigned long long)1000 + tv.tv_usec/1000; } -HV_INLINE unsigned long long gettimeofday_us() { +HV_INLINE unsigned long long gettimeofday_us(void) { struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec * (unsigned long long)1000000 + tv.tv_usec; } -HV_EXPORT unsigned long long gethrtime_us(); +HV_EXPORT unsigned long long gethrtime_us(void); -HV_EXPORT datetime_t datetime_now(); +HV_EXPORT datetime_t datetime_now(void); HV_EXPORT datetime_t datetime_localtime(time_t seconds); HV_EXPORT time_t datetime_mktime(datetime_t* dt); @@ -95,7 +95,7 @@ HV_EXPORT const char* month_itoa(int month); HV_EXPORT int weekday_atoi(const char* weekday); HV_EXPORT const char* weekday_itoa(int weekday); -HV_EXPORT datetime_t hv_compile_datetime(); +HV_EXPORT datetime_t hv_compile_datetime(void); /* * minute hour day week month action diff --git a/ww/eventloop/base/hversion.c b/ww/eventloop/base/hversion.c index 31a97d97..49bfcb8f 100644 --- a/ww/eventloop/base/hversion.c +++ b/ww/eventloop/base/hversion.c @@ -2,7 +2,7 @@ #include "htime.h" -const char* hv_compile_version() { +const char* hv_compile_version(void) { static char s_version[16] = {0}; datetime_t dt = hv_compile_datetime(); snprintf(s_version, sizeof(s_version), "%d.%d.%d.%d", diff --git a/ww/eventloop/base/hversion.h b/ww/eventloop/base/hversion.h index d88dd42b..0bbb0b8b 100644 --- a/ww/eventloop/base/hversion.h +++ b/ww/eventloop/base/hversion.h @@ -17,11 +17,11 @@ BEGIN_EXTERN_C #define HV_VERSION_NUMBER ((HV_VERSION_MAJOR << 16) | (HV_VERSION_MINOR << 8) | HV_VERSION_PATCH) -HV_INLINE const char* hv_version() { +HV_INLINE const char* hv_version(void) { return HV_VERSION_STRING; } -HV_EXPORT const char* hv_compile_version(); +HV_EXPORT const char* hv_compile_version(void); // 1.2.3.4 => 0x01020304 HV_EXPORT int version_atoi(const char* str); diff --git a/ww/eventloop/event/epoll.c b/ww/eventloop/event/epoll.c index 5fc6871e..3456de73 100644 --- a/ww/eventloop/event/epoll.c +++ b/ww/eventloop/event/epoll.c @@ -16,7 +16,7 @@ typedef int epoll_handle_t; #include "array.h" #define EVENTS_INIT_SIZE 64 -ARRAY_DECL(struct epoll_event, events); +ARRAY_DECL(struct epoll_event, events) typedef struct epoll_ctx_s { epoll_handle_t epfd; diff --git a/ww/eventloop/event/hevent.c b/ww/eventloop/event/hevent.c index b277065e..36f70983 100644 --- a/ww/eventloop/event/hevent.c +++ b/ww/eventloop/event/hevent.c @@ -4,12 +4,12 @@ #include "hlog.h" #include "herr.h" // todo (invesitage) how a dynamic node can have these? -uint64_t hloop_next_event_id() { +uint64_t hloop_next_event_id(void) { static hatomic_t s_id = HATOMIC_VAR_INIT(0); return ++s_id; } -uint32_t hio_next_id() { +uint32_t hio_next_id(void) { static hatomic_t s_id = HATOMIC_VAR_INIT(0); return ++s_id; } diff --git a/ww/eventloop/event/hevent.h b/ww/eventloop/event/hevent.h index 1c9cc34a..991ba980 100644 --- a/ww/eventloop/event/hevent.h +++ b/ww/eventloop/event/hevent.h @@ -24,8 +24,8 @@ #define HIO_READ_UNTIL_LENGTH 0x2 #define HIO_READ_UNTIL_DELIM 0x4 -ARRAY_DECL(hio_t*, io_array); -QUEUE_DECL(hevent_t, event_queue); +ARRAY_DECL(hio_t*, io_array) +QUEUE_DECL(hevent_t, event_queue) struct hloop_s { uint32_t flags; @@ -64,7 +64,7 @@ struct hloop_s { hhybridmutex_t custom_events_mutex; }; -uint64_t hloop_next_event_id(); +uint64_t hloop_next_event_id(void); struct hidle_s { HEVENT_FIELDS @@ -97,7 +97,8 @@ struct hperiod_s { int8_t month; }; -QUEUE_DECL(shift_buffer_t*, write_queue); +QUEUE_DECL(shift_buffer_t*, write_queue) + // sizeof(struct hio_s)=416 on linux-x64 struct hio_s { HEVENT_FIELDS @@ -182,7 +183,7 @@ void hio_init(hio_t* io); void hio_ready(hio_t* io); void hio_done(hio_t* io); void hio_free(hio_t* io); -uint32_t hio_next_id(); +uint32_t hio_next_id(void); void hio_accept_cb(hio_t* io); void hio_connect_cb(hio_t* io); diff --git a/ww/eventloop/event/hloop.c b/ww/eventloop/event/hloop.c index 34aeefa7..0e1bdca4 100644 --- a/ww/eventloop/event/hloop.c +++ b/ww/eventloop/event/hloop.c @@ -694,7 +694,7 @@ void htimer_del(htimer_t* timer) { EVENT_DEL(timer); } -const char* hio_engine() { +const char* hio_engine(void) { #ifdef EVENT_SELECT return "select"; #elif defined(EVENT_POLL) diff --git a/ww/eventloop/event/hloop.h b/ww/eventloop/event/hloop.h index 9cb022a3..35a19c2c 100644 --- a/ww/eventloop/event/hloop.h +++ b/ww/eventloop/event/hloop.h @@ -228,7 +228,7 @@ const char* hio_engine() { #endif } */ -HV_EXPORT const char* hio_engine(); +HV_EXPORT const char* hio_engine(void); HV_EXPORT hio_t* hio_get(hloop_t* loop, int fd); HV_EXPORT int hio_add(hio_t* io, hio_cb cb, int events DEFAULT(HV_READ)); diff --git a/ww/frand.c b/ww/frand.c index b0f22dea..553df992 100644 --- a/ww/frand.c +++ b/ww/frand.c @@ -1,3 +1,3 @@ #include "frand.h" -extern uint32_t fastRand(void); \ No newline at end of file +extern uint32_t fastRand(void); diff --git a/ww/http_def.c b/ww/http_def.c index c7af0d28..a4ddfda7 100644 --- a/ww/http_def.c +++ b/ww/http_def.c @@ -106,4 +106,4 @@ enum http_content_type httpContentTypeEnumBySuffix(const char* str) { #undef XX return kContentTypeUndefined; } -//NOLINTEND \ No newline at end of file +//NOLINTEND diff --git a/ww/idle_table.c b/ww/idle_table.c index 0ea87a1c..26ddb581 100644 --- a/ww/idle_table.c +++ b/ww/idle_table.c @@ -141,7 +141,7 @@ bool removeIdleItemByHash(idle_table_t *self, hash_t key) } idle_item_t *item = (find_result.ref->second); hmap_idles_t_erase_at(&(self->hmap), find_result); - *item = (idle_item_t){}; + *item = (idle_item_t){0}; heapq_idles_t_make_heap(&self->hqueue); hhybridmutex_unlock(&(self->mutex)); @@ -194,4 +194,4 @@ void idleCallBack(htimer_t *timer) } } hhybridmutex_unlock(&(self->mutex)); -} \ No newline at end of file +} diff --git a/ww/idle_table.h b/ww/idle_table.h index aa964d34..c335b9a9 100644 --- a/ww/idle_table.h +++ b/ww/idle_table.h @@ -14,7 +14,7 @@ you also can keep updating the item timeout The time checking has no cost and won't syscall at all, and the checking is synced by the - eventloop which by default wakes up every 100 ms. + eventloop which by default wakes up every 100 ms. (debug note: current interval is set to 60s) idle item is a threadlocal item, it belongs to the thread that created it and other threads must not change , remove or do anything to it diff --git a/ww/library_loader.h b/ww/library_loader.h index 188c8653..acef4e2c 100644 --- a/ww/library_loader.h +++ b/ww/library_loader.h @@ -17,7 +17,7 @@ typedef struct tunnel_lib_s struct tunnel_s *(*createHandle)(node_instance_context_t *instance_info); struct tunnel_s *(*destroyHandle)(struct tunnel_s *instance); api_result_t (*apiHandle)(struct tunnel_s *instance, const char *msg); - tunnel_metadata_t (*getMetadataHandle)(); + tunnel_metadata_t (*getMetadataHandle)(void); hash_t hash_name; } tunnel_lib_t; diff --git a/ww/loggers/core_logger.c b/ww/loggers/core_logger.c index 3d73a40e..1a9278f9 100644 --- a/ww/loggers/core_logger.c +++ b/ww/loggers/core_logger.c @@ -41,7 +41,7 @@ static void coreLoggerHandle(int loglevel, const char *buf, int len) logfile_write(logger, buf, len); } -logger_t *getCoreLogger() +logger_t *getCoreLogger(void) { return logger; } @@ -69,7 +69,7 @@ logger_t *createCoreLogger(const char *log_file, bool console) return logger; } -core_logger_handle_t getCoreLoggerHandle() +core_logger_handle_t getCoreLoggerHandle(void) { return logger_handle(logger); -} \ No newline at end of file +} diff --git a/ww/loggers/core_logger.h b/ww/loggers/core_logger.h index 8770ae8c..f1fee0ee 100644 --- a/ww/loggers/core_logger.h +++ b/ww/loggers/core_logger.h @@ -34,7 +34,7 @@ #endif -logger_t *getCoreLogger(); +logger_t *getCoreLogger(void); void setCoreLogger(logger_t *newlogger); logger_t *createCoreLogger(const char *log_file, bool console); @@ -44,4 +44,4 @@ static inline void setCoreLoggerLevelByStr(const char *log_level) } typedef void (*core_logger_handle_t)(int, const char *, int); -core_logger_handle_t getCoreLoggerHandle(); \ No newline at end of file +core_logger_handle_t getCoreLoggerHandle(void); diff --git a/ww/loggers/dns_logger.c b/ww/loggers/dns_logger.c index 94463775..5440c1f8 100644 --- a/ww/loggers/dns_logger.c +++ b/ww/loggers/dns_logger.c @@ -42,7 +42,7 @@ static void dnsLoggerHandle(int loglevel, const char *buf, int len) logfile_write(logger, buf, len); } -logger_t *getDnsLogger() +logger_t *getDnsLogger(void) { return logger; } diff --git a/ww/loggers/dns_logger.h b/ww/loggers/dns_logger.h index d228602f..4bc8e382 100644 --- a/ww/loggers/dns_logger.h +++ b/ww/loggers/dns_logger.h @@ -34,7 +34,7 @@ #endif -logger_t *getDnsLogger(); +logger_t *getDnsLogger(void); void setDnsLogger(logger_t *newlogger); logger_t *createDnsLogger(const char *log_file, bool console); diff --git a/ww/loggers/network_logger.c b/ww/loggers/network_logger.c index bee1ef3a..a31ab6fb 100644 --- a/ww/loggers/network_logger.c +++ b/ww/loggers/network_logger.c @@ -42,7 +42,7 @@ static void networkLoggerHandle(int loglevel, const char *buf, int len) logfile_write(logger, buf, len); } -logger_t *getNetworkLogger() +logger_t *getNetworkLogger(void) { return logger; } diff --git a/ww/loggers/network_logger.h b/ww/loggers/network_logger.h index c1ffb4fa..ea5c5e45 100644 --- a/ww/loggers/network_logger.h +++ b/ww/loggers/network_logger.h @@ -34,7 +34,7 @@ #endif -logger_t *getNetworkLogger(); +logger_t *getNetworkLogger(void); void setNetworkLogger(logger_t *newlogger); logger_t *createNetworkLogger(const char *log_file, bool console); diff --git a/ww/managers/node_manager.c b/ww/managers/node_manager.c index 3ee97530..e1acbdd1 100644 --- a/ww/managers/node_manager.c +++ b/ww/managers/node_manager.c @@ -71,7 +71,7 @@ void runNode(node_t *n1, size_t chain_index) } } -static void runNodes() +static void runNodes(void) { begin:; c_foreach(p1, map_node_t, state->node_map) @@ -85,7 +85,7 @@ begin:; } } -static void pathWalk() +static void pathWalk(void) { c_foreach(p1, map_node_t, state->node_map) @@ -111,7 +111,7 @@ static void pathWalk() } } -static void cycleProcess() +static void cycleProcess(void) { c_foreach(n1, map_node_t, state->node_map) { @@ -221,14 +221,14 @@ node_t *getNode(hash_t hash_node_name) return (iter.ref->second); } -node_t *newNode() +node_t *newNode(void) { node_t *new_node = malloc(sizeof(node_t)); memset(new_node, 0, sizeof(node_t)); return new_node; } -static void startParsingFiles() +static void startParsingFiles(void) { cJSON *nodes_json = state->config_file->nodes; cJSON *node_json = NULL; @@ -267,7 +267,7 @@ static tunnel_t *getTunnel(hash_t hash_node_name) return (iter.ref->second)->instance; } -struct node_manager_s *getNodeManager() +struct node_manager_s *getNodeManager(void) { return state; } @@ -283,7 +283,7 @@ void runConfigFile(config_file_t *config_file) startParsingFiles(); } -node_manager_t *createNodeManager() +node_manager_t *createNodeManager(void) { assert(state == NULL); diff --git a/ww/managers/node_manager.h b/ww/managers/node_manager.h index 32f0746e..979a24c7 100644 --- a/ww/managers/node_manager.h +++ b/ww/managers/node_manager.h @@ -26,9 +26,9 @@ struct node_manager_s; void runNode(node_t *n1, size_t chain_index); node_t *getNode(hash_t hash_node_name); -node_t *newNode(); +node_t *newNode(void); void registerNode(node_t *new_node, cJSON *node_settings); void runConfigFile(config_file_t *config_file); -struct node_manager_s *getNodeManager(); +struct node_manager_s *getNodeManager(void); void setNodeManager(struct node_manager_s *state); -struct node_manager_s *createNodeManager(); \ No newline at end of file +struct node_manager_s *createNodeManager(void); diff --git a/ww/managers/socket_manager.c b/ww/managers/socket_manager.c index bfcac951..633cd05f 100644 --- a/ww/managers/socket_manager.c +++ b/ww/managers/socket_manager.c @@ -94,7 +94,7 @@ static bool redirectPortUdp(unsigned int port, unsigned int to) return execCmd(b).exit_code == 0; } -static bool resetIptables() +static bool resetIptables(void) { LOGD("SocketManager: clearing iptables nat rules"); #if SUPOPRT_V6 @@ -104,7 +104,7 @@ static bool resetIptables() return execCmd("iptables -t nat -F").exit_code == 0 && execCmd("iptables -t nat -X").exit_code == 0; } -static void exitHook() +static void exitHook(void) { if (state->iptables_used) { @@ -257,11 +257,11 @@ void registerSocketAcceptor(tunnel_t *tunnel, socket_filter_option_t option, onA hhybridmutex_unlock(&(state->mutex)); } -static inline uint16_t getCurrentDistrbuteTid() +static inline uint16_t getCurrentDistrbuteTid(void) { return state->last_round_tid; } -static inline void incrementDistrbuteTid() +static inline void incrementDistrbuteTid(void) { state->last_round_tid++; if (state->last_round_tid >= workers_count) @@ -391,7 +391,7 @@ static void onAcceptTcpMultiPort(hio_t *io) distributeTcpSocket(io, (pbuf[2] << 8) | pbuf[3]); } -static multiport_backend_t getDefaultMultiPortBackend() +static multiport_backend_t getDefaultMultiPortBackend(void) { if (state->iptables_installed) { @@ -733,7 +733,7 @@ static HTHREAD_ROUTINE(accept_thread) // NOLINT return 0; } -struct socket_manager_s *getSocketManager() +struct socket_manager_s *getSocketManager(void) { return state; } @@ -744,14 +744,14 @@ void setSocketManager(struct socket_manager_s *new_state) state = new_state; } -void startSocketManager() +void startSocketManager(void) { assert(state != NULL); // accept_thread(accept_thread_loop); state->accept_thread = hthread_create(accept_thread,NULL); } -socket_manager_state_t *createSocketManager() +socket_manager_state_t *createSocketManager(void) { assert(state == NULL); state = malloc(sizeof(socket_manager_state_t)); diff --git a/ww/managers/socket_manager.h b/ww/managers/socket_manager.h index f5db0908..e45b30a7 100644 --- a/ww/managers/socket_manager.h +++ b/ww/managers/socket_manager.h @@ -63,9 +63,9 @@ typedef struct udp_payload_s } udp_payload_t; -struct socket_manager_s *getSocketManager(); -struct socket_manager_s *createSocketManager(); +struct socket_manager_s *getSocketManager(void); +struct socket_manager_s *createSocketManager(void); void setSocketManager(struct socket_manager_s *state); -void startSocketManager(); +void startSocketManager(void); void registerSocketAcceptor(tunnel_t *tunnel, socket_filter_option_t option, onAccept cb); void postUdpWrite(hio_t *socket_io, shift_buffer_t *buf); diff --git a/ww/shiftbuffer.c b/ww/shiftbuffer.c index b129550c..f49b68b3 100644 --- a/ww/shiftbuffer.c +++ b/ww/shiftbuffer.c @@ -175,7 +175,7 @@ void sliceBufferTo(shift_buffer_t *dest, shift_buffer_t *source, unsigned int by *dest = tmp; setLen(source, total - bytes); - memcpy(rawBufMut(source), rawBuf(dest) + bytes, total - bytes); + memcpy(rawBufMut(source), &(((char*)rawBuf(dest))[bytes]), total - bytes); setLen(dest, bytes); } @@ -205,7 +205,7 @@ shift_buffer_t *sliceBuffer(shift_buffer_t *self, unsigned int bytes) .refc = tmp_refc, .pbuf = tmp_pbuf}; - memcpy(rawBufMut(self), rawBuf(newbuf) + bytes, bufLen(newbuf) - bytes); + memcpy(rawBufMut(self), &(((char*)rawBuf(newbuf))[bytes]), bufLen(newbuf) - bytes); shiftr(self, bytes); setLen(newbuf, bytes); return newbuf; @@ -217,4 +217,4 @@ shift_buffer_t *shallowSliceBuffer(shift_buffer_t *self, unsigned int bytes) setLen(shallow, bytes); shiftr(self, bytes); return shallow; -} \ No newline at end of file +} diff --git a/ww/shiftbuffer.h b/ww/shiftbuffer.h index 1a2670fc..0e6b20a8 100644 --- a/ww/shiftbuffer.h +++ b/ww/shiftbuffer.h @@ -38,6 +38,7 @@ struct shift_buffer_s unsigned int cap; // half of full cap unsigned int full_cap; }; + typedef struct shift_buffer_s shift_buffer_t; shift_buffer_t *newShiftBuffer(unsigned int pre_cap); diff --git a/ww/sync_dns.c b/ww/sync_dns.c index 7522f1f6..b2b0e28d 100644 --- a/ww/sync_dns.c +++ b/ww/sync_dns.c @@ -39,4 +39,4 @@ bool resolveContextSync(socket_context_t *sctx) sctx->domain_resolved = true; return true; -} \ No newline at end of file +} diff --git a/ww/tunnel.c b/ww/tunnel.c index 770a5dab..c751b93f 100644 --- a/ww/tunnel.c +++ b/ww/tunnel.c @@ -57,7 +57,7 @@ void chain(tunnel_t *from, tunnel_t *to) to->chain_index = from->chain_index + 1; } -tunnel_t *newTunnel() +tunnel_t *newTunnel(void) { tunnel_t *t = malloc(sizeof(tunnel_t)); *t = (tunnel_t){ diff --git a/ww/tunnel.h b/ww/tunnel.h index cb586015..9f844f8f 100644 --- a/ww/tunnel.h +++ b/ww/tunnel.h @@ -93,7 +93,7 @@ struct tunnel_s typedef struct tunnel_s tunnel_t; -tunnel_t *newTunnel(); +tunnel_t *newTunnel(void); void destroyTunnel(tunnel_t *self); void chain(tunnel_t *from, tunnel_t *to); void chainDown(tunnel_t *from, tunnel_t *to); @@ -307,4 +307,4 @@ inline void reuseContextBuffer(context_t *c) assert(c->payload != NULL); reuseBuffer(getContextBufferPool(c), c->payload); c->payload = NULL; -} \ No newline at end of file +} diff --git a/ww/utils/hashutils.h b/ww/utils/hashutils.h index 9458fb25..d9e430f5 100644 --- a/ww/utils/hashutils.h +++ b/ww/utils/hashutils.h @@ -12,6 +12,9 @@ // todo (benchmark) komihash vs Flower–Noll–Vo // todo (siphash) add sip hash + + +//Flower–Noll–Vo static inline uint64_t hashFnv1a64(const uint8_t *buf, size_t len) { const uint64_t prime = 0x100000001B3; // pow(2,40) + pow(2,8) + 0xb3 @@ -27,7 +30,19 @@ static inline uint64_t hashFnv1a64(const uint8_t *buf, size_t len) // #define CALC_HASH_PRIMITIVE(x) hashFnv1a64((const uint8_t *) &(x), sizeof((x))) // #define CALC_HASH_BYTES(x, len) hashFnv1a64((const uint8_t *) (x), (len)) + + + + + +// Komi-Hash + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" #include "komihash.h" +#pragma GCC diagnostic pop + + // zero as seed provides more performance #define KOMIHASH_SEED 0 #define CALC_HASH_PRIMITIVE(x) komihash((const uint8_t *) &(x), sizeof((x)), KOMIHASH_SEED) diff --git a/ww/utils/userutils.h b/ww/utils/userutils.h index 33048500..57367707 100644 --- a/ww/utils/userutils.h +++ b/ww/utils/userutils.h @@ -3,4 +3,4 @@ #include "cJSON.h" struct user_s; -struct user_s *parseUserFromJsonObject(const cJSON *user_json); \ No newline at end of file +struct user_s *parseUserFromJsonObject(const cJSON *user_json); diff --git a/ww/ww.c b/ww/ww.c index 239d1360..18378c13 100644 --- a/ww/ww.c +++ b/ww/ww.c @@ -64,7 +64,7 @@ void setWW(struct ww_runtime_state_s *state) free(state); } -struct ww_runtime_state_s *getWW() +struct ww_runtime_state_s *getWW(void) { struct ww_runtime_state_s *state = malloc(sizeof(struct ww_runtime_state_s)); memset(state, 0, sizeof(struct ww_runtime_state_s)); @@ -88,7 +88,7 @@ void idleFreeMem(htimer_t *timer) malloc_trim(0); } -_Noreturn void runMainThread() +_Noreturn void runMainThread(void) { // htimer_add_period(loops[0], idleFreeMem, 1, 0, 0, 0, 0, INFINITE); hloop_run(loops[0]); diff --git a/ww/ww.h b/ww/ww.h index 6896cbc0..c73570f9 100644 --- a/ww/ww.h +++ b/ww/ww.h @@ -33,7 +33,7 @@ struct ww_runtime_state_s; WWEXPORT void setWW(struct ww_runtime_state_s *state); -struct ww_runtime_state_s *getWW(); +struct ww_runtime_state_s *getWW(void); typedef struct { @@ -63,7 +63,7 @@ typedef struct void createWW(ww_construction_data_t data); -_Noreturn void runMainThread(); +_Noreturn void runMainThread(void); extern unsigned int workers_count; extern hthread_t *workers;