Browse Source

Merge branch 'stat_interrupt' of stefan.schmidt/ID2T-toolkit into master

Jens Keim 5 years ago
parent
commit
4009ec1efe
2 changed files with 33 additions and 3 deletions
  1. 5 3
      code_boost/src/cxx/pcap_processor.cpp
  2. 28 0
      code_boost/src/cxx/statistics_db.cpp

+ 5 - 3
code_boost/src/cxx/pcap_processor.cpp

@@ -1,3 +1,6 @@
+#include <pybind11/pybind11.h>
+namespace py = pybind11;
+
 #include "pcap_processor.h"
 
 using namespace Tins;
@@ -208,6 +211,8 @@ void pcap_processor::collect_statistics() {
                 std::cout << std::fixed << std::setprecision(1) << (static_cast<float>(packetCount)*100/totalPackets) << "%";
                 std::cout << " (" << packetCount << "/" << totalPackets << ")" << std::flush;
                 lastPrinted = std::chrono::system_clock::now();
+
+                if (PyErr_CheckSignals()) throw py::error_already_set();
             }
         }
 
@@ -412,9 +417,6 @@ bool inline pcap_processor::file_exists(const std::string &filePath) {
  * Comment out if executable should be build & run
  * Comment in if library should be build
  */
-#include <pybind11/pybind11.h>
-namespace py = pybind11;
-
 PYBIND11_MODULE (libpcapreader, m) {
     py::class_<pcap_processor>(m, "pcap_processor")
             .def(py::init<std::string, std::string>())

+ 28 - 0
code_boost/src/cxx/statistics_db.cpp

@@ -5,6 +5,8 @@
 #include <fstream>
 #include <unistd.h>
 #include <stdio.h>
+#include <pybind11/pybind11.h>
+namespace py = pybind11;
 
 /**
  * Creates a new statistics_db object. Opens an existing database located at database_path. If not existing, creates
@@ -55,6 +57,8 @@ void statistics_db::writeStatisticsIP(const std::unordered_map<std::string, entr
             query.bindNoCopy(8, e.ip_class);
             query.exec();
             query.reset();
+
+            if (PyErr_CheckSignals()) throw py::error_already_set();
         }
         transaction.commit();
     }
@@ -88,6 +92,8 @@ void statistics_db::writeStatisticsDegree(const std::unordered_map<std::string,
             query.bind(4, e.overall_degree);
             query.exec();
             query.reset();
+
+            if (PyErr_CheckSignals()) throw py::error_already_set();
         }
         transaction.commit();
     }
@@ -119,6 +125,8 @@ void statistics_db::writeStatisticsTTL(const std::unordered_map<ipAddress_ttl, i
             query.bind(3, it->second);
             query.exec();
             query.reset();
+
+            if (PyErr_CheckSignals()) throw py::error_already_set();
         }
         transaction.commit();
     }
@@ -150,6 +158,8 @@ void statistics_db::writeStatisticsMSS(const std::unordered_map<ipAddress_mss, i
             query.bind(3, it->second);
             query.exec();
             query.reset();
+
+            if (PyErr_CheckSignals()) throw py::error_already_set();
         }
         transaction.commit();
     }
@@ -180,6 +190,8 @@ void statistics_db::writeStatisticsToS(const std::unordered_map<ipAddress_tos, i
             query.bind(3, it->second);
             query.exec();
             query.reset();
+
+            if (PyErr_CheckSignals()) throw py::error_already_set();
         }
         transaction.commit();
     }
@@ -211,6 +223,8 @@ void statistics_db::writeStatisticsWin(const std::unordered_map<ipAddress_win, i
             query.bind(3, it->second);
             query.exec();
             query.reset();
+
+            if (PyErr_CheckSignals()) throw py::error_already_set();
         }
         transaction.commit();
     }
@@ -243,6 +257,8 @@ void statistics_db::writeStatisticsProtocols(const std::unordered_map<ipAddress_
             query.bind(4, it->second.byteCount);
             query.exec();
             query.reset();
+
+            if (PyErr_CheckSignals()) throw py::error_already_set();
         }
         transaction.commit();
     }
@@ -288,6 +304,8 @@ void statistics_db::writeStatisticsPorts(const std::unordered_map<ipAddress_inOu
             query.bindNoCopy(7, portService);
             query.exec();
             query.reset();
+
+            if (PyErr_CheckSignals()) throw py::error_already_set();
         }
         transaction.commit();
     }
@@ -315,6 +333,8 @@ void statistics_db::writeStatisticsIpMac(const std::unordered_map<std::string, s
             query.bindNoCopy(2, it->second);
             query.exec();
             query.reset();
+
+            if (PyErr_CheckSignals()) throw py::error_already_set();
         }
         transaction.commit();
     }
@@ -431,6 +451,8 @@ void statistics_db::writeStatisticsConv(std::unordered_map<conv, entry_convStat>
                 query.bind(9, maxDelay);
                 query.exec();
                 query.reset();
+
+                if (PyErr_CheckSignals()) throw py::error_already_set();
             }
         }
         transaction.commit();
@@ -524,6 +546,8 @@ void statistics_db::writeStatisticsConvExt(std::unordered_map<convWithProt, entr
                 query.bind(14, e.total_comm_duration);
                 query.exec();
                 query.reset();
+
+                if (PyErr_CheckSignals()) throw py::error_already_set();
             }
             
         }
@@ -583,6 +607,8 @@ void statistics_db::writeStatisticsInterval(const std::unordered_map<std::string
             query.bind(16, e.novel_mss_count);
             query.exec();
             query.reset();
+
+            if (PyErr_CheckSignals()) throw py::error_already_set();
         }
         transaction.commit();
     }
@@ -727,6 +753,8 @@ void statistics_db::writeStatisticsUnrecognizedPDUs(const std::unordered_map<unr
             query.bindNoCopy(5, it->second.timestamp_last_occurrence);
             query.exec();
             query.reset();
+
+            if (PyErr_CheckSignals()) throw py::error_already_set();
         }
         transaction.commit();
     }