Improving tests

This commit is contained in:
nik012003
2022-06-26 00:56:03 +02:00
committed by DomySh
parent bf3a97e9e0
commit 282438b005
3 changed files with 49 additions and 42 deletions

View File

@@ -5,6 +5,7 @@
#include <csignal> #include <csignal>
#include <fstream> #include <fstream>
#include <regex> #include <regex>
#include <mutex>
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
@@ -13,7 +14,7 @@
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
//#define DEBUG #define DEBUG
using namespace std; using namespace std;
@@ -38,18 +39,21 @@ unhexlify(InputIterator first, InputIterator last, OutputIterator ascii) {
return 0; return 0;
} }
vector<pair<string,regex>> regex_s_c_w, regex_c_s_w, regex_s_c_b, regex_c_s_b; vector<pair<string,regex>> *regex_s_c_w, *regex_c_s_w, *regex_s_c_b, *regex_c_s_b;
const char* config_file; const char* config_file;
mutex mtx;
bool filter_data(unsigned char* data, const size_t& bytes_transferred, vector<pair<string,regex>> const &blacklist, vector<pair<string,regex>> const &whitelist){ bool filter_data(unsigned char* data, const size_t& bytes_transferred, vector<pair<string,regex>> *const blacklist, vector<pair<string,regex>> *const whitelist){
#ifdef DEBUG #ifdef DEBUG_PACKET
cout << "---------------- Packet ----------------" << endl; cout << "---------------- Packet ----------------" << endl;
for(int i=0;i<bytes_transferred;i++){ for(int i=0;i<bytes_transferred;i++){
cout << data[i]; cout << data[i];
} }
cout << "\n" << "---------------- End Packet ----------------" << endl; cout << "\n" << "---------------- End Packet ----------------" << endl;
#endif #endif
for (pair<string,regex> ele:blacklist){ vector<pair<string,regex>> *bp = blacklist;
for (pair<string,regex> ele:*bp){
cout << "TRYING" << ele.first << endl;
cmatch what; cmatch what;
try{ try{
regex_search(reinterpret_cast<const char*>(data), reinterpret_cast<const char*>(data)+bytes_transferred, what, ele.second); regex_search(reinterpret_cast<const char*>(data), reinterpret_cast<const char*>(data)+bytes_transferred, what, ele.second);
@@ -61,7 +65,8 @@ bool filter_data(unsigned char* data, const size_t& bytes_transferred, vector<pa
cerr << "Error while matching regex: " << ele.first << endl; cerr << "Error while matching regex: " << ele.first << endl;
} }
} }
for (pair<string,regex> ele:whitelist){ vector<pair<string,regex>> *wp = whitelist;
for (pair<string,regex> ele:*wp){
cmatch what; cmatch what;
try{ try{
regex_search(reinterpret_cast<const char*>(data),reinterpret_cast<const char*>(data)+bytes_transferred, what, ele.second); regex_search(reinterpret_cast<const char*>(data),reinterpret_cast<const char*>(data)+bytes_transferred, what, ele.second);
@@ -320,7 +325,8 @@ namespace tcp_proxy
}; };
} }
void push_regex(char* arg, bool case_sensitive, vector<pair<string,regex>> &v){ void push_regex(char* arg, bool case_sensitive, vector<pair<string,regex>> *v){
std::unique_lock<std::mutex> lck(mtx);
size_t expr_len = (strlen(arg)-2)/2; size_t expr_len = (strlen(arg)-2)/2;
char expr[expr_len]; char expr[expr_len];
unhexlify(arg+2, arg+strlen(arg)-1, expr); unhexlify(arg+2, arg+strlen(arg)-1, expr);
@@ -331,13 +337,13 @@ void push_regex(char* arg, bool case_sensitive, vector<pair<string,regex>> &v){
#ifdef DEBUG #ifdef DEBUG
cout << "Added case sensitive regex " << expr_str << endl; cout << "Added case sensitive regex " << expr_str << endl;
#endif #endif
v.push_back(make_pair(string(arg), regex)); v->push_back(make_pair(string(arg), regex));
} else { } else {
regex regex(expr_str,regex_constants::icase); regex regex(expr_str,regex_constants::icase);
#ifdef DEBUG #ifdef DEBUG
cout << "Added case insensitive regex " << expr_str << endl; cout << "Added case insensitive regex " << expr_str << endl;
#endif #endif
v.push_back(make_pair(string(arg), regex)); v->push_back(make_pair(string(arg), regex));
} }
} catch(...){ } catch(...){
cerr << "Regex " << expr << " was not compiled successfully" << endl; cerr << "Regex " << expr << " was not compiled successfully" << endl;
@@ -352,11 +358,16 @@ void update_regex(){
cerr << "Error: config file couln't be opened" << endl; cerr << "Error: config file couln't be opened" << endl;
exit(1); exit(1);
} }
/*
regex_s_c_w.clear(); regex_s_c_w.reset(new vector<pair<string,regex>>);
regex_c_s_w.clear(); regex_c_s_w.reset(new vector<pair<string,regex>>);
regex_s_c_b.clear(); regex_s_c_b.reset(new vector<pair<string,regex>>);
regex_c_s_b.clear(); regex_c_s_b.reset(new vector<pair<string,regex>>);
*/
regex_s_c_w = new vector<pair<string,regex>>;
regex_c_s_w = new vector<pair<string,regex>>;
regex_s_c_b = new vector<pair<string,regex>>;
regex_c_s_b = new vector<pair<string,regex>>;
string line; string line;
while(getline(fd, line)){ while(getline(fd, line)){

View File

@@ -1,31 +1,29 @@
1C3733353138303461313162386234323563313931613664373937666264356630 1C3733353138303461313162386234323563313931613664373937666264356630
1S3733353138303461313162386234323563313931613664373937666264356630 1S3733353138303461313162386234323563313931613664373937666264356630
1S3065376433366539666631353833373263633764613966396235313538633766
1C3638316561366437356466353765656265383933396630326262393338336438
1S3638316561366437356466353765656265383933396630326262393338336438
1C3739663566343265663536633261656665623338346135616464633539663930
1S3739663566343265663536633261656665623338346135616464633539663930
1C3733353138303461313162386234323563313931613664373937666264356630
1S3733353138303461313162386234323563313931613664373937666264356630
1C3065376433366539666631353833373263633764613966396235313538633766 1C3065376433366539666631353833373263633764613966396235313538633766
1S3065376433366539666631353833373263633764613966396235313538633766 1S3065376433366539666631353833373263633764613966396235313538633766
1C3638316561366437356466353765656265383933396630326262393338336438 1C3638316561366437356466353765656265383933396630326262393338336438
1S3638316561366437356466353765656265383933396630326262393338336438 1S3638316561366437356466353765656265383933396630326262393338336438
1C3739663566343265663536633261656665623338346135616464633539663930 1C3739663566343265663536633261656665623338346135616464633539663930
1S3739663566343265663536633261656665623338346135616464633539663930 1S3739663566343265663536633261656665623338346135616464633539663930
1C3733353138303461313162386234323563313931613664373937666264356630 1C3733353138303461313162386234323563313931613664373937666264356630
1S3733353138303461313162386234323563313931613664373937666264356630 1S3733353138303461313162386234323563313931613664373937666264356630
1C3065376433366539666631353833373263633764613966396235313538633766 1C3065376433366539666631353833373263633764613966396235313538633766
1S3065376433366539666631353833373263633764613966396235313538633766 1S3065376433366539666631353833373263633764613966396235313538633766
1C3638316561366437356466353765656265383933396630326262393338336438 1C3638316561366437356466353765656265383933396630326262393338336438
1S3638316561366437356466353765656265383933396630326262393338336438 1S3638316561366437356466353765656265383933396630326262393338336438
1C3739663566343265663536633261656665623338346135616464633539663930 1C3739663566343265663536633261656665623338346135616464633539663930
1S3739663566343265663536633261656665623338346135616464633539663930 1S3739663566343265663536633261656665623338346135616464633539663930
1C3733353138303461313162386234323563313931613664373937666264356630 1C3733353138303461313162386234323563313931613664373937666264356630
1S3733353138303461313162386234323563313931613664373937666264356630 1S3733353138303461313162386234323563313931613664373937666264356630
1C3065376433366539666631353833373263633764613966396235313538633766 1C3065376433366539666631353833373263633764613966396235313538633766
1S3065376433366539666631353833373263633764613966396235313538633766
1C3638316561366437356466353765656265383933396630326262393338336438
1S3638316561366437356466353765656265383933396630326262393338336438
1C3739663566343265663536633261656665623338346135616464633539663930
1S3739663566343265663536633261656665623338346135616464633539663930
1C3733353138303461313162386234323563313931613664373937666264356630
1S3733353138303461313162386234323563313931613664373937666264356630
1C3065376433366539666631353833373263633764613966396235313538633766
1S3065376433366539666631353833373263633764613966396235313538633766
1C3638316561366437356466353765656265383933396630326262393338336438 1C3638316561366437356466353765656265383933396630326262393338336438
1S3638316561366437356466353765656265383933396630326262393338336438 1S3638316561366437356466353765656265383933396630326262393338336438
1C3739663566343265663536633261656665623338346135616464633539663930 1C3739663566343265663536633261656665623338346135616464633539663930

View File

@@ -33,7 +33,7 @@ parser.add_argument("--num_of_streams", "-s", type=int, required=False, help='Ou
args = parser.parse_args() args = parser.parse_args()
sep() sep()
puts(f"Benchmarking with {args.num_of_regexes} will start on ", color=colors.cyan, end="") puts(f"Benchmarking with {args.num_of_regexes} regexes will start on ", color=colors.cyan, end="")
puts(f"{args.address}", color=colors.yellow) puts(f"{args.address}", color=colors.yellow)
s = Session() s = Session()
@@ -77,9 +77,7 @@ def getReading(port):
client.port = port client.port = port
client.protocol = 'tcp' client.protocol = 'tcp'
client.num_streams = args.num_of_streams client.num_streams = args.num_of_streams
run = client.run() return round(client.run().json['end']['sum_received']['bits_per_second']/8e+6 , 3)
print(run)
return round(run.json['end']['sum_received']['bits_per_second']/8e+6 , 3)
server = Process(target=startServer) server = Process(target=startServer)
server.start() server.start()