Skip to content

Commit

Permalink
Restructure code, reformat, update global naming conventions, and imp…
Browse files Browse the repository at this point in the history
…rove styling
  • Loading branch information
radkesvat committed Jul 19, 2024
1 parent d806fcf commit 0149f67
Show file tree
Hide file tree
Showing 66 changed files with 517 additions and 582 deletions.
34 changes: 17 additions & 17 deletions core/core_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void initCoreSettings(void)
{
assert(settings == NULL);

settings = wwmGlobalMalloc(sizeof(struct core_settings_s));
settings = globalMalloc(sizeof(struct core_settings_s));
memset(settings, 0, sizeof(struct core_settings_s));

settings->config_paths = vec_config_path_t_with_capacity(2);
Expand All @@ -58,8 +58,8 @@ static void parseLogPartOfJsonNoCheck(const cJSON *log_obj)
}
else
{
settings->core_log_level = wwmGlobalMalloc(strlen(DEFAULT_CORE_LOG_LEVEL) + 1);
settings->core_log_file = wwmGlobalMalloc(strlen(DEFAULT_CORE_LOG_FILE) + 1);
settings->core_log_level = globalMalloc(strlen(DEFAULT_CORE_LOG_LEVEL) + 1);
settings->core_log_file = globalMalloc(strlen(DEFAULT_CORE_LOG_FILE) + 1);

#if defined(OS_UNIX)
strcpy(settings->core_log_level, DEFAULT_CORE_LOG_LEVEL);
Expand Down Expand Up @@ -87,8 +87,8 @@ static void parseLogPartOfJsonNoCheck(const cJSON *log_obj)
}
else
{
settings->network_log_level = wwmGlobalMalloc(strlen(DEFAULT_NETWORK_LOG_LEVEL) + 1);
settings->network_log_file = wwmGlobalMalloc(strlen(DEFAULT_NETWORK_LOG_FILE) + 1);
settings->network_log_level = globalMalloc(strlen(DEFAULT_NETWORK_LOG_LEVEL) + 1);
settings->network_log_file = globalMalloc(strlen(DEFAULT_NETWORK_LOG_FILE) + 1);
#if defined(OS_UNIX)
strcpy(settings->network_log_level, DEFAULT_NETWORK_LOG_LEVEL);
strcpy(settings->network_log_file, DEFAULT_NETWORK_LOG_FILE);
Expand All @@ -112,8 +112,8 @@ static void parseLogPartOfJsonNoCheck(const cJSON *log_obj)
}
else
{
settings->dns_log_level = wwmGlobalMalloc(strlen(DEFAULT_DNS_LOG_LEVEL) + 1);
settings->dns_log_file = wwmGlobalMalloc(strlen(DEFAULT_DNS_LOG_FILE) + 1);
settings->dns_log_level = globalMalloc(strlen(DEFAULT_DNS_LOG_LEVEL) + 1);
settings->dns_log_file = globalMalloc(strlen(DEFAULT_DNS_LOG_FILE) + 1);

#if defined(OS_UNIX)
strcpy(settings->dns_log_level, DEFAULT_DNS_LOG_LEVEL);
Expand All @@ -136,13 +136,13 @@ static void parseLogPartOfJson(cJSON *log_obj)
else
{

settings->log_path = wwmGlobalMalloc(strlen(DEFAULT_LOG_PATH) + 1);
settings->core_log_file = wwmGlobalMalloc(strlen(DEFAULT_CORE_LOG_FILE) + 1);
settings->core_log_level = wwmGlobalMalloc(strlen(DEFAULT_CORE_LOG_LEVEL) + 1);
settings->network_log_file = wwmGlobalMalloc(strlen(DEFAULT_NETWORK_LOG_FILE) + 1);
settings->network_log_level = wwmGlobalMalloc(strlen(DEFAULT_NETWORK_LOG_LEVEL) + 1);
settings->dns_log_file = wwmGlobalMalloc(strlen(DEFAULT_DNS_LOG_FILE) + 1);
settings->dns_log_level = wwmGlobalMalloc(strlen(DEFAULT_DNS_LOG_LEVEL) + 1);
settings->log_path = globalMalloc(strlen(DEFAULT_LOG_PATH) + 1);
settings->core_log_file = globalMalloc(strlen(DEFAULT_CORE_LOG_FILE) + 1);
settings->core_log_level = globalMalloc(strlen(DEFAULT_CORE_LOG_LEVEL) + 1);
settings->network_log_file = globalMalloc(strlen(DEFAULT_NETWORK_LOG_FILE) + 1);
settings->network_log_level = globalMalloc(strlen(DEFAULT_NETWORK_LOG_LEVEL) + 1);
settings->dns_log_file = globalMalloc(strlen(DEFAULT_DNS_LOG_FILE) + 1);
settings->dns_log_level = globalMalloc(strlen(DEFAULT_DNS_LOG_LEVEL) + 1);

#if defined(OS_UNIX)
strcpy(settings->log_path, DEFAULT_LOG_PATH);
Expand Down Expand Up @@ -188,7 +188,7 @@ static void parseConfigPartOfJson(const cJSON *config_array)
{
had_child = true;
unsigned long size = strlen(path->valuestring) + 1;
char *buf = wwmGlobalMalloc(size);
char *buf = globalMalloc(size);
#if defined(OS_UNIX)
strcpy(buf, path->valuestring);
#else
Expand Down Expand Up @@ -283,7 +283,7 @@ static void parseMiscPartOfJson(cJSON *misc_obj)

exit(1);
}
wwmGlobalFree(string_ram_profile);
globalFree(string_ram_profile);
}
else
{
Expand All @@ -293,7 +293,7 @@ static void parseMiscPartOfJson(cJSON *misc_obj)
else
{
unsigned long size = strlen(DEFAULT_LIBS_PATH) + 1;
settings->libs_path = wwmGlobalMalloc(size);
settings->libs_path = globalMalloc(size);
#if defined(OS_UNIX)
strcpy(settings->libs_path, DEFAULT_LIBS_PATH);
#else
Expand Down
2 changes: 1 addition & 1 deletion core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int main(void)
exit(1);
}
parseCoreSettings(core_file_content);
wwmGlobalFree(core_file_content);
globalFree(core_file_content);

// [Runtime setup]
hv_mkdir_p(getCoreSettings()->log_path);
Expand Down
4 changes: 2 additions & 2 deletions tunnels/adapters/bridge/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ tunnel_t *newBridge(node_instance_context_t *instance_info)
exit(1);
}

bridge_state_t *state = wwmGlobalMalloc(sizeof(bridge_state_t));
bridge_state_t *state = globalMalloc(sizeof(bridge_state_t));
memset(state, 0, sizeof(bridge_state_t));

hash_t hash_pairname = CALC_HASH_BYTES(pair_node_name, strlen(pair_node_name));
Expand All @@ -87,7 +87,7 @@ tunnel_t *newBridge(node_instance_context_t *instance_info)
LOGF("Bridge: pair node \"%s\" not found", pair_node_name);
exit(1);
}
wwmGlobalFree(pair_node_name);
globalFree(pair_node_name);

