aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/gnunet/dht/DistributedHashTable.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/gnunet/dht/DistributedHashTable.java')
-rw-r--r--src/main/java/org/gnunet/dht/DistributedHashTable.java41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/main/java/org/gnunet/dht/DistributedHashTable.java b/src/main/java/org/gnunet/dht/DistributedHashTable.java
index 0246992..27bac92 100644
--- a/src/main/java/org/gnunet/dht/DistributedHashTable.java
+++ b/src/main/java/org/gnunet/dht/DistributedHashTable.java
@@ -21,6 +21,7 @@
21package org.gnunet.dht; 21package org.gnunet.dht;
22 22
23import com.google.common.base.Charsets; 23import com.google.common.base.Charsets;
24import org.gnunet.dht.messages.*;
24import org.gnunet.mq.Envelope; 25import org.gnunet.mq.Envelope;
25import org.gnunet.requests.MatchingRequestContainer; 26import org.gnunet.requests.MatchingRequestContainer;
26import org.gnunet.requests.Request; 27import org.gnunet.requests.Request;
@@ -37,7 +38,7 @@ import java.util.List;
37import java.util.Set; 38import java.util.Set;
38 39
39/** 40/**
40 * API for the gnunet dht service. 41 * API for the GNUnet dht service.
41 * <p/> 42 * <p/>
42 * Stores data under a key, distributed across the network. 43 * Stores data under a key, distributed across the network.
43 * <p/> 44 * <p/>
@@ -230,6 +231,7 @@ public class DistributedHashTable {
230 231
231 @Override 232 @Override
232 public void handleError() { 233 public void handleError() {
234 // FIXME
233 } 235 }
234 } 236 }
235 237
@@ -256,12 +258,10 @@ public class DistributedHashTable {
256 * @param routeOptions additional options 258 * @param routeOptions additional options
257 * @param type type of the data to store 259 * @param type type of the data to store
258 * @param expiration how long should the value be stored? TODO: what is the maximum? 260 * @param expiration how long should the value be stored? TODO: what is the maximum?
259 * @param timeout how long after we give up on storing the value?
260 * @param cont called after the put operation failed or succeeded 261 * @param cont called after the put operation failed or succeeded
261 */ 262 */
262 public void put(HashCode key, byte[] data, int replicationLevel, Set<RouteOption> routeOptions, 263 public void put(HashCode key, byte[] data, int replicationLevel, Set<RouteOption> routeOptions,
263 int type, AbsoluteTime expiration, 264 int type, AbsoluteTime expiration, final Continuation cont) {
264 RelativeTime timeout, final Continuation cont) {
265 PutRequest pr = new PutRequest(); 265 PutRequest pr = new PutRequest();
266 pr.key = key; 266 pr.key = key;
267 pr.data = data; 267 pr.data = data;
@@ -296,10 +296,21 @@ public class DistributedHashTable {
296 getRequest.type = type; 296 getRequest.type = type;
297 getRequest.replication = type; 297 getRequest.replication = type;
298 getRequest.xquery = xquery; 298 getRequest.xquery = xquery;
299 getRequest.replication = replication;
299 300
300 return getRequests.addRequest(getRequest.uid, getRequest); 301 return getRequests.addRequest(getRequest.uid, getRequest);
301 } 302 }
302 303
304 /**
305 * Start monitoring certain types of requests.
306 *
307 * @param blockType block type of requests we're interested in
308 * @param key key we're interested in
309 * @param getHandler listener for get requests
310 * @param getResponseHandler listener for get responses
311 * @param putHandler listener for put requests
312 * @return a handle to cancel the monitoring
313 */
303 public Cancelable startMonitor(int blockType, HashCode key, MonitorGetHandler getHandler, 314 public Cancelable startMonitor(int blockType, HashCode key, MonitorGetHandler getHandler,
304 MonitorGetResponseHandler getResponseHandler, 315 MonitorGetResponseHandler getResponseHandler,
305 MonitorPutHandler putHandler) { 316 MonitorPutHandler putHandler) {
@@ -389,17 +400,17 @@ public class DistributedHashTable {
389 400
390 dht.put(new HashCode(key), data.getBytes(), replication, EnumSet.of(RouteOption.NONE), 401 dht.put(new HashCode(key), data.getBytes(), replication, EnumSet.of(RouteOption.NONE),
391 BlockType.TEST.val, AbsoluteTime.now().add(RelativeTime.HOUR), 402 BlockType.TEST.val, AbsoluteTime.now().add(RelativeTime.HOUR),
392 RelativeTime.SECOND, new Continuation() { 403 new Continuation() {
393 @Override 404 @Override
394 public void cont(boolean success) { 405 public void cont(boolean success) {
395 if (success) { 406 if (success) {
396 System.out.println("put getRequestIdentifier sent"); 407 System.out.println("put getRequestIdentifier sent");
397 } else { 408 } else {
398 System.out.println("error"); 409 System.out.println("error");
399 } 410 }
400 dht.destroy(); 411 dht.destroy();
401 } 412 }
402 }); 413 });
403 } else if (monitor) { 414 } else if (monitor) {
404 final DistributedHashTable dht = new DistributedHashTable(cfg); 415 final DistributedHashTable dht = new DistributedHashTable(cfg);
405 dht.startMonitor(BlockType.TEST.val, null, 416 dht.startMonitor(BlockType.TEST.val, null,