Ejemplo n.º 1
0
void
dhblock_keyhash_srv::real_store (chordID key, str od, str nd, u_int32_t exp, cb_dhstat cb)
{
  u_int32_t v1 = dhblock_keyhash::version (nd.cstr (), nd.len ());
  if (od.len ()) {
    u_int32_t v0 = dhblock_keyhash::version (od.cstr (), od.len ());
    if (v0 > v1) {
      chordID p = node->my_pred ()->id ();
      chordID m = node->my_ID ();
      if (betweenrightincl (p, m, key))
	cb (DHASH_STALE);
      else
	cb (DHASH_RETRY);
    } else {
      info << "db delete: " << key << "\n";
      db->remove (key, v0, 
		  wrap (this, &dhblock_keyhash_srv::delete_cb, key, 
			nd, v1, exp, cb));
    }
  } else {
    info << "db write: " << node->my_ID ()
	 << " N " << key << " " << nd.len () << "\n";
    db_store (key, nd, v1, exp, cb);
  }
}
Ejemplo n.º 2
0
Archivo: server.C Proyecto: Amit-DU/dht
void
vnode_impl::find_succlist_hop_cb (cbroute_t cb, route_iterator *ri, u_long m,
				  bool done)
{
  static bool shave = true;
  static bool initialized = false;
  if (!initialized) {
    int x = 1;
    assert (Configurator::only ().get_int ("chord.find_succlist_shaving", x));
    shave = (x == 1);
    initialized = true;
  }

  vec<chord_node> cs = ri->successors ();
  if (done) {
    cb (cs, ri->path (), ri->status ());
    delete ri;
    return;
  }
  if (shave) {
    size_t left = 0;
    if (cs.size () < m)
      left = cs.size ();
    else
      left = cs.size () - m;
    for (size_t i = 1; i < left; i++) {
      if (betweenrightincl (cs[i-1].x, cs[i].x, ri->key ())) {
	trace << myID << ": find_succlist (" << ri->key () << "): skipping " << i << " nodes.\n";
	cs.popn_front (i);
	cb (cs, ri->path (), ri->status ());
	delete ri;
	return;
      }
    }
  }

  ri->next_hop ();
}
Ejemplo n.º 3
0
void
pmaint::pmaint_gotkey (adb_status stat, u_int32_t id, vec<adb_keyaux_t> keys)
{
  if (stat == ADB_OK && keys.size () > 0) {
    chordID key = keys[0].key;
    pmaint_getkeys_id = id;
    vec<ptr<location> > preds = host_node->preds ();
  
    if (preds.size () >= dhblock_chash::num_efrags () &&
	betweenrightincl (preds[dhblock_chash::num_efrags () - 1]->id(), 
			  host_node->my_ID (),
			  key)) {
      active_cb = delaycb (PRTTMTINY, wrap (this, &pmaint::pmaint_next));
      return;
    }
    cli->lookup (key, wrap (this, &pmaint::pmaint_lookup, key));
    active_cb = NULL;
  } else { 
    //data base is empty
    //check back later
    info << host_node->my_ID () << " PMAINT NEXT: db empty\n";
    active_cb = delaycb (PRTTMLONG, wrap (this, &pmaint::pmaint_next));
  }
}