[OpenDHT-Users] Problem using bambooDHT API version 3
Zahir Koradia
zahir.koradia at gmail.com
Mon Oct 16 03:19:49 PDT 2006
I have been using Bamboo version 2 to read and write entries in
OpenDHT and want to shift to versio 3 to have the remove capability.
In version 3 I am able to write (result is bamboo_ok) but
bamboo_dht_proc_get_3(&args, p_node) returns null. I am am copying the
read and write functions here.
write(const RegRecord& rr, int ttl)
{
int count;
std::string::size_type pos=0;
std::string addr = "";
CLIENT* p_node = get_node();
if (p_node == NULL) return false;
//printf("TcaRegistry::write: using node %d\n", int(p_node));
uint8 key[DHT_KEYLEN];
uint8 secret_key[DHT_SECRETLEN];
hash(rr.host_, key);
hash(rr.host_, secret_key);
// dump_digest(key);
bamboo_put_arguments args;
memset(&args, 0, sizeof(args));
args.application = const_cast<char*>(APP_STRING);
args.client_library = const_cast<char*>(CLIB_STRING);
memcpy(args.key, key, DHT_KEYLEN);
args.secret_hash.algorithm = const_cast<char*>(HASH_STRING);
args.secret_hash.hash.hash_len = DHT_SECRETLEN;
args.secret_hash.hash.hash_val = (char *)malloc(DHT_SECRETLEN);
memcpy(args.secret_hash.hash.hash_val, secret_key, DHT_SECRETLEN);
addr = rr.gateways_addr_;
do
{
for(count=0;count<3;count++)
{
pos = addr.find("|",pos + 1);
if(pos == std::string::npos)
break;
}
if(count == 3)
{
addr.erase(0,pos + 1);
}
}while(pos != std::string::npos);
args.value.bamboo_value_len = addr.length() + 1;
args.value.bamboo_value_val = const_cast<char*>(addr.c_str());
args.ttl_sec = ttl;
bamboo_stat* res = bamboo_dht_proc_put_3(&args, p_node);
return (*res == BAMBOO_OK);
}
read(RegRecord& rr)
{
int i;
u_int n_values,count=0;
bamboo_value* p_val;
std::string addr = "";
std::string::size_type pos;
bamboo_get_result* res;
CLIENT* p_node = get_node();
if (p_node == NULL) return false;
// printf("TcaRegistry::read: using node %d\n", int(p_node));
uint8 key[DHT_KEYLEN];
hash(rr.host_, key);
// dump_digest(key);
bamboo_get_args args;
memset(&args, 0, sizeof(args));
args.application = const_cast<char*>(APP_STRING);
args.client_library = const_cast<char*>(CLIB_STRING);
memcpy(args.key, key, DHT_KEYLEN);
// Note: to here, this function is identical to write()
do{
args.maxvals = MAX_RECORDS;
res = bamboo_dht_proc_get_3(&args, p_node);
if (res == NULL)
{
printf("TcaRegistry::read: get returned NULL\n");
return false;
}
n_values = res->values.values_len;
count += n_values;
if(count > MAX_RECORDS)
{
printf("Error: number of records returnd from DHT are more
than %d.\n",MAX_RECORDS);
return false;
}
for (i=0;(u_int)i<n_values;i++)
{
p_val = &(res->values.values_val[i].value);
addr = p_val->bamboo_value_val;
if(addr.find(",",0)!=std::string::npos)
{
pos = addr.find("|",0);
addr.erase(0,pos + 1);
}
rr.gateways_addr_ = rr.gateways_addr_ + addr;
}
args.placemark.bamboo_placemark_val = res->placemark.bamboo_placemark_val;
args.placemark.bamboo_placemark_len = res->placemark.bamboo_placemark_len;
}while(res->placemark.bamboo_placemark_val != NULL);
if(count != 0)
{
printf("TcaRegistry::read: succeeded! value=%s\n",
rr.gateways_addr_.c_str());
fflush(stdout);
}
return count;
}
I have verified that the key sent to the bamboo functions in case of
read and write are the same. The return value of null means that the
rpc call in gateway_prot_clnt.c has returned something other than
RPC_SUCCESS. Can anyone find anything wrong with the code? Has anyone
faced a similar problem before?
Thanks
Zahir koradia
More information about the OpenDHT-Users
mailing list