Skip to content

Commit

Permalink
proxy: router refactor and cmap fallback
Browse files Browse the repository at this point in the history
Allows specifying a commandmap on a router as well as a map and default
route. Lookup order is:
- Check map, if entry is map, check that
- If none matched, check fallback command map
- If nothing matched, return default route handler if exists

Also removes the router struct from the funcgen object, saving 32 bytes
and letting me extend the size of the router struct without bloating
every allocated fgen. This will later allow inlining the lookup map into
the router struct for a lookup speedup.

Finally, this adds support for "cmap only routers", which is mostly
useful when working with abstractions like routelib.
  • Loading branch information
dormando committed Jun 19, 2024
1 parent a5d3a2a commit 5f69c6d
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 100 deletions.
50 changes: 28 additions & 22 deletions proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,29 @@ enum mcp_rqueue_e {
QWAIT_SLEEP,
};

#define FGEN_NAME_MAXLEN 80
struct mcp_funcgen_s {
LIBEVENT_THREAD *thread; // worker thread that created this funcgen.
int generator_ref; // reference to the generator function.
int self_ref; // self-reference if we're attached anywhere
int argument_ref; // reference to an argument to pass to generator
int max_queues; // how many queue slots rctx's have
unsigned int refcount; // reference counter
unsigned int total; // total contexts managed
unsigned int free; // free contexts
unsigned int free_max; // size of list below.
unsigned int free_pressure; // "pressure" for when to early release rctx
bool closed; // the hook holding this fgen has been replaced
bool ready; // if we're locked down or not.
bool is_router; // if this fgen is actually a router object.
mcp_rcontext_t **list;
struct mcp_rqueue_s *queue_list;
char name[FGEN_NAME_MAXLEN+1]; // string name for the generator.
};

enum mcp_funcgen_router_e {
FGEN_ROUTER_NONE = 0,
FGEN_ROUTER_CMDMAP,
FGEN_ROUTER_SHORTSEP,
FGEN_ROUTER_LONGSEP,
FGEN_ROUTER_ANCHORSM,
Expand All @@ -669,37 +690,22 @@ struct mcp_router_long_s {
char stop[KEY_HASH_FILTER_MAX+1];
};

// To simplify the attach/start code we wrap a funcgen with the router
// structure. This allows us to have a larger router structure without
// bloating the fgen object itself, and still benefit from letting funcgen
// new/cleanup handle most of the memory management.
struct mcp_funcgen_router {
mcp_funcgen_t fgen_self;
enum mcp_funcgen_router_e type;
union {
char sep;
char lsep[KEY_HASH_FILTER_MAX+1];
char anchorsm[2]; // short anchored mode.
struct mcp_router_long_s big;
} conf;
mcp_funcgen_t *def_fgen; // default route
int map_ref;
};

#define FGEN_NAME_MAXLEN 80
struct mcp_funcgen_s {
LIBEVENT_THREAD *thread; // worker thread that created this funcgen.
int generator_ref; // reference to the generator function.
int self_ref; // self-reference if we're attached anywhere
int argument_ref; // reference to an argument to pass to generator
int max_queues; // how many queue slots rctx's have
unsigned int refcount; // reference counter
unsigned int total; // total contexts managed
unsigned int free; // free contexts
unsigned int free_max; // size of list below.
unsigned int free_pressure; // "pressure" for when to early release rctx
unsigned int routecount; // total routes if this fgen is a router.
bool closed; // the hook holding this fgen has been replaced
bool ready; // if we're locked down or not.
mcp_rcontext_t **list;
struct mcp_rqueue_s *queue_list;
struct mcp_funcgen_router router;
char name[FGEN_NAME_MAXLEN+1]; // string name for the generator.
mcp_funcgen_t *def_fgen; // default route
mcp_funcgen_t *cmap[CMD_END_STORAGE]; // fallback command map
};

#define RQUEUE_TYPE_NONE 0
Expand Down
Loading

0 comments on commit 5f69c6d

Please sign in to comment.