]> git.tdb.fi Git - netvis.git/commitdiff
Improve the algorithm for deleting hosts
authorMikko Rasa <tdb@tdb.fi>
Wed, 21 Oct 2009 18:49:27 +0000 (18:49 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 21 Oct 2009 18:49:27 +0000 (18:49 +0000)
Add some missing includes

source/netvis.cpp
source/netvis.h
source/packet.cpp

index 3a0f09219449f46dc9bb5d1be56f116cffc0ad0b..e0148d908ce089915b7b3f13475e6ceac2a18a65 100644 (file)
@@ -6,6 +6,9 @@ Distributed unter the GPL
 */
 
 #include <iostream>
+#include <limits>
+#include <cstdlib>
+#include <cmath>
 #include <signal.h>
 #include <netinet/ip.h>
 #include <netinet/tcp.h>
@@ -31,6 +34,8 @@ using namespace std;
 using namespace Msp;
 
 NetVis::NetVis(int argc, char **argv):
+       max_hosts(1000),
+       max_visible_hosts(30),
        draw_labels(true),
        blend(true),
        frames(0)
@@ -122,7 +127,7 @@ void NetVis::tick()
 
        {
                Debug::ProfilingScope s(profiler, "capture");
-               while(pcap_dispatch(pcap, -1, &capture_handler, reinterpret_cast<unsigned char *>(this))>0);
+               while(pcap_dispatch(pcap, -1, &capture_handler, reinterpret_cast<unsigned char *>(this))>0) ;
        }
 
        {
@@ -130,27 +135,33 @@ void NetVis::tick()
 
                resolver->tick();
 
-               float min_activity=1e7f;
+               float min_activity=numeric_limits<float>::max();
                for(map<unsigned, Host *>::iterator i=hosts.begin(); i!=hosts.end(); ++i)
                {
                        i->second->tick(dt);
                        min_activity=min(min_activity, i->second->get_activity());
                }
-               for(map<unsigned, Host *>::iterator i=disabled_hosts.begin(); i!=disabled_hosts.end(); ++i)
-                       i->second->tick(dt);
-
+               float del_limit=pow(10, 6-0.1*(max_hosts-hosts.size()-disabled_hosts.size()));
                for(map<unsigned, Host *>::iterator i=disabled_hosts.begin(); i!=disabled_hosts.end();)
                {
+                       i->second->tick(dt);
+
                        if(i->second->get_activity()>min_activity)
                        {
                                i->second->set_active(true);
                                hosts.insert(*i);
                                disabled_hosts.erase(i++);
                        }
+                       else if(i->second->get_activity()<del_limit)
+                       {
+                               delete i->second;
+                               disabled_hosts.erase(i++);
+                       }
                        else
                                ++i;
                }
-               if(hosts.size()>20)
+
+               if(hosts.size()>max_visible_hosts)
                {
                        list<float> activity;
                        for(map<unsigned, Host *>::iterator i=hosts.begin(); i!=hosts.end(); ++i)
@@ -158,7 +169,7 @@ void NetVis::tick()
                        activity.sort();
 
                        list<float>::iterator j=activity.begin();
-                       advance(j, activity.size()-20);
+                       advance(j, activity.size()-max_visible_hosts);
                        float limit=*j;
 
                        for(map<unsigned, Host *>::iterator i=hosts.begin(); i!=hosts.end();)
index 9e8661e58307c43ed9efe5d289fcb1e9eaacde8a..50170386c9ece06ab538295541e5937a58b3f9b1 100644 (file)
@@ -30,6 +30,8 @@ private:
        std::string iface;
        pcap_t *pcap;
        std::list<Packet *> packets;
+       unsigned max_hosts;
+       unsigned max_visible_hosts;
        std::map<unsigned, Host *> hosts;
        std::map<unsigned, Host *> disabled_hosts;
        Msp::Graphics::Display *dpy;
index 512144a9517414bfd18576c0b9a18478392c0db3..89f77790166d86134e4d2e0d0ef04e6c60588b0e 100644 (file)
@@ -6,6 +6,7 @@ Distributed unter the GPL
 */
 
 #include <cmath>
+#include <cstdlib>
 #include <msp/gl/immediate.h>
 #include <msp/gl/matrix.h>
 #include <msp/gl/transform.h>