/* * Class for processing messages containing abstract Membership Management Communication. * A message has to consist of (namely): Src, Dst, Type, Time. */ #ifndef BOTNET_COMM_PROCESSOR_H #define BOTNET_COMM_PROCESSOR_H #include #include #include #include #include #include #include #include /* * Botnet communication types (equal to the ones contained in the MessageType class in MembersMgmtCommAttack.py) */ #define TIMEOUT 3 #define SALITY_NL_REQUEST 101 #define SALITY_NL_REPLY 102 #define SALITY_HELLO 103 #define SALITY_HELLO_REPLY 104 /* * Needed because of machine inprecision. E.g a time difference of 0.1s is stored as >0.1s */ #define EPS_TOLERANCE 1e-12 // works for a difference of 0.1 /* * For quick usage */ namespace py = boost::python; /* * Definition of structs */ /* * Struct used as data structure to represent an abstract communication message: * - Source ID * - Destination ID * - Message type * - Time of message */ struct abstract_msg { unsigned int src; unsigned int dst; unsigned short type; double time; }; /* * Struct used as data structure to represent an interval of communication: * - A set of all initiator IDs contained in the interval * - The number of messages sent in the interval (excluding timeouts) * - The start index of the interval with respect to the member variable 'packets' * - The end index of the interval with respect to the member variable 'packets' */ struct comm_interval { std::set ids; unsigned int comm_sum; unsigned int start_idx; unsigned int end_idx; }; /* * A greater than operator desgined to handle slight machine inprecision up to EPS_TOLERANCE. * @param a The first number * @param b The second number * @return true (1) if a > b, otherwise false(0) */ int greater_than(double a, double b){ return b - a < -1 * EPS_TOLERANCE; } class botnet_comm_processor { public: /* * Class constructor */ botnet_comm_processor(py::list packets); /* * Methods */ py::list find_interval(int number_ids, double max_int_time); private: /* * Methods */ void print_message(abstract_msg packet); int msgtype_is_request(unsigned short mtype); int msgtype_is_response(unsigned short mtype); // py::list std_vector_to_py_list(std::vector intervals) py::list convert_to_py_repr(const std::vector& intervals); void find_interval_helper(std::promise > && p, int number_ids, double max_int_time, int start_idx, int end_idx); /* * Attributes */ std::vector messages; }; #endif //BOTNET_COMM_PROCESSOR_H