state->pair_node = pair_node;
state->mode_upside = instance_info->node->next == NULL;
Expand Down
2 changes: 1 addition & 1 deletion tunnels/adapters/connector/connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static void downStream(tunnel_t *self, context_t *c)

tunnel_t *newConnector(node_instance_context_t *instance_info)
{
connector_state_t *state = wwmGlobalMalloc(sizeof(connector_state_t));
connector_state_t *state = globalMalloc(sizeof(connector_state_t));
memset(state, 0, sizeof(connector_state_t));
cJSON *settings = instance_info->node_settings_json;

Expand Down
8 changes: 4 additions & 4 deletions tunnels/adapters/connector/tcp/tcp_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static void cleanup(tcp_connector_con_state_t *cstate, bool write_queue)
}
doneLineUpSide(cstate->line);
destroyContextQueue(cstate->data_queue);
wwmGlobalFree(cstate);
globalFree(cstate);
}

static bool resumeWriteQueue(tcp_connector_con_state_t *cstate)
Expand Down Expand Up @@ -211,7 +211,7 @@ static void upStream(tunnel_t *self, context_t *c)
if (c->init)
{
tcp_connector_state_t *state = TSTATE(self);
CSTATE_MUT(c) = wwmGlobalMalloc(sizeof(tcp_connector_con_state_t));
CSTATE_MUT(c) = globalMalloc(sizeof(tcp_connector_con_state_t));
cstate = CSTATE(c);

*cstate = (tcp_connector_con_state_t) {.buffer_pool = getContextBufferPool(c),
Expand Down Expand Up @@ -312,7 +312,7 @@ static void upStream(tunnel_t *self, context_t *c)

// sockaddr_set_ipport(&(dest_ctx.addr), "127.0.0.1", 443);

hloop_t *loop = loops[c->line->tid];
hloop_t *loop = WORKERS[c->line->tid].loop;;
int sockfd = socket(dest_ctx->address.sa.sa_family, SOCK_STREAM, 0);
if (sockfd < 0)
{
Expand Down Expand Up @@ -406,7 +406,7 @@ static void downStream(tunnel_t *self, context_t *c)

tunnel_t *newTcpConnector(node_instance_context_t *instance_info)
{
tcp_connector_state_t *state = wwmGlobalMalloc(sizeof(tcp_connector_state_t));
tcp_connector_state_t *state = globalMalloc(sizeof(tcp_connector_state_t));
memset(state, 0, sizeof(tcp_connector_state_t));
const cJSON *settings = instance_info->node_settings_json;

Expand Down
8 changes: 4 additions & 4 deletions tunnels/adapters/connector/udp/udp_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

static void cleanup(udp_connector_con_state_t *cstate)
{
wwmGlobalFree(cstate);
globalFree(cstate);
}
static void onRecvFrom(hio_t *io, shift_buffer_t *buf)
{
Expand Down Expand Up @@ -66,15 +66,15 @@ static void upStream(tunnel_t *self, context_t *c)
{
udp_connector_state_t *state = TSTATE(self);

CSTATE_MUT(c) = wwmGlobalMalloc(sizeof(udp_connector_con_state_t));
CSTATE_MUT(c) = globalMalloc(sizeof(udp_connector_con_state_t));
memset(CSTATE(c), 0, sizeof(udp_connector_con_state_t));
cstate = CSTATE(c);

cstate->buffer_pool = getContextBufferPool(c);
cstate->tunnel = self;
cstate->line = c->line;
// sockaddr_set_ipport(&(dest->addr),"www.gstatic.com",80);
hloop_t *loop = loops[c->line->tid];
hloop_t *loop = WORKERS[c->line->tid].loop;
sockaddr_u host_addr = {0};
sockaddr_set_ipport(&host_addr, "0.0.0.0", 0);

Expand Down Expand Up @@ -181,7 +181,7 @@ static void downStream(tunnel_t *self, context_t *c)

tunnel_t *newUdpConnector(node_instance_context_t *instance_info)
{
udp_connector_state_t *state = wwmGlobalMalloc(sizeof(udp_connector_state_t));
udp_connector_state_t *state = globalMalloc(sizeof(udp_connector_state_t));
memset(state, 0, sizeof(udp_connector_state_t));
const cJSON *settings = instance_info->node_settings_json;

Expand Down
2 changes: 1 addition & 1 deletion tunnels/adapters/listener/listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static void downStream(tunnel_t *self, context_t *c)

tunnel_t *newListener(node_instance_context_t *instance_info)
{
listener_state_t *state = wwmGlobalMalloc(sizeof(listener_state_t));
listener_state_t *state = globalMalloc(sizeof(listener_state_t));
memset(state, 0, sizeof(listener_state_t));
cJSON *settings = instance_info->node_settings_json;

Expand Down
8 changes: 4 additions & 4 deletions tunnels/adapters/listener/tcp/tcp_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static void cleanup(tcp_listener_con_state_t *cstate, bool write_queue)
doneLineDownSide(cstate->line);
destroyContextQueue(cstate->data_queue);
destroyLine(cstate->line);
wwmGlobalFree(cstate);
globalFree(cstate);
}

static bool resumeWriteQueue(tcp_listener_con_state_t *cstate)
Expand Down Expand Up @@ -267,7 +267,7 @@ static void onInboundConnected(hevent_t *ev)

tunnel_t *self = data->tunnel;
line_t *line = newLine(tid);
tcp_listener_con_state_t *cstate = wwmGlobalMalloc(sizeof(tcp_listener_con_state_t));
tcp_listener_con_state_t *cstate = globalMalloc(sizeof(tcp_listener_con_state_t));

LSTATE_MUT(line) = cstate;
line->src_ctx.address_protocol = kSapTcp;
Expand Down Expand Up @@ -366,7 +366,7 @@ static void parsePortSection(tcp_listener_state_t *state, const cJSON *settings)
}
tunnel_t *newTcpListener(node_instance_context_t *instance_info)
{
tcp_listener_state_t *state = wwmGlobalMalloc(sizeof(tcp_listener_state_t));
tcp_listener_state_t *state = globalMalloc(sizeof(tcp_listener_state_t));
memset(state, 0, sizeof(tcp_listener_state_t));
const cJSON *settings = instance_info->node_settings_json;

Expand Down Expand Up @@ -411,7 +411,7 @@ tunnel_t *newTcpListener(node_instance_context_t *instance_info)
size_t len = cJSON_GetArraySize(wlist);
if (len > 0)
{
char **list = (char **) wwmGlobalMalloc(sizeof(char *) * (len + 1));
char **list = (char **) globalMalloc(sizeof(char *) * (len + 1));
memset((void *) list, 0, sizeof(char *) * (len + 1));
list[len] = 0x0;
int i = 0;
Expand Down
8 changes: 4 additions & 4 deletions tunnels/adapters/listener/tun/tun_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typedef struct tun_listener_con_state_s
static void cleanup(tun_listener_con_state_t *cstate, bool write_queue)
{

wwmGlobalFree(cstate);
globalFree(cstate);
}

static bool resumeWriteQueue(tun_listener_con_state_t *cstate)
Expand Down Expand Up @@ -193,7 +193,7 @@ static void onInboundConnected(hevent_t *ev)

tunnel_t *self = data->tunnel;
line_t *line = newLine(tid);
tun_listener_con_state_t *cstate = wwmGlobalMalloc(sizeof(tun_listener_con_state_t));
tun_listener_con_state_t *cstate = globalMalloc(sizeof(tun_listener_con_state_t));

LSTATE_MUT(line) = cstate;
line->src_ctx.address_protocol = kSapTcp;
Expand Down Expand Up @@ -292,7 +292,7 @@ static void parsePortSection(tun_listener_state_t *state, const cJSON *settings)
}
tunnel_t *newTunListener(node_instance_context_t *instance_info)
{
tun_listener_state_t *state = wwmGlobalMalloc(sizeof(tun_listener_state_t));
tun_listener_state_t *state = globalMalloc(sizeof(tun_listener_state_t));
memset(state, 0, sizeof(tun_listener_state_t));
const cJSON *settings = instance_info->node_settings_json;

Expand Down Expand Up @@ -337,7 +337,7 @@ tunnel_t *newTunListener(node_instance_context_t *instance_info)
size_t len = cJSON_GetArraySize(wlist);
if (len > 0)
{
char **list = (char **) wwmGlobalMalloc(sizeof(char *) * (len + 1));
char **list = (char **) globalMalloc(sizeof(char *) * (len + 1));
memset((void *) list, 0, sizeof(char *) * (len + 1));
list[len] = 0x0;
int i = 0;
Expand Down
14 changes: 7 additions & 7 deletions tunnels/adapters/listener/udp/udp_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void cleanup(udp_listener_con_state_t *cstate)
{
if (removeIdleItemByHash(cstate->idle_handle->tid, cstate->uio->table, cstate->idle_handle->hash))
{
wwmGlobalFree(cstate);
globalFree(cstate);
}
else
{
Expand All @@ -57,7 +57,7 @@ static void cleanup(udp_listener_con_state_t *cstate)
}
else
{
wwmGlobalFree(cstate);
globalFree(cstate);
}
}

Expand Down Expand Up @@ -134,7 +134,7 @@ static void onUdpConnectonExpire(idle_item_t *idle_udp)
assert(cstate != NULL);
if (cstate->tunnel == NULL)
{
wwmGlobalFree(cstate);
globalFree(cstate);
return;
}
LOGD("UdpListener: expired idle udp FD:%x ", hio_fd(cstate->uio->io));
Expand All @@ -148,13 +148,13 @@ static void onUdpConnectonExpire(idle_item_t *idle_udp)
static udp_listener_con_state_t *newConnection(uint8_t tid, tunnel_t *self, udpsock_t *uio, uint16_t real_localport)
{
line_t *line = newLine(tid);
udp_listener_con_state_t *cstate = wwmGlobalMalloc(sizeof(udp_listener_con_state_t));
udp_listener_con_state_t *cstate = globalMalloc(sizeof(udp_listener_con_state_t));
LSTATE_MUT(line) = cstate;
line->src_ctx.address_type = line->src_ctx.address.sa.sa_family == AF_INET ? kSatIPV4 : kSatIPV6;
line->src_ctx.address_protocol = kSapUdp;
line->src_ctx.address = *(sockaddr_u *) hio_peeraddr(uio->io);

*cstate = (udp_listener_con_state_t) {.loop = loops[tid],
*cstate = (udp_listener_con_state_t) {.loop = WORKERS[tid].loop,
.line = line,
.buffer_pool = getThreadBufferPool(tid),
.uio = uio,
Expand Down Expand Up @@ -280,7 +280,7 @@ static void parsePortSection(udp_listener_state_t *state, const cJSON *settings)
}
tunnel_t *newUdpListener(node_instance_context_t *instance_info)
{
udp_listener_state_t *state = wwmGlobalMalloc(sizeof(udp_listener_state_t));
udp_listener_state_t *state = globalMalloc(sizeof(udp_listener_state_t));
memset(state, 0, sizeof(udp_listener_state_t));
const cJSON *settings = instance_info->node_settings_json;

Expand Down Expand Up @@ -324,7 +324,7 @@ tunnel_t *newUdpListener(node_instance_context_t *instance_info)
size_t len = cJSON_GetArraySize(wlist);
if (len > 0)
{
char **list = (char **) wwmGlobalMalloc(sizeof(char *) * (len + 1));
char **list = (char **) globalMalloc(sizeof(char *) * (len + 1));
memset((void *) list, 0, sizeof(char *) * (len + 1));
list[len] = 0x0;
int i = 0;
Expand Down
Loading

0 comments on commit 0149f67

Please sign in to comment.