[OpenDHT-Users] Problem using bambooDHT API version 3: More
Sean Rhea
sean.c.rhea at gmail.com
Wed Oct 18 12:12:05 PDT 2006
On 10/18/06, Zahir Koradia <zahir.koradia at gmail.com> wrote:
> Just to add to the previous mail when null is not returned in read, the
> number of entries retrieved by it is zero. I also tried using version API
> for writing and version 2 API for reading but it does not seem to work. Zero
> entries are returned in this case too. Can some please help me out. If
> anyone has a piece of code that uses the version 3 API and it works fine
> then I would appreciate it if he/she could send me the code snippet.
Zahir,
It seems to work for me using both versions of the API.
bamboo.dht.Put uses version 3:
$ run-java bamboo.dht.Put opendht.nyuld.net 5852 colors red 3600 donttell
BAMBOO_OK
$ run-java bamboo.dht.Put opendht.nyuld.net 5852 colors blue 3600 donttell
BAMBOO_OK
bamboo.dht.Get uses version 2 of the API:
$ run-java -q bamboo.dht.Get opendht.nyuld.net 5852 colors
red
blue
And the attached, hacked-up version of Get uses version 3 of the API:
$ run-java -q bamboo.dht.Get opendht.nyuld.net 5852 colors
value="red", ttl rem=3192
value="blue", ttl rem=3529
Is it still not working for you?
Sean
--
Looking for a PGP signature?
See http://srhea.net/gmail-explain.txt
-------------- next part --------------
/*
* Copyright (c) 2001-2003 Regents of the University of California.
* All rights reserved.
*
* See the file LICENSE included in this distribution for details.
*/
package bamboo.dht;
import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
import static org.acplt.oncrpc.OncRpcProtocols.*;
public class Get {
public static void main(String [] args) throws Exception {
if (args.length < 3) {
System.out.println("usage: java bamboo.dht.Get <server_host> "
+ "<server_port> <key> [max_vals]");
System.exit(1);
}
InetAddress h = InetAddress.getByName(args[0]);
int p = Integer.parseInt(args[1]);
bamboo_get_args getArgs = new bamboo_get_args();
getArgs.application = Get.class.getName();
getArgs.client_library = "Remote Tea ONC/RPC";
MessageDigest md = MessageDigest.getInstance("SHA");
getArgs.key = new bamboo_key();
// If key is of the form 0x12345678, parse it as a hexidecimal value
// of the first 8 digits of the key, rather than hashing it.
if (args[2].substring(0, 2).equals("0x")) {
// Must use a long to handle keys whose first binary digit is 1.
long keyPrefix = Long.parseLong(args[2].substring(2), 16);
getArgs.key.value = new byte[20];
ByteBuffer.wrap(getArgs.key.value).putInt((int) keyPrefix);
}
else {
getArgs.key.value = md.digest(args[2].getBytes());
}
if (args.length > 3)
getArgs.maxvals = Integer.parseInt(args[3]);
else
getArgs.maxvals = Integer.MAX_VALUE;
getArgs.placemark = new bamboo_placemark();
getArgs.placemark.value = new byte [0];
gateway_protClient client = new gateway_protClient(h, p, ONCRPC_TCP);
while (true) {
bamboo_get_result res = client.BAMBOO_DHT_PROC_GET_3(getArgs);
// bamboo_get_res res = client.BAMBOO_DHT_PROC_GET_2(getArgs);
for (int i = 0; i < res.values.length; ++i) {
// System.out.println(new String (res.values[i].value));
System.out.println("value=\""
+ new String (res.values[i].value.value)
+ "\", ttl rem="
+ res.values[i].ttl_sec_rem);
}
if (res.placemark.value.length == 0)
break;
getArgs.placemark = res.placemark;
}
}
}
More information about the OpenDHT-Users
mailing list