Merge branch develop-0.0
This commit is contained in:
81
src/main.cpp
81
src/main.cpp
@@ -7,38 +7,43 @@
|
||||
***********************************************************************************************
|
||||
*/
|
||||
|
||||
#include "./common/global_var.h"
|
||||
#include "./packet_io/packet_io.h"
|
||||
#include "./session_manager/session_manager.h"
|
||||
#include "./plugin_manager/plugin_manager.h"
|
||||
#include "../sdk/include/http.h"
|
||||
#include "../sdk/include/logger.h"
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct packet_io_loop_arg
|
||||
#include "global_var.h"
|
||||
#include "logger.h"
|
||||
#include "packet_io.h"
|
||||
#include "session_manager.h"
|
||||
#include "plugin_manager.h"
|
||||
#include "http.h"
|
||||
|
||||
struct stellar_event_base_loop_arg
|
||||
{
|
||||
struct packet_io_device *dev;
|
||||
int thread_id;
|
||||
struct session_manager *session_mgr;
|
||||
struct plugin_manager *plug_mgr;
|
||||
int tid;
|
||||
};
|
||||
|
||||
void packet_io_loop(struct packet_io_loop_arg *arg)
|
||||
void *stellar_event_base_loop(void *arg)
|
||||
{
|
||||
struct packet *rx_pkt;
|
||||
struct session_event *event;
|
||||
struct stellar_packet *rx_pkt;
|
||||
struct stellar_event *event;
|
||||
struct stellar_event_base_loop_arg *thread_arg = (struct stellar_event_base_loop_arg *)arg;
|
||||
while(1)
|
||||
{
|
||||
int fetch_num = packet_io_device_rx(arg->dev, arg->thread_id, &rx_pkt, 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(rx_pkt);
|
||||
event = session_manager_commit(thread_arg->session_mgr, rx_pkt);
|
||||
while(event)
|
||||
{
|
||||
plugin_manager_dispatch(event);
|
||||
event = session_manager_fetch_event();
|
||||
}*/
|
||||
printf("fetch_num:%d\n", fetch_num);
|
||||
plugin_manager_dispatch(thread_arg->plug_mgr ,event);
|
||||
event = session_manager_fetch_event(thread_arg->session_mgr);
|
||||
}
|
||||
|
||||
//clean session_manager event queue
|
||||
packet_io_device_tx(arg->dev, arg->thread_id, &rx_pkt, 1);
|
||||
packet_io_device_tx(thread_arg->dev, thread_arg->tid, &rx_pkt, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -48,7 +53,7 @@ void packet_io_loop(struct packet_io_loop_arg *arg)
|
||||
//dispatch to trigger polling event
|
||||
}
|
||||
}
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,23 +76,33 @@ packet_io_init(const char *instance_name, const enum packet_io_run_mode mode, co
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
/* global engine instance init */
|
||||
memset(&g_engine_instance, 0, sizeof(g_engine_instance));
|
||||
//packet_io_init
|
||||
struct packet_io_device *dev = packet_io_init("stellar", PACKET_IO_RUN_MODE_PCAP_LIVE, 2);
|
||||
|
||||
g_engine_instance.config.packet_io.mode = PACKET_IO_RUN_MODE_PCAP_FILE;
|
||||
strncpy(g_engine_instance.config.packet_io.dev_name[0], "./test.pcap", sizeof(NAME_MAX));
|
||||
g_engine_instance.config.packet_io.dev_cnt = 1;
|
||||
//manager_init
|
||||
struct session_manager *session_mgr = session_manager_init();
|
||||
struct plugin_manager *plug_mgr = plugin_manager_create();
|
||||
|
||||
/* packet io init */
|
||||
packet_io_init("stellar", g_engine_instance.config.packet_io.mode, 2);
|
||||
// register build-in plugin
|
||||
plugin_manager_register(plug_mgr, "HTTP", SESSION_EVENT_ALL, http_decoder);
|
||||
|
||||
// load external plugins
|
||||
char file_path[] = "./plugs/plugins.inf";
|
||||
plugin_manager_load(plug_mgr, file_path);
|
||||
|
||||
//session_manager_session_event_register(http_decoder, SESSION_TYPE_HTTP);
|
||||
struct packet_io_loop_arg arg;
|
||||
while (1) {
|
||||
//packet_io_loop();
|
||||
}
|
||||
//create_worker_thread
|
||||
|
||||
stellar_event_base_loop_arg arg = {dev, session_mgr, plug_mgr, 0};
|
||||
pthread_t worker_pid;
|
||||
pthread_create(&worker_pid, nullptr, stellar_event_base_loop, (void *)&arg);
|
||||
//main_loop
|
||||
while (1)
|
||||
{
|
||||
/* main loop code */
|
||||
usleep(1);
|
||||
}
|
||||
|
||||
plugin_manager_unload(plug_mgr);
|
||||
plugin_manager_destory(plug_mgr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user