summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-02-02 10:02:11 +0800
committeryangwei <[email protected]>2024-02-28 19:14:21 +0800
commitdee44c13354d1c3d7c0e5e1828f5175e55790f3a (patch)
treebc0adf5b95904a7ded7da7a1a5134b32feadc4df /include
parent9649bafbd6eef60541ab1a1e8e50e6d4312981c4 (diff)
🦄 refactor(API implementation): Refactor API to use new headers
Diffstat (limited to 'include')
-rw-r--r--include/stellar/session.h42
-rw-r--r--include/stellar/session_exdata.h10
-rw-r--r--include/stellar/session_mq.h24
-rw-r--r--include/stellar/stellar.h36
4 files changed, 48 insertions, 64 deletions
diff --git a/include/stellar/session.h b/include/stellar/session.h
index 1289c82..605aed0 100644
--- a/include/stellar/session.h
+++ b/include/stellar/session.h
@@ -1,10 +1,10 @@
#pragma once
+#include "stellar.h"
+
#include <stdint.h>
#include <stddef.h>
-#include "stellar.h"
-
enum session_type
{
SESSION_TYPE_TCP,
@@ -22,8 +22,7 @@ enum session_state
__SESSION_STATE_MAX,
};
-
-struct session;
+enum session_type session_get_type(struct session *sess);
#define SESSION_SEEN_C2S_FLOW (1 << 0)
#define SESSION_SEEN_S2C_FLOW (1 << 1)
@@ -43,8 +42,8 @@ int session_is_symmetric(struct session *sess, unsigned char *flag);
#define SESSION_IS_TUNNLE_SOCKS (1 << 8)
#define SESSION_IS_TUNNLE_HTTP_PROXY (1 << 9)
-int session_is_outer_tunnel(struct session *sess, uint64_t *flag);
-int session_is_inner_most(struct session *sess, uint64_t *flag);
+int session_is_outmost(struct session *sess, uint64_t *flag);
+int session_is_innermost(struct session *sess, uint64_t *flag);
#define SESSION_DIRECTION_IN 0
#define SESSION_DIRECTION_OUT 1
@@ -108,7 +107,6 @@ const char *session_get0_route_ctx(struct session *sess, int session_direction,
int session_set_session_id(struct session *sess, uint64_t session_id);
int session_set_preappend_segment_id_list(struct session *sess, uint16_t *sid, size_t sid_num);
-struct packet;
const struct packet *session_get0_current_packet(struct session *sess);
#define PACKET_DIRECTION_C2S 0
@@ -116,32 +114,4 @@ const struct packet *session_get0_current_packet(struct session *sess);
int packet_get_direction(const struct packet *pkt);
const char *packet_get0_data(const struct packet *pkt, size_t *data_len);
int packet_arrive_time(const struct packet *pkt, struct timeval *ts);
-
-
-
-
-#define SESS_EV_OPENING 1<<1
-#define SESS_EV_PACKET 1<<2
-#define SESS_EV_CLOSING 1<<3
-#define SESS_EV_CONTROL 1<<6
-
-#define SESS_EV_TCP 1<<4
-#define SESS_EV_UDP 1<<5
-
-
-typedef int session_event_cb_func(struct session *sess, int events, const struct packet *pkt, void *cb_arg);
-
-struct session_event;
-//return plugin_id
-int stellar_plugin_register(struct stellar *st, int events, session_event_cb_func *cb, void *cb_arg);// register intrinsic event
-struct session_event *session_get_intrinsic_event(struct session *sess, int plugin_id);
-
-void session_plugin_detach_others(struct session *sess, int plugin_id);
-
-#include <sys/time.h>
-
-struct session_event *session_event_new(struct stellar *st, struct session *sess, int events, session_event_cb_func *cb, void *cb_arg);
-int session_event_add(struct session_event *ev, const struct timeval *timeout);
-int session_event_del(struct session_event *ev);
-int session_event_assign(struct session_event *ev, struct stellar *st, struct session *sess, int events, session_event_cb_func *cb, void *cb_arg);
-void session_event_free(struct session_event *ev); \ No newline at end of file
+unsigned char packet_get_ip_protocol(struct packet *pkt);
diff --git a/include/stellar/session_exdata.h b/include/stellar/session_exdata.h
index b1febc2..6f97c94 100644
--- a/include/stellar/session_exdata.h
+++ b/include/stellar/session_exdata.h
@@ -1,10 +1,8 @@
#pragma once
-#include "session.h"
#include "stellar.h"
-typedef void session_ex_free(struct session *sess, int idx, void *ex_ptr, void *arg);
-int stellar_session_get_ex_new_index(struct stellar *st, const char *name, session_ex_free *free_func,void *arg);
-int session_set_ex_data(struct session *sess, int idx, void *ex_ptr);
-void *session_get_ex_data(struct session *sess, int idx);
-
+typedef void session_exdata_free(struct session *sess, int idx, void *ex_ptr, void *arg);
+int stellar_session_exdata_new_index(struct stellar *st, const char *name, session_exdata_free *free_func,void *arg);
+int session_exdata_set(struct session *sess, int idx, void *ex_ptr);
+void *session_exdata_get(struct session *sess, int idx); \ No newline at end of file
diff --git a/include/stellar/session_mq.h b/include/stellar/session_mq.h
index 72c5af4..bb3be4d 100644
--- a/include/stellar/session_mq.h
+++ b/include/stellar/session_mq.h
@@ -1,24 +1,24 @@
#pragma once
-#include "session.h"
#include "stellar.h"
-#include <sys/time.h>
-
//session mq
-typedef void msg_free_cb_func(void *msg, void *cb_arg);
-typedef int on_msg_cb_func(struct session *sess, int topic_id, const void *msg, void *cb_arg);
+typedef void msg_free_cb_func(void *msg, void *msg_free_arg);
+typedef void on_msg_cb_func(struct session *sess, int topic_id, const void *msg, void *per_session_ctx, void *plugin_env);
//return topic_id
-int session_mq_create_topic(struct stellar *st, const char *topic_name, msg_free_cb_func *free_cb, void *cb_arg);
-int session_mq_get_topic_id(struct stellar *st, const char *topic_name);
+int stellar_session_mq_create_topic(struct stellar *st, const char *topic_name, msg_free_cb_func *msg_free_cb, void *msg_free_arg);
+
+int stellar_session_mq_get_topic_id(struct stellar *st, const char *topic_name);
-int session_mq_update_topic(struct stellar *st, int topic_id, msg_free_cb_func *free_cb, void *cb_arg);
+int stellar_session_mq_update_topic(struct stellar *st, int topic_id, msg_free_cb_func *msg_free_cb, void *msg_free_arg);
-int session_mq_destroy_topic(struct stellar *st, int topic_id);
+int stellar_session_mq_destroy_topic(struct stellar *st, int topic_id);
-//return sub_id >=0 if success, otherwise return -1.
-int session_mq_subscribe_topic(struct stellar *st, int topic_id, on_msg_cb_func *sub_cb, void *cb_arg);
+//return 0 if success, otherwise return -1.
+int stellar_session_mq_subscribe(struct stellar *st, int topic_id, on_msg_cb_func *plugin_on_msg_cb, int plugin_id);
int session_mq_publish_message(struct session *sess, int topic_id, void *msg);
-int session_mq_ignore_message(struct session *sess, int topic_id, int sub_id); \ No newline at end of file
+
+int session_mq_ignore_message(struct session *sess, int topic_id, int plugin_id);
+int session_mq_unignore_message(struct session *sess, int topic_id, int plugin_id);
diff --git a/include/stellar/stellar.h b/include/stellar/stellar.h
index c10c8ec..a41a159 100644
--- a/include/stellar/stellar.h
+++ b/include/stellar/stellar.h
@@ -1,20 +1,36 @@
#pragma once
-#include <sys/time.h>
-
+struct session;
struct stellar;
-int stellar_get_worker_thread_num(struct stellar *st);
-int stellar_get_current_thread_id(struct stellar *st);
+//return plugin_env
+typedef void *plugin_on_load_func(struct stellar *st);
+typedef void plugin_on_unload_func(void *plugin_env);
+
+//return per_session_ctx
+typedef void *session_ctx_new_func(struct session *sess, void *plugin_env);
+typedef void session_ctx_free_func(struct session *sess, void *session_ctx, void *plugin_env);
+
+#define TOPIC_TCP "TCP"
+#define TOPIC_TCP_STREAM "TCP_STREAM"
+#define TOPIC_UDP "UDP"
+#define TOPIC_EGRESS "EGRESS"
+#define TOPIC_CONTROL_PACKET "CONTROL_PACKET"
+
+//return session plugin_id
+int stellar_session_plugin_register(struct stellar *st,
+ session_ctx_new_func session_ctx_new,
+ session_ctx_free_func session_ctx_free,
+ void *plugin_env);
+
+void stellar_session_plugin_dettach_current_session(struct session *sess);
-int stellar_get_session_mq_topic_cnt(struct stellar *st);
-int stellar_get_session_mq_subscriber_cnt(struct stellar *st, int topic_id);
-typedef void *plugin_init_callback(struct stellar *st);
-typedef void plugin_exit_callback(void *plugin_ctx);
+struct packet;
+typedef void *plugin_on_packet_func(struct packet *pkt, unsigned char ip_protocol, void *plugin_env);
-typedef int stellar_periodic_cb_func(struct stellar *st, void *cb_arg);
+//return packet plugin_id
+int stellar_packet_plugin_register(struct stellar *st, unsigned char ip_protocol, plugin_on_packet_func on_packet, void *plugin_env);
-int stellar_worker_thread_periodic_add(struct stellar *st, stellar_periodic_cb_func *periodic_cb, void *cb_arg, const struct timeval *interval);