Add duplicated packet filter
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "packet.h"
|
||||
#include "timestamp.h"
|
||||
#include "session_manager.h"
|
||||
#include "dupkt_filter.h"
|
||||
|
||||
#ifndef STELLAR_LOG_ERROR
|
||||
#define STELLAR_LOG_ERROR(format, ...) \
|
||||
@@ -30,23 +31,41 @@ struct thread_ctx
|
||||
uint64_t need_exit;
|
||||
uint64_t is_runing;
|
||||
struct session_manager *sess_mgr;
|
||||
struct dupkt_filter *dupkt_filter;
|
||||
};
|
||||
|
||||
struct stellar_ctx
|
||||
{
|
||||
uint64_t need_exit;
|
||||
uint16_t max_worker_num;
|
||||
|
||||
// session manager
|
||||
uint64_t sess_mgr_max_session_num;
|
||||
uint64_t sess_mgr_timeout_ms_toclsoing;
|
||||
uint64_t sess_mgr_timeout_ms_toclosed;
|
||||
|
||||
// duplicated packet filter
|
||||
uint8_t dupkt_filter_enable;
|
||||
unsigned int dupkt_filter_capacity;
|
||||
double dupkt_filter_error_rate;
|
||||
int dupkt_filter_timeout_s;
|
||||
|
||||
// thread
|
||||
struct thread_ctx thread_ctx[128];
|
||||
} g_stellar_ctx = {
|
||||
.need_exit = 0,
|
||||
.max_worker_num = 1,
|
||||
|
||||
// session manager
|
||||
.sess_mgr_max_session_num = 1000000,
|
||||
.sess_mgr_timeout_ms_toclsoing = 1000,
|
||||
.sess_mgr_timeout_ms_toclosed = 10000,
|
||||
};
|
||||
|
||||
// duplicated packet filter
|
||||
.dupkt_filter_enable = 1,
|
||||
.dupkt_filter_capacity = 1000000,
|
||||
.dupkt_filter_error_rate = 0.0001,
|
||||
.dupkt_filter_timeout_s = 10};
|
||||
|
||||
// TODO
|
||||
static int recv_packet(const char **data)
|
||||
@@ -98,11 +117,15 @@ static void thread_ctx_init(struct stellar_ctx *ctx)
|
||||
thd_ctx->index = i;
|
||||
thd_ctx->need_exit = 0;
|
||||
thd_ctx->is_runing = 0;
|
||||
// session manager
|
||||
thd_ctx->sess_mgr = session_manager_create(ctx->sess_mgr_max_session_num);
|
||||
assert(thd_ctx->sess_mgr != NULL);
|
||||
session_manager_set_session_eventcb(thd_ctx->sess_mgr, plugin_dispatch, thd_ctx);
|
||||
session_manager_set_timeout_toclosing(thd_ctx->sess_mgr, ctx->sess_mgr_timeout_ms_toclsoing);
|
||||
session_manager_set_timeout_toclosed(thd_ctx->sess_mgr, ctx->sess_mgr_timeout_ms_toclosed);
|
||||
// duplicated packet filter
|
||||
thd_ctx->dupkt_filter = dupkt_filter_create(ctx->dupkt_filter_enable, ctx->dupkt_filter_capacity, ctx->dupkt_filter_error_rate, ctx->dupkt_filter_timeout_s);
|
||||
assert(thd_ctx->dupkt_filter != NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +149,7 @@ static void *thread_cycle(void *arg)
|
||||
struct session *sess = NULL;
|
||||
struct thread_ctx *thd_ctx = (struct thread_ctx *)arg;
|
||||
struct session_manager *sess_mgr = thd_ctx->sess_mgr;
|
||||
struct dupkt_filter *dupkt_filter = thd_ctx->dupkt_filter;
|
||||
char thread_name[16];
|
||||
|
||||
ATOMIC_SET(&thd_ctx->is_runing, 1);
|
||||
@@ -141,7 +165,12 @@ static void *thread_cycle(void *arg)
|
||||
// parse packet
|
||||
packet_parse(&pkt, data, len);
|
||||
|
||||
// TODO duplicated packet filter
|
||||
// duplicated packet filter
|
||||
if (dupkt_filter_search(dupkt_filter, &pkt) == 0)
|
||||
{
|
||||
STELLAR_LOG_DEBUG("duplicated packet, forward it");
|
||||
goto fast_forward;
|
||||
}
|
||||
|
||||
// update session
|
||||
sess = session_manager_update(sess_mgr, &pkt);
|
||||
@@ -149,7 +178,11 @@ static void *thread_cycle(void *arg)
|
||||
{
|
||||
goto fast_forward;
|
||||
}
|
||||
|
||||
// TODO session synchronization
|
||||
|
||||
session_manager_dispatch(sess_mgr, sess);
|
||||
dupkt_filter_add(dupkt_filter, &pkt);
|
||||
|
||||
fast_forward:
|
||||
// TODO send packet
|
||||
|
||||
Reference in New Issue
Block a user