udphole

Basic UDP wormhole proxy
git clone git://git.finwo.net/app/udphole
Log | Files | Refs | README | LICENSE

commit f8246f9a12e36930914c84ff0918ca94f707f0c9
parent 51a13a397904c238e6687f5247013047d89c6fc4
Author: Robin Bron <robin.bron@yourhosting.nl>
Date:   Sat,  7 Mar 2026 16:20:15 +0100

Change from hashmap to mindex

Diffstat:
MMakefile | 2+-
Mpackage.ini | 4++--
Msrc/domain/daemon/session.c | 1-
Msrc/interface/api/server.c | 56+++++++++++++++++++++++++++++---------------------------
4 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/Makefile b/Makefile @@ -7,7 +7,7 @@ SRC:= # UNAME_SYSTEM=$(call lc,$(shell uname -s)) BIN?=udphole -VERSION?=1.3.9 +VERSION?=1.3.10 CC:=gcc CPP:=g++ diff --git a/package.ini b/package.ini @@ -1,10 +1,10 @@ [dependencies] benhoyt/inih=master cofyc/argparse=master +finwo/mindex=main +finwo/url-parser=main graphitemaster/incbin=main rxi/log=master -tidwall/hashmap=master -finwo/url-parser=main [package] name=finwo/udphole diff --git a/src/domain/daemon/session.c b/src/domain/daemon/session.c @@ -19,7 +19,6 @@ #include "common/socket_util.h" #include "domain/config.h" #include "rxi/log.h" -#include "tidwall/hashmap.h" static resp_object *get_udphole_cfg(void) { return domain_cfg ? resp_map_get(domain_cfg, "udphole") : NULL; diff --git a/src/interface/api/server.c b/src/interface/api/server.c @@ -27,9 +27,9 @@ #include "common/socket_util.h" #include "common/url_utils.h" #include "domain/config.h" +#include "finwo/mindex.h" #include "infrastructure/config.h" #include "rxi/log.h" -#include "tidwall/hashmap.h" int api_client_pt(int64_t timestamp, struct pt_task *task); @@ -63,8 +63,8 @@ typedef struct { domain_cmd_fn func; } domain_cmd_entry; -static struct hashmap *cmd_map = NULL; -static struct hashmap *domain_cmd_map = NULL; +static struct mindex_t *cmd_map = NULL; +static struct mindex_t *domain_cmd_map = NULL; typedef struct { int *server_fds; @@ -213,11 +213,6 @@ static bool user_has_permit(api_client_t *c, const char *cmd) { return false; } -static uint64_t cmd_hash(const void *item, uint64_t seed0, uint64_t seed1) { - const api_cmd_entry *cmd = item; - return hashmap_sip(cmd->name, strlen(cmd->name), seed0, seed1); -} - static int cmd_compare(const void *a, const void *b, void *udata) { (void)udata; const api_cmd_entry *ca = a; @@ -225,15 +220,18 @@ static int cmd_compare(const void *a, const void *b, void *udata) { return strcasecmp(ca->name, cb->name); } -void api_register_cmd(const char *name, char (*func)(api_client_t *, char **, int)) { - if (!cmd_map) cmd_map = hashmap_new(sizeof(api_cmd_entry), 0, 0, 0, cmd_hash, cmd_compare, NULL, NULL); - hashmap_set(cmd_map, &(api_cmd_entry){.name = name, .func = func}); - log_trace("api: registered command '%s'", name); +static void cmd_purge(void *item, void *udata) { + (void)item; + (void)udata; } -static uint64_t domain_cmd_hash(const void *item, uint64_t seed0, uint64_t seed1) { - const domain_cmd_entry *cmd = item; - return hashmap_sip(cmd->name, strlen(cmd->name), seed0, seed1); +void api_register_cmd(const char *name, char (*func)(api_client_t *, char **, int)) { + if (!cmd_map) cmd_map = mindex_init(cmd_compare, cmd_purge, NULL); + api_cmd_entry *entry = malloc(sizeof(api_cmd_entry)); + entry->name = name; + entry->func = func; + mindex_set(cmd_map, entry); + log_trace("api: registered command '%s'", name); } static int domain_cmd_compare(const void *a, const void *b, void *udata) { @@ -243,10 +241,18 @@ static int domain_cmd_compare(const void *a, const void *b, void *udata) { return strcasecmp(ca->name, cb->name); } +static void domain_cmd_purge(void *item, void *udata) { + (void)item; + (void)udata; +} + void api_register_domain_cmd(const char *name, domain_cmd_fn func) { if (!domain_cmd_map) - domain_cmd_map = hashmap_new(sizeof(domain_cmd_entry), 0, 0, 0, domain_cmd_hash, domain_cmd_compare, NULL, NULL); - hashmap_set(domain_cmd_map, &(domain_cmd_entry){.name = name, .func = func}); + domain_cmd_map = mindex_init(domain_cmd_compare, domain_cmd_purge, NULL); + domain_cmd_entry *entry = malloc(sizeof(domain_cmd_entry)); + entry->name = name; + entry->func = func; + mindex_set(domain_cmd_map, entry); log_trace("api: registered domain command '%s'", name); } @@ -298,10 +304,8 @@ static char cmdCOMMAND(api_client_t *c, char **args, int nargs) { if (!result) return 0; if (domain_cmd_map) { - size_t iter = 0; - void *item; - while (hashmap_iter(domain_cmd_map, &iter, &item)) { - const domain_cmd_entry *e = item; + for (size_t i = 0; i < mindex_length(domain_cmd_map); i++) { + const domain_cmd_entry *e = mindex_nth(domain_cmd_map, i); if (!user_has_permit(c, e->name)) continue; resp_array_append_bulk(result, e->name); @@ -317,10 +321,8 @@ static char cmdCOMMAND(api_client_t *c, char **args, int nargs) { } if (cmd_map) { - size_t iter = 0; - void *item; - while (hashmap_iter(cmd_map, &iter, &item)) { - const api_cmd_entry *e = item; + for (size_t i = 0; i < mindex_length(cmd_map); i++) { + const api_cmd_entry *e = mindex_nth(cmd_map, i); if (!is_builtin(e->name) && !user_has_permit(c, e->name)) continue; resp_array_append_bulk(result, e->name); @@ -365,7 +367,7 @@ static void dispatch_command(api_client_t *c, char **args, int nargs) { for (char *p = args[0]; *p; p++) *p = (char)tolower((unsigned char)*p); - const domain_cmd_entry *dcmd = hashmap_get(domain_cmd_map, &(domain_cmd_entry){.name = args[0]}); + const domain_cmd_entry *dcmd = mindex_get(domain_cmd_map, &(domain_cmd_entry){.name = args[0]}); if (dcmd) { if (!is_builtin(args[0])) { if (!user_has_permit(c, args[0])) { @@ -403,7 +405,7 @@ static void dispatch_command(api_client_t *c, char **args, int nargs) { return; } - const api_cmd_entry *cmd = hashmap_get(cmd_map, &(api_cmd_entry){.name = args[0]}); + const api_cmd_entry *cmd = mindex_get(cmd_map, &(api_cmd_entry){.name = args[0]}); if (!cmd) { api_write_err(c, "unknown command"); return;