Skip to content

Commit

Permalink
HevSocks5TProxy: Add support for multiple workers.
Browse files Browse the repository at this point in the history
  • Loading branch information
heiher committed Jan 6, 2025
1 parent 6502ef3 commit 0c49a2e
Show file tree
Hide file tree
Showing 7 changed files with 759 additions and 599 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ ndk-build
### Config

```yaml
main:
workers: 1

socks5:
port: 1080
address: 127.0.0.1
Expand Down
4 changes: 4 additions & 0 deletions conf/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Main configuration for hev-socks5-tproxy

main:
# Worker threads
workers: 1

socks5:
# Socks5 server port
port: 1080
Expand Down
47 changes: 46 additions & 1 deletion src/hev-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "hev-logger.h"
#include "hev-config.h"

static unsigned int workers = 1;
static HevConfigServer srv;
static char tcp_address[256];
static char tcp_port[8];
Expand All @@ -31,6 +32,42 @@ static int read_write_timeout = 60000;
static int limit_nofile = 65535;
static int log_level = HEV_LOGGER_WARN;

static int
hev_config_parse_main (yaml_document_t *doc, yaml_node_t *base)
{
yaml_node_pair_t *pair;

if (!base || YAML_MAPPING_NODE != base->type)
return -1;

for (pair = base->data.mapping.pairs.start;
pair < base->data.mapping.pairs.top; pair++) {
yaml_node_t *node;
const char *key, *value;

if (!pair->key || !pair->value)
break;

node = yaml_document_get_node (doc, pair->key);
if (!node || YAML_SCALAR_NODE != node->type)
break;
key = (const char *)node->data.scalar.value;

node = yaml_document_get_node (doc, pair->value);
if (!node || YAML_SCALAR_NODE != node->type)
break;
value = (const char *)node->data.scalar.value;

if (0 == strcmp (key, "workers"))
workers = strtoul (value, NULL, 10);
}

if (!workers)
workers = 1;

return 0;
}

static int
hev_config_parse_server (yaml_document_t *doc, yaml_node_t *base,
const char *sec, HevConfigServer *srv)
Expand Down Expand Up @@ -315,7 +352,9 @@ hev_config_parse_doc (yaml_document_t *doc)
key = (const char *)node->data.scalar.value;
node = yaml_document_get_node (doc, pair->value);

if (0 == strcmp (key, "socks5"))
if (0 == strcmp (key, "main"))
res = hev_config_parse_main (doc, node);
else if (0 == strcmp (key, "socks5"))
res = hev_config_parse_server (doc, node, key, &srv);
else if (0 == strcmp (key, "tcp"))
res = hev_config_parse_addr (doc, node, key, tcp_address, tcp_port);
Expand Down Expand Up @@ -372,6 +411,12 @@ hev_config_fini (void)
{
}

unsigned int
hev_config_get_workers (void)
{
return workers;
}

HevConfigServer *
hev_config_get_socks5_server (void)
{
Expand Down
2 changes: 2 additions & 0 deletions src/hev-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct _HevConfigServer
int hev_config_init (const char *path);
void hev_config_fini (void);

unsigned int hev_config_get_workers (void);

HevConfigServer *hev_config_get_socks5_server (void);
const char *hev_config_get_tcp_address (void);
const char *hev_config_get_tcp_port (void);
Expand Down
Loading

0 comments on commit 0c49a2e

Please sign in to comment.