Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Apr 24, 2024
1 parent 26ae1f5 commit fa2f055
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
4 changes: 4 additions & 0 deletions core/core_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ static void parseMiscPartOfJson(cJSON *misc_obj)
{
printf("workers unspecified in json (misc), fallback to cpu cores: %d\n", settings->workers_count);
}
if (settings->workers_count <= 0)
{
settings->workers_count = get_ncpu();
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion tunnels/adapters/connector/udp/udp_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static void upStream(tunnel_t *self, context_t *c)
size_t nwrite = hio_write(cstate->io, c->payload);
c->payload = NULL;

assert(nwrite <= 0 || nwrite == bytes);
// assert(nwrite <= 0 || nwrite == bytes);
destroyContext(c);
}
else
Expand Down
10 changes: 8 additions & 2 deletions tunnels/server/trojan/socks/trojan_socks_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ static bool processUdp(tunnel_t *self, trojan_socks_server_con_state_t *cstate,
{
LOGD("TrojanSocksServer: udp domain %.*s", domain_len, rawBuf(c->payload));
}

socketContextDomainSet(dest_context, rawBuf(c->payload), domain_len);
shiftr(c->payload, domain_len);

Expand All @@ -333,6 +333,8 @@ static bool processUdp(tunnel_t *self, trojan_socks_server_con_state_t *cstate,
break;

default:
reuseContextBuffer(c);
destroyContext(c);
return false;
break;
}
Expand All @@ -351,6 +353,8 @@ static bool processUdp(tunnel_t *self, trojan_socks_server_con_state_t *cstate,
// len(2) + crlf(2)
if (bufLen(c->payload) < 4)
{
reuseContextBuffer(c);
destroyContext(c);
return false;
}
// memcpy(&(c->packet_size), rawBuf(c->payload), 2);
Expand All @@ -372,6 +376,8 @@ static bool processUdp(tunnel_t *self, trojan_socks_server_con_state_t *cstate,
if (! isAlive(c->line))
{
LOGW("TrojanSocksServer: next node instantly closed the init with fin");
reuseContextBuffer(c);
destroyContext(c);
return true;
}
cstate->init_sent = true;
Expand All @@ -381,7 +387,7 @@ static bool processUdp(tunnel_t *self, trojan_socks_server_con_state_t *cstate,

// line is alvie because caller is holding a context, but still fin could received
// and state is gone
if (line->chains_state[self->chain_index] == NULL)
if (! isAlive(line))
{
return true;
}
Expand Down
14 changes: 7 additions & 7 deletions ww/shiftbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

struct shift_buffer_s
{
unsigned int calc_len;
unsigned int lenpos;
unsigned int curpos;
unsigned int cap; // half of full cap
unsigned int full_cap;
unsigned short *refc;
char * pbuf;
unsigned int calc_len;
unsigned int lenpos;
unsigned int curpos;
unsigned int cap; // half of full cap
unsigned int full_cap;
unsigned int *refc;
char * pbuf;
};
typedef struct shift_buffer_s shift_buffer_t;

Expand Down

0 comments on commit fa2f055

Please sign in to comment.