X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fnetvis.cpp;h=3aff9cd48ef210a3f543a8e2adc2e5f258773ed9;hb=afc5702fb7a8cb7011886093cd4ea0357ce8abce;hp=bcdba3f28c6314ff1ebf72a9891181e797dba08d;hpb=42bd2e83d66a98584540dd8cc5b47ee2349fe844;p=netvis.git diff --git a/source/netvis.cpp b/source/netvis.cpp index bcdba3f..3aff9cd 100644 --- a/source/netvis.cpp +++ b/source/netvis.cpp @@ -9,10 +9,10 @@ Distributed unter the GPL #include #include #include +#include #include #include #include -#include #include #include #include @@ -26,6 +26,7 @@ Distributed unter the GPL #include #include #include +#include "history.h" #include "host.h" #include "netvis.h" #include "packet.h" @@ -42,8 +43,6 @@ NetVis::NetVis(int argc, char **argv): font(0), max_hosts(1000), max_visible_hosts(30), - draw_labels(true), - blend(true), frames(0) { if(argc<2) @@ -67,7 +66,6 @@ NetVis::NetVis(int argc, char **argv): wnd = new Graphics::SimpleGLWindow(1024, 768); wnd->set_title("NetVis"); wnd->signal_close.connect(sigc::bind(sigc::mem_fun(this, &NetVis::exit), 0)); - wnd->signal_key_press.connect(sigc::mem_fun(this, &NetVis::key_press)); wnd->show(); GL::enable(GL::BLEND); @@ -76,6 +74,8 @@ NetVis::NetVis(int argc, char **argv): font = new GL::Font; DataFile::load(*font, "dejavu-10.font"); + history = new History(*this, 301, 100); + catch_signal(SIGINT); } @@ -117,6 +117,8 @@ void NetVis::tick() while(pcap_dispatch(pcap, -1, &capture_handler, reinterpret_cast(this))>0) ; resolver->tick(); + history->tick(tick_t); + float min_activity = numeric_limits::max(); for(map::iterator i=hosts.begin(); i!=hosts.end(); ++i) @@ -133,6 +135,8 @@ void NetVis::tick() { i->second->set_active(true); hosts.insert(*i); + for(unsigned j=0; j<100; ++j) + i->second->tick(100*Time::msec); disabled_hosts.erase(i++); } else if(i->second->get_activity()draw_string(format("%.2f fps", fps)); GL::Texture::unbind(); GL::pop_matrix(); + + GL::push_matrix(); + GL::translate(170, -370, 0); + history->render(); + GL::pop_matrix(); } Host &NetVis::get_host(unsigned a) @@ -241,6 +250,8 @@ Host &NetVis::get_host(unsigned a) host->set_local(true); resolver->push(host); host->set_position(Vector2(rand()*400.0/RAND_MAX-200.0, rand()*400.0/RAND_MAX-200.0)); + for(unsigned j=0; j<100; ++j) + host->tick(100*Time::msec); hosts[a] = host; return *host; } @@ -255,17 +266,6 @@ const Port &NetVis::get_port(unsigned number) return *port; } -void NetVis::key_press(unsigned key, unsigned, wchar_t) -{ - if(key==46) - draw_labels = !draw_labels; - else if(key==56) - { - blend = !blend; - GL::set(GL_BLEND, blend); - } -} - void NetVis::capture_handler(unsigned char *user, const pcap_pkthdr *, const unsigned char *data) { NetVis *self = reinterpret_cast(user); @@ -302,6 +302,11 @@ void NetVis::capture_handler(unsigned char *user, const pcap_pkthdr *, const uns shost.add_activity(size); if(dhost) dhost->add_activity(size); + + if((ntohl(ip->saddr)&self->localnet_mask)==self->localnet) + self->history->activity(0, size); + else if((ntohl(ip->daddr)&self->localnet_mask)==self->localnet) + self->history->activity(size, 0); } }