Browse Source

go through ip stats timestamps in reverse

Jens Keim 5 years ago
parent
commit
409bb8ada1
2 changed files with 7 additions and 4 deletions
  1. 6 3
      code_boost/src/cxx/statistics.cpp
  2. 1 1
      code_boost/src/cxx/statistics_db.h

+ 6 - 3
code_boost/src/cxx/statistics.cpp

@@ -58,10 +58,11 @@ std::vector<float> statistics::calculateLastIntervalIPsEntropy(std::chrono::micr
 
         for (auto i = ip_statistics.begin(); i != ip_statistics.end(); i++) {
             int IPsSrcPktsCount = 0;
-            // TODO: iter backwards and break
-            for (auto j = i->second.pkts_sent_timestamp.begin(); j != i->second.pkts_sent_timestamp.end(); j++) {
+            for (auto j = i->second.pkts_sent_timestamp.end(); j != i->second.pkts_sent_timestamp.begin(); j--) {
                 if(*j >= intervalStartTimestamp)
                     IPsSrcPktsCount++;
+                else
+                    break;
             }
             if(IPsSrcPktsCount != 0) {
                 IPsSrcPktsCounts.push_back(IPsSrcPktsCount);
@@ -69,9 +70,11 @@ std::vector<float> statistics::calculateLastIntervalIPsEntropy(std::chrono::micr
             }
 
             int IPsDstPktsCount = 0;
-            for (auto j = i->second.pkts_received_timestamp.begin(); j != i->second.pkts_received_timestamp.end(); j++) {
+            for (auto j = i->second.pkts_received_timestamp.end(); j != i->second.pkts_received_timestamp.begin(); j--) {
                 if(*j >= intervalStartTimestamp)
                     IPsDstPktsCount++;
+                else
+                    break;
             }
             if(IPsDstPktsCount != 0) {
                 IPsDstPktsCounts.push_back(IPsDstPktsCount);

+ 1 - 1
code_boost/src/cxx/statistics_db.h

@@ -25,7 +25,7 @@ public:
     /*
      * Database version: Increment number on every change in the C++ code!
      */
-    static const int DB_VERSION = 19;
+    static const int DB_VERSION = 20;
 
     /*
      * Methods to read from database