summaryrefslogtreecommitdiff
path: root/infra/stellar_core.c
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-11-26 14:37:05 +0800
committeryangwei <[email protected]>2024-11-26 14:37:05 +0800
commit78562a8dd879a3753debae14198f00fe2dc0112a (patch)
tree0c316ea52a36bda174b9df7fbd3df44bb65e7908 /infra/stellar_core.c
parent1ddd1f6b783573aa8ae5e1594430865b20c9f0a3 (diff)
✨ feat(stellar core): module & node register in stellar_new
Diffstat (limited to 'infra/stellar_core.c')
-rw-r--r--infra/stellar_core.c67
1 files changed, 65 insertions, 2 deletions
diff --git a/infra/stellar_core.c b/infra/stellar_core.c
index 9141daf..52d9501 100644
--- a/infra/stellar_core.c
+++ b/infra/stellar_core.c
@@ -10,7 +10,6 @@
#include "utils_internal.h"
#include "packet_internal.h"
#include "packet_manager.h"
-#include "module_manager_interna.h"
#define CORE_LOG_FATAL(format, ...) STELLAR_LOG_FATAL(__thread_local_logger, "core", format, ##__VA_ARGS__)
#define CORE_LOG_ERROR(format, ...) STELLAR_LOG_ERROR(__thread_local_logger, "core", format, ##__VA_ARGS__)
@@ -131,6 +130,64 @@ static void stellar_thread_join(struct stellar *st)
}
}
+#include "stellar/monitor.h"
+#include "stellar/session.h"
+
+struct module_hooks mod_hooks[] = {
+ {monitor_on_init, monitor_on_exit, NULL, NULL},
+ {packet_manager_on_init, packet_manager_on_exit, packet_manager_on_thread_init, packet_manager_on_thread_exit},
+ {session_manager_on_init, session_manager_on_exit, session_manager_on_thread_init, session_manager_on_thread_exit},
+ {session_monitor_on_init, session_monitor_on_exit, NULL, NULL},
+ };
+
+
+struct packet_node_spec
+{
+ const char *module_name;
+ const char *node_name;
+ enum packet_stage stage;
+ uint64_t interested_tag_key_bits;
+ uint64_t interested_tag_val_bits;
+ on_packet_callback *cb;
+};
+
+
+struct packet_node_spec packet_nodes[] = {
+ {SESSION_MANAGER_MODULE_NAME, "session_manager",PACKET_STAGE_FORWARD, PKT_TAG_KEY_IPPROTO, PKT_TAG_VAL_IPPROTO_TCP | PKT_TAG_VAL_IPPROTO_UDP, session_manager_on_packet_forward},
+ {SESSION_MANAGER_MODULE_NAME, "session_manager",PACKET_STAGE_OUTPUT, PKT_TAG_KEY_IPPROTO, PKT_TAG_VAL_IPPROTO_TCP | PKT_TAG_VAL_IPPROTO_UDP, session_manager_on_packet_output}
+};
+
+
+int module_register_packet_node(struct module_manager *mod_mgr, struct packet_node_spec *specs, size_t n_specs)
+{
+ struct module *pkt_mgr_mod = module_manager_get_module(mod_mgr, PACKET_MANAGER_MODULE_NAME);
+ struct packet_manager *pkt_mgr = module_to_packet_manager(pkt_mgr_mod);
+
+ struct module *mod = NULL;
+
+ for(size_t i=0; i < n_specs; i++)
+ {
+ mod= module_manager_get_module(mod_mgr, specs[i].module_name);
+ if(mod == NULL)
+ {
+ CORE_LOG_ERROR("unable to get module %s", specs[i].module_name);
+ return -1;
+ }
+ if(packet_manager_register_node(pkt_mgr,
+ specs[i].node_name,
+ specs[i].stage,
+ specs[i].interested_tag_key_bits,
+ specs[i].interested_tag_val_bits,
+ specs[i].cb,
+ mod)<0)
+ {
+ CORE_LOG_ERROR("failed to subscribe PACKET_STAGE_FORWARD");
+ return -1;
+ }
+ }
+ return 0;
+}
+
struct stellar *stellar_new(const char *toml_file)
{
if (toml_file == NULL)
@@ -168,7 +225,7 @@ struct stellar *stellar_new(const char *toml_file)
goto error_out;
}
- st->mod_mgr = module_manager_new_with_toml(toml_file, st->thread_num, st->mq_schema, st->logger);
+ st->mod_mgr = module_manager_new(mod_hooks, count_of(mod_hooks),st->thread_num, toml_file, st->mq_schema, st->logger);
if (st->mod_mgr == NULL)
{
CORE_LOG_ERROR("unable to create packet manager");
@@ -182,6 +239,12 @@ struct stellar *stellar_new(const char *toml_file)
goto error_out;
}
+ if(module_register_packet_node(st->mod_mgr, packet_nodes, count_of(packet_nodes)) != 0)
+ {
+ CORE_LOG_ERROR("unable to register packet node");
+ goto error_out;
+ }
+
return st;
error_out: