Example #1
0
File: nodeq.C Project: Amit-DU/dht
void
processreslist_cb (str desc, vec<ptr<node> > *list,
		   chord_nodelistextres *res, clnt_stat status)
{
  outstanding--;
  if (status) {
    errors++;
    warnx << "no " << desc << ": " << status << "\n";
    if (outstanding == 0)
      finish ();
    return;
  }

  size_t sz = res->resok->nlist.size ();
  vec<chord_node> zs;
  for (size_t i = 0; i < sz; i++) {
    ptr<node> nn = New refcounted<node> (i, res->resok->nlist[i]);
    list->push_back (nn);
    
    if (do_reverse_lookup) {
      outstanding++;
      struct in_addr ar;
      ar.s_addr = htonl (res->resok->nlist[i].n.machine_order_ipv4_addr);
      dns_hostbyaddr (ar, wrap (&dns_lookup_cb, nn));
    }
  }
  delete res;
  
  if (outstanding == 0)
    finish ();
}
Example #2
0
void
f_node::dnslookup (void)
{
  struct in_addr ar;
  inet_aton (host, &ar);
  dns_hostbyaddr (ar, wrap (this, &f_node::dnslookup_cb));
  hostname = host;
}
Example #3
0
void
identptr (int fd, callback<void, str, ptr<hostent>, int>::ref cb)
{
  struct sockaddr_in la, ra;
  socklen_t len;

  len = sizeof (la);
  bzero (&la, sizeof (la));
  bzero (&ra, sizeof (ra));
  errno = 0;
  if (getsockname (fd, (struct sockaddr *) &la, &len) < 0
      || la.sin_family != AF_INET
      || getpeername (fd, (struct sockaddr *) &ra, &len) < 0
      || ra.sin_family != AF_INET
      || len != sizeof (la)) {
    warn ("ident: getsockname/getpeername: %s\n", strerror (errno));
    (*cb) ("*disconnected*", NULL, ARERR_CANTSEND);
    return;
  }

  u_int lp = ntohs (la.sin_port);
  la.sin_port = htons (0);
  u_int rp = ntohs (ra.sin_port);
  ra.sin_port = htons (AUTH_PORT);

  int ifd = socket (AF_INET, SOCK_STREAM, 0);
  if (ifd >= 0) {
    close_on_exec (ifd);
    make_async (ifd);
    if (connect (ifd, (sockaddr *) &ra, sizeof (ra)) < 0
	&& errno != EINPROGRESS) {
      close (ifd);
      ifd = -1;
    }
  }

  identstat *is = New identstat;
  is->err = 0;
  is->cb = cb;
  is->host = inet_ntoa (ra.sin_addr);

  if (ifd >= 0) {
    is->ncb = 2;
    close_on_exec (ifd);
    is->a = aios::alloc (ifd);
    is->a << rp << ", " << lp << "\r\n";
    is->a->settimeout (15);
    is->a->readline (wrap (is, &identstat::identcb));
  }
  else
    is->ncb = 1;

  dns_hostbyaddr (ra.sin_addr, wrap (is, &identstat::dnscb));
}