X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fhost.cpp;h=93c537ea104fae71d27977f7486feca149821ebd;hb=e7ccd0d35487219da5d1e447e5fd435ad763ba4c;hp=afa61b71e775a4eaa5ab49c8c87fc799ce5f71b0;hpb=cb4b88367edde2829e40015f0bc02d653db2a6a8;p=netvis.git diff --git a/source/host.cpp b/source/host.cpp index afa61b7..93c537e 100644 --- a/source/host.cpp +++ b/source/host.cpp @@ -19,17 +19,15 @@ Distributed unter the GPL using namespace std; using namespace Msp; -Host::Host(NetVis &nv, unsigned a): +Host::Host(NetVis &nv, const Address &a): netvis(nv), addr(a), + name(addr.str()), + short_name(name), local(false), active(true), throttle(0) { - in_addr ina; - ina.s_addr = htonl(addr); - name = inet_ntoa(ina); - short_name = name; } void Host::set_name(const string &n) @@ -99,11 +97,11 @@ void Host::tick(const Msp::Time::TimeDelta &td) if(!active) return; - const map &hosts = netvis.get_hosts(); + const map &hosts = netvis.get_hosts(); float center_force = (local ? 0.5 : 0.1); float fx = -pos.x*center_force; float fy = -pos.y*center_force; - for(map::const_iterator i=hosts.begin(); i!=hosts.end(); ++i) + for(map::const_iterator i=hosts.begin(); i!=hosts.end(); ++i) { if(i->second!=this) { @@ -113,10 +111,7 @@ void Host::tick(const Msp::Time::TimeDelta &td) 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; + unsigned matching_bits = addr.common_prefix_length(i->second->get_address()); float optimal_dist = 100+(24-min(matching_bits, 24U))*12; float f = 5000.0*(1.0/optimal_dist-1.0/d);