*/
#include <iostream>
+#include <limits>
+#include <cstdlib>
+#include <cmath>
#include <signal.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
using namespace Msp;
NetVis::NetVis(int argc, char **argv):
+ max_hosts(1000),
+ max_visible_hosts(30),
draw_labels(true),
blend(true),
frames(0)
{
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) ;
}
{
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)
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();)
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;