123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- #ifndef BOTNET_COMM_PROCESSOR_H
- #define BOTNET_COMM_PROCESSOR_H
- #include <iostream>
- #include <boost/python.hpp>
- #include <boost/algorithm/string/replace.hpp>
- #include <vector>
- #include <thread>
- #include <deque>
- #include <set>
- #include <future>
- #include <fstream>
- #include <string>
- #include <istream>
- #include <iomanip>
- #define TIMEOUT 3
- #define SALITY_NL_REQUEST 101
- #define SALITY_NL_REPLY 102
- #define SALITY_HELLO 103
- #define SALITY_HELLO_REPLY 104
- #define EPS_TOLERANCE 1e-12
- namespace py = boost::python;
- struct abstract_msg {
-
- abstract_msg (unsigned int src, unsigned int dst, unsigned short type, double time, int line_no) :
- src(src), dst(dst), type(type), time(time), line_no(line_no) {}
- abstract_msg () {}
-
- unsigned int src = 0;
- unsigned int dst = 0;
- unsigned short type = 0;
- double time = 0.0;
- int line_no = -1;
- };
- struct comm_interval {
- std::set<unsigned int> ids;
- unsigned int comm_sum;
- unsigned int start_idx;
- unsigned int end_idx;
- };
- int greater_than(double a, double b){
- return b - a < -1 * EPS_TOLERANCE;
- }
- class botnet_comm_processor {
- public:
-
- botnet_comm_processor();
- botnet_comm_processor(const py::list &messages_pyboost);
-
- py::dict find_interval_from_startidx(int start_idx, int number_ids, double max_int_time);
- py::dict find_interval_from_endidx(int end_idx, int number_ids, double max_int_time);
- py::list find_optimal_interval(int number_ids, double max_int_time);
- py::list get_interval_init_ids(int start_idx, int end_idx);
- py::list get_messages(unsigned int start_idx, unsigned int end_idx);
- int get_message_count();
- unsigned int parse_csv(const std::string &);
- unsigned int parse_xml(const std::string &);
- void set_messages(const py::list &messages_pyboost);
- std::string write_xml(const std::string &);
- private:
-
- py::list convert_intervals_to_py_repr(const std::vector<comm_interval>& intervals);
- void find_optimal_interval_helper(std::promise<std::vector<comm_interval> > && p, int number_ids, double max_int_time, int start_idx, int end_idx);
- int msgtype_is_request(unsigned short mtype);
- int msgtype_is_response(unsigned short mtype);
-
- void process_csv_attrib(abstract_msg &msg, const std::string &cur_word);
- void process_kv(abstract_msg &msg, const std::string &key, const std::string &value);
- void process_xml_attrib_assign(abstract_msg &msg, const std::string &cur_word);
-
- std::vector<abstract_msg> messages;
- };
- #endif
|