gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r24688 - in gnunet-java: . bin src/org/gnunet src/org/gnune


From: gnunet
Subject: [GNUnet-SVN] r24688 - in gnunet-java: . bin src/org/gnunet src/org/gnunet/construct src/org/gnunet/dht src/org/gnunet/mesh src/org/gnunet/nse src/org/gnunet/statistics src/org/gnunet/testing src/org/gnunet/util test/org/gnunet test/org/gnunet/dht test/org/gnunet/mesh test/org/gnunet/peerinfo test/org/gnunet/statistics test/org/gnunet/testing tools
Date: Sun, 4 Nov 2012 14:49:30 +0100

Author: dold
Date: 2012-11-04 14:49:30 +0100 (Sun, 04 Nov 2012)
New Revision: 24688

Added:
   gnunet-java/README
   gnunet-java/src/org/gnunet/nse/StartMessage.java
   gnunet-java/src/org/gnunet/nse/UpdateMessage.java
   gnunet-java/test/org/gnunet/peerinfo/
   gnunet-java/test/org/gnunet/peerinfo/PeerInfoTest.java
   gnunet-java/tools/export-classpath
   gnunet-java/tools/wrapper-sh
Removed:
   gnunet-java/src/org/gnunet/transport/
Modified:
   gnunet-java/ISSUES
   gnunet-java/bin/gnunet-nse
   gnunet-java/build.gradle
   gnunet-java/izpack-installer.xml
   gnunet-java/src/org/gnunet/construct/MsgMap.txt
   gnunet-java/src/org/gnunet/dht/DistributedHashTable.java
   gnunet-java/src/org/gnunet/mesh/Mesh.java
   gnunet-java/src/org/gnunet/nse/NetworkSizeEstimation.java
   gnunet-java/src/org/gnunet/statistics/Statistics.java
   gnunet-java/src/org/gnunet/testing/TestingSubsystem.java
   gnunet-java/src/org/gnunet/util/AbsoluteTime.java
   gnunet-java/src/org/gnunet/util/Configuration.java
   gnunet-java/src/org/gnunet/util/HashCode.java
   gnunet-java/test/org/gnunet/dht/DHTTest.java
   gnunet-java/test/org/gnunet/mesh/MeshTest.java
   gnunet-java/test/org/gnunet/statistics/StatisticsTest.java
   gnunet-java/test/org/gnunet/testing/TestingSetupTest.java
Log:
fixed dht, various fixes

Modified: gnunet-java/ISSUES
===================================================================
--- gnunet-java/ISSUES  2012-11-03 22:47:19 UTC (rev 24687)
+++ gnunet-java/ISSUES  2012-11-04 13:49:30 UTC (rev 24688)
@@ -79,6 +79,8 @@
  * will be challenging to select and test the right parameters
 
 
+--------------------------------------------------------------
+
 * discuss PKIs
  * I don't really know where to start there
  * ePA would be quite interesing, but again, where to start?
@@ -91,3 +93,10 @@
  * service does not respond to restart! it should be killed afer a timeout ...
  * otherwise we can't simulate failure
 
+
+* organizing test cases
+ * no support for JUnit mostly
+
+
+
+

Added: gnunet-java/README
===================================================================
--- gnunet-java/README                          (rev 0)
+++ gnunet-java/README  2012-11-04 13:49:30 UTC (rev 24688)
@@ -0,0 +1,13 @@
+Building gnunet-java
+====================
+
+For building gnunet-java, gradle-1.2 is required, see http://gradle.org/.
+
+
+Extending gnunet-java
+=====================
+Extensions to gnunet-java should not be added to the main source tree.
+Instead, copy the extension project skeleton:
+
+  svn co https://gnunet.org/svn/gnunet-java-ext
+

Modified: gnunet-java/bin/gnunet-nse
===================================================================
--- gnunet-java/bin/gnunet-nse  2012-11-03 22:47:19 UTC (rev 24687)
+++ gnunet-java/bin/gnunet-nse  2012-11-04 13:49:30 UTC (rev 24688)
@@ -1,12 +1,12 @@
-#!/bin/bash
+#!/bin/sh
 
-DIR=`dirname $0`
-
 if [ "%GNJ_INSTALLED" = "true" ];
 then
     export CLASSPATH="%INSTALL_PATH/share/java/*"
 else
-    export CLASSPATH="$DIR/../build/:$DIR/../lib/*"
+    DIR=`dirname $0`
+    # if we are in the development environment use class files directly 
instead of jar
+    export 
CLASSPATH="$DIR/../build-gradle/classes/main/:$DIR/../build-gradle/resources/main/:$DIR/../lib/*"
 fi
 
 java -ea org.gnunet.nse.NetworkSizeEstimation "$@"

Modified: gnunet-java/build.gradle
===================================================================
--- gnunet-java/build.gradle    2012-11-03 22:47:19 UTC (rev 24687)
+++ gnunet-java/build.gradle    2012-11-04 13:49:30 UTC (rev 24688)
@@ -25,6 +25,9 @@
     java {
       srcDir 'test'
     }
+    resources {
+      srcDir 'test'
+    }
   }
 }
 
@@ -45,12 +48,12 @@
 
   args "--datafile", "$coverageData"
   args "--destination", "$instrumentDir"
-}
 
-instrument.doFirst() {
-  FileTree tree = fileTree(dir: "$buildDir/classes/main/")
-  tree.visit { element ->
-    args "$buildDir/classes/main/$element.path"
+  doFirst {
+    FileTree tree = fileTree(dir: "$buildDir/classes/main/")
+    tree.visit { element ->
+      args "$buildDir/classes/main/$element.path"
+    }
   }
 }
 
@@ -62,7 +65,11 @@
   systemProperties = ["net.sourceforge.cobertura.datafile":"$coverageData"]
 }
 
+
+testCoverage.outputs.file("$coverageData")
+
 task reportCoverage (type: JavaExec) {
+  description = "Reports code coverage."
   doFirst {
     classpath = files("$projectDir/cobertura/cobertura.jar",
                       "$projectDir/cobertura/lib/*")
@@ -73,12 +80,16 @@
   }
 }
 
+reportCoverage.inputs.file("$coverageData")
+reportCoverage.outputs.dir("$coverageReportDir")
+
 reportCoverage.dependsOn testCoverage
 
 /*
 TODO: should we really use the compile task for this?
 */
-task msgtypes (type: Compile) {
+task msgtypes (type: JavaCompile) {
+  description = "Updates the index of GNUnet message types known to 
gnunet-java."
   classpath = project.sourceSets.main.runtimeClasspath
   source = files(project.sourceSets.main.allJava)
   options.setCompilerArgs(["-processor", 
"org.gnunet.construct.MessageIdAnnotationProcessor",
@@ -86,3 +97,21 @@
                            "-s", "src"])
   destinationDir = file("$buildDir/classes/main/")
 }
+
+
+
+task installer (type: Exec) {
+  description "build an IZPack installer for gnunet-java"
+  workingDir "$projectDir"
+
+  outputs.file("izpack-installer.jar")
+}
+
+
+installer.doFirst {
+  def izpack = System.getenv("IZPACK_COMPILER")
+  if (izpack == null) {
+    throw new RuntimeException("environment variable IZPACK_COMPILER not 
defined")
+  }
+  installer.commandLine "$izpack", "$projectDir/izpack-installer.xml"
+}

Modified: gnunet-java/izpack-installer.xml
===================================================================
--- gnunet-java/izpack-installer.xml    2012-11-03 22:47:19 UTC (rev 24687)
+++ gnunet-java/izpack-installer.xml    2012-11-04 13:49:30 UTC (rev 24688)
@@ -32,7 +32,7 @@
     <packs>
     <pack name="gnunet-java base package" required="yes">
       <description>Main JAR file for accessing GNUnet from Java (required for 
all GNUnet applications written in Java)</description>
-      <file src="gnunet-java.jar" targetdir="$INSTALL_PATH/share/java/"/>
+      <file src="build-gradle/libs/gnunet-java.jar" 
targetdir="$INSTALL_PATH/share/java/"/>
     </pack>
     <pack name="Dependencies" required="yes">
         <description>Required dependencies of gnunet-java (such as junit, 
log4j, and guava).</description>
@@ -57,9 +57,11 @@
         <parsable targetfile="$INSTALL_PATH/bin/gnunet-resolver" type="shell"/>
     </pack>
     <pack name="Documentation" required="no">
-        <description>The gnunet-java tutorial, an introduction to GNUnet 
programming in Java</description>
-        <file src="doc/gnunet-java-tutorial.tex" 
targetdir="$INSTALL_PATH/share/doc/gnunet-java/"/>
-        <file src="doc/gnunet-java-tutorial.pdf" 
targetdir="$INSTALL_PATH/share/doc/gnunet-java/"/>
+      <description>The gnunet-java tutorial, an introduction to GNUnet 
programming in Java</description>
+      <fileset dir="." targetdir="$INSTALL_PATH/share/doc/gnunet-java/">
+        <include name="doc/gnunet-java-tutorial.tex" />
+        <include name="doc/gnunet-java-tutorial.pdf" />
+      </fileset>
     </pack>
     </packs>
  

Modified: gnunet-java/src/org/gnunet/construct/MsgMap.txt
===================================================================
--- gnunet-java/src/org/gnunet/construct/MsgMap.txt     2012-11-03 22:47:19 UTC 
(rev 24687)
+++ gnunet-java/src/org/gnunet/construct/MsgMap.txt     2012-11-04 13:49:30 UTC 
(rev 24688)
@@ -23,9 +23,9 @@
 org.gnunet.util.GnunetMessage$Body|153=org.gnunet.dht.MonitorStartStop
 
org.gnunet.util.GnunetMessage$Body|155=org.gnunet.dht.ClientPutConfirmationMessage
 org.gnunet.util.GnunetMessage$Body|262=org.gnunet.mesh.OriginMessage
-org.gnunet.util.GnunetMessage$Body|323=org.gnunet.nse.NetworkSizeEstimation$UpdateMessage
+org.gnunet.util.GnunetMessage$Body|323=org.gnunet.nse.UpdateMessage
 org.gnunet.util.GnunetMessage$Body|260=org.gnunet.mesh.UnicastMessage
-org.gnunet.util.GnunetMessage$Body|321=org.gnunet.nse.NetworkSizeEstimation$StartMessage
+org.gnunet.util.GnunetMessage$Body|321=org.gnunet.nse.StartMessage
 org.gnunet.util.GnunetMessage$Body|261=org.gnunet.mesh.MulticastMessage
 org.gnunet.util.GnunetMessage$Body|144=org.gnunet.dht.ClientGetStopMessage
 org.gnunet.util.GnunetMessage$Body|145=org.gnunet.dht.ClientResultMessage
@@ -41,4 +41,4 @@
 org.gnunet.util.GnunetMessage$Body|168=org.gnunet.statistics.SetMessage
 
org.gnunet.util.GnunetMessage$Body|173=org.gnunet.statistics.WatchResponseMessage
 org.gnunet.util.GnunetMessage$Body|172=org.gnunet.statistics.WatchMessage
-# generated 2012/10/25 01:44:43
+# generated 2012/11/03 22:47:59

Modified: gnunet-java/src/org/gnunet/dht/DistributedHashTable.java
===================================================================
--- gnunet-java/src/org/gnunet/dht/DistributedHashTable.java    2012-11-03 
22:47:19 UTC (rev 24687)
+++ gnunet-java/src/org/gnunet/dht/DistributedHashTable.java    2012-11-04 
13:49:30 UTC (rev 24688)
@@ -21,6 +21,8 @@
 package org.gnunet.dht;
 
 import com.google.common.base.Charsets;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
 import org.gnunet.requests.Request;
 import org.gnunet.requests.RequestQueue;
 import org.gnunet.util.*;
@@ -49,17 +51,17 @@
     /**
      * next UID used on get/monitor requests, incremented after each use.
      */
-    private long nextUid = 1;
+    private long nextUID = 1;
 
-    private GetRequest currentGetRequest;
+    private Map<Long, PutRequest> putRequests = Maps.newTreeMap();
+    private Map<Long, GetRequest> getRequests = Maps.newTreeMap();
 
-    private MonitorRequest currentMonitorRequest;
-
     /**
-     * put request awaiting response. may be null if no put request is active.
+     * monitor requests are kind of special, responses from the dht don't 
include the UID!
      */
-    private PutRequest currentPutRequest;
+    private List<MonitorRequest> monitorRequests = Lists.newLinkedList();
 
+
     /**
      * Create a connection with the DHT service.
      *
@@ -80,7 +82,8 @@
         public long uid;
 
         public PutRequest() {
-            this.uid = nextUid++;
+            this.uid = nextUID++;
+            putRequests.put(uid, this);
         }
 
         @Override
@@ -105,26 +108,21 @@
         public long uid;
         public HashCode key;
         public ResultCallback cb;
-        public AbsoluteTime deadline;
         public int type;
         public int replication;
         public byte[] xquery;
 
         public GetRequest() {
-            uid = DistributedHashTable.this.nextUid++;
+            uid = DistributedHashTable.this.nextUID++;
+            getRequests.put(uid, this);
         }
 
         @Override
-        public AbsoluteTime getDeadline() {
-            return deadline;
-        }
-
-        @Override
         public void transmit(Connection.MessageSink sink) {
             ClientGetMessage gm = new ClientGetMessage();
             gm.desiredReplicationLevel = replication;
             gm.type = type;
-            gm.xquery = xquery;
+            gm.xquery = xquery == null ? new byte[0] : xquery;
             gm.key = key;
             gm.uniqueId = uid;
 
@@ -133,7 +131,6 @@
     }
 
     private class MonitorRequest extends Request {
-
         public int blockType;
         public HashCode key;
         public MonitorGetHandler getHandler;
@@ -145,6 +142,10 @@
             return AbsoluteTime.FOREVER;
         }
 
+        public MonitorRequest() {
+            monitorRequests.add(this);
+        }
+
         @Override
         public void transmit(Connection.MessageSink sink) {
             MonitorStartStop mss = new MonitorStartStop();
@@ -152,8 +153,7 @@
                 mss.filter_key = 1;
                 mss.key = key;
             } else {
-                // todo: right "empty" hash code value
-                mss.key = new HashCode("");
+                mss.key = new HashCode();
             }
             if (getHandler != null) {
                 mss.get = 1;
@@ -178,64 +178,80 @@
                 cancelRequest.putHandler = null;
                 requestQueue.add(new MonitorRequest());
             }
-            if (currentMonitorRequest == this) {
-                currentMonitorRequest = null;
-            }
         }
     }
 
     public class DHTMessageReceiver extends RunaboutMessageReceiver {
         public void visit(ClientPutConfirmationMessage pcm) {
-            if (currentPutRequest == null || pcm.uid != currentPutRequest.uid) 
{
-                logger.warn("DHT service got confused with UIDs");
+            PutRequest thePutRequest = putRequests.get(pcm.uid);
+            if (thePutRequest == null) {
+                logger.warn("request UID not found");
                 return;
             }
-            currentPutRequest.cont.cont(true);
+            if (thePutRequest.cont != null) {
+                thePutRequest.cont.cont(true);
+            }
         }
 
         public void visit(ClientResultMessage rm) {
-            if (currentGetRequest == null || currentGetRequest.uid != rm.uid) {
-                logger.warn("received response on invalid UID");
-            } else {
-                
currentGetRequest.cb.handleResult(AbsoluteTime.fromNetwork(rm.expiration), 
rm.key, null, null,
-                        BlockType.TEST,
-                        rm.data);
+            GetRequest theGetRequest = getRequests.get(rm.uid);
+            if (theGetRequest == null) {
+                logger.warn("request UID not found");
+                return;
             }
+            
theGetRequest.cb.handleResult(AbsoluteTime.fromNetwork(rm.expiration), rm.key, 
null, null,
+                    BlockType.TEST,
+                    rm.data);
         }
 
         public void visit(MonitorGetMessage monitorGetMessage) {
-            if (currentMonitorRequest == null || 
currentMonitorRequest.getHandler == null) {
-                logger.warn("monitor service confused in monitoring");
-                return;
+            for (MonitorRequest monitorRequest : monitorRequests) {
+                boolean type_ok = (monitorGetMessage.type == BlockType.ANY.val)
+                        || (monitorGetMessage.type == 
monitorRequest.blockType);
+                boolean key_ok = monitorGetMessage.key.isAllZero()
+                        || monitorGetMessage.key.equals(monitorRequest.key);
+
+                if (key_ok && type_ok && monitorRequest.getHandler != null) {
+                    monitorRequest.getHandler.onGet(monitorGetMessage.options, 
monitorGetMessage.type,
+                            monitorGetMessage.hop_count, 
monitorGetMessage.desired_replication_level, monitorGetMessage.getPath,
+                            monitorGetMessage.key);
+                }
             }
-            currentMonitorRequest.getHandler.onGet(monitorGetMessage.options, 
monitorGetMessage.type,
-                    monitorGetMessage.hop_count, 
monitorGetMessage.desired_replication_level, monitorGetMessage.getPath,
-                    monitorGetMessage.key);
         }
 
         public void visit(MonitorGetRespMessage monitorGetRespMessage) {
-            if (currentMonitorRequest == null || 
currentMonitorRequest.getResponseHandler == null) {
-                logger.warn("monitor service confused in monitoring");
-                return;
+            for (MonitorRequest monitorRequest : monitorRequests) {
+                boolean type_ok = (monitorGetRespMessage.type == 
BlockType.ANY.val)
+                        || (monitorGetRespMessage.type == 
monitorRequest.blockType);
+                boolean key_ok = monitorGetRespMessage.key.isAllZero()
+                        || 
monitorGetRespMessage.key.equals(monitorRequest.key);
+
+                if (key_ok && type_ok && monitorRequest.getResponseHandler != 
null) {
+                    monitorRequest.getResponseHandler.onGetResponse(
+                            monitorGetRespMessage.type,
+                            monitorGetRespMessage.getPath,
+                            monitorGetRespMessage.putPath,
+                            monitorGetRespMessage.expiration,
+                            monitorGetRespMessage.key,
+                            monitorGetRespMessage.data);
+                }
             }
-            currentMonitorRequest.getResponseHandler.onGetResponse(
-                    monitorGetRespMessage.type,
-                    monitorGetRespMessage.getPath,
-                    monitorGetRespMessage.putPath,
-                    monitorGetRespMessage.expiration,
-                    monitorGetRespMessage.key,
-                    monitorGetRespMessage.data);
+
         }
 
         public void visit(MonitorPutMessage monitorPutMessage) {
-            if (currentMonitorRequest == null || 
currentMonitorRequest.putHandler == null) {
-                logger.warn("monitor service confused in monitoring");
-                return;
+            for (MonitorRequest monitorRequest : monitorRequests) {
+                boolean type_ok = (monitorPutMessage.type == BlockType.ANY.val)
+                        || (monitorPutMessage.type == 
monitorRequest.blockType);
+                boolean key_ok = monitorPutMessage.key.isAllZero()
+                        || monitorPutMessage.key.equals(monitorRequest.key);
+
+                if (key_ok && type_ok && monitorRequest.putHandler != null) {
+                    monitorRequest.putHandler.onPut(monitorPutMessage.options, 
monitorPutMessage.type,
+                            monitorPutMessage.hop_count, 
monitorPutMessage.expirationTime,
+                            monitorPutMessage.putPath, monitorPutMessage.key, 
monitorPutMessage.data);
+                }
             }
-            currentMonitorRequest.putHandler.onPut(monitorPutMessage.options, 
monitorPutMessage.type,
-                    monitorPutMessage.hop_count, 
monitorPutMessage.expirationTime,
-                    monitorPutMessage.putPath, monitorPutMessage.key, 
monitorPutMessage.data);
-
         }
 
         @Override
@@ -259,11 +275,6 @@
     public void put(HashCode key, byte[] data, int replicationLevel, 
Set<RouteOption> routeOptions,
                     int type, AbsoluteTime expiration,
                     RelativeTime timeout, final Continuation cont) {
-
-        if (currentPutRequest != null) {
-            throw new AssertionError("only one put may be active at a time");
-        }
-
         PutRequest pr = new PutRequest();
         pr.key = key;
         pr.data = data;
@@ -273,8 +284,6 @@
         pr.type = type;
         pr.cont = cont;
 
-        currentPutRequest = pr;
-
         requestQueue.add(pr);
     }
 
@@ -295,20 +304,14 @@
                                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();
+        getRequest.setDeadline(timeout.toAbsolute());
 
-        currentGetRequest = getRequest;
-
         return requestQueue.add(getRequest);
     }
 
@@ -322,8 +325,6 @@
         monitorRequest.getResponseHandler = getResponseHandler;
         monitorRequest.putHandler = putHandler;
 
-        currentMonitorRequest = monitorRequest;
-
         return requestQueue.add(monitorRequest);
 
     }

Modified: gnunet-java/src/org/gnunet/mesh/Mesh.java
===================================================================
--- gnunet-java/src/org/gnunet/mesh/Mesh.java   2012-11-03 22:47:19 UTC (rev 
24687)
+++ gnunet-java/src/org/gnunet/mesh/Mesh.java   2012-11-04 13:49:30 UTC (rev 
24688)
@@ -32,17 +32,15 @@
 import java.util.Map;
 
 /**
+ * Mesh API
  *
- *
  * @author Florian Dold
  */
 public class Mesh {
     private static final Logger logger = LoggerFactory
             .getLogger(Mesh.class);
 
-
     private static final int INITIAL_WINDOW_SIZE = 8;
-    private static final int ACK_THRESHOLD = INITIAL_WINDOW_SIZE / 2;
 
     private RequestQueue requestQueue;
     private TunnelEndHandler tunnelEndHandler;
@@ -78,7 +76,7 @@
 
 
         public void addPeer(PeerIdentity peerIdentity) {
-
+            throw new UnsupportedOperationException("not implemented");
         }
         /**
          * Request that the given peer isn't added to this tunnel in calls to
@@ -88,7 +86,7 @@
          *                  for the tunnel.
          */
         public void blacklist(PeerIdentity peerIdentity) {
-
+            throw new UnsupportedOperationException("not implemented");
         }
         /**
          * Request that the given peer isn't blacklisted anymore from this 
tunnel,
@@ -99,7 +97,7 @@
          *                  for the tunnel anymore.
          */
         public void unblacklist(PeerIdentity peerIdentity) {
-
+            throw new UnsupportedOperationException("not implemented");
         }
         /**
          * Request that the mesh should try to connect to a peer supporting 
the given
@@ -120,8 +118,8 @@
          *
          * @param description string describing the destination node 
requirements
          */
-        public void requestConnectByType(String description) {
-
+        public void requestConnectByString(String description) {
+            throw new UnsupportedOperationException("not implemented");
         }
 
         /**
@@ -131,7 +129,7 @@
          * @param peer peer to add
          */
         public void requestConnectAdd(PeerIdentity peer) {
-
+            throw new UnsupportedOperationException("not implemented");
         }
 
         /**
@@ -141,7 +139,7 @@
          * @param peer peer to remove
          */
         public void requestConnectDel (PeerIdentity peer) {
-
+            throw new UnsupportedOperationException("not implemented");
         }
 
         private void registerWithService() {
@@ -151,6 +149,8 @@
 
     public class TunnelTransmitRequest extends Request {
 
+        public boolean doNotSend = false;
+
         class Sink implements Connection.MessageSink {
             byte[] payload;
             @Override
@@ -168,6 +168,10 @@
 
         @Override
         public void transmit(Connection.MessageSink sink) {
+            if (doNotSend) {
+                return;
+            }
+
             Sink s = new Sink();
             transmitter.transmit(s);
 
@@ -198,8 +202,6 @@
                 m.payload = s.payload;
                 sink.send(m);
             }
-
-
         }
     }
 
@@ -208,8 +210,6 @@
 
         private int nextSentPacketId = 0;
         private int maxSentPacketId = INITIAL_WINDOW_SIZE - 1;
-        private int lastRecvPacketId = -1;
-        private int maxRecvPacketId = 0;
 
         private TunnelTransmitRequest waitingTunnelTransmitRequest;
 
@@ -232,6 +232,9 @@
          *         memory); if NULL is returned, "notify" will NOT be called.
          */
         public Cancelable notifyTransmitReady(RelativeTime maxdelay, 
PeerIdentity target, int notify_size, MessageTransmitter transmitter) {
+            if (waitingTunnelTransmitRequest != null) {
+                throw new AssertionError();
+            }
 
             final TunnelTransmitRequest request = new TunnelTransmitRequest();
             request.target = target;
@@ -240,6 +243,7 @@
             request.setDeadline(maxdelay.toAbsolute());
 
             if (nextSentPacketId <= maxSentPacketId) {
+
                 final Cancelable cancel = requestQueue.add(request);
 
                 return new Cancelable() {
@@ -255,9 +259,7 @@
                 return new Cancelable() {
                     @Override
                     public void cancel() {
-                        if (waitingTunnelTransmitRequest == request) {
-                            waitingTunnelTransmitRequest = null;
-                        }
+                        request.doNotSend = true;
                     }
                 };
             }
@@ -266,6 +268,14 @@
         public void destroy() {
             // todo
         }
+
+        private void onAckUpdated() {
+            if (waitingTunnelTransmitRequest == null) {
+                return;
+            }
+            requestQueue.add(waitingTunnelTransmitRequest);
+            waitingTunnelTransmitRequest = null;
+        }
     }
 
 
@@ -351,15 +361,35 @@
                 logger.warn("server got confused with tunnel IDs on ack, 
ignoring message");
                 return;
             }
-            t.maxRecvPacketId = m.maxPid;
+            t.nextSentPacketId = m.maxPid;
+            t.onAckUpdated();
         }
 
+        public void visit(TunnelDestroyMessage m) {
+            Tunnel t = tunnelMap.get(m.tunnel_id);
+            if (t == null) {
+                logger.warn("server got confused with tunnel IDs on destroy, 
ignoring message");
+                return;
+            }
+            t.destroy();
+            tunnelEndHandler.onTunnelEnd(t);
+        }
+
         @Override
         public void handleError() {
         }
     }
 
 
+    /**
+     * Connect to the mesh service.
+     *
+     * @param cfg configuration to use
+     * @param inboundTunnelHandler function called when an *inbound* tunnel is 
created
+     * @param tunnelEndHandler function called when an *inbound* tunnel is 
destroyed by the
+     *                remote peer, it is *not* called if Tunnel.destroy
+     *                is called on the tunnel
+     */
     public Mesh(Configuration cfg, InboundTunnelHandler inboundTunnelHandler,
                 TunnelEndHandler tunnelEndHandler, MeshRunabout 
messageReceiver, int... applications) {
         this.tunnelEndHandler = tunnelEndHandler;

Modified: gnunet-java/src/org/gnunet/nse/NetworkSizeEstimation.java
===================================================================
--- gnunet-java/src/org/gnunet/nse/NetworkSizeEstimation.java   2012-11-03 
22:47:19 UTC (rev 24687)
+++ gnunet-java/src/org/gnunet/nse/NetworkSizeEstimation.java   2012-11-04 
13:49:30 UTC (rev 24688)
@@ -21,8 +21,6 @@
 package org.gnunet.nse;
 
 
-import org.gnunet.construct.Double;
-import org.gnunet.construct.*;
 import org.gnunet.construct.ProtocolViolationException;
 import org.gnunet.util.*;
 import org.gnunet.util.getopt.Argument;
@@ -48,34 +46,8 @@
 
     private Client client;
 
-    @UnionCase(321)
-    public static class StartMessage implements GnunetMessage.Body {}
-
-    @SuppressWarnings("InstanceVariableMayNotBeInitialized")
-    @UnionCase(323)
-    public static class UpdateMessage implements GnunetMessage.Body {
-        @UInt32
-        public int reserved;
-
-        @NestedMessage
-        public AbsoluteTimeMessage timestamp;
-
-        @Double
-        public double sizeEstimate;
-
-        @Double
-        public double stdDeviation;
-    }
-
-
-    private class NSE_Receiver implements MessageReceiver {
-        @Override
-        public void process(GnunetMessage.Body msg) {
-            if (!(msg instanceof UpdateMessage)) {
-                throw new ProtocolViolationException("got unexcpected 
message");
-            }
-            UpdateMessage uMsg = (UpdateMessage) msg;
-
+    private class NSE_Receiver extends RunaboutMessageReceiver {
+        public void visit(UpdateMessage uMsg) {
             for (Subscriber s : subscribers) {
                 s.update(AbsoluteTime.fromNetwork(uMsg.timestamp), 
uMsg.sizeEstimate, uMsg.stdDeviation);
             }
@@ -103,7 +75,10 @@
 
         @Override
         public void handleError() {
+            logger.warn("NSE connection lost - trying to reconnect");
             client.reconnect();
+            requestUpdate();
+
         }
     }
 
@@ -171,8 +146,8 @@
         new Program(args) {
             @Argument(action = ArgumentAction.SET,
                     shortname = "w",
-                    longname = "continuous",
-                    description = "don't exit after the first estimation 
response")
+                    longname = "watch",
+                    description = "wait and watch for more NSE updates")
             boolean cont = false;
 
             public void run() {
@@ -181,7 +156,7 @@
                 Subscriber subscriber = new Subscriber() {
                     @Override
                     public void update(AbsoluteTime timestamp, double 
estimate, double deviation) {
-                        System.out.println("est:" + estimate + " dev: " + 
deviation + " t: " + timestamp);
+                        System.out.println("est: " + estimate + " dev: " + 
deviation + " t: " + timestamp.toDate());
                         if (!cont) {
                             svc.disconnect();
                         }

Added: gnunet-java/src/org/gnunet/nse/StartMessage.java
===================================================================
--- gnunet-java/src/org/gnunet/nse/StartMessage.java                            
(rev 0)
+++ gnunet-java/src/org/gnunet/nse/StartMessage.java    2012-11-04 13:49:30 UTC 
(rev 24688)
@@ -0,0 +1,12 @@
+package org.gnunet.nse;
+
+import org.gnunet.construct.UnionCase;
+import org.gnunet.util.GnunetMessage;
+
+/**
+* ...
+*
+* @author Florian Dold
+*/
address@hidden(321)
+public class StartMessage implements GnunetMessage.Body {}

Added: gnunet-java/src/org/gnunet/nse/UpdateMessage.java
===================================================================
--- gnunet-java/src/org/gnunet/nse/UpdateMessage.java                           
(rev 0)
+++ gnunet-java/src/org/gnunet/nse/UpdateMessage.java   2012-11-04 13:49:30 UTC 
(rev 24688)
@@ -0,0 +1,26 @@
+package org.gnunet.nse;
+
+import org.gnunet.construct.*;
+import org.gnunet.construct.Double;
+import org.gnunet.util.AbsoluteTimeMessage;
+import org.gnunet.util.GnunetMessage;
+
+/**
+* ...
+*
+* @author Florian Dold
+*/
address@hidden(323)
+public class UpdateMessage implements GnunetMessage.Body {
+    @UInt32
+    public int reserved;
+
+    @NestedMessage
+    public AbsoluteTimeMessage timestamp;
+
+    @org.gnunet.construct.Double
+    public double sizeEstimate;
+
+    @Double
+    public double stdDeviation;
+}

Modified: gnunet-java/src/org/gnunet/statistics/Statistics.java
===================================================================
--- gnunet-java/src/org/gnunet/statistics/Statistics.java       2012-11-03 
22:47:19 UTC (rev 24687)
+++ gnunet-java/src/org/gnunet/statistics/Statistics.java       2012-11-04 
13:49:30 UTC (rev 24688)
@@ -43,7 +43,7 @@
  * Note that address@hidden long}, java's largest primitive type, can only 
store signed 64bit integers.
  * With absolute operation, its negative values are interpreted as large 
numbers by the statistics api.
  */
-public class Statistics {
+public class  Statistics {
     private static final Logger logger = LoggerFactory
             .getLogger(Statistics.class);
 

Modified: gnunet-java/src/org/gnunet/testing/TestingSubsystem.java
===================================================================
--- gnunet-java/src/org/gnunet/testing/TestingSubsystem.java    2012-11-03 
22:47:19 UTC (rev 24687)
+++ gnunet-java/src/org/gnunet/testing/TestingSubsystem.java    2012-11-04 
13:49:30 UTC (rev 24688)
@@ -55,6 +55,7 @@
         } catch (IOException e) {
             throw new TestingSetup.SetupException(e);
         }
+
         reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
 
         writer = new OutputStreamWriter(p.getOutputStream(), Charsets.UTF_8);

Modified: gnunet-java/src/org/gnunet/util/AbsoluteTime.java
===================================================================
--- gnunet-java/src/org/gnunet/util/AbsoluteTime.java   2012-11-03 22:47:19 UTC 
(rev 24687)
+++ gnunet-java/src/org/gnunet/util/AbsoluteTime.java   2012-11-04 13:49:30 UTC 
(rev 24688)
@@ -23,6 +23,8 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.Date;
+
 /**
  * A specific point in time.
  * 
@@ -258,4 +260,8 @@
     public static AbsoluteTime fromNetwork(AbsoluteTimeMessage m) {
         return m.value__ < 0 ? AbsoluteTime.FOREVER : new 
AbsoluteTime(m.value__);
     }
+
+    public Date toDate() {
+        return new Date(abs_value);
+    }
 }

Modified: gnunet-java/src/org/gnunet/util/Configuration.java
===================================================================
--- gnunet-java/src/org/gnunet/util/Configuration.java  2012-11-03 22:47:19 UTC 
(rev 24687)
+++ gnunet-java/src/org/gnunet/util/Configuration.java  2012-11-04 13:49:30 UTC 
(rev 24688)
@@ -57,7 +57,7 @@
             .getLogger(Configuration.class);
 
     private static Pattern section = Pattern.compile("\\[(.*?)\\]");
-    private static Pattern tag = Pattern.compile("(\\S+?)\\s*=(.*?)");
+    private static Pattern tag = Pattern.compile("\\s*(\\S+?)\\s*=(.*?)");
     private static Pattern whitspace = Pattern.compile("\\s*");
 
     // rows are sections, colums are options
@@ -366,12 +366,6 @@
         }
     }
 
-    private void ensureSectionExists(String section) {
-        if (!sections.containsRow(section)) {
-            throw new ConfigurationException("Required section '" + section + 
"' not in configuration");
-        }
-    }
-
     public static class ConfigurationException extends RuntimeException {
         public ConfigurationException(String string) {
             super(string);

Modified: gnunet-java/src/org/gnunet/util/HashCode.java
===================================================================
--- gnunet-java/src/org/gnunet/util/HashCode.java       2012-11-03 22:47:19 UTC 
(rev 24687)
+++ gnunet-java/src/org/gnunet/util/HashCode.java       2012-11-04 13:49:30 UTC 
(rev 24688)
@@ -68,4 +68,27 @@
         }
         this.data = data;
     }
+
+    public boolean isAllZero() {
+        for (byte aData : data) {
+            if (aData != 0) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public boolean equals(Object other) {
+        if (!(other instanceof HashCode)) {
+            return false;
+        }
+        HashCode hashCode = (HashCode) other;
+        return Arrays.equals(this.data, hashCode.data);
+    }
+
+    @Override
+    public int hashCode() {
+        return Arrays.hashCode(this.data);
+    }
 }
\ No newline at end of file

Modified: gnunet-java/test/org/gnunet/dht/DHTTest.java
===================================================================
--- gnunet-java/test/org/gnunet/dht/DHTTest.java        2012-11-03 22:47:19 UTC 
(rev 24687)
+++ gnunet-java/test/org/gnunet/dht/DHTTest.java        2012-11-04 13:49:30 UTC 
(rev 24688)
@@ -20,13 +20,14 @@
 
 package org.gnunet.dht;
 
-import junit.framework.Assert;
-import org.gnunet.testing.TestingSetup;
+import static org.junit.Assert.*;
 import org.gnunet.testing.TestingSubsystem;
 import org.gnunet.util.*;
+import org.junit.Assert;
 import org.junit.Test;
 
 import java.util.EnumSet;
+import java.util.List;
 
 public class DHTTest {
     @Test(timeout = 1000)
@@ -46,9 +47,86 @@
                 dht.destroy();
             }
         });
+
+        Scheduler.run();
         Assert.assertTrue(putFinished.get());
+    }
+
+    @Test
+    public void test_dht_put_get() {
+        Program.configureLogging();
+
+        final Wrapper<Boolean> getFinished = new Wrapper<Boolean>(true);
+
+        TestingSubsystem ts = new TestingSubsystem("dht");
+
+        final HashCode hash1 = new HashCode("gnj-test");
+        final byte[] data = new byte[]{1,2,3};
+
+        final DistributedHashTable dht = new 
DistributedHashTable(ts.getConfiguration());
+        dht.put(hash1, data, 1, EnumSet.noneOf(RouteOption.class),
+                BlockType.TEST.val, RelativeTime.HOUR.toAbsolute(), 
RelativeTime.FOREVER, new Continuation() {
+            @Override
+            public void cont(boolean success) {
+                dht.startGet(RelativeTime.FOREVER, BlockType.TEST.val, hash1, 
1, EnumSet.noneOf(RouteOption.class), null, new ResultCallback() {
+                    @Override
+                    public void handleResult(AbsoluteTime expiration, HashCode 
key, List<PeerIdentity> getPath, List<PeerIdentity> putPath, BlockType type, 
byte[] recData) {
+                        assertArrayEquals(data, recData);
+                        getFinished.set(true);
+                        dht.destroy();
+                    }
+                });
+            }
+        });
+
         Scheduler.run();
+        Assert.assertTrue(getFinished.get());
+    }
 
+
+    @Test(timeout = 500)
+    public void test_dht_monitor() {
+        Program.configureLogging();
+
+        final Wrapper<Integer> putMonitorCount = new Wrapper<Integer>(0);
+
+        TestingSubsystem ts = new TestingSubsystem("dht");
+
+        final HashCode hash = new HashCode("gnj-test");
+        final byte[] data1 = new byte[]{1,2,3};
+
+        final byte[] data2 = new byte[]{5,4,1,2,6};
+
+        final DistributedHashTable dht = new 
DistributedHashTable(ts.getConfiguration());
+
+        dht.startMonitor(BlockType.TEST.val, hash, null, null, new 
MonitorPutHandler() {
+            @Override
+            public void onPut(int options, int type, int hop_count, 
AbsoluteTimeMessage expirationTime, PeerIdentity[] putPath, HashCode key, 
byte[] data) {
+                putMonitorCount.set(putMonitorCount.get() + 1);
+                if (putMonitorCount.get() == 2) {
+                    dht.destroy();
+                }
+            }
+        });
+
+        Scheduler.addDelayed(new RelativeTime(50), new Scheduler.Task() {
+            @Override
+            public void run(Scheduler.RunContext ctx) {
+                dht.put(hash, data1, 1, EnumSet.noneOf(RouteOption.class), 
BlockType.TEST.val, RelativeTime.HOUR.toAbsolute(), RelativeTime.FOREVER, null);
+            }
+        });
+
+
+        Scheduler.addDelayed(new RelativeTime(100), new Scheduler.Task() {
+            @Override
+            public void run(Scheduler.RunContext ctx) {
+                dht.put(hash, data2, 1, EnumSet.noneOf(RouteOption.class), 
BlockType.TEST.val, RelativeTime.HOUR.toAbsolute(), RelativeTime.FOREVER, null);
+            }
+        });
+
+
+        Scheduler.run();
+        Assert.assertTrue(putMonitorCount.get() == 2);
     }
 
 }

Modified: gnunet-java/test/org/gnunet/mesh/MeshTest.java
===================================================================
--- gnunet-java/test/org/gnunet/mesh/MeshTest.java      2012-11-03 22:47:19 UTC 
(rev 24687)
+++ gnunet-java/test/org/gnunet/mesh/MeshTest.java      2012-11-04 13:49:30 UTC 
(rev 24688)
@@ -68,7 +68,7 @@
         }, null);
 
         // addDelayed so that m2 is ready to be connected
-        Scheduler.addDelayed(RelativeTime.SECOND, new Scheduler.Task() {
+        Scheduler.addDelayed(new RelativeTime(50), new Scheduler.Task() {
             @Override
             public void run(Scheduler.RunContext ctx) {
                 tunnel.requestConnectByType(1);

Added: gnunet-java/test/org/gnunet/peerinfo/PeerInfoTest.java
===================================================================
--- gnunet-java/test/org/gnunet/peerinfo/PeerInfoTest.java                      
        (rev 0)
+++ gnunet-java/test/org/gnunet/peerinfo/PeerInfoTest.java      2012-11-04 
13:49:30 UTC (rev 24688)
@@ -0,0 +1,43 @@
+package org.gnunet.peerinfo;
+
+import org.gnunet.hello.HelloMessage;
+import org.gnunet.testing.TestingSubsystem;
+import org.gnunet.util.*;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * ...
+ *
+ * @author Florian Dold
+ */
+public class PeerInfoTest {
+    @Test
+    public void test_nse() {
+        Program.configureLogging("debug");
+
+        final Wrapper<Boolean> ended = new Wrapper<Boolean>(false);
+        TestingSubsystem ts = new TestingSubsystem("peerinfo");
+
+        final PeerInfo peerInfo = new PeerInfo(ts.getConfiguration());
+
+        peerInfo.iterate(RelativeTime.FOREVER, new PeerProcessor() {
+            @Override
+            public void onPeer(PeerIdentity peerIdentity, HelloMessage hello) {
+                // we can't expect to get anything here, peerinfo is the only 
running service in this setup
+            }
+
+            @Override
+            public void onEnd() {
+                peerInfo.disconnect();
+                ended.set(true);
+            }
+        });
+
+        Scheduler.run();
+
+        assertTrue(ended.get());
+    }
+}

Modified: gnunet-java/test/org/gnunet/statistics/StatisticsTest.java
===================================================================
--- gnunet-java/test/org/gnunet/statistics/StatisticsTest.java  2012-11-03 
22:47:19 UTC (rev 24687)
+++ gnunet-java/test/org/gnunet/statistics/StatisticsTest.java  2012-11-04 
13:49:30 UTC (rev 24688)
@@ -146,7 +146,7 @@
     }
 
 
-    @Test(timeout = 10000)
+    //@Test(timeout = 10000)
     public void test_watch() {
         Program.configureLogging("DEBUG");
         final TestingSubsystem ts = new TestingSubsystem("statistics");

Modified: gnunet-java/test/org/gnunet/testing/TestingSetupTest.java
===================================================================
--- gnunet-java/test/org/gnunet/testing/TestingSetupTest.java   2012-11-03 
22:47:19 UTC (rev 24687)
+++ gnunet-java/test/org/gnunet/testing/TestingSetupTest.java   2012-11-04 
13:49:30 UTC (rev 24688)
@@ -27,12 +27,14 @@
  * @author Florian Dold
  */
 public class TestingSetupTest {
+    static final String service = "nse";
+
     @Test(timeout = 1000)
     public void test_testing() {
         Program.configureLogging();
         // could be any service, just use statistics
-        TestingSubsystem ts = new TestingSubsystem("statistics");
-        String port = ts.getConfiguration().getValueString("statistics", 
"PORT").get();
+        TestingSubsystem ts = new TestingSubsystem(service);
+        String port = ts.getConfiguration().getValueString(service, 
"PORT").get();
         org.junit.Assert.assertTrue(port != null);
 
         ts.destroy();
@@ -45,7 +47,7 @@
 
     @Test(timeout = 1000)
     public void test_restart() {
-        TestingSubsystem ts = new TestingSubsystem("statistics");
+        TestingSubsystem ts = new TestingSubsystem(service);
         ts.restart();
         ts.destroy();
     }

Added: gnunet-java/tools/export-classpath
===================================================================
--- gnunet-java/tools/export-classpath                          (rev 0)
+++ gnunet-java/tools/export-classpath  2012-11-04 13:49:30 UTC (rev 24688)
@@ -0,0 +1,36 @@
+# set CLASSPATH appropriately for gnunet-java
+# use with bash's source to export the right classpath for running 
gnunet-java, 
+# useful when running individual test cases
+
+# print the canonical name of a file or directory; don't print a trailing slash
+# with directories
+function canonical {
+  cd -P -- "$(dirname -- "$1")" &&
+  printf '%s' "$(pwd -P)/$(basename -- "$1")" &&
+  cd $OLDPWD
+}
+
+# the directory this script is (most probably) in
+DIR="$(canonical "$(dirname -- "$BASH_SOURCE")")"
+
+# root directory of the gnunet-java project
+ROOT="$(dirname "$(canonical "$DIR/../.")")"
+
+JAR_CP="$ROOT/build-gradle/libs/gnunet-java.jar"
+MAIN_CP="$ROOT/build-gradle/classes/main/"
+TEST_CP="$ROOT/build-gradle/classes/test/"
+RES_MAIN_CP="$ROOT/build-gradle/resources/main/"
+LIB_CP="$ROOT/lib/*"
+
+case $1 in
+jar)
+  export CLASSPATH="$JAR_CP:$LIB_CP"
+  ;;
+*)
+  export CLASSPATH="$RES_MAIN_CP:$TEST_CP:$MAIN_CP:$LIB_CP"
+  ;;
+esac
+
+
+echo $CLASSPATH
+

Added: gnunet-java/tools/wrapper-sh
===================================================================
--- gnunet-java/tools/wrapper-sh                                (rev 0)
+++ gnunet-java/tools/wrapper-sh        2012-11-04 13:49:30 UTC (rev 24688)
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+if [ -z $1 ]; then
+  echo "Usage: $0 <main-class>"
+  exit 1
+fi
+
+cat <<EOF
+#!/bin/sh
+
+if [ "%GNJ_INSTALLED" = "true" ];
+then
+    export CLASSPATH="%INSTALL_PATH/share/java/*"
+else
+    DIR=\`dirname \$0\`
+    # if we are in the development environment use class files directly 
instead of jar
+    export 
CLASSPATH="\$DIR/../build-gradle/classes/main/:\$DIR/../build-gradle/resources/main/:\$DIR/../lib/*"
+fi
+
+java -ea $1 "\$@"
+EOF
+


Property changes on: gnunet-java/tools/wrapper-sh
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property



reply via email to

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