gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r21381 - in gnunet-java: . src/org/gnunet/dht src/org/gnune


From: gnunet
Subject: [GNUnet-SVN] r21381 - in gnunet-java: . src/org/gnunet/dht src/org/gnunet/util
Date: Wed, 9 May 2012 15:23:40 +0200

Author: dold
Date: 2012-05-09 15:23:40 +0200 (Wed, 09 May 2012)
New Revision: 21381

Modified:
   gnunet-java/ISSUES
   gnunet-java/src/org/gnunet/dht/DistributedHashTable.java
   gnunet-java/src/org/gnunet/util/HashCode.java
Log:
dht get works again

Modified: gnunet-java/ISSUES
===================================================================
--- gnunet-java/ISSUES  2012-05-09 13:02:28 UTC (rev 21380)
+++ gnunet-java/ISSUES  2012-05-09 13:23:40 UTC (rev 21381)
@@ -23,6 +23,11 @@
 * Statistics:
  * currently watches can't be canceled on the service level, only on the api 
level, is this intentional?
 
+* DHT:
+ * getStart timeout does not really make sense (why timeout for transmission 
to the service,
+   but not for retrieval of answers?)
+   Is this just a documentation error?
+
 * with the changes in ARM there is no way to restart gnunet with arm if some 
client is misbehaving
 
 * I'm often getting

Modified: gnunet-java/src/org/gnunet/dht/DistributedHashTable.java
===================================================================
--- gnunet-java/src/org/gnunet/dht/DistributedHashTable.java    2012-05-09 
13:02:28 UTC (rev 21380)
+++ gnunet-java/src/org/gnunet/dht/DistributedHashTable.java    2012-05-09 
13:23:40 UTC (rev 21381)
@@ -28,8 +28,9 @@
      */
     private long nextUid = 1;
 
-    private List<GetRequest> activeGetRequests = new ArrayList<GetRequest>(5);
+    private GetRequest currentGetRequest;
 
+    private MonitorRequest currentMonitorRequest;
 
     /**
      * put request awaiting response. may be null if no put request is active.
@@ -89,7 +90,9 @@
         public HashCode key;
         public ResultCallback cb;
         public AbsoluteTime deadline;
-        public boolean canceled = false;
+        public int type;
+        public int replication;
+        public byte[] xquery;
 
         public GetRequest() {
             uid = DistributedHashTable.this.nextUid++;
@@ -102,10 +105,17 @@
 
         @Override
         public void transmit(Connection.MessageSink sink) {
+            ClientGetMessage gm = new ClientGetMessage();
+            gm.desiredReplicationLevel = replication;
+            gm.type = type;
+            gm.xquery = xquery;
+            gm.key = key;
+            gm.uniqueId = uid;
+
+            sink.send(gm);
         }
     }
 
-
     public class DHTMessageReceiver extends RunaboutMessageReceiver {
         public void visit(ClientPutConfirmationMessage pcm) {
             if (currentPutRequest == null || pcm.uid != currentPutRequest.uid) 
{
@@ -116,18 +126,10 @@
         }
 
         public void visit(ClientResultMessage rm) {
-            GetRequest request = null;
-
-            for (GetRequest r : activeGetRequests) {
-                if (r.uid == rm.uid) {
-                    request = r;
-                    break;
-                }
-            }
-            if (request == null) {
+            if (currentGetRequest == null || currentGetRequest.uid != rm.uid) {
                 logger.warn("received response on invalid UID");
             } else {
-                
request.cb.handleResult(AbsoluteTime.fromNetwork(rm.expiration), rm.key, null, 
null, BlockType.TEST,
+                
currentGetRequest.cb.handleResult(AbsoluteTime.fromNetwork(rm.expiration), 
rm.key, null, null, BlockType.TEST,
                         rm.data);
             }
         }
@@ -185,15 +187,24 @@
      * @param cb           the callback object for results or failure 
indication
      * @return a handle to cancel the request
      */
-    public Cancelable startGet(RelativeTime timeout, BlockType type, HashCode 
key,
+    public Cancelable startGet(RelativeTime timeout, int type, HashCode key,
                                int replication, EnumSet<RouteOption> 
routeOptions,
                                byte[] xquery, ResultCallback cb) {
 
+        if (currentGetRequest != null) {
+            throw new AssertionError("only one getRequest may be active at a 
time");
+        }
+
         final GetRequest getRequest = new GetRequest();
         getRequest.key = key;
         getRequest.cb = cb;
+        getRequest.type = type;
+        getRequest.replication = type;
+        getRequest.xquery = xquery;
         getRequest.deadline = timeout.toAbsolute();
 
+        currentGetRequest = getRequest;
+
         return requestQueue.add(getRequest);
     }
 
@@ -298,7 +309,7 @@
 
                     final DistributedHashTable dht = new 
DistributedHashTable(cfg);
 
-                    dht.startGet(RelativeTime.SECOND, BlockType.TEST, new 
HashCode(key), replication, null,
+                    dht.startGet(RelativeTime.SECOND, BlockType.TEST.val, new 
HashCode(key), replication, null,
                             new byte[0], new ResultCallback() {
                         @Override
                         public void handleResult(AbsoluteTime expiration, 
HashCode key, List<PeerIdentity>
@@ -321,4 +332,5 @@
     private class MonitorPutHandler {}
 
 
+    private class MonitorRequest {}
 }

Modified: gnunet-java/src/org/gnunet/util/HashCode.java
===================================================================
--- gnunet-java/src/org/gnunet/util/HashCode.java       2012-05-09 13:02:28 UTC 
(rev 21380)
+++ gnunet-java/src/org/gnunet/util/HashCode.java       2012-05-09 13:23:40 UTC 
(rev 21381)
@@ -14,8 +14,13 @@
 public class HashCode implements Message {
 
     @FixedSizeByteArray(length = 64)
-    public final byte[] data;
+    public byte[] data; // should be immutable, final, can't be due to 
construct
 
+
+    public HashCode() {
+        // construct needs a default c'tor
+    }
+
     public HashCode(byte[] hash) {
         if (hash.length != 64) {
             throw new AssertionError("HashCode has to have length 64");




reply via email to

[Prev in Thread] Current Thread [Next in Thread]