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)
if(!active)
return;
- const map<unsigned, Host *> &hosts = netvis.get_hosts();
+ const map<Address, Host *> &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<unsigned, Host *>::const_iterator i=hosts.begin(); i!=hosts.end(); ++i)
+ for(map<Address, Host *>::const_iterator i=hosts.begin(); i!=hosts.end(); ++i)
{
if(i->second!=this)
{
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);