update session manager interface definition; define ex_data interface; delete the event design
This commit is contained in:
12
src/main.cpp
12
src/main.cpp
@@ -28,20 +28,20 @@ struct stellar_event_base_loop_arg
|
||||
void *stellar_event_base_loop(void *arg)
|
||||
{
|
||||
struct stellar_packet *rx_pkt;
|
||||
struct stellar_event *event;
|
||||
struct stellar_session *session;
|
||||
struct stellar_event_base_loop_arg *thread_arg = (struct stellar_event_base_loop_arg *)arg;
|
||||
while(1)
|
||||
{
|
||||
int fetch_num = packet_io_device_rx(thread_arg->dev, thread_arg->tid, &rx_pkt, 1);
|
||||
if(fetch_num > 0)
|
||||
{
|
||||
event = session_manager_commit(thread_arg->session_mgr, rx_pkt);
|
||||
while(event)
|
||||
session = session_manager_commit(thread_arg->session_mgr, rx_pkt, thread_arg->tid);
|
||||
while(session)
|
||||
{
|
||||
plugin_manager_dispatch(thread_arg->plug_mgr ,event);
|
||||
event = session_manager_fetch_event(thread_arg->session_mgr);
|
||||
plugin_manager_dispatch(thread_arg->plug_mgr ,session);
|
||||
session = session_manager_fetch_session(thread_arg->session_mgr, session, thread_arg->tid);
|
||||
}
|
||||
|
||||
|
||||
//clean session_manager event queue
|
||||
packet_io_device_tx(thread_arg->dev, thread_arg->tid, &rx_pkt, 1);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ extern "C" void custom_event_plugin_tcp_entry(const struct stellar_session *sess
|
||||
{
|
||||
(*per_tcp_session_ctx)->flags = SESSION_EVENT_ORDPKT;
|
||||
|
||||
struct stellar_session_event_extras *info = (struct stellar_session_event_extras *)custom_decode(payload, len, ctx);
|
||||
struct session_event_extras *info = (struct session_event_extras *)custom_decode(payload, len, ctx);
|
||||
struct stellar_session *new_session = session_manager_session_derive(session, "CUSTOM");
|
||||
|
||||
session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info);
|
||||
|
||||
@@ -3,13 +3,9 @@
|
||||
#include "sdk/include/session.h"
|
||||
#include "sdk/include/http.h"
|
||||
|
||||
void http_entry(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx)
|
||||
void http_entry(const struct stellar_session *session, enum session_state state, int thread_id, void **ctx)
|
||||
{
|
||||
struct stellar_session_event_extras *info = NULL;
|
||||
struct stellar_session *new_session = session_manager_session_derive(session, "HTTP");
|
||||
|
||||
session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info);
|
||||
session_manager_trigger_event(new_session, SESSION_EVENT_META, info);
|
||||
struct stellar_session *new_session = session_derive(session, "HTTP");
|
||||
}
|
||||
|
||||
struct http_decoder *http_session_get_decoder(const struct stellar_session *http_session)
|
||||
@@ -28,4 +24,4 @@ void http_decoder_fetch_request_line(struct http_decoder *decoder, struct http_r
|
||||
|
||||
void http_decoder_fetch_status_line(struct http_decoder *decoder, struct http_status_line *status_line)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
add_library(session_manager
|
||||
session_manager.cpp
|
||||
session_ex_data.cpp
|
||||
session_utils.cpp
|
||||
parser/ethernet.cpp
|
||||
)
|
||||
target_include_directories(session_manager PUBLIC ${CMAKE_SOURCE_DIR})
|
||||
target_include_directories(session_manager PUBLIC ${CMAKE_SOURCE_DIR})
|
||||
|
||||
0
src/session_manager/parser/ethernet.cpp
Normal file
0
src/session_manager/parser/ethernet.cpp
Normal file
30
src/session_manager/session_ex_data.cpp
Normal file
30
src/session_manager/session_ex_data.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "session_ex_data.h"
|
||||
#include "sdk/include/session.h"
|
||||
|
||||
int session_get_ex_data_index(struct stellar_session *session, const char *key)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *session_get_ex_data(struct stellar_session *session, int idx)
|
||||
{
|
||||
return nullptr;
|
||||
|
||||
}
|
||||
void session_set_ex_data(struct stellar_session *session, int idx, void *ex_data, free_ex_data *free_cb, void *cb_arg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void session_del_ex_data(struct stellar_session *session, int idx, free_ex_data *free_cb, void *cb_arg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void session_trigger_ex_data_event(stellar_session *session, int idx, enum session_state state)
|
||||
{
|
||||
|
||||
}
|
||||
18
src/session_manager/session_ex_data.h
Normal file
18
src/session_manager/session_ex_data.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef _SESSION_EX_DATA_H_
|
||||
#define _SESSION_EX_DATA_H_
|
||||
|
||||
#ifdef __cpluscplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
62
src/session_manager/session_internal_types.h
Normal file
62
src/session_manager/session_internal_types.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#ifndef _SESSION_INTERNAL_TYPES_H_
|
||||
#define _SESSION_INTERNAL_TYPES_H_
|
||||
|
||||
#ifdef __cpluscplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "sdk/include/types.h"
|
||||
#include "sdk/include/session.h"
|
||||
|
||||
struct layer_addr
|
||||
{
|
||||
enum addr_type type; /* definition in enum addr_type */
|
||||
uint8_t addrlen;
|
||||
//uint8_t pkttype; /* packet special features, definition in MACRO PKT_TYPE_xxx */
|
||||
//uint8_t pktipfragtype; /* ip frag packetfeatures, definition in MACRO PKT_TYPE_xxx */
|
||||
uint8_t padding[3]; /* pad for alignment */
|
||||
union
|
||||
{
|
||||
struct layer_addr_mac *mac;
|
||||
struct layer_addr_ipv4 *ipv4;
|
||||
struct layer_addr_ipv6 *ipv6;
|
||||
struct layer_addr_vlan *vlan;
|
||||
//struct layer_addr_gre *gre;
|
||||
struct layer_addr_tuple4 *tcp;
|
||||
struct layer_addr_tuple6 *udp;
|
||||
struct layer_addr_pppoe *pppoe;
|
||||
struct layer_addr_l2tp *l2tp;
|
||||
struct layer_addr_pptp *pptp;
|
||||
struct layer_addr_gtp *gtp;
|
||||
struct layer_addr_mpls *mpls;
|
||||
void *paddr;
|
||||
};
|
||||
};
|
||||
|
||||
struct stellar_session
|
||||
{
|
||||
const char *name;
|
||||
uint8_t is_tunnel:1;
|
||||
uint8_t padding:3;
|
||||
uint8_t session_dir:2;
|
||||
uint8_t current_dir:2;
|
||||
uint8_t close_reason;
|
||||
uint32_t hash_index;
|
||||
uint64_t createtime; // struct timespec
|
||||
uint64_t lastmtime; // struct timespec
|
||||
enum session_type type;
|
||||
struct layer_addr *addr;
|
||||
void *ex_data; // array or list
|
||||
struct session_manager *instance;
|
||||
struct stellar_session *next;
|
||||
struct stellar_session *prev;
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,97 +5,45 @@
|
||||
|
||||
struct session_manager
|
||||
{
|
||||
int thread_num;
|
||||
uint32_t tcp_timeout_s;
|
||||
uint32_t tcp_table_max_size;
|
||||
uint32_t tcp_reordered_num;
|
||||
uint32_t udp_timeout_s;
|
||||
uint32_t udp_table_max_size;
|
||||
struct stellar_session **tcp_table;
|
||||
struct stellar_session **udp_table;
|
||||
struct stellar_session **udp_table;
|
||||
};
|
||||
|
||||
struct session_manager *session_manager_init()
|
||||
void session_close(const struct stellar_session *session)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
struct stellar_session *session_derive(const struct stellar_session *this_session, const char *session_name)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void session_manager_trigger_event(struct stellar_session *s, enum session_event_type type, struct stellar_session_event_extras *info)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
struct stellar_session *session_manager_session_derive(const struct stellar_session *this_session, const char *session_name)
|
||||
struct session_manager *session_manager_create(int thread_num)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
struct stellar_event *session_manager_commit(struct session_manager *h, struct stellar_packet *p)
|
||||
void session_manager_destroy(struct session_manager *instance)
|
||||
{
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
struct stellar_event *session_manager_fetch_event(struct session_manager *h)
|
||||
struct stellar_session *session_manager_commit(struct session_manager *instance, struct stellar_packet *pkt, int thread_id)
|
||||
{
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* stellar_event API For Plugin Manager
|
||||
******************************************************************************/
|
||||
|
||||
struct session_plugin_ctx *stellar_event_get_plugin_ctx(struct stellar_event *event)
|
||||
struct stellar_session *session_manager_fetch_session(struct session_manager *instance, struct stellar_session *session, int thread_id)
|
||||
{
|
||||
return event->session_event_data->plugin_ctx;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void stellar_event_set_plugin_ctx(struct stellar_event *event, struct session_plugin_ctx *plugin_ctx)
|
||||
{
|
||||
event->session_event_data->plugin_ctx = plugin_ctx;
|
||||
}
|
||||
|
||||
enum session_event_type stellar_event_get_type(struct stellar_event *event)
|
||||
{
|
||||
return event->session_event_data->type;
|
||||
}
|
||||
|
||||
const char *stellar_event_get_session_name(struct stellar_event *event)
|
||||
{
|
||||
return event->session_event_data->s->name;
|
||||
}
|
||||
|
||||
const struct stellar_session *stellar_event_get_session(struct stellar_event *event)
|
||||
{
|
||||
return event->session_event_data->s;
|
||||
}
|
||||
|
||||
// TODO
|
||||
struct stellar_packet *stellar_event_get_packet(struct stellar_event *event)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// TODO
|
||||
const char *stellar_event_get_payload(struct stellar_event *event)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// TODO
|
||||
uint16_t stellar_event_get_payload_length(struct stellar_event *event)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* stellar_session API For Plugin Manager
|
||||
******************************************************************************/
|
||||
|
||||
struct session_plugin_ctx *stellar_session_get_plugin_ctx(const struct stellar_session *session)
|
||||
{
|
||||
struct stellar_session_event_data *evdata = session->event_data;
|
||||
return evdata->plugin_ctx;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* stellar_session API For Plugin
|
||||
******************************************************************************/
|
||||
|
||||
const char *stellar_session_get_name(const struct stellar_session *session)
|
||||
{
|
||||
return session->name;
|
||||
}
|
||||
@@ -1,47 +1,23 @@
|
||||
#pragma once
|
||||
#ifndef _SESSION_MANAGER_H_
|
||||
#define _SESSION_MANAGER_H_
|
||||
|
||||
#ifdef __cpluscplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "sdk/include/session.h"
|
||||
|
||||
struct stellar_session_event_data
|
||||
{
|
||||
struct stellar_session *s;
|
||||
enum session_event_type type;
|
||||
long last_active;
|
||||
struct session_plugin_ctx *plugin_ctx;
|
||||
};
|
||||
|
||||
struct session_manager;
|
||||
struct session_manager *session_manager_init();
|
||||
struct session_manager *session_manager_create(int thread_num);
|
||||
void session_manager_destroy(struct session_manager *instance);
|
||||
|
||||
struct stellar_event *session_manager_commit(struct session_manager *session_mgr, struct stellar_packet *pkt);
|
||||
struct stellar_event *session_manager_fetch_event(struct session_manager *session_mgr);
|
||||
struct stellar_session *session_manager_commit(struct session_manager *instance, struct stellar_packet *pkt, int thread_id);
|
||||
struct stellar_session *session_manager_fetch_session(struct session_manager *instance, struct stellar_session *session, int thread_id);
|
||||
|
||||
struct stellar_session
|
||||
{
|
||||
stellar_session_type type;
|
||||
const char *name;
|
||||
void *addr;
|
||||
void *data;
|
||||
struct stellar_session_event_data *event_data;
|
||||
};
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* stellar_event API For Plugin Manager
|
||||
******************************************************************************/
|
||||
#endif
|
||||
|
||||
struct session_plugin_ctx *stellar_event_get_plugin_ctx(struct stellar_event *event);
|
||||
void stellar_event_set_plugin_ctx(struct stellar_event *event, struct session_plugin_ctx *plugin_ctx);
|
||||
|
||||
enum session_event_type stellar_event_get_type(struct stellar_event *event);
|
||||
const char *stellar_event_get_session_name(struct stellar_event *event);
|
||||
const struct stellar_session *stellar_event_get_session(struct stellar_event *event);
|
||||
struct stellar_packet *stellar_event_get_packet(struct stellar_event *event);
|
||||
|
||||
const char *stellar_event_get_payload(struct stellar_event *event);
|
||||
uint16_t stellar_event_get_payload_length(struct stellar_event *event);
|
||||
|
||||
/******************************************************************************
|
||||
* stellar_session API For Plugin Manager
|
||||
******************************************************************************/
|
||||
|
||||
struct session_plugin_ctx *stellar_session_get_plugin_ctx(const struct stellar_session *session);
|
||||
55
src/session_manager/session_utils.cpp
Normal file
55
src/session_manager/session_utils.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include "session_internal_types.h"
|
||||
|
||||
|
||||
const char *session_get_name(const struct stellar_session *session)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint8_t session_get_direction(const struct stellar_session *session)
|
||||
{
|
||||
return SESSION_DIR_DOUBLE;
|
||||
}
|
||||
|
||||
uint8_t session_get_current_direction(const struct stellar_session *session)
|
||||
{
|
||||
return SESSION_DIR_C2S;
|
||||
}
|
||||
|
||||
uint64_t session_get_createtime_ms(const struct stellar_session *session)
|
||||
{
|
||||
return 123456778;
|
||||
}
|
||||
|
||||
uint64_t session_get_lasttime_ms(const struct stellar_session *session)
|
||||
{
|
||||
return 123457890;
|
||||
}
|
||||
|
||||
enum session_type session_get_type(const struct stellar_session *session)
|
||||
{
|
||||
return SESSION_TYPE_TCP;
|
||||
}
|
||||
|
||||
struct stellar_packet *session_get_packet(struct stellar_session *session)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
enum session_state session_get_state(struct stellar_session *session)
|
||||
{
|
||||
return SESSION_STATE_ACTIVE;
|
||||
}
|
||||
|
||||
const char *session_get_payload(struct stellar_session *session)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t session_get_payload_length(struct stellar_session *session)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user