From: Mikko Rasa Date: Wed, 21 Oct 2009 18:49:27 +0000 (+0000) Subject: Improve the algorithm for deleting hosts X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f3939c5da4add9af55a26293c99f0f013052cc25;p=netvis.git Improve the algorithm for deleting hosts Add some missing includes --- diff --git a/source/netvis.cpp b/source/netvis.cpp index 3a0f092..e0148d9 100644 --- a/source/netvis.cpp +++ b/source/netvis.cpp @@ -6,6 +6,9 @@ Distributed unter the GPL */ #include +#include +#include +#include #include #include #include @@ -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(this))>0); + while(pcap_dispatch(pcap, -1, &capture_handler, reinterpret_cast(this))>0) ; } { @@ -130,27 +135,33 @@ void NetVis::tick() resolver->tick(); - float min_activity=1e7f; + float min_activity=numeric_limits::max(); for(map::iterator i=hosts.begin(); i!=hosts.end(); ++i) { i->second->tick(dt); min_activity=min(min_activity, i->second->get_activity()); } - for(map::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::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()second; + disabled_hosts.erase(i++); + } else ++i; } - if(hosts.size()>20) + + if(hosts.size()>max_visible_hosts) { list activity; for(map::iterator i=hosts.begin(); i!=hosts.end(); ++i) @@ -158,7 +169,7 @@ void NetVis::tick() activity.sort(); list::iterator j=activity.begin(); - advance(j, activity.size()-20); + advance(j, activity.size()-max_visible_hosts); float limit=*j; for(map::iterator i=hosts.begin(); i!=hosts.end();) diff --git a/source/netvis.h b/source/netvis.h index 9e8661e..5017038 100644 --- a/source/netvis.h +++ b/source/netvis.h @@ -30,6 +30,8 @@ private: std::string iface; pcap_t *pcap; std::list packets; + unsigned max_hosts; + unsigned max_visible_hosts; std::map hosts; std::map disabled_hosts; Msp::Graphics::Display *dpy; diff --git a/source/packet.cpp b/source/packet.cpp index 512144a..89f7779 100644 --- a/source/packet.cpp +++ b/source/packet.cpp @@ -6,6 +6,7 @@ Distributed unter the GPL */ #include +#include #include #include #include