diff --git a/sdk/example/custom_event_plugin.cpp b/sdk/example/custom_event_plugin.cpp index 7decbc4..7bf014e 100644 --- a/sdk/example/custom_event_plugin.cpp +++ b/sdk/example/custom_event_plugin.cpp @@ -9,17 +9,17 @@ void *custom_decode(const char *payload, uint32_t len, void **pme) return nullptr; } -int custom_plugin_entry(const struct session *s, int what, struct packet *p, const char *payload, uint32_t len, void **pme) +int custom_plugin_entry(const struct stellar_session *s, int what, struct stellar_packet *p, const char *payload, uint32_t len, void **pme) { - void *info= custom_decode(payload, len, pme); - struct session *new_session=session_manager_custom_session_derive(s, _event); + struct stellar_session_event_extras *info= (struct stellar_session_event_extras *)custom_decode(payload, len, pme); + struct stellar_session *new_session=session_manager_session_derive(s, "CUSTOM_A"); session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info); session_manager_trigger_event(new_session, SESSION_EVENT_META, info); return 0; } -int custom_event_plugin_entry(const struct session *s, int what, struct packet *p, const char *payload, uint32_t len, void **pme) +int custom_event_plugin_entry(const struct stellar_session *s, int what, struct stellar_packet *p, const char *payload, uint32_t len, void **pme) { return 0; @@ -27,9 +27,12 @@ int custom_event_plugin_entry(const struct session *s, int what, struct packet * int custom_plugin_init() { - _event = session_manager_custom_session_event_register("SESSION_TYPE_CUSTOM", (int)(SESSION_EVENT_OPENING|SESSION_EVENT_RAW_PKT|SESSION_EVENT_META|SESSION_EVENT_CLOSING)); - plugin_session_event_register(SESSION_TYPE_TCP, custom_plugin_entry, nullptr); - - plugin_custom_session_event_register("SESSION_TYPE_CUSTOM", custom_event_plugin_entry, nullptr); + plugin_session_event_register("TCP", custom_plugin_entry, nullptr); + plugin_session_event_register("CUSTOM_A", custom_event_plugin_entry, nullptr); return 0; +} + +void custom_plugin_destroy() +{ + return ; } \ No newline at end of file diff --git a/sdk/example/http_event_plugin.cpp b/sdk/example/http_event_plugin.cpp index 98fffd9..e8ac0bb 100644 --- a/sdk/example/http_event_plugin.cpp +++ b/sdk/example/http_event_plugin.cpp @@ -5,13 +5,18 @@ -int http_event_plugin_entry(const struct session *s, int what, struct packet *p, const char *payload, uint32_t len, void **pme) +int http_event_plugin_entry(const struct stellar_session *s, int what, struct stellar_packet *p, const char *payload, uint32_t len, void **pme) { return 0; } int http_event_plugin_init() { - plugin_session_event_register(SESSION_TYPE_HTTP, http_event_plugin_entry, nullptr); + plugin_session_event_register("HTTP", http_event_plugin_entry, nullptr); return 0; +} + +void http_event_plugin_destroy() +{ + return ; } \ No newline at end of file diff --git a/sdk/example/plugin.inf b/sdk/example/plugin.inf deleted file mode 100644 index e69de29..0000000 diff --git a/sdk/example/plugins/custom_event_plugin/custom_event_plugin.inf b/sdk/example/plugins/custom_event_plugin/custom_event_plugin.inf new file mode 100644 index 0000000..78107e1 --- /dev/null +++ b/sdk/example/plugins/custom_event_plugin/custom_event_plugin.inf @@ -0,0 +1,13 @@ +[PLUGINFO] +INIT_FUNC=custom_plugin_init +DESTROY_FUNC=custom_plugin_destroy +LIBARY_PATH=./plugins/custom_event_plugin/custom_event_plugin.so + + +[SESSION_TYPE.TCP] +SESSION_EVENT_TYPE=ALL +SESSION_EVENT_CALLBACK=custom_plugin_entry + +[SESSION_TYPE.CUSTOM_A] +SESSION_EVENT_TYPE=ALL +SESSION_EVENT_CALLBACK=custom_event_plugin_entry \ No newline at end of file diff --git a/sdk/example/plugins/http_event_plugin/http_event_plugin.inf b/sdk/example/plugins/http_event_plugin/http_event_plugin.inf new file mode 100644 index 0000000..62b7a4a --- /dev/null +++ b/sdk/example/plugins/http_event_plugin/http_event_plugin.inf @@ -0,0 +1,9 @@ +[PLUGINFO] +INIT_FUNC=http_event_plugin_init +DESTROY_FUNC=http_event_plugin_destroy +LIBARY_PATH=./plugins/http_event_plugin/http_event_plugin.so + + +[SESSION_TYPE_HTTP] +SESSION_EVENT_TYPE=ALL +SESSION_EVENT_CALLBACK=http_event_plugin_entry \ No newline at end of file diff --git a/sdk/example/plugins/plugins.inf b/sdk/example/plugins/plugins.inf new file mode 100644 index 0000000..50e40af --- /dev/null +++ b/sdk/example/plugins/plugins.inf @@ -0,0 +1,2 @@ +./http_event_plugin/http_event_plugin.inf +./custom_event_plugin/custom_event_plugin.inf \ No newline at end of file diff --git a/sdk/include/event.h b/sdk/include/event.h new file mode 100644 index 0000000..9f374db --- /dev/null +++ b/sdk/include/event.h @@ -0,0 +1,18 @@ + +enum stellar_event_type +{ + STELLAR_SESSION_EVENT, +}; + +struct stellar_session_event_data; + +struct stellar_event +{ + stellar_event_type type; + union + { + struct stellar_session_event_data *session_event_data; + void *event_data; + }; +}; + diff --git a/sdk/include/http.h b/sdk/include/http.h index abef6c7..62b1fbd 100644 --- a/sdk/include/http.h +++ b/sdk/include/http.h @@ -3,4 +3,4 @@ #include "packet.h" #include "session.h" -int http_decoder(const struct session *s, int what, struct packet *p, const char *payload, uint32_t len, void **pme); +int http_decoder(const struct stellar_session *s, int what, struct stellar_packet *p, const char *payload, uint32_t len, void **pme); diff --git a/sdk/include/packet.h b/sdk/include/packet.h index 5121457..5e4c102 100644 --- a/sdk/include/packet.h +++ b/sdk/include/packet.h @@ -1,4 +1,4 @@ #pragma once -struct packet; +struct stellar_packet; diff --git a/sdk/include/plugin.h b/sdk/include/plugin.h index 10cacd1..e8d0f98 100644 --- a/sdk/include/plugin.h +++ b/sdk/include/plugin.h @@ -3,7 +3,9 @@ #include "session.h" #include -int plugin_session_event_register(int session_type, fn_session_event_callback cb, void *entry_arg); -int plugin_session_timer_register(struct session *s, fn_session_timer cb, void *timer_arg, const struct timeval *timeout); +int plugin_session_event_register(const char *session_name, + fn_session_event_callback call_back, + const struct timeval *timeout); -int plugin_custom_session_event_register(const char *event_name, fn_session_event_callback cb, void *entry_arg); +void plugin_session_event_delete(struct stellar_event *ev, + struct stellar_session *s); \ No newline at end of file diff --git a/sdk/include/session.h b/sdk/include/session.h index 2671589..17bea1d 100644 --- a/sdk/include/session.h +++ b/sdk/include/session.h @@ -1,12 +1,12 @@ #pragma once #include "packet.h" +#include "event.h" #include -struct session; -struct session_event; +struct stellar_session; -enum session_type +enum stellar_session_type { SESSION_TYPE_CUSTOM, SESSION_TYPE_IP, @@ -23,7 +23,7 @@ enum session_type SESSION_TYPE_MAX, }; -enum session_event_type +enum stellar_session_event_type { SESSION_EVENT_OPENING=0x01, SESSION_EVENT_RAW_PKT=0x02, @@ -32,19 +32,13 @@ enum session_event_type SESSION_EVENT_CLOSING=0x10, }; +struct stellar_session_event_extras; -typedef int (*fn_session_event_callback)(const struct session *s, int what, struct packet *p, const char *payload, uint32_t len, void **pme); -typedef int (*fn_session_timer)(const struct session *s, void **pme); +typedef int (*fn_session_event_callback)(const struct stellar_session *s, int what, struct stellar_packet *p, const char *payload, uint32_t len, void **pme); -void session_manager_trigger_event(struct session *s, session_event_type event, void *event_info); +void session_manager_trigger_event(struct stellar_session *s, + stellar_session_event_type type, + struct stellar_session_event_extras *info); - -struct session_event *session_manager_commit(struct packet *p); - -struct custom_session_event; - -struct custom_session_event *session_manager_custom_session_event_register(const char *event_name, int available_event); -struct session *session_manager_custom_session_derive(const struct session *cur_session, struct custom_session_event *event); - - -struct session_event *session_manager_fetch_event(); +struct stellar_session *session_manager_session_derive(const struct stellar_session *this_session, + const char *new_session_name); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index b607270..3031933 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,16 +3,16 @@ #include "plugin_manager.h" #include "http.h" -struct packet_io_loop_arg +struct stellar_event_base_loop_arg { struct packet_io_device *dev; int thread_id; }; -void packet_io_loop(struct packet_io_loop_arg *arg) +void stellar_event_base_loop(struct stellar_event_base_loop_arg *arg) { - struct packet *rx_pkt; - struct session_event *event; + struct stellar_packet *rx_pkt; + struct stellar_event *event; while(1) { int fetch_num = packet_io_rx(arg->dev, arg->thread_id, &rx_pkt, 1); @@ -50,7 +50,7 @@ int main(int argc, char ** argv) { //config_manager_init - session_manager_session_event_register(http_decoder, SESSION_TYPE_HTTP); + plugin_session_event_register("HTTP", http_decoder, nullptr); //packet_io_init //create_worker_thread diff --git a/src/packet_io/packet_io.cpp b/src/packet_io/packet_io.cpp index 43b9e7d..1b786c1 100644 --- a/src/packet_io/packet_io.cpp +++ b/src/packet_io/packet_io.cpp @@ -26,12 +26,12 @@ void packet_io_close_device(struct packet_io_device *dev) return; } -int packet_io_rx(struct packet_io_device *dev, uint32_t rx_queue_id, struct packet *p[], int nr_p) +int packet_io_rx(struct packet_io_device *dev, uint32_t rx_queue_id, struct stellar_packet *p[], int nr_p) { return 0; } -int packet_io_tx(struct packet_io_device *dev, uint32_t rx_queue_id, struct packet *p[], int nr_p) +int packet_io_tx(struct packet_io_device *dev, uint32_t rx_queue_id, struct stellar_packet *p[], int nr_p) { return 0; } \ No newline at end of file diff --git a/src/packet_io/packet_io.h b/src/packet_io/packet_io.h index 85cc16f..39414ca 100644 --- a/src/packet_io/packet_io.h +++ b/src/packet_io/packet_io.h @@ -19,5 +19,5 @@ void packet_io_destory(struct packet_io_instance *instance); struct packet_io_device *packet_io_open_device(struct packet_io_instance *instance, const char *dev_sym, uint32_t nr_rxqueue, uint32_t nr_txqueue); void packet_io_close_device(struct packet_io_device *dev); -int packet_io_rx(struct packet_io_device *dev, uint32_t rx_queue_id, struct packet *p[], int nr_p); -int packet_io_tx(struct packet_io_device *dev, uint32_t rx_queue_id, struct packet *p[], int nr_p); \ No newline at end of file +int packet_io_rx(struct packet_io_device *dev, uint32_t rx_queue_id, struct stellar_packet *p[], int nr_p); +int packet_io_tx(struct packet_io_device *dev, uint32_t rx_queue_id, struct stellar_packet *p[], int nr_p); \ No newline at end of file diff --git a/src/packet_io/test/gtest_packet_io.cpp b/src/packet_io/test/gtest_packet_io.cpp index ff0ea7f..8618e2e 100644 --- a/src/packet_io/test/gtest_packet_io.cpp +++ b/src/packet_io/test/gtest_packet_io.cpp @@ -1,6 +1,6 @@ #include -#include "packet_io.h" +#include "../packet_io.h" TEST(PACKET_IO_Test, packet_io_create) { EXPECT_EQ(packet_io_create(PACKET_IO_PCAP, "TEST"), nullptr); diff --git a/src/plugin_manager/CMakeLists.txt b/src/plugin_manager/CMakeLists.txt index 212664d..5850d1f 100644 --- a/src/plugin_manager/CMakeLists.txt +++ b/src/plugin_manager/CMakeLists.txt @@ -1,4 +1,4 @@ -include_directories(${CMAKE_SOURCE_DIR}/session_manager/) add_library(plugin_manager plugin_manager.cpp -) \ No newline at end of file +) +target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}) \ No newline at end of file diff --git a/src/plugin_manager/plugin_manager.cpp b/src/plugin_manager/plugin_manager.cpp index c5b7fe1..4fe54ce 100644 --- a/src/plugin_manager/plugin_manager.cpp +++ b/src/plugin_manager/plugin_manager.cpp @@ -1,13 +1,16 @@ -#include "plugin.h" +#include "deps/uthash/uthash.h" + +#include "sdk/include/session.h" + + #include "session_manager.h" -#include "utils.h" - +#if 0 struct session_event_callback { const char *session_name; fn_session_event_callback callback; - TAILQ_ENTRY(session_event_callback) session_event_cb_tq_entries; + TAILQ_ENTRY(session_event_callback) entries; UT_hash_handle hh; }; @@ -26,9 +29,18 @@ struct plugin_manager }; struct plugin_manager g_plug_mgr; +#endif -void plugin_manager_dispatch(struct session_event *event) +int plugin_session_event_register(const char *session_name, + fn_session_event_callback call_back, + const struct timeval *timeout) { + return 0; +} + +void plugin_manager_dispatch(struct stellar_event *event) +{ +#if 0 struct session *s = container_of(event, struct session, cur_ev); struct session_event_callback_map *t_map; struct session_event_callback *session_ev_cb; @@ -55,6 +67,6 @@ void plugin_manager_dispatch(struct session_event *event) default: break; } - +#endif return; } \ No newline at end of file diff --git a/src/plugin_manager/plugin_manager.h b/src/plugin_manager/plugin_manager.h index 6159957..d2b9672 100644 --- a/src/plugin_manager/plugin_manager.h +++ b/src/plugin_manager/plugin_manager.h @@ -1,6 +1,25 @@ #pragma once -#include "plugin.h" +#include -void plugin_manager_dispatch(struct session_event *event); \ No newline at end of file +#include "sdk/include/session.h" +#include "sdk/include/plugin.h" + +struct stellar_plugin_ctx +{ + void *call_back_arg; + const struct timeval timeout; + fn_session_event_callback call_back; + TAILQ_ENTRY(stellar_plugin_ctx) tqe; +}; + +TAILQ_HEAD(stellar_plugin_ctx_list, stellar_plugin_ctx); + +struct stellar_plugin_data +{ + stellar_plugin_ctx_list plugin_ctx_list; +}; + + +void plugin_manager_dispatch(struct stellar_event *ev); \ No newline at end of file diff --git a/src/protocol_decoder/http/CMakeLists.txt b/src/protocol_decoder/http/CMakeLists.txt index 50ed35d..dd8482f 100644 --- a/src/protocol_decoder/http/CMakeLists.txt +++ b/src/protocol_decoder/http/CMakeLists.txt @@ -2,4 +2,5 @@ add_library(http http.cpp -) \ No newline at end of file +) +target_include_directories(http PUBLIC ${CMAKE_SOURCE_DIR}) \ No newline at end of file diff --git a/src/protocol_decoder/http/http.cpp b/src/protocol_decoder/http/http.cpp index e8b19b5..13fd4d6 100644 --- a/src/protocol_decoder/http/http.cpp +++ b/src/protocol_decoder/http/http.cpp @@ -1,16 +1,16 @@ #include "http.h" #include "session_manager.h" -int http_decoder(const struct session *s, int what, struct packet *p, const char *payload, uint32_t len, void **pme) +int http_decoder(const struct stellar_session *s, int what, struct stellar_packet *p, const char *payload, uint32_t len, void **pme) { - void *info; - struct session *new_session=session_manager_session_derive(s, SESSION_TYPE_HTTP); + struct stellar_session_event_extras *info; + struct stellar_session *new_session=session_manager_session_derive(s, "HTTP"); session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info); session_manager_trigger_event(new_session, SESSION_EVENT_META, info); return 0; } -int http_peek(const struct session *s, const char *payload, uint32_t len) +int http_peek(const struct stellar_session *s, const char *payload, uint32_t len) { return 0; } \ No newline at end of file diff --git a/src/session_manager/CMakeLists.txt b/src/session_manager/CMakeLists.txt index 23fe595..b78722f 100644 --- a/src/session_manager/CMakeLists.txt +++ b/src/session_manager/CMakeLists.txt @@ -1,4 +1,4 @@ - add_library(session_manager session_manager.cpp -) \ No newline at end of file +) +target_include_directories(session_manager PUBLIC ${CMAKE_SOURCE_DIR}) \ No newline at end of file diff --git a/src/session_manager/session_manager.cpp b/src/session_manager/session_manager.cpp index a5592c8..10d41bd 100644 --- a/src/session_manager/session_manager.cpp +++ b/src/session_manager/session_manager.cpp @@ -2,42 +2,29 @@ struct session_manager { - struct session **tcp_table, **udp_table; + struct stellar_session **tcp_table, **udp_table; }; -void session_manager_session_event_register(fn_session_event_callback decoder, session_type type) +void session_manager_trigger_event(struct stellar_session *s, + stellar_session_event_type type, + struct stellar_session_event_extras *info) { return; } -struct session *session_manager_custom_session_derive(const struct session *cur_session, struct custom_session_event *event) +struct stellar_session *session_manager_session_derive(const struct stellar_session *this_session, + const char *new_session_name) { return nullptr; } -void session_manager_trigger_event(struct session *s, session_event_type event, void *event_info) -{ - return; -} - - -struct session_event *session_manager_commit(struct packet *p) +struct stellar_event *session_manager_commit(struct stellar_packet *p) { return nullptr; }; -struct custom_session_event *session_manager_custom_session_event_register(const char *event_name, int available_event) -{ - return nullptr; -} - -struct session *session_manager_session_derive(const struct session *cur_session, session_type type) -{ - return nullptr; -} - -struct session_event *session_manager_fetch_event() +struct stellar_event *session_manager_fetch_event() { return nullptr; } diff --git a/src/session_manager/session_manager.h b/src/session_manager/session_manager.h index 17f2e0d..3bac9f0 100644 --- a/src/session_manager/session_manager.h +++ b/src/session_manager/session_manager.h @@ -1,47 +1,24 @@ #pragma once -#include "session.h" -#include "uthash/uthash.h" +#include "sdk/include/session.h" -#include /* TAILQ(3) */ +struct stellar_plugin_data; -struct session_data +struct stellar_session_event_data { - /* data */ + struct stellar_session *s; + stellar_session_event_type type; + long last_active; + struct stellar_plugin_data *plugin_data; }; -enum session_state +struct stellar_event *session_manager_commit(struct stellar_packet *pkt); +struct stellar_event *session_manager_fetch_event(); + +struct stellar_session { - SESSION_STATE_OPENING, - SESSION_STATE_ACTIVE, - SESSION_STATE_CLOSING, - SESSION_STATE_CLOSED + stellar_session_type type; + const char *name; + void *addr; + void *data; }; - -struct session_event -{ - enum session_state state; - void *cb_pme; - fn_session_event_callback callback; - TAILQ_ENTRY(session_event) session_event_tq_entries; -}; - -TAILQ_HEAD(session_event_list, session_event); - -struct session -{ - const char *name; - enum session_type type; - enum session_state state; - struct session_data data; - struct session_event cur_ev; - struct session_event_list ev_list; - TAILQ_ENTRY(session) session_tq_entries; - UT_hash_handle hh; -}; - - - - -void session_manager_session_event_register(fn_session_event_callback session_ev_cb, session_type type); -struct session *session_manager_session_derive(const struct session *cur_session, session_type type);