]> git.tdb.fi Git - netvis.git/commitdiff
Update coding style
authorMikko Rasa <tdb@tdb.fi>
Wed, 21 Oct 2009 19:23:43 +0000 (19:23 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 21 Oct 2009 19:23:43 +0000 (19:23 +0000)
source/host.cpp
source/netvis.cpp
source/packet.cpp
source/resolver.cpp

index e5eafc899fd98db7bd9d851fb208b237f72b1619..991e7741a04eb9a4acef1292992c707f08456b40 100644 (file)
@@ -28,108 +28,108 @@ Host::Host(NetVis &nv, unsigned a):
        throttle(0)
 {
        in_addr ina;
-       ina.s_addr=htonl(addr);
-       name=inet_ntoa(ina);
-       short_name=name;
+       ina.s_addr = htonl(addr);
+       name = inet_ntoa(ina);
+       short_name = name;
 }
 
 void Host::set_name(const string &n)
 {
-       name=n;
+       name = n;
 
        if(local)
        {
-               unsigned dot=name.find('.');
-               short_name=name.substr(0, dot);
+               unsigned dot = name.find('.');
+               short_name = name.substr(0, dot);
        }
        else
        {
-               unsigned dot=name.size();
+               unsigned dot = name.size();
                for(unsigned i=0; (dot>0 && dot!=string::npos); ++i)
                {
-                       unsigned prev=name.rfind('.', dot-1);
+                       unsigned prev = name.rfind('.', dot-1);
                        if(prev+15<name.size() && i>1)
                                break;
-                       dot=prev;
+                       dot = prev;
                }
 
                if(dot==string::npos)
-                       short_name=name;
+                       short_name = name;
                else
-                       short_name="..."+name.substr(dot+1);
+                       short_name = "..."+name.substr(dot+1);
        }
 }
 
 void Host::set_local(bool l)
 {
-       local=l;
+       local = l;
 }
 
 void Host::set_position(const Vector2 &p)
 {
-       pos=p;
+       pos = p;
 }
 
 void Host::set_active(bool a)
 {
-       active=a;
+       active = a;
 }
 
 void Host::add_activity(unsigned bytes)
 {
-       activity+=bytes*0.06935;
+       activity += bytes*0.06935;
 }
 
 float Host::send_packet()
 {
-       float ret=throttle;
+       float ret = throttle;
        if(throttle<1)
-               throttle+=0.025;
+               throttle += 0.025;
        return ret;
 }
 
 void Host::tick(const Msp::Time::TimeDelta &td)
 {
-       float dt=td/Msp::Time::sec;
+       float dt = td/Msp::Time::sec;
 
-       activity*=pow(0.933f, dt);
-       throttle-=dt;
+       activity *= pow(0.933f, dt);
+       throttle -= dt;
        if(throttle<0)
-               throttle=0;
+               throttle = 0;
 
        if(!active)
                return;
 
-       const map<unsigned, Host *> &hosts=netvis.get_hosts();
-       float fx=-pos.x*0.1;
-       float fy=-pos.y*0.1;
+       const map<unsigned, Host *> &hosts = netvis.get_hosts();
+       float fx = -pos.x*0.1;
+       float fy = -pos.y*0.1;
        for(map<unsigned, Host *>::const_iterator i=hosts.begin(); i!=hosts.end(); ++i)
        {
                if(i->second!=this)
                {
-                       const Vector2 &other_pos=i->second->get_position();
-                       float dx=other_pos.x-pos.x;
-                       float dy=other_pos.y-pos.y;
-                       float d2=dx*dx+dy*dy;
-                       float d=sqrt(d2);
-
-                       unsigned other_addr=i->second->get_address();
-                       unsigned matching_bits=0;
+                       const Vector2 &other_pos = i->second->get_position();
+                       float dx = other_pos.x-pos.x;
+                       float dy = other_pos.y-pos.y;
+                       float d2 = dx*dx+dy*dy;
+                       float d = sqrt(d2);
+
+                       unsigned other_addr = i->second->get_address();
+                       unsigned matching_bits = 0;
                        for(unsigned j=32; (j-- && !((addr^other_addr)>>j));)
                                ++matching_bits;
 
-                       float optimal_dist=100+(24-min(matching_bits, 24U))*12;
-                       float f=5000.0*(1.0/optimal_dist-1.0/d);
+                       float optimal_dist = 100+(24-min(matching_bits, 24U))*12;
+                       float f = 5000.0*(1.0/optimal_dist-1.0/d);
 
-                       fx+=dx/d*f;
-                       fy+=dy/d*f;
+                       fx += dx/d*f;
+                       fy += dy/d*f;
                }
        }
 
        if(fx<-4 || fx>4)
-               pos.x+=fx*dt;
+               pos.x += fx*dt;
        if(fy<-4 || fy>4)
-               pos.y+=fy*dt;
+               pos.y += fy*dt;
 }
 
 void Host::render() const
@@ -157,7 +157,7 @@ void Host::render_label() const
        if(!active)
                return;
 
-       const GL::Font &font=netvis.get_font();
+       const GL::Font &font = netvis.get_font();
 
        GL::push_matrix();
        GL::translate(static_cast<int>(pos.x)-static_cast<int>(font.get_string_width(short_name)*5), static_cast<int>(pos.y)+6, 0);
index e0148d908ce089915b7b3f13475e6ceac2a18a65..917c04252986b1345de2e78b9b60a6b70155fc0a 100644 (file)
@@ -42,13 +42,13 @@ NetVis::NetVis(int argc, char **argv):
 {
        if(argc<2)
                throw UsageError("No interface given");
-       iface=argv[1];
+       iface = argv[1];
 }
 
 int NetVis::main()
 {
        char err[1024];
-       pcap=pcap_open_live(iface.c_str(), 128, true, 0, err);
+       pcap = pcap_open_live(iface.c_str(), 128, true, 0, err);
        if(!pcap)
                throw Exception(err);
 
@@ -56,12 +56,12 @@ int NetVis::main()
                throw Exception(err);
 
        pcap_lookupnet(iface.c_str(), &localnet, &localnet_mask, err);
-       localnet=ntohl(localnet);
-       localnet_mask=ntohl(localnet_mask);
+       localnet = ntohl(localnet);
+       localnet_mask = ntohl(localnet_mask);
 
-       dpy=new Graphics::Display;
-       wnd=new Graphics::Window(*dpy, 1024, 768);
-       glc=new Graphics::GLContext(*wnd);
+       dpy = new Graphics::Display;
+       wnd = new Graphics::Window(*dpy, 1024, 768);
+       glc = new Graphics::GLContext(*wnd);
        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));
@@ -70,15 +70,15 @@ int NetVis::main()
        GL::enable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
-       font=new GL::Font;
+       font = new GL::Font;
        DataFile::load(*font, "dejavu-10.font");
-       font_tex=new GL::Texture2D;
+       font_tex = new GL::Texture2D;
        DataFile::load(*font_tex, "dejavu-10.tex");
        font->set_texture(*font_tex);
 
        catch_signal(SIGINT);
 
-       resolver=new Resolver;
+       resolver = new Resolver;
 
        //set_loop_mode(TICK_BUSY);
 
@@ -110,17 +110,17 @@ int NetVis::main()
 
 void NetVis::tick()
 {
-       Msp::Time::TimeStamp t=Msp::Time::now();
+       Msp::Time::TimeStamp t = Msp::Time::now();
        Msp::Time::TimeDelta dt;
        if(tick_t)
-               dt=t-tick_t;
-       tick_t=t;
+               dt = t-tick_t;
+       tick_t = t;
 
        if(tick_t>fps_t+Msp::Time::sec)
        {
-               fps=frames/((tick_t-fps_t)/Msp::Time::sec);
-               fps_t=tick_t;
-               frames=0;
+               fps = frames/((tick_t-fps_t)/Msp::Time::sec);
+               fps_t = tick_t;
+               frames = 0;
        }
 
        dpy->tick();
@@ -135,13 +135,13 @@ void NetVis::tick()
 
                resolver->tick();
 
-               float min_activity=numeric_limits<float>::max();
+               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());
+                       min_activity = min(min_activity, i->second->get_activity());
                }
-               float del_limit=pow(10, 6-0.1*(max_hosts-hosts.size()-disabled_hosts.size()));
+               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);
@@ -168,9 +168,9 @@ void NetVis::tick()
                                activity.push_back(i->second->get_activity());
                        activity.sort();
 
-                       list<float>::iterator j=activity.begin();
+                       list<float>::iterator j = activity.begin();
                        advance(j, activity.size()-max_visible_hosts);
-                       float limit=*j;
+                       float limit = *j;
 
                        for(map<unsigned, Host *>::iterator i=hosts.begin(); i!=hosts.end();)
                        {
@@ -191,7 +191,7 @@ void NetVis::tick()
                        if((*i)->get_stale())
                        {
                                delete *i;
-                               i=packets.erase(i);
+                               i = packets.erase(i);
                        }
                        else
                                ++i;
@@ -225,10 +225,10 @@ void NetVis::tick()
 
                GL::push_matrix();
                GL::translate(-500, 360, 0);
-               unsigned n=0;
+               unsigned n = 0;
                for(map<unsigned, GL::Color>::iterator i=port_colors.begin(); (i!=port_colors.end() && n<20); ++i, ++n)
                {
-                       GL::Color &color=i->second;
+                       GL::Color &color = i->second;
 
                        imm.begin(GL::QUADS);
                        imm.color(color.r, color.g, color.b, color.a);
@@ -252,7 +252,7 @@ void NetVis::tick()
                        GL::translate(-484, 361, 0);
                        GL::scale_uniform(10);
                        glColor4f(1.0, 1.0, 1.0, 1.0);
-                       n=0;
+                       n = 0;
                        for(map<unsigned, GL::Color>::iterator i=port_colors.begin(); (i!=port_colors.end() && n<20); ++i, ++n)
                        {
                                font->draw_string(format("%d", i->first));
@@ -281,80 +281,80 @@ void NetVis::tick()
 
 Host &NetVis::get_host(unsigned a)
 {
-       map<unsigned, Host *>::iterator i=hosts.find(a);
+       map<unsigned, Host *>::iterator i = hosts.find(a);
        if(i!=hosts.end())
                return *i->second;
 
-       i=disabled_hosts.find(a);
+       i = disabled_hosts.find(a);
        if(i!=disabled_hosts.end())
                return *i->second;
 
-       Host *host=new Host(*this, a);
+       Host *host = new Host(*this, a);
        if((a&localnet_mask)==localnet)
                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));
-       hosts[a]=host;
+       hosts[a] = host;
        return *host;
 }
 
 GL::Color &NetVis::get_port_color(unsigned port)
 {
-       map<unsigned, GL::Color>::iterator i=port_colors.find(port);
+       map<unsigned, GL::Color>::iterator i = port_colors.find(port);
        if(i!=port_colors.end())
                return i->second;
 
        GL::Color color;
        while(1)
        {
-               color.r=rand()*1.0/RAND_MAX;
-               color.g=rand()*1.0/RAND_MAX;
-               color.b=rand()*1.0/RAND_MAX;
+               color.r = rand()*1.0/RAND_MAX;
+               color.g = rand()*1.0/RAND_MAX;
+               color.b = rand()*1.0/RAND_MAX;
                if(color.r>0.5 || color.g>0.5 || color.b>0.7)
                        break;
        }
-       color.a=0.4f;
-       return port_colors[port]=color;
+       color.a = 0.4f;
+       return port_colors[port] = color;
 }
 
 void NetVis::key_press(unsigned key, unsigned, wchar_t)
 {
        if(key==46)
-               draw_labels=!draw_labels;
+               draw_labels = !draw_labels;
        else if(key==56)
        {
-               blend=!blend;
+               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<NetVis *>(user);
+       NetVis *self = reinterpret_cast<NetVis *>(user);
 
-       const ethhdr *eth=reinterpret_cast<const ethhdr *>(data);
+       const ethhdr *eth = reinterpret_cast<const ethhdr *>(data);
        if(ntohs(eth->h_proto)==ETH_P_IP)
        {
-               const iphdr *ip=reinterpret_cast<const iphdr *>(eth+1);
+               const iphdr *ip = reinterpret_cast<const iphdr *>(eth+1);
 
-               unsigned size=ntohs(ip->tot_len);
-               unsigned port=0;
+               unsigned size = ntohs(ip->tot_len);
+               unsigned port = 0;
                if(ip->protocol==IPPROTO_TCP)
                {
-                       const tcphdr *tcp=reinterpret_cast<const tcphdr *>(ip+1);
-                       port=min(ntohs(tcp->source), ntohs(tcp->dest));
+                       const tcphdr *tcp = reinterpret_cast<const tcphdr *>(ip+1);
+                       port = min(ntohs(tcp->source), ntohs(tcp->dest));
                }
                else if(ip->protocol==IPPROTO_UDP)
                {
-                       const udphdr *udp=reinterpret_cast<const udphdr *>(ip+1);
-                       port=min(ntohs(udp->source), ntohs(udp->dest));
+                       const udphdr *udp = reinterpret_cast<const udphdr *>(ip+1);
+                       port = min(ntohs(udp->source), ntohs(udp->dest));
                }
-               Host &shost=self->get_host(ntohl(ip->saddr));
-               Host *dhost=0;
+               Host &shost = self->get_host(ntohl(ip->saddr));
+               Host *dhost = 0;
                if((ntohl(ip->daddr)&0xFF)!=0xFF)
-                       dhost=&self->get_host(ntohl(ip->daddr));
+                       dhost = &self->get_host(ntohl(ip->daddr));
 
-               float throttle=shost.send_packet();
+               float throttle = shost.send_packet();
                if(throttle<1)
                {
                        self->packets.push_back(new Packet(shost, dhost, self->get_port_color(port), size));
index 89f77790166d86134e4d2e0d0ef04e6c60588b0e..213f6b2d8d597e6a459fd5bdd0662c61af5555ac 100644 (file)
@@ -28,15 +28,15 @@ Packet::Packet(const Host &s, const Host *d, const GL::Color &c, unsigned i):
 
 void Packet::tick(const Time::TimeDelta &dt)
 {
-       double f=dt/Time::sec;
-       x+=f;
+       double f = dt/Time::sec;
+       x += f;
        if(x>1)
-               x=1;
-       angle+=rspeed*f;
+               x = 1;
+       angle += rspeed*f;
        if(angle<0)
-               angle+=M_PI*2;
+               angle += M_PI*2;
        if(angle>=M_PI*2)
-               angle-=M_PI;
+               angle -= M_PI;
 }
 
 void Packet::render(GL::PrimitiveBuilder &bld) const
@@ -46,11 +46,11 @@ void Packet::render(GL::PrimitiveBuilder &bld) const
        if(!src.get_active() || (dest && !dest->get_active()))
                return;
 
-       const Vector2 &spos=src.get_position();
+       const Vector2 &spos = src.get_position();
 
        if(dest)
        {
-               const Vector2 &dpos=dest->get_position();
+               const Vector2 &dpos = dest->get_position();
                Vector2 pos(spos.x*(1-x)+dpos.x*x, spos.y*(1-x)+dpos.y*x);
                Vector2 corner(cos(angle)*size, sin(angle)*size);
 
@@ -73,7 +73,7 @@ void Packet::render(GL::PrimitiveBuilder &bld) const
                bld.vertex(spos.x, spos.y);
                for(unsigned i=0; i<=24; ++i)
                {
-                       float a=i*M_PI/12;
+                       float a = i*M_PI/12;
                        bld.vertex(spos.x+cos(a)*x*200, spos.y+sin(a)*x*200);
                }
        }
index 1a0b99fb4c12e78a61f409513b59152d7ee292a1..1bf6c39c4eb19958f4b1540edfa9d080e77086e0 100644 (file)
@@ -23,7 +23,7 @@ Resolver::Resolver():
 
 Resolver::~Resolver()
 {
-       done=true;
+       done = true;
        join();
 }
 
@@ -54,15 +54,15 @@ void Resolver::main()
                                MutexLock l_(mutex);
                                if(in_queue.empty())
                                        break;
-                               host=in_queue.front();
+                               host = in_queue.front();
                                in_queue.erase(in_queue.begin());
                        }
                        
                        sockaddr_in addr;
-                       addr.sin_family=AF_INET;
-                       addr.sin_addr.s_addr=htonl(host->get_address());
+                       addr.sin_family = AF_INET;
+                       addr.sin_addr.s_addr = htonl(host->get_address());
                        char buf[128];
-                       int err=getnameinfo(reinterpret_cast<sockaddr *>(&addr), sizeof(addr), buf, sizeof(buf), 0, 0, NI_NOFQDN|NI_NAMEREQD);
+                       int err = getnameinfo(reinterpret_cast<sockaddr *>(&addr), sizeof(addr), buf, sizeof(buf), 0, 0, NI_NOFQDN|NI_NAMEREQD);
                        if(err==0)
                        {
                                MutexLock l_(mutex);