Skip to content

Commit

Permalink
fix some mistakes in warnings / change ww compile settings related to…
Browse files Browse the repository at this point in the history
… warnings
  • Loading branch information
radkesvat committed May 15, 2024
1 parent 7fa5708 commit 320e650
Show file tree
Hide file tree
Showing 37 changed files with 182 additions and 207 deletions.
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,6 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(Waterwall PRIVATE DEBUG=1)
endif()

add_compile_options(
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic -Werror>
)


if(ENABLE_ASAN AND CMAKE_BUILD_TYPE STREQUAL "Debug")
Expand Down
18 changes: 8 additions & 10 deletions tunnels/adapters/connector/tcp/tcp_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -179,7 +179,6 @@ static void upStream(tunnel_t *self, context_t *c)
hio_setcb_write(cstate->io, onWriteComplete);
}
destroyContext(c);

}
}
else
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 1 addition & 14 deletions tunnels/adapters/connector/udp/udp_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
{
Expand All @@ -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))
{
Expand All @@ -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);
}
Expand Down
19 changes: 9 additions & 10 deletions tunnels/adapters/listener/tcp/tcp_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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 "
Expand Down
2 changes: 0 additions & 2 deletions tunnels/adapters/listener/udp/udp_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 "
Expand Down
22 changes: 12 additions & 10 deletions tunnels/client/http2/http2_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand All @@ -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 == ':')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 18 additions & 18 deletions tunnels/client/http2/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
1 change: 0 additions & 1 deletion tunnels/client/preconnect/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions tunnels/client/preconnect/preconnect_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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++)
Expand All @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions tunnels/client/preconnect/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct connect_arg
{
uint8_t tid;
unsigned int delay;
tunnel_t * t;
tunnel_t *t;
};
typedef enum
{
Expand All @@ -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;
Expand All @@ -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;
Loading

0 comments on commit 320e650

Please sign in to comment.