diff --git a/backend/app.py b/backend/app.py index fcae439..6ee7d0d 100644 --- a/backend/app.py +++ b/backend/app.py @@ -64,6 +64,7 @@ def get_status(): @app.route("/api/login", methods = ['POST']) def login(): + if DEBUG: return { "status":"ok" } if app.config["STATUS"] != "run": return abort(404) req = request.get_json(force = True) @@ -89,12 +90,14 @@ def login(): @app.route("/api/logout") def logout(): + if DEBUG: return { "status":"ok" } session["loggined"] = False return { "status":"ok" } @app.route('/api/change-password', methods = ['POST']) @login_required def change_password(): + if DEBUG: return { "status":"ok" } if app.config["STATUS"] != "run": return abort(404) req = request.get_json(force = True) @@ -123,6 +126,7 @@ def change_password(): @app.route('/api/set-password', methods = ['POST']) def set_password(): + if DEBUG: return { "status":"ok" } if app.config["STATUS"] != "init": return abort(404) req = request.get_json(force = True) try: diff --git a/backend/proxy/proxy.cpp b/backend/proxy/proxy.cpp index 24c7aff..370dd1d 100644 --- a/backend/proxy/proxy.cpp +++ b/backend/proxy/proxy.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include @@ -45,15 +45,15 @@ struct regex_rules{ shared_ptr regex_config; const char* config_file; -mutex mtx; +mutex update_mutex; bool filter_data(unsigned char* data, const size_t& bytes_transferred, vector> const &blacklist, vector> const &whitelist){ #ifdef DEBUG_PACKET - cout << "---------------- Packet ----------------" << endl; + cerr << "---------------- Packet ----------------" << endl; for(int i=0;i ele:blacklist){ try{ @@ -76,7 +76,7 @@ bool filter_data(unsigned char* data, const size_t& bytes_transferred, vector> &v){ - std::unique_lock lck(mtx); size_t expr_len = (strlen(arg)-2)/2; char expr[expr_len]; unhexlify(arg+2, arg+strlen(arg)-1, expr); @@ -334,13 +333,13 @@ void push_regex(char* arg, bool case_sensitive, vector> &v){ if (case_sensitive){ regex regex(expr_str); #ifdef DEBUG - cout << "Added case sensitive regex " << expr_str << endl; + cerr << "Added case sensitive regex " << expr_str << endl; #endif v.push_back(make_pair(string(arg), regex)); } else { regex regex(expr_str,regex_constants::icase); #ifdef DEBUG - cout << "Added case insensitive regex " << expr_str << endl; + cerr << "Added case insensitive regex " << expr_str << endl; #endif v.push_back(make_pair(string(arg), regex)); } @@ -351,6 +350,7 @@ void push_regex(char* arg, bool case_sensitive, vector> &v){ void update_regex(){ + std::unique_lock lck(update_mutex); fstream fd; fd.open(config_file,ios::in); if (!fd.is_open()){ @@ -397,13 +397,19 @@ void signal_handler(int signal_num) { if (signal_num == SIGUSR1){ #ifdef DEBUG - cout << "Updating configurtation" << endl; + cerr << "Updating configurtation" << endl; #endif update_regex(); }else if(signal_num == SIGTERM){ if (ios_loop != nullptr) ios_loop->stop(); + #ifdef DEBUG + cerr << "Close Requested" << endl; + #endif exit(0); }else if (signal_num == SIGSEGV){ + #ifdef DEBUG + cerr << "Forced Close" << endl; + #endif exit(0); } } diff --git a/backend/proxy/test b/backend/proxy/test deleted file mode 100644 index 483135d..0000000 --- a/backend/proxy/test +++ /dev/null @@ -1,126 +0,0 @@ -S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -1C3733353138303461313162386234323563313931613664373937666264356630 -1S3733353138303461313162386234323563313931613664373937666264356630 -1C3065376433366539666631353833373263633764613966396235313538633766 -1S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -1C3733353138303461313162386234323563313931613664373937666264356630 -1S3733353138303461313162386234323563313931613664373937666264356630 -1C3065376433366539666631353833373263633764613966396235313538633766 -1S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -1C3733353138303461313162386234323563313931613664373937666264356630 -1S3733353138303461313162386234323563313931613664373937666264356630 -1C3065376433366539666631353833373263633764613966396235313538633766 -1S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -1C3733353138303461313162386234323563313931613664373937666264356630 -1S3733353138303461313162386234323563313931613664373937666264356630 -1C3065376433366539666631353833373263633764613966396235313538633766 -1S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -1C3733353138303461313162386234323563313931613664373937666264356630 -1S3733353138303461313162386234323563313931613664373937666264356630 -1C3065376433366539666631353833373263633764613966396235313538633766 -1S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -1C3733353138303461313162386234323563313931613664373937666264356630 -1S3733353138303461313162386234323563313931613664373937666264356630 -1C3065376433366539666631353833373263633764613966396235313538633766 -1S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -1C3733353138303461313162386234323563313931613664373937666264356630 -1S3733353138303461313162386234323563313931613664373937666264356630 -1C3065376433366539666631353833373263633764613966396235313538633766 -1S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -1C3733353138303461313162386234323563313931613664373937666264356630 -1S3733353138303461313162386234323563313931613664373937666264356630 -1C3065376433366539666631353833373263633764613966396235313538633766 -1S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -1C3733353138303461313162386234323563313931613664373937666264356630 -1S3733353138303461313162386234323563313931613664373937666264356630 -1C3065376433366539666631353833373263633764613966396235313538633766 -1S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -1C3733353138303461313162386234323563313931613664373937666264356630 -1S3733353138303461313162386234323563313931613664373937666264356630 -1C3065376433366539666631353833373263633764613966396235313538633766 -1S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -1C3733353138303461313162386234323563313931613664373937666264356630 -1S3733353138303461313162386234323563313931613664373937666264356630 -1C3065376433366539666631353833373263633764613966396235313538633766 -1S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 -1C3733353138303461313162386234323563313931613664373937666264356630 -1S3733353138303461313162386234323563313931613664373937666264356630 -1C3065376433366539666631353833373263633764613966396235313538633766 -1S3065376433366539666631353833373263633764613966396235313538633766 -1C3638316561366437356466353765656265383933396630326262393338336438 -1S3638316561366437356466353765656265383933396630326262393338336438 -1C3739663566343265663536633261656665623338346135616464633539663930 -1S3739663566343265663536633261656665623338346135616464633539663930 diff --git a/docs/FiregexBenchmark.png b/docs/FiregexBenchmark.png index 9acb796..4f9a050 100644 Binary files a/docs/FiregexBenchmark.png and b/docs/FiregexBenchmark.png differ diff --git a/tests/README.md b/tests/README.md index f90f6d6..b28c90f 100644 --- a/tests/README.md +++ b/tests/README.md @@ -29,23 +29,25 @@ The testing methodology will soon be updated with more edge-cases. # Running a Benchmark ./benchmark.py options: - -h, --help show this help message and exit - --address ADDRESS, -a ADDRESS - Address of firegex backend - --service_port SERVICE_PORT, -P SERVICE_PORT - Port of the Benchmark service - --service_name SERVICE_NAME, -n SERVICE_NAME - Name of the Benchmark service - --password PASSWORD, -p PASSWORD - Firegex password - --num_of_regexes NUM_OF_REGEXES, -r NUM_OF_REGEXES - Number of regexes to benchmark with - --duration DURATION, -d DURATION - Duration of the Benchmark in seconds - --output_file OUTPUT_FILE, -o OUTPUT_FILE - Output results csv file + --address ADDRESS, -a ADDRESS + Address of firegex backend + --service_port SERVICE_PORT, -P SERVICE_PORT + Port of the Benchmark service + --service_name SERVICE_NAME, -n SERVICE_NAME + Name of the Benchmark service + --password PASSWORD, -p PASSWORD + Firegex password + --num_of_regexes NUM_OF_REGEXES, -r NUM_OF_REGEXES + Number of regexes to benchmark with + --duration DURATION, -d DURATION + Duration of the Benchmark in seconds + --output_file OUTPUT_FILE, -o OUTPUT_FILE + Output results csv file + --num_of_streams NUM_OF_STREAMS, -s NUM_OF_STREAMS + Output results csv file + --new_istance, -i Create a new service -Benchmarks let you evaluate the performance of the proxy. You can run one by typing in a shell ```test.py -p FIREGEX_PASSWORD -r NUM_OF_REGEX -d BENCHMARK_DURATION```. +Benchmarks let you evaluate the performance of the proxy. You can run one by typing in a shell ```test.py -p FIREGEX_PASSWORD -r NUM_OF_REGEX -d BENCHMARK_DURATION -i```. It uses iperf3 to benchmark the throughput in MB/s of the server, both with proxy, without proxy, and for each new added regex. It will automatically add a new random regex untill it has reached NUM_OF_REGEX specified in the arguments. diff --git a/tests/benchmark.py b/tests/benchmark.py index 9e0d0f7..7076ac3 100755 --- a/tests/benchmark.py +++ b/tests/benchmark.py @@ -22,7 +22,7 @@ def puts(text, *args, color=colors.white, is_bold=False, **kwargs): def sep(): puts("-----------------------------------", is_bold=True) parser = argparse.ArgumentParser() -parser.add_argument("--address", "-a", type=str , required=False, help='Address of firegex backend', default="http://127.0.0.1:5000/") +parser.add_argument("--address", "-a", type=str , required=False, help='Address of firegex backend', default="http://127.0.0.1:4444/") parser.add_argument("--service_port", "-P", type=int , required=False, help='Port of the Benchmark service', default=1337) parser.add_argument("--service_name", "-n", type=str , required=False, help='Name of the Benchmark service', default="Benchmark Service") parser.add_argument("--password", "-p", type=str, required=True, help='Firegex password') @@ -127,4 +127,4 @@ if args.new_istance: assert req.json()["status"] == "ok", f"Benchmark Failed: Couldn't delete service {req.text}" puts(f"Sucessfully delete service with id {service_id} ✔", color=colors.green) -server.terminate() \ No newline at end of file +server.terminate()