⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 misc_utils.c

📁 chord 源码 http://pdos.csail.mit.edu/chord/
💻 C
字号:
#include "misc_utils.h"#include "id_utils.h"#include "location.h"#include <amisc.h>#define MAX_INT 0x7fffffffconst int modelnet_on (getenv("MODELNET") ? 1 : 0 );boolin_vector (const vec<chordID> &v, chordID N){  for (unsigned int i = 0; i < v.size (); i++)    if (v[i] == N) return true;  return false;}boolin_vector (const vec<ptr<location> > &l, chordID N){  for (unsigned int i = 0; i < l.size (); i++)    if (l[i]->id () == N) return true;  return false;}str gettime(){  str buf ("");  timespec ts;  clock_gettime (CLOCK_REALTIME, &ts);  buf = strbuf (" %d:%06d", int (ts.tv_sec), int (ts.tv_nsec/1000));  return buf;}u_int64_tgetusec (){  timeval tv;  gettimeofday (&tv, NULL);  return tv.tv_sec * INT64(1000000) + tv.tv_usec;}floatuniform_random_f (float max){  float f;  unsigned long c = random ();  f = 2*max*(((float)c)/((float)RAND_MAX));  f -= max;  return f;}u_int32_tuniform_random(double a, double b){  double f;  int c = random();  if (c == MAX_INT) c--;  f = (b - a)*((double)c)/((double)MAX_INT);  return (u_int32_t)(a + f);}chord_hostnamemy_addr () {  vec<in_addr> addrs;  if (!myipaddrs (&addrs))    fatal ("my_addr: cannot find my IP address.\n");  in_addr *addr = addrs.base ();  in_addr *loopback = 0;  while (addr < addrs.lim ()) {    if (ntohl (addr->s_addr) == INADDR_LOOPBACK) loopback = addr;    else break;    addr++;  }  if (addr >= addrs.lim () && (loopback == NULL))    fatal ("my_addr: cannot find my IP address.\n");  if (addr >= addrs.lim ()) {    warnx << "my_addr: use loopback address as my address\n";    addr = loopback;  }  str ids = inet_ntoa (*addr);  return ids;}chord_nodemake_chord_node (const chord_node_wire &nl){  chord_node n;  struct in_addr x;  x.s_addr = htonl (nl.machine_order_ipv4_addr);  if (modelnet_on) {    x.s_addr = x.s_addr & 0xffff00ff; //JY: clear the modelnet bits  }  n.r.hostname = inet_ntoa (x);  n.r.port     = nl.machine_order_port_vnnum >> 16;  n.vnode_num  = nl.machine_order_port_vnnum & 0xFFFF;  n.x = make_chordID (n.r.hostname, n.r.port, n.vnode_num);  n.coords = nl.coords;  n.e = nl.e;  //jy  n.budget = nl.budget;  n.knownup = nl.knownup;  n.age = nl.age;  return n;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -