Skip to content

Commit

Permalink
reformat / small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Jul 10, 2024
1 parent b214fdc commit 5e90757
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 43 deletions.
29 changes: 16 additions & 13 deletions tunnels/adapters/connector/tcp/tcp_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ static void cleanup(tcp_connector_con_state_t *cstate, bool write_queue)

hio_close(cstate->io);
}
if (cstate->write_paused)
{
resumeLineDownSide(cstate->line);
}
doneLineUpSide(cstate->line);
resumeLineDownSide(cstate->line);
destroyContextQueue(cstate->data_queue);
wwmGlobalFree(cstate);
}
Expand Down Expand Up @@ -207,15 +210,15 @@ 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 = CSTATE(c);
tcp_connector_state_t *state = TSTATE(self);
CSTATE_MUT(c) = wwmGlobalMalloc(sizeof(tcp_connector_con_state_t));
cstate = CSTATE(c);

*cstate = (tcp_connector_con_state_t){.buffer_pool = getContextBufferPool(c),
.tunnel = self,
.line = c->line,
.data_queue = newContextQueue(),
.write_paused = true};
*cstate = (tcp_connector_con_state_t) {.buffer_pool = getContextBufferPool(c),
.tunnel = self,
.line = c->line,
.data_queue = newContextQueue(),
.write_paused = true};

#ifdef PROFILE
gettimeofday(&(cstate->__profile_conenct), NULL);
Expand Down Expand Up @@ -294,8 +297,8 @@ static void upStream(tunnel_t *self, context_t *c)
uint64_t calc = ntohll(*addr_ptr);
calc = calc & ~(state->outbound_ip_range - 1ULL);
calc = htonll(calc + large_random);
memcpy(8+((char*)&(dest_ctx->address.sin6.sin6_addr)), &calc, sizeof(calc));

memcpy(8 + ((char *) &(dest_ctx->address.sin6.sin6_addr)), &calc, sizeof(calc));
}
break;

Expand Down Expand Up @@ -538,7 +541,7 @@ api_result_t apiTcpConnector(tunnel_t *self, const char *msg)
{
(void) (self);
(void) (msg);
return (api_result_t){0};
return (api_result_t) {0};
}

tunnel_t *destroyTcpConnector(tunnel_t *self)
Expand All @@ -549,5 +552,5 @@ tunnel_t *destroyTcpConnector(tunnel_t *self)

tunnel_metadata_t getMetadataTcpConnector(void)
{
return (tunnel_metadata_t){.version = 0001, .flags = 0x0};
return (tunnel_metadata_t) {.version = 0001, .flags = 0x0};
}
31 changes: 17 additions & 14 deletions tunnels/adapters/listener/tcp/tcp_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ enum
typedef struct tcp_listener_state_s
{
// settings
char *address;
char **white_list_raddr;
char **black_list_raddr;
char *address;
char **white_list_raddr;
char **black_list_raddr;
int multiport_backend;
uint16_t port_min;
uint16_t port_max;
Expand Down Expand Up @@ -69,8 +69,11 @@ static void cleanup(tcp_listener_con_state_t *cstate, bool write_queue)
}
hio_close(cstate->io);
}
if (cstate->write_paused)
{
resumeLineUpSide(cstate->line);
}
doneLineDownSide(cstate->line);
resumeLineUpSide(cstate->line);
destroyContextQueue(cstate->data_queue);
destroyLine(cstate->line);
wwmGlobalFree(cstate);
Expand Down Expand Up @@ -277,14 +280,14 @@ static void onInboundConnected(hevent_t *ev)
line->src_ctx.address_protocol = kSapTcp;
line->src_ctx.address = *(sockaddr_u *) hio_peeraddr(io);

*cstate = (tcp_listener_con_state_t){.line = line,
.buffer_pool = getThreadBufferPool(tid),
.data_queue = newContextQueue(),
.io = io,
.tunnel = self,
.write_paused = false,
.established = false,
.first_packet_sent = false};
*cstate = (tcp_listener_con_state_t) {.line = line,
.buffer_pool = getThreadBufferPool(tid),
.data_queue = newContextQueue(),
.io = io,
.tunnel = self,
.write_paused = false,
.established = false,
.first_packet_sent = false};

setupLineDownSide(line, onLinePaused, cstate, onLineResumed);

Expand Down Expand Up @@ -456,7 +459,7 @@ api_result_t apiTcpListener(tunnel_t *self, const char *msg)
{
(void) (self);
(void) (msg);
return (api_result_t){0};
return (api_result_t) {0};
}

tunnel_t *destroyTcpListener(tunnel_t *self)
Expand All @@ -466,5 +469,5 @@ tunnel_t *destroyTcpListener(tunnel_t *self)
}
tunnel_metadata_t getMetadataTcpListener(void)
{
return (tunnel_metadata_t){.version = 0001, .flags = kNodeFlagChainHead};
return (tunnel_metadata_t) {.version = 0001, .flags = kNodeFlagChainHead};
}
14 changes: 0 additions & 14 deletions tunnels/server/reality/reality_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,6 @@ typedef struct reality_server_con_state_s

} reality_server_con_state_t;

// static size_t paddingDecisionCb(SSL *ssl, int type, size_t len, void *arg)
// {
// (void) ssl;
// (void) type;
// (void) len;
// reality_server_con_state_t *cstate = arg;

// if (cstate->reply_sent_tit >= 1 && cstate->reply_sent_tit < 6)
// {
// return (16 * (160 + (0x7F & (size_t) fastRand())));
// }

// return 0;
// }

static void cleanup(tunnel_t *self, context_t *c)
{
Expand Down
2 changes: 1 addition & 1 deletion ww/buffer_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

enum
{
kQCap = 32
kQCap = 16
};

buffer_stream_t *newBufferStream(struct buffer_pool_s *pool)
Expand Down
2 changes: 1 addition & 1 deletion ww/tunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ static inline void unLockLine(line_t *line)
}

/*
Only the line creator must call this when it wants to end the line, this dose net necessarily free the context
Only the line creator must call this when it wants to end the line, this dose not necessarily free the line
instantly, but it will be freed as soon as the refc becomes zero which means no context is alive for this line, and
the line can still be used regularly during the time that it has at least 1 ref
Expand Down

0 comments on commit 5e90757

Please sign in to comment.