gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r21061 - in gnunet-java: . src/org/gnunet src/org/gnunet/co


From: gnunet
Subject: [GNUnet-SVN] r21061 - in gnunet-java: . src/org/gnunet src/org/gnunet/construct src/org/gnunet/construct/parsers src/org/gnunet/core src/org/gnunet/dht src/org/gnunet/nse src/org/gnunet/statistics src/org/gnunet/util src/org/gnunet/util/getopt test/org/gnunet/services
Date: Sun, 22 Apr 2012 01:09:41 +0200

Author: dold
Date: 2012-04-22 01:09:41 +0200 (Sun, 22 Apr 2012)
New Revision: 21061

Added:
   gnunet-java/src/org/gnunet/construct/ProtocolViolation.java
Removed:
   gnunet-java/src/org/gnunet/exceptions/
   gnunet-java/src/org/gnunet/util/IntEnum.java
   gnunet-java/src/org/gnunet/util/datastructures/
Modified:
   gnunet-java/ISSUES
   gnunet-java/src/org/gnunet/construct/Construct.java
   gnunet-java/src/org/gnunet/construct/MessageLoader.java
   gnunet-java/src/org/gnunet/construct/ReflectUtil.java
   gnunet-java/src/org/gnunet/construct/parsers/ByteFillParser.java
   gnunet-java/src/org/gnunet/construct/parsers/DoubleParser.java
   gnunet-java/src/org/gnunet/construct/parsers/FillParser.java
   gnunet-java/src/org/gnunet/construct/parsers/FixedSizeByteArrayParser.java
   gnunet-java/src/org/gnunet/construct/parsers/NestedParser.java
   gnunet-java/src/org/gnunet/construct/parsers/StringParser.java
   gnunet-java/src/org/gnunet/construct/parsers/UnionParser.java
   gnunet-java/src/org/gnunet/core/Core.java
   gnunet-java/src/org/gnunet/dht/DistributedHashTable.java
   gnunet-java/src/org/gnunet/nse/NetworkSizeEstimation.java
   gnunet-java/src/org/gnunet/statistics/Statistics.java
   gnunet-java/src/org/gnunet/util/ATSInformation.java
   gnunet-java/src/org/gnunet/util/AbsoluteTimeMessage.java
   gnunet-java/src/org/gnunet/util/Client.java
   gnunet-java/src/org/gnunet/util/Configuration.java
   gnunet-java/src/org/gnunet/util/Connection.java
   gnunet-java/src/org/gnunet/util/GnunetMessage.java
   gnunet-java/src/org/gnunet/util/HashCode.java
   gnunet-java/src/org/gnunet/util/MessageReceiver.java
   gnunet-java/src/org/gnunet/util/MessageTransmitter.java
   gnunet-java/src/org/gnunet/util/PeerIdentity.java
   gnunet-java/src/org/gnunet/util/Program.java
   gnunet-java/src/org/gnunet/util/RelativeTimeMessage.java
   gnunet-java/src/org/gnunet/util/Resolver.java
   gnunet-java/src/org/gnunet/util/RunaboutMessageReceiver.java
   gnunet-java/src/org/gnunet/util/Scheduler.java
   gnunet-java/src/org/gnunet/util/Server.java
   gnunet-java/src/org/gnunet/util/Service.java
   gnunet-java/src/org/gnunet/util/getopt/Parser.java
   gnunet-java/test/org/gnunet/services/NetworkSizeEstimationServiceTest.java
Log:
added comments, fixed stuff, revising statistics API implementation

Modified: gnunet-java/ISSUES
===================================================================
--- gnunet-java/ISSUES  2012-04-21 18:16:21 UTC (rev 21060)
+++ gnunet-java/ISSUES  2012-04-21 23:09:41 UTC (rev 21061)
@@ -523,5 +523,19 @@
 
  
---------------------------------------------------------------------------------
 
- * revisitid connection: concurrent address probe bad wrt ipv4/ipv6 sockets
-   (client tries to connect twice to the service, one connection always 
dropped)
\ No newline at end of file
+ * revisited connection: concurrent address probe bad wrt ipv4/ipv6 sockets
+   (client tries to connect twice to the service, one connection always 
dropped)
+
+
+
+
+* todo:
+ * implement server / service
+ * revise statistics api / it's queue
+ * implement DHT stuff
+ * refactor construct
+ * write tutorial
+ * write tests/weed out bugs
+
+
+* idea: a request queue, with timeouts, cancel
\ No newline at end of file

Modified: gnunet-java/src/org/gnunet/construct/Construct.java
===================================================================
--- gnunet-java/src/org/gnunet/construct/Construct.java 2012-04-21 18:16:21 UTC 
(rev 21060)
+++ gnunet-java/src/org/gnunet/construct/Construct.java 2012-04-21 23:09:41 UTC 
(rev 21061)
@@ -1,7 +1,6 @@
 package org.gnunet.construct;
 
 import org.gnunet.construct.parsers.*;
-import org.gnunet.exceptions.InterfaceViolationException;
 import org.grothoff.Runabout;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -94,7 +93,7 @@
         SequenceParser parser = new SequenceParser();
 
         if (!Modifier.isPublic(c.getModifiers())) {
-            throw new InterfaceViolationException(String.format("Construct 
Message %s not declared public", c));
+            throw new AssertionError(String.format("Construct Message %s not 
declared public", c));
         }
 
         for (Field f : getMessageFields(c)) {
@@ -104,7 +103,7 @@
                 continue;
             }
             if (!Modifier.isPublic(f.getModifiers())) {
-                throw new InterfaceViolationException(String.format("Field %s 
of Message %s not declared public", f, c));
+                throw new AssertionError(String.format("Field %s of Message %s 
not declared public", f, c));
             }
             pg.field = f;
             pg.annotations = as;
@@ -165,7 +164,7 @@
                 try {
                     f = current.getField(member);
                 } catch (NoSuchFieldException e) {
-                    throw new InterfaceViolationException("invalid field path, 
component " + member + " not found");
+                    throw new AssertionError("invalid field path, component " 
+ member + " not found");
                 }
 
                 fp.add(f);
@@ -189,13 +188,13 @@
             frameSizePath.add(field);
 
             if (annotationsIdx != 0) {
-                throw new InterfaceViolationException(
+                throw new AssertionError(
                         "FrameSize must be the first annotation on a Field");
             }
 
             annotationsIdx++;
             if (annotationsIdx >= annotations.length) {
-                throw new InterfaceViolationException(
+                throw new AssertionError(
                         "FrameSize must be followed by an numeric parser");
             }
             visitAppropriate(annotations[annotationsIdx]);
@@ -276,7 +275,7 @@
 
         public void visit(ByteFill bf) {
             if (frameSizePath == null) {
-                throw new InterfaceViolationException(
+                throw new AssertionError(
                         "no total size found before variable size element");
             }
 
@@ -304,7 +303,7 @@
 
         public void visit(Double d) {
             if (!field.getType().equals(java.lang.Double.TYPE)) {
-                throw new InterfaceViolationException("@Double target must be 
a primitive 'double' field");
+                throw new AssertionError("@Double target must be a primitive 
'double' field");
             }
             parser = new DoubleParser(field);
         }
@@ -332,12 +331,12 @@
                         .lengthField()), f);
 
             } catch (SecurityException e) {
-                throw new InterfaceViolationException(
+                throw new AssertionError(
                         String.format(
                                 "VariableSizeArray: length field '%s' not 
declared public",
                                 vsa.lengthField()));
             } catch (NoSuchFieldException e) {
-                throw new InterfaceViolationException(String.format(
+                throw new AssertionError(String.format(
                         "VariableSizeArray: length field '%s' does not exist 
in class %s",
                         vsa.lengthField(), old_c));
             }

Modified: gnunet-java/src/org/gnunet/construct/MessageLoader.java
===================================================================
--- gnunet-java/src/org/gnunet/construct/MessageLoader.java     2012-04-21 
18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/construct/MessageLoader.java     2012-04-21 
23:09:41 UTC (rev 21061)
@@ -23,8 +23,6 @@
 package org.gnunet.construct;
 
 
-import org.gnunet.exceptions.InternalLogicError;
-import org.gnunet.exceptions.MessageFormatException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,6 +35,10 @@
 import java.util.HashMap;
 import java.util.Map;
 
+
+/**
+ * Load message maps
+ */
 public class MessageLoader {
     private static final Logger logger = LoggerFactory
             .getLogger(MessageLoader.class);
@@ -133,9 +135,9 @@
         try {
             msgClass = (Class<MessageUnion>) cl.loadClass(className);
         } catch (ClassNotFoundException e) {
-            throw new InternalLogicError(String.format("message class '%s' not 
found in classpath", className));
+            throw new AssertionError(String.format("message class '%s' not 
found in classpath", className));
         } catch (ClassCastException e) {
-            throw new InternalLogicError(String.format("Class %s does not 
inherit from MessageUnion", className));
+            throw new AssertionError(String.format("Class %s does not inherit 
from MessageUnion", className));
         }
         return msgClass;
     }
@@ -143,12 +145,12 @@
     public static Class<? extends MessageUnion> getUnionClass(Class<? extends 
MessageUnion> unionInterface, int tag) {
         Map<Integer, Class<? extends MessageUnion>> map = 
unionmap.get(unionInterface);
         if (map == null) {
-            throw new InternalLogicError("don't know how to handle unions of 
type '" + unionInterface + "'");
+            throw new AssertionError("don't know how to handle unions of type 
'" + unionInterface + "'");
         }
 
         Class<? extends MessageUnion> cls = map.get(tag);
         if (cls == null) {
-            throw new MessageFormatException("don't know how to translate 
message of type " + tag);
+            throw new ProtocolViolation("don't know how to translate message 
of type " + tag);
         }
 
         return cls;
@@ -157,9 +159,9 @@
     public static int getUnionTag(Class<? extends MessageUnion> 
unionInterface, Class<? extends MessageUnion> unionCase) {
         Map<Class<? extends MessageUnion>, Integer> map = 
tagmap.get(unionInterface);
         if (map == null)
-            throw new InternalLogicError(String.format("%s is not a known 
union type", unionInterface));
+            throw new AssertionError(String.format("%s is not a known union 
type", unionInterface));
         if (!map.containsKey(unionCase))
-            throw new InternalLogicError(String.format("%s is not a known 
instance of %s", unionCase, unionInterface));
+            throw new AssertionError(String.format("%s is not a known instance 
of %s", unionCase, unionInterface));
         return map.get(unionCase);
     }
 }

Copied: gnunet-java/src/org/gnunet/construct/ProtocolViolation.java (from rev 
21055, gnunet-java/src/org/gnunet/exceptions/MessageFormatException.java)
===================================================================
--- gnunet-java/src/org/gnunet/construct/ProtocolViolation.java                 
        (rev 0)
+++ gnunet-java/src/org/gnunet/construct/ProtocolViolation.java 2012-04-21 
23:09:41 UTC (rev 21061)
@@ -0,0 +1,15 @@
+package org.gnunet.construct;
+
+
+/**
+ * Thrown when a received message is invalid
+ * 
+ * @author Florian Dold
+ *
+ */
+public class ProtocolViolation extends RuntimeException {
+
+    public ProtocolViolation(String s) {
+        super(s);
+    }
+}

Modified: gnunet-java/src/org/gnunet/construct/ReflectUtil.java
===================================================================
--- gnunet-java/src/org/gnunet/construct/ReflectUtil.java       2012-04-21 
18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/construct/ReflectUtil.java       2012-04-21 
23:09:41 UTC (rev 21061)
@@ -1,8 +1,6 @@
 package org.gnunet.construct;
 
 
-import org.gnunet.exceptions.InterfaceViolationException;
-
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.math.BigInteger;
@@ -13,15 +11,15 @@
         try {
             return c.getConstructor().newInstance();
         } catch (InstantiationException e) {
-            throw new InterfaceViolationException("Cannot instantiate " + c);
+            throw new AssertionError("Cannot instantiate " + c);
         } catch (IllegalAccessException e) {
-            throw new InterfaceViolationException(
+            throw new AssertionError(
                     String.format("Cannot instantiate Message %s (illegal 
access)", c));
         } catch (NoSuchMethodException e) {
-            throw new InterfaceViolationException(
+            throw new AssertionError(
                     String.format("No suitable default constructor for class 
%s", c));
         } catch (InvocationTargetException e) {
-            throw new InterfaceViolationException(
+            throw new AssertionError(
                     String.format("Exception thrown while constructing object 
of class %s", c));
         }
     }
@@ -61,7 +59,7 @@
             } else if (f.getType().equals(BigInteger.class)) {
                 targetType = NumFieldType.BIGNUM;
             } else {
-                throw new InterfaceViolationException(
+                throw new AssertionError(
                         "expected numeric type, got: " + f.getType());
             }
         }
@@ -89,9 +87,9 @@
                         break;
                 }
             } catch (IllegalArgumentException e) {
-                throw new InterfaceViolationException("cannot access field");
+                throw new AssertionError("cannot access field");
             } catch (IllegalAccessException e) {
-                throw new InterfaceViolationException("cannot access field");
+                throw new AssertionError("cannot access field");
             }
         }
         
@@ -99,7 +97,7 @@
             try {
                 targetField.set(obj, val);
             } catch (IllegalAccessException e) {
-                throw new InterfaceViolationException("cannot access field");
+                throw new AssertionError("cannot access field");
             }
         }
 
@@ -122,7 +120,7 @@
                         throw new AssertionError("unreachable");
                 }
             } catch (IllegalAccessException e) {
-                throw new InterfaceViolationException("cannot access field");
+                throw new AssertionError("cannot access field");
             }
         }
         
@@ -148,7 +146,7 @@
             } catch (IllegalArgumentException e) {
                 throw new RuntimeException(e);
             } catch (IllegalAccessException e) {
-                throw new InterfaceViolationException("cannot access field " + 
fl.get(i)
+                throw new AssertionError("cannot access field " + fl.get(i)
                         + " of " + obj.getClass());
             }
         }
@@ -167,7 +165,7 @@
         try {
             return f.get(obj);
         } catch (IllegalAccessException e) {
-            throw new InterfaceViolationException(
+            throw new AssertionError(
                     String.format("Cannot access private field '%s' in class 
%s", f, obj.getClass()));
         } catch (IllegalArgumentException e) {
             throw new AssertionError("Cannot access field '" + f.getName() + 
"' in class " + obj.getClass());
@@ -178,7 +176,7 @@
         try {
             f.set(obj, val);
         } catch (IllegalAccessException e) {
-            throw new InterfaceViolationException(
+            throw new AssertionError(
                     String.format("Cannot access private field %s in class 
%s", f, obj.getClass()));
         }
     }

Modified: gnunet-java/src/org/gnunet/construct/parsers/ByteFillParser.java
===================================================================
--- gnunet-java/src/org/gnunet/construct/parsers/ByteFillParser.java    
2012-04-21 18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/construct/parsers/ByteFillParser.java    
2012-04-21 23:09:41 UTC (rev 21061)
@@ -2,7 +2,7 @@
 
 import org.gnunet.construct.Message;
 import org.gnunet.construct.ReflectUtil;
-import org.gnunet.exceptions.MessageFormatException;
+import org.gnunet.construct.ProtocolViolation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -52,7 +52,7 @@
         int remaining = frameOffset + frameSize - srcBuf.position();
 
         if (remaining < 0) {
-            throw new MessageFormatException("negative size remaining for 
variable size message");
+            throw new ProtocolViolation("negative size remaining for variable 
size message");
         }
 
         if (remaining == 0) {

Modified: gnunet-java/src/org/gnunet/construct/parsers/DoubleParser.java
===================================================================
--- gnunet-java/src/org/gnunet/construct/parsers/DoubleParser.java      
2012-04-21 18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/construct/parsers/DoubleParser.java      
2012-04-21 23:09:41 UTC (rev 21061)
@@ -2,7 +2,6 @@
 
 
 import org.gnunet.construct.Message;
-import org.gnunet.exceptions.InternalLogicError;
 
 import java.lang.reflect.Field;
 import java.nio.ByteBuffer;
@@ -26,7 +25,7 @@
         try {
             targetField.setDouble(dstObj, d);
         } catch (IllegalAccessException e) {
-            throw new InternalLogicError("cannot access field (should have 
been caught in Construct)");
+            throw new AssertionError("cannot access field (should have been 
caught in Construct)");
         }
         return Double.SIZE / 8;
     }
@@ -37,7 +36,7 @@
         try {
             d = targetField.getDouble(srcObj);
         } catch (IllegalAccessException e) {
-            throw new InternalLogicError("field does not exist (should be 
caught in Construct)");
+            throw new AssertionError("field does not exist (should be caught 
in Construct)");
         }
         dstBuf.putDouble(d);
         return 8;

Modified: gnunet-java/src/org/gnunet/construct/parsers/FillParser.java
===================================================================
--- gnunet-java/src/org/gnunet/construct/parsers/FillParser.java        
2012-04-21 18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/construct/parsers/FillParser.java        
2012-04-21 23:09:41 UTC (rev 21061)
@@ -2,8 +2,6 @@
 
 import org.gnunet.construct.Message;
 import org.gnunet.construct.ReflectUtil;
-import org.gnunet.exceptions.InterfaceViolationException;
-
 import java.lang.reflect.Array;
 import java.lang.reflect.Field;
 import java.nio.ByteBuffer;
@@ -65,7 +63,7 @@
         try {
             targetField.set(dstObj, list.toArray());
         } catch (IllegalAccessException e) {
-            throw new InterfaceViolationException("cannot acces field");
+            throw new AssertionError("cannot acces field");
         }
 
         return size;

Modified: 
gnunet-java/src/org/gnunet/construct/parsers/FixedSizeByteArrayParser.java
===================================================================
--- gnunet-java/src/org/gnunet/construct/parsers/FixedSizeByteArrayParser.java  
2012-04-21 18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/construct/parsers/FixedSizeByteArrayParser.java  
2012-04-21 23:09:41 UTC (rev 21061)
@@ -2,7 +2,6 @@
 
 import org.gnunet.construct.Message;
 import org.gnunet.construct.ReflectUtil;
-import org.gnunet.exceptions.InterfaceViolationException;
 
 import java.lang.reflect.Field;
 import java.nio.ByteBuffer;
@@ -33,7 +32,7 @@
     public int write(ByteBuffer dstBuf, Message srcObj) {
         byte[] data = (byte[]) ReflectUtil.justGet(srcObj, targetField);
         if (data.length != elemNumber) {
-            throw new InterfaceViolationException("fixed size array has wrong 
size");
+            throw new AssertionError("fixed size array has wrong size");
         }
         dstBuf.put(data);
         return elemNumber;

Modified: gnunet-java/src/org/gnunet/construct/parsers/NestedParser.java
===================================================================
--- gnunet-java/src/org/gnunet/construct/parsers/NestedParser.java      
2012-04-21 18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/construct/parsers/NestedParser.java      
2012-04-21 23:09:41 UTC (rev 21061)
@@ -2,7 +2,7 @@
 
 import org.gnunet.construct.Message;
 import org.gnunet.construct.ReflectUtil;
-import org.gnunet.exceptions.MessageFormatException;
+import org.gnunet.construct.ProtocolViolation;
 
 import java.lang.reflect.Field;
 import java.nio.ByteBuffer;
@@ -48,11 +48,11 @@
         if (optional) {
             int remaining = frameOffset + getSizeFieldValue(frameObj) - 
srcBuf.position();
             if (remaining < 0) {
-                throw new MessageFormatException("remaining size negative");
+                throw new ProtocolViolation("remaining size negative");
             }
             if (remaining == 0) {
                 if (!optional) {
-                    throw new MessageFormatException("not optional");
+                    throw new ProtocolViolation("not optional");
                 }
                 ReflectUtil.justSet(dstObj, targetField, null);
                 return 0;

Modified: gnunet-java/src/org/gnunet/construct/parsers/StringParser.java
===================================================================
--- gnunet-java/src/org/gnunet/construct/parsers/StringParser.java      
2012-04-21 18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/construct/parsers/StringParser.java      
2012-04-21 23:09:41 UTC (rev 21061)
@@ -1,9 +1,8 @@
 package org.gnunet.construct.parsers;
 
 import org.gnunet.construct.Message;
+import org.gnunet.construct.ProtocolViolation;
 import org.gnunet.construct.ReflectUtil;
-import org.gnunet.exceptions.InterfaceViolationException;
-import org.gnunet.exceptions.MessageFormatException;
 
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Field;
@@ -28,7 +27,7 @@
             if (optional) {
                 return 0;
             } else {
-                throw new InterfaceViolationException("non-optional string 
cannot be null");
+                throw new AssertionError("non-optional string cannot be null");
             }
         }
         try {
@@ -44,7 +43,7 @@
 
         if (srcBuf.get(srcBuf.position()) == 0) {
             if (!optional) {
-                throw new MessageFormatException("no data received for 
non-optional string");
+                throw new ProtocolViolation("no data received for non-optional 
string");
             }
             ReflectUtil.justSet(dstObj, targetField, null);
             return 1;
@@ -83,7 +82,7 @@
         
         if (s == null) {
             if (!optional) {
-                throw new InterfaceViolationException("non-optional string 
cannot be null");
+                throw new AssertionError("non-optional string cannot be null");
             }
             return 0;
         }

Modified: gnunet-java/src/org/gnunet/construct/parsers/UnionParser.java
===================================================================
--- gnunet-java/src/org/gnunet/construct/parsers/UnionParser.java       
2012-04-21 18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/construct/parsers/UnionParser.java       
2012-04-21 23:09:41 UTC (rev 21061)
@@ -1,7 +1,7 @@
 package org.gnunet.construct.parsers;
 
 import org.gnunet.construct.*;
-import org.gnunet.exceptions.MessageFormatException;
+import org.gnunet.construct.ProtocolViolation;
 
 import java.lang.reflect.Field;
 import java.nio.ByteBuffer;
@@ -52,7 +52,7 @@
             int remaining = frameOffset + getSizeFieldValue(frameObj) - 
srcBuf.position();
             if (remaining <= 0) {
                 if (!optional) {
-                    throw new MessageFormatException("not optional");
+                    throw new ProtocolViolation("not optional");
                 }
                 ReflectUtil.justSet(dstObj, targetField, null);
                 return 0;

Modified: gnunet-java/src/org/gnunet/core/Core.java
===================================================================
--- gnunet-java/src/org/gnunet/core/Core.java   2012-04-21 18:16:21 UTC (rev 
21060)
+++ gnunet-java/src/org/gnunet/core/Core.java   2012-04-21 23:09:41 UTC (rev 
21061)
@@ -12,6 +12,12 @@
 import java.util.LinkedList;
 import java.util.Map;
 
+
+/**
+ * API for the gnunet core service.
+ *
+ * Sends messages to connected peers.
+ */
 public class Core {
     private static final Logger logger = LoggerFactory
             .getLogger(Core.class);
@@ -550,7 +556,7 @@
         if (transmitHandle != null) {
             logger.info("calling NTR for transmitHandle");
             currentClientTransmitHandle = 
client.notifyTransmitReady(RelativeTime.FOREVER, false,
-                    new MessageTransmitter() {
+                    0, new MessageTransmitter() {
                         @Override
                         public void transmit(Connection.MessageSink sink) {
                             logger.info("transmitHandle NTR done");
@@ -585,7 +591,7 @@
         if (sm != null) {
             logger.info("calling NTR for apprvedSendMessages");
             currentClientTransmitHandle = 
client.notifyTransmitReady(RelativeTime.FOREVER, false,
-                    new MessageTransmitter() {
+                    0, new MessageTransmitter() {
                         @Override
                         public void transmit(Connection.MessageSink sink) {
                             currentClientTransmitHandle = null;

Modified: gnunet-java/src/org/gnunet/dht/DistributedHashTable.java
===================================================================
--- gnunet-java/src/org/gnunet/dht/DistributedHashTable.java    2012-04-21 
18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/dht/DistributedHashTable.java    2012-04-21 
23:09:41 UTC (rev 21061)
@@ -1,7 +1,6 @@
 package org.gnunet.dht;
 
 import org.gnunet.construct.*;
-import org.gnunet.exceptions.InterfaceViolationException;
 import org.gnunet.util.*;
 import org.gnunet.util.getopt.Option;
 import org.gnunet.util.getopt.OptionAction;
@@ -12,11 +11,23 @@
 import java.util.EnumSet;
 import java.util.List;
 
+
+/**
+ * API for the gnunet dht service.
+ * <p/>
+ * Stores data under a key, distributed across the network.
+ * <p/>
+ * TODO: implement monitoring
+ */
 public class DistributedHashTable {
     private static final Logger logger = LoggerFactory
             .getLogger(DistributedHashTable.class);
 
-    enum BlockType {
+
+    /**
+     * Information on how to interpret a block of data.
+     */
+    public enum BlockType {
         /**
          * Any type of block, used as a wildcard when searching.  Should
          * never be attached to a specific block.
@@ -74,6 +85,9 @@
     }
 
 
+    /**
+     * Options passed to the dht service for routing requests.
+     */
     enum RouteOption {
         /**
          * Default.  Do nothing special.
@@ -179,18 +193,29 @@
     }
 
 
+    /**
+     * Callback object for requests to the dht
+     */
     public interface ResultCallback {
+        /**
+         * Called when the dht returns a result
+         *
+         * @param expiration
+         * @param key
+         * @param getPath
+         * @param putPath
+         * @param type
+         * @param data
+         */
         public void handleResult(AbsoluteTime expiration, HashCode key,
                                  List<PeerIdentity> getPath, 
List<PeerIdentity> putPath,
                                  BlockType type, byte[] data);
     }
 
-    enum PutResult {
-        OK, TIMEOUT
-    }
+    public interface Continuation {
+        public void onSuccess();
 
-    public interface Continuation {
-        public void call(PutResult r);
+        public void onError();
     }
 
 
@@ -210,14 +235,16 @@
 
 
     /**
-     * @param key              key
-     * @param data             data
-     * @param replicationLevel
+     * Put data into the dht.
+     *
+     * @param key              key key to store the data under
+     * @param data             data data to store
+     * @param replicationLevel  how many peers should store this value
      * @param routeOptions
      * @param type
-     * @param expiration
-     * @param timeout
-     * @param cont
+     * @param expiration how long should the value be stored? TODO: what is 
the maximum?
+     * @param timeout   how long after we give up on storing the value?
+     * @param cont  called after the put operation failed or succeeded
      */
     public void put(HashCode key, byte[] data, int replicationLevel, 
EnumSet<RouteOption> routeOptions,
                     BlockType type, AbsoluteTime expiration,
@@ -230,17 +257,17 @@
         cpm.type = type.val;
 
         client.notifyTransmitReady(timeout, true,
-                new MessageTransmitter() {
+                0, new MessageTransmitter() {
                     @Override
                     public void transmit(Connection.MessageSink sink) {
                         sink.send(cpm);
                         // is there no way to get an ack from the dht service?
-                        cont.call(PutResult.OK);
+                        cont.onSuccess();
                     }
 
                     @Override
                     public void handleError() {
-                        cont.call(PutResult.TIMEOUT);
+                        cont.onError();
                     }
                 });
     }
@@ -259,7 +286,7 @@
 
         public void cancel() {
             if (!activeRequests.contains(this)) {
-                throw new InterfaceViolationException("cancel called on 
invalid request");
+                throw new AssertionError("cancel called on invalid request");
             }
 
             canceled = true;
@@ -270,7 +297,7 @@
                 receiveHandle.cancel();
             }
 
-            client.notifyTransmitReady(RelativeTime.FOREVER, false, new 
MessageTransmitter() {
+            client.notifyTransmitReady(RelativeTime.FOREVER, false, 0, new 
MessageTransmitter() {
                 @Override
                 public void transmit(Connection.MessageSink sink) {
                     final DHTClientGetStopMessage sm = new 
DHTClientGetStopMessage();
@@ -286,12 +313,12 @@
         }
     }
 
-    List<GetRequest> activeRequests = new ArrayList<GetRequest>(5);
+    private List<GetRequest> activeRequests = new ArrayList<GetRequest>(5);
 
-    Cancelable receiveHandle = null;
+    private Cancelable receiveHandle = null;
 
 
-    public class ResponseDispatcher implements MessageReceiver {
+    private class ResponseDispatcher implements MessageReceiver {
         @Override
         public void process(GnunetMessage.Body msg) {
             receiveHandle = null;
@@ -308,7 +335,8 @@
             if (request == null) {
                 logger.warn("received response on invalid UID");
             } else {
-                
request.cb.handleResult(AbsoluteTime.fromNetwork(rm.expiration), rm.key, null, 
null, BlockType.TEST, rm.data);
+                
request.cb.handleResult(AbsoluteTime.fromNetwork(rm.expiration), rm.key, null, 
null, BlockType.TEST,
+                        rm.data);
             }
 
             if (!activeRequests.isEmpty()) {
@@ -324,6 +352,7 @@
     private final ResponseDispatcher rh = new ResponseDispatcher();
 
     /**
+     * Request results from the DHT.
      *
      * @param timeout
      * @param type
@@ -357,8 +386,8 @@
         if (receiveHandle == null) {
             receiveHandle = client.receive(RelativeTime.FOREVER, rh);
         }
-        
-        client.notifyTransmitReady(timeout, false, new MessageTransmitter() {
+
+        client.notifyTransmitReady(timeout, false, 0, new MessageTransmitter() 
{
             @Override
             public void transmit(Connection.MessageSink sink) {
                 sink.send(getMessage);
@@ -374,7 +403,7 @@
                 }
             }
         });
-        
+
         Scheduler.addDelayed(timeout, new Scheduler.Task() {
             @Override
             public void run(Scheduler.RunContext ctx) {
@@ -389,10 +418,19 @@
         return request;
     }
 
+
+    /**
+     * not yet implemented
+     * @return
+     */
     public Cancelable startMonitor() {
         return null;
     }
 
+
+    /**
+     * Destroy the connection to the service.
+     */
     public void destroy() {
         client.disconnect();
     }
@@ -455,14 +493,14 @@
                             BlockType.TEST, 
AbsoluteTime.now().add(RelativeTime.HOUR),
                             RelativeTime.SECOND, new Continuation() {
                         @Override
-                        public void call(PutResult r) {
-                            if (r.equals(PutResult.OK)) {
-                                System.out.println("put request sent");
-                            } else {
-                                System.out.println("timeout");
-                            }
-                            dht.destroy();
+                        public void onSuccess() {
+                            System.out.println("put request sent");
                         }
+
+                        @Override
+                        public void onError() {
+                            System.out.println("error");
+                        }
                     });
                 } else {
                     if (data != null) {
@@ -471,7 +509,7 @@
                     }
 
                     final DistributedHashTable dht = new 
DistributedHashTable(cfg);
-                    
+
                     dht.startGet(RelativeTime.SECOND, BlockType.TEST, new 
HashCode(key), replication, 0,
                             new byte[0], new ResultCallback() {
                         @Override

Modified: gnunet-java/src/org/gnunet/nse/NetworkSizeEstimation.java
===================================================================
--- gnunet-java/src/org/gnunet/nse/NetworkSizeEstimation.java   2012-04-21 
18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/nse/NetworkSizeEstimation.java   2012-04-21 
23:09:41 UTC (rev 21061)
@@ -3,7 +3,7 @@
 
 import org.gnunet.construct.Double;
 import org.gnunet.construct.*;
-import org.gnunet.exceptions.MessageFormatException;
+import org.gnunet.construct.ProtocolViolation;
 import org.gnunet.util.*;
 import org.gnunet.util.getopt.Option;
 import org.gnunet.util.getopt.OptionAction;
@@ -23,15 +23,14 @@
     private static final Logger logger = LoggerFactory
             .getLogger(NetworkSizeEstimation.class);
 
-    private Collection<NSE_Subscriber> subscribers = new 
HashSet<NSE_Subscriber>(1);
+    private Collection<Subscriber> subscribers = new HashSet<Subscriber>(1);
     private boolean disconnected = false;
 
     private Client client;
 
 
-
     @UnionCase(321)
-    public static class StartMessage implements GnunetMessage.Body { }
+    public static class StartMessage implements GnunetMessage.Body {}
 
     @SuppressWarnings("InstanceVariableMayNotBeInitialized")
     @UnionCase(323)
@@ -54,11 +53,11 @@
         @Override
         public void process(GnunetMessage.Body msg) {
             if (!(msg instanceof UpdateMessage)) {
-                throw new MessageFormatException("got unexcpected message");
+                throw new ProtocolViolation("got unexcpected message");
             }
             UpdateMessage uMsg = (UpdateMessage) msg;
 
-            for (NSE_Subscriber s : subscribers) {
+            for (Subscriber s : subscribers) {
                 s.update(AbsoluteTime.fromNetwork(uMsg.timestamp), 
uMsg.sizeEstimate, uMsg.stdDeviation);
             }
 
@@ -69,17 +68,15 @@
 
         @Override
         public void handleError() {
-            logger.warn("NSE connection list - trying to reconnect");
+            logger.warn("NSE connection lost - trying to reconnect");
             client.reconnect();
             requestUpdate();
         }
     }
 
     private class NSE_Transmitter implements MessageTransmitter {
-
         @Override
         public void transmit(Connection.MessageSink sink) {
-            logger.debug("ready to transmit");
             StartMessage m = new StartMessage();
             sink.send(m);
             client.receive(RelativeTime.FOREVER, new NSE_Receiver());
@@ -87,7 +84,7 @@
 
         @Override
         public void handleError() {
-            throw new RuntimeException("unexpected transmitt error");
+            client.reconnect();
         }
     }
 
@@ -96,10 +93,10 @@
      * A handle for a subscription to the network size estimation service, may 
be used to cancel the
      * subscription.
      */
-    public class NSE_Subscription {
-        private NSE_Subscriber sub;
+    public class Subscription implements Cancelable {
+        private Subscriber sub;
 
-        private NSE_Subscription(NSE_Subscriber sub) {
+        private Subscription(Subscriber sub) {
             this.sub = sub;
         }
 
@@ -114,24 +111,22 @@
     /**
      * A NSE_Subscriber receives updates from the service.
      */
-    public interface NSE_Subscriber {
+    public interface Subscriber {
         public void update(AbsoluteTime timestamp, double estimate, double 
deviation);
     }
 
-
     /**
      * Subscribe for updates from the service.
      *
      * @param s callback for updates
      * @return a subscription handle that may be used to cancel the 
subscription
      */
-    public NSE_Subscription subscribe(NSE_Subscriber s) {
+    public Cancelable subscribe(Subscriber s) {
         subscribers.add(s);
         requestUpdate();
-        return new NSE_Subscription(s);
+        return new Subscription(s);
     }
 
-
     /**
      * Create a connection to the network size estimation service.
      *
@@ -139,11 +134,10 @@
      */
     public NetworkSizeEstimation(Configuration cfg) {
         client = new Client("nse", cfg);
-        logger.debug("lifeness in NSE ctor: {}", 
Scheduler.getCurrentLifeness());
     }
 
     private void requestUpdate() {
-        client.notifyTransmitReady(RelativeTime.FOREVER, true, new 
NSE_Transmitter());
+        client.notifyTransmitReady(RelativeTime.FOREVER, true, 0, new 
NSE_Transmitter());
     }
 
     /**
@@ -165,7 +159,7 @@
             public void run() {
                 final NetworkSizeEstimation svc = new 
NetworkSizeEstimation(cfg);
 
-                NSE_Subscriber subscriber = new NSE_Subscriber() {
+                Subscriber subscriber = new Subscriber() {
                     @Override
                     public void update(AbsoluteTime timestamp, double 
estimate, double deviation) {
                         System.out.println("est:" + estimate + " dev: " + 
deviation + " t: " + timestamp);

Modified: gnunet-java/src/org/gnunet/statistics/Statistics.java
===================================================================
--- gnunet-java/src/org/gnunet/statistics/Statistics.java       2012-04-21 
18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/statistics/Statistics.java       2012-04-21 
23:09:41 UTC (rev 21061)
@@ -13,11 +13,17 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.LinkedList;
+
+/**
+ * API for the gnunet statistics service.
+ * <p/>
+ * Write and read statistic values, represented as 64bit integer.
+ */
 public class Statistics {
     private static final Logger logger = LoggerFactory
             .getLogger(Statistics.class);
 
-
     private Client client;
 
     @UnionCase(169)
@@ -55,14 +61,83 @@
         public String subsystemName;
         @ZeroTerminatedString
         public String statisticName;
+    }
 
+
+    private abstract class StatisticsRequest implements Cancelable, 
MessageTransmitter {
+        public String name;
+        public String subsystem;
+        public StatisticsReceiver receiver;
+        public AbsoluteTime deadline;
     }
 
+    private class StatisticsGetRequest extends StatisticsRequest implements 
Cancelable {
+        @Override
+        public void cancel() {
+        }
+
+        @Override
+        public void transmit(Connection.MessageSink sink) {
+            if (sink == null) {
+                logger.error("unable to connect to statistics service");
+                return;
+            }
+            RequestMessage rm = new RequestMessage();
+            rm.statisticsName = name;
+            rm.subsystemName = subsystem;
+
+            sink.send(rm);
+
+            client.receive(deadline.getRemaining(), new MessageReceiver() {
+                @Override
+                public void process(GnunetMessage.Body msg) {
+                    if (msg instanceof ResponseValueMessage) {
+                        ResponseValueMessage rvm = (ResponseValueMessage) msg;
+                        receiver.onReceive(rvm.subsystemName, 
rvm.statisticName, rvm.value);
+                        client.receive(deadline.getRemaining(), this);
+                    } else if (msg instanceof ResponseEndMessage) {
+                        receiver.onDone();
+                        logger.info("all statistics received");
+                    } else {
+                        logger.error("message format error in response from 
the service");
+                    }
+                }
+
+                @Override
+                public void handleError() {
+                    logger.error("unable to read from statistics service");
+                }
+            });
+        }
+
+        @Override
+        public void handleError() {
+            throw new RuntimeException("unexpected transmit error");
+        }
+    }
+
+    private class StatisticsPutRequest extends StatisticsRequest implements 
Cancelable {
+        public long value;
+
+        @Override
+        public void cancel() {
+        }
+
+        @Override
+        public void transmit(Connection.MessageSink sink) {
+        }
+
+        @Override
+        public void handleError() {
+        }
+    }
+
+    private LinkedList<StatisticsRequest> requests = new 
LinkedList<StatisticsRequest>();
+
     public Statistics(Configuration cfg) {
         client = new Client("statistics", cfg);
     }
 
-
     public interface StatisticsReceiver {
         public void onReceive(String subsystem, String name, long value);
 
@@ -71,73 +146,57 @@
         public void onDone();
     }
 
-    public Cancelable get(RelativeTime timeout, final String subsystem, final 
String name, final StatisticsReceiver srh) {
-        final AbsoluteTime deadline = timeout.toAbsolute();
+    /**
+     * Retrieve values from statistics.
+     *
+     * @param timeout   time after we give up and call receiver.onTimeout
+     * @param subsystem name of the subsistem the statistics value belongs to
+     * @param name      name of the statistics value belongs to
+     * @param receiver  callback
+     * @return handle to cancel the request
+     */
+    public Cancelable get(RelativeTime timeout, final String subsystem, final 
String name,
+                          final StatisticsReceiver receiver) {
 
-        client.notifyTransmitReady(deadline.getRemaining(), true, new 
MessageTransmitter() {
-            @Override
-            public void transmit(Connection.MessageSink sink) {
-                if (sink == null) {
-                    logger.error("unable to connect to statistics service");
-                    return;
-                }
-                RequestMessage rm = new RequestMessage();
-                rm.statisticsName = name;
-                rm.subsystemName = subsystem;
+        final StatisticsGetRequest getRequest = new StatisticsGetRequest();
+        getRequest.deadline = timeout.toAbsolute();
+        getRequest.name = name;
+        getRequest.subsystem = subsystem;
+        getRequest.receiver = receiver;
 
-                sink.send(rm);
+        requests.add(getRequest);
 
+        handleNextRequest();
 
-                client.receive(deadline.getRemaining(), new MessageReceiver() {
-                    @Override
-                    public void process(GnunetMessage.Body msg) {
-                        if (msg instanceof ResponseValueMessage) {
-                            ResponseValueMessage rvm = (ResponseValueMessage) 
msg;
-                            srh.onReceive(rvm.subsystemName, 
rvm.statisticName, rvm.value);
-                            client.receive(deadline.getRemaining(), this);
-                        } else if (msg instanceof ResponseEndMessage) {
-                            srh.onDone();
-                            logger.info("all statistics received");
-                        } else {
-                            logger.error("message format error in response 
from the service");
-                        }
-                    }
+        return getRequest;
+    }
 
-                    @Override
-                    public void handleError() {
-                        logger.error("unable to read from statistics service");
-                    }
+    private void handleNextRequest() {
 
-                }
-                );
-            }
-
-            @Override
-            public void handleError() {
-                throw new RuntimeException("unexpected transmit error");
-            }
-        }
-
-        );
-        return null;
     }
 
     public Cancelable get(RelativeTime timeout, StatisticsReceiver srh) {
         return get(timeout, "", "", srh);
     }
 
-    public interface SetCompleted {
-        public void onCompleted();
 
-        public void onTimeout();
+    /**
+     *
+     * @param subsystem
+     * @param name
+     * @param value
+     * @param persist keep value even if the statistics service restarts
+     * @return
+     */
+    public Cancelable set(final String subsystem, final String name, final 
long value, boolean persist) {
+        StatisticsPutRequest putRequest = new StatisticsPutRequest();
+        putRequest.deadline =
+        putRequest.subsystem = subsystem;
+        putRequest.name = name;
+        putRequest.value = value;
 
-    }
+        client.notifyTransmitReady(timeout, true, 0, new MessageTransmitter() {
 
-
-    public Cancelable set(RelativeTime timeout, final String subsystem, final 
String name, final long value,
-                          final SetCompleted cb) {
-        client.notifyTransmitReady(timeout, true, new MessageTransmitter() {
-
             @Override
             public void transmit(Connection.MessageSink sink) {
                 if (sink == null) {
@@ -166,8 +225,17 @@
         };
     }
 
+
+    /**
+     * Destroy handle to the statistics service.
+     *
+     * @param putPending wait until all pending put requests have been 
submitted or timed out
+     */
+    public void destroy(boolean putPending) {
+        client.disconnect();
+    }
+
     public static void main(String[] args) {
-
         new Program(args) {
             @Option(
                     shortname = "x",

Modified: gnunet-java/src/org/gnunet/util/ATSInformation.java
===================================================================
--- gnunet-java/src/org/gnunet/util/ATSInformation.java 2012-04-21 18:16:21 UTC 
(rev 21060)
+++ gnunet-java/src/org/gnunet/util/ATSInformation.java 2012-04-21 23:09:41 UTC 
(rev 21061)
@@ -4,6 +4,10 @@
 import org.gnunet.construct.Message;
 import org.gnunet.construct.UInt32;
 
+
+/**
+ * Information related to Automatic Transport Selection.
+ */
 public class ATSInformation implements Message {
     @UInt32
     public long type;

Modified: gnunet-java/src/org/gnunet/util/AbsoluteTimeMessage.java
===================================================================
--- gnunet-java/src/org/gnunet/util/AbsoluteTimeMessage.java    2012-04-21 
18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/util/AbsoluteTimeMessage.java    2012-04-21 
23:09:41 UTC (rev 21061)
@@ -4,6 +4,10 @@
 import org.gnunet.construct.UInt64;
 
 
+
+/**
+ * Representation of an AbsoluteTime object, to be sent over the network.
+ */
 public class AbsoluteTimeMessage implements Message {
     @UInt64
     public long value__;

Modified: gnunet-java/src/org/gnunet/util/Client.java
===================================================================
--- gnunet-java/src/org/gnunet/util/Client.java 2012-04-21 18:16:21 UTC (rev 
21060)
+++ gnunet-java/src/org/gnunet/util/Client.java 2012-04-21 23:09:41 UTC (rev 
21061)
@@ -19,12 +19,11 @@
  */
 package org.gnunet.util;
 
-import org.gnunet.exceptions.ConfigurationException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Represents a connection to a service.
+ * A connection to a gnunet service.
  */
 public class Client {
     private static final Logger logger = LoggerFactory
@@ -77,16 +76,14 @@
         // get the hostname from the configuration
         hostname = cfg.getValueString(serviceName, "HOSTNAME");
         if (hostname.isEmpty()) {
-            throw new ConfigurationException(String.format("hostname of 
service '%s' empty", serviceName));
+            throw new 
Configuration.ConfigurationException(String.format("hostname of service '%s' 
empty", serviceName));
         }
         reconnect();
     }
 
 
     /**
-     * Receive one message from the service.
-     * <p/>
-     * todo: comment on when this can be called (wrt notifyTransmitReady)
+     * Receive one message from the service. Can only be called after sending 
a message to the server.
      *
      * @param timeout  deadline after which MessageReceiver.deadline will be 
called
      * @param receiver MessageReceiver that is responsible for the received 
message
@@ -108,19 +105,19 @@
     /**
      * Ask the client to call us once it is able to send a message.
      *
-     * @param size        number of bytes to send
+     *
      * @param timeout     after how long should we give up (and call 
transmitter.transmit(null))
      * @param autoRetry   if the connection to the service dies, should we
      *                    automatically reconnect and retry (within the 
deadline period)
      *                    or should we immediately fail in this case?  Pass 
true
      *                    if the caller does not care about temporary 
connection errors,
      *                    for example because the protocol is stateless
-     * @param transmitter the MessageTransmitter object to call once the 
client is ready to transmit or
-     *                    when the timeout is over. Guaranteed to be called 
*after* notifyTransmitReady has returned.
-     * @return a handle that can be used to cancel the transmit request
+     * @param size        size of the message we want to transmit, can be an 
upper bound
+     address@hidden transmitter the MessageTransmitter object to call once the 
client is ready to transmit or
+     *                    when the timeout is over. Guaranteed to be called 
*after* notifyTransmitReady has returned.  @return a handle that can be used to 
cancel the transmit request
      */
     public Cancelable notifyTransmitReady(final RelativeTime timeout,
-                                          final boolean autoRetry, final 
MessageTransmitter transmitter) {
+                                          final boolean autoRetry, int size, 
final MessageTransmitter transmitter) {
         if (connection.isConnected()) {
             return connection.notifyTransmitReady(timeout, transmitter);
         } else {
@@ -149,7 +146,7 @@
     public void transmitAndGetResponse(final GnunetMessage.Body message, final 
RelativeTime timeout,
                                        final boolean autoRetry,
                                        final MessageReceiver receiver) {
-        notifyTransmitReady(timeout, autoRetry, new MessageTransmitter() {
+        notifyTransmitReady(timeout, autoRetry, 0, new MessageTransmitter() {
             @Override
             public void transmit(Connection.MessageSink sink) {
                 sink.send(message);

Modified: gnunet-java/src/org/gnunet/util/Configuration.java
===================================================================
--- gnunet-java/src/org/gnunet/util/Configuration.java  2012-04-21 18:16:21 UTC 
(rev 21060)
+++ gnunet-java/src/org/gnunet/util/Configuration.java  2012-04-21 23:09:41 UTC 
(rev 21061)
@@ -22,7 +22,6 @@
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.LineIterator;
-import org.gnunet.exceptions.ConfigurationException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -378,4 +377,10 @@
             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/Connection.java
===================================================================
--- gnunet-java/src/org/gnunet/util/Connection.java     2012-04-21 18:16:21 UTC 
(rev 21060)
+++ gnunet-java/src/org/gnunet/util/Connection.java     2012-04-21 23:09:41 UTC 
(rev 21061)
@@ -1,8 +1,6 @@
 package org.gnunet.util;
 
 import org.gnunet.construct.Construct;
-import org.gnunet.exceptions.InterfaceViolationException;
-import org.gnunet.exceptions.InternalLogicError;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -17,7 +15,7 @@
 import java.util.LinkedList;
 
 /**
- * Integrate socket with the gnunet-java message loop / the scheduler.
+ * Integrates sockets with the gnunet-java message loop / the scheduler.
  */
 public class Connection {
     private static final Logger logger = LoggerFactory
@@ -143,13 +141,20 @@
                 try {
                     int n = connectionChannel.read(recvBuffer);
                     if (n == -1) {
-                        logger.error("end of stream in channel before complete 
message, read {} bytes",
+                        logger.error("lost connection to service",
                                 recvBuffer.position());
                         connectionChannel.close();
                         connectionChannel = null;
                         receiver.handleError();
                         return;
                     }
+                    if (n == 0) {
+                        logger.info("service gracefully disconnected us");
+                        connectionChannel.close();
+                        connectionChannel = null;
+                        receiver.handleError();
+                        return;
+                    }
                     logger.debug(String.format("connectionChannel read %s 
bytes", n));
                 } catch (IOException e) {
                     logger.error("read failed with exception:", e);
@@ -191,7 +196,7 @@
 
         public void cancel() {
             if (finished) {
-                throw new InterfaceViolationException("canceling finished 
receive");
+                throw new AssertionError("canceling finished receive");
             }
             if (recvTask != null) {
                 recvTask.cancel();
@@ -289,7 +294,7 @@
             gm.header.messageSize = Construct.getSize(gm);
             byte[] b = Construct.toBinary(gm);
             if (b.length != gm.header.messageSize) {
-                throw new InternalLogicError(
+                throw new AssertionError(
                         String.format("tried to send message with binary size 
%s but size in header %s",
                                 b.length, gm.header.messageSize));
             }
@@ -461,7 +466,7 @@
      */
     public TransmitHandle notifyTransmitReady(RelativeTime timeout, final 
MessageTransmitter transmitter) {
         if (nextTransmitHelper != null) {
-            throw new InterfaceViolationException(
+            throw new AssertionError(
                     "previous transmit request must have completed before 
calling notifyTransmitReady again");
         }
 

Modified: gnunet-java/src/org/gnunet/util/GnunetMessage.java
===================================================================
--- gnunet-java/src/org/gnunet/util/GnunetMessage.java  2012-04-21 18:16:21 UTC 
(rev 21060)
+++ gnunet-java/src/org/gnunet/util/GnunetMessage.java  2012-04-21 23:09:41 UTC 
(rev 21061)
@@ -3,9 +3,21 @@
 
 import org.gnunet.construct.*;
 
+
+/**
+ * Every message used to communicate between gnunet components uses this 
format.
+ * First, a header is sent, containing the size of the overall message 
(including the header), as
+ * well as the type of the message. After that the message body is sent, whose 
format is specified
+ * by the message type.
+ *
+ */
 public final class GnunetMessage implements Message {
     public final int MINIMAL_SIZE = Header.SIZE;
 
+
+    /**
+     * The header of every gnunet message.
+     */
     public static final class Header implements Message {
         public static final int SIZE = 4;
 
@@ -17,9 +29,21 @@
         public int messageType;
     }
 
+    /**
+     * The common interface for every message body.
+     *
+     */
     public static interface Body extends MessageUnion {
     }
-    
+
+
+    /**
+     * Create a GnunetMessage from its body only. The header is added and 
filled with the relevant information
+     * automatically.
+     *
+     * @param b the message body to convert
+     * @return a complete and valid gnunet message
+     */
     public static GnunetMessage fromBody(Body b) {
         GnunetMessage msg = new GnunetMessage();
         msg.header = new Header();

Modified: gnunet-java/src/org/gnunet/util/HashCode.java
===================================================================
--- gnunet-java/src/org/gnunet/util/HashCode.java       2012-04-21 18:16:21 UTC 
(rev 21060)
+++ gnunet-java/src/org/gnunet/util/HashCode.java       2012-04-21 23:09:41 UTC 
(rev 21061)
@@ -3,11 +3,14 @@
 
 import org.gnunet.construct.FixedSizeByteArray;
 import org.gnunet.construct.Message;
-import org.gnunet.exceptions.InterfaceViolationException;
 
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 
+
+/**
+ * 512-bit hash code
+ */
 public class HashCode implements Message {
 
     @FixedSizeByteArray(length = 64)
@@ -15,7 +18,7 @@
 
     public HashCode(byte[] hash) {
         if (hash.length != 64) {
-            throw new InterfaceViolationException("HashCode has to have length 
64");
+            throw new AssertionError("HashCode has to have length 64");
         }
         data = hash;
     }

Deleted: gnunet-java/src/org/gnunet/util/IntEnum.java
===================================================================
--- gnunet-java/src/org/gnunet/util/IntEnum.java        2012-04-21 18:16:21 UTC 
(rev 21060)
+++ gnunet-java/src/org/gnunet/util/IntEnum.java        2012-04-21 23:09:41 UTC 
(rev 21061)
@@ -1,16 +0,0 @@
-package org.gnunet.util;
-
-
-public interface IntEnum {
-    public int getInt();
-}
-
-
-/*
-Template for IntEnums:
-class $NAME$ implements IntEnum {
-    private final int val;
-    public int getInt() { return val; }
-    public $NAME$(int i) { val = i; }
-}
-*/
\ No newline at end of file

Modified: gnunet-java/src/org/gnunet/util/MessageReceiver.java
===================================================================
--- gnunet-java/src/org/gnunet/util/MessageReceiver.java        2012-04-21 
18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/util/MessageReceiver.java        2012-04-21 
23:09:41 UTC (rev 21061)
@@ -21,18 +21,21 @@
 package org.gnunet.util;
 
 /**
+ * Callback object for receiving messages.
  * 
- * @author Florian Dold
- * 
  */
 public interface MessageReceiver {
 
     /**
-     * Method to call when we receive a message from the service.
+     * Called when a message is received
      * 
      * @param msg   message received, null on deadline or fatal error
      */
     public void process(GnunetMessage.Body msg);
 
+
+    /**
+     * Called when an error (timeout, loss of connection) occured before 
receiving the message.
+     */
     public void handleError();
 }

Modified: gnunet-java/src/org/gnunet/util/MessageTransmitter.java
===================================================================
--- gnunet-java/src/org/gnunet/util/MessageTransmitter.java     2012-04-21 
18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/util/MessageTransmitter.java     2012-04-21 
23:09:41 UTC (rev 21061)
@@ -1,5 +1,9 @@
 package org.gnunet.util;
 
+
+/**
+ * Callback object for transmitting messages.
+ */
 public interface MessageTransmitter {
     /**
      * Called when the client is ready to transmit messages, or on 
timeout/error.
@@ -9,5 +13,11 @@
      */
     public void transmit(Connection.MessageSink sink);
 
+
+    /**
+     * Called when the transmit request could not be fullfilled.
+     *
+     * After transmit has been called, handleError will not be called anymore 
(until the next transmit request)
+     */
     void handleError();
 }

Modified: gnunet-java/src/org/gnunet/util/PeerIdentity.java
===================================================================
--- gnunet-java/src/org/gnunet/util/PeerIdentity.java   2012-04-21 18:16:21 UTC 
(rev 21060)
+++ gnunet-java/src/org/gnunet/util/PeerIdentity.java   2012-04-21 23:09:41 UTC 
(rev 21061)
@@ -6,6 +6,10 @@
 
 import java.util.Arrays;
 
+
+/**
+ * Identity of a peer, stored as 512-bit public key.
+ */
 public class PeerIdentity implements Message {
 
     @FixedSizeByteArray(length = 64)

Modified: gnunet-java/src/org/gnunet/util/Program.java
===================================================================
--- gnunet-java/src/org/gnunet/util/Program.java        2012-04-21 18:16:21 UTC 
(rev 21060)
+++ gnunet-java/src/org/gnunet/util/Program.java        2012-04-21 23:09:41 UTC 
(rev 21061)
@@ -9,6 +9,12 @@
 
 import java.io.IOException;
 
+
+/**
+ * Program is the entry point class for everything that uses gnunet services 
or APIs.
+ *
+ * @see Service
+ */
 public abstract class Program {
     private static final Logger logger = LoggerFactory
             .getLogger(Resolver.class);
@@ -16,7 +22,6 @@
 
     protected final Configuration cfg = new Configuration();
 
-
     @Option(shortname = "c", longname = "config",
             description = "Path of the configuration file",
             argumentName = "FILENAME",
@@ -117,28 +122,39 @@
         Resolver.getInstance().setConfiguration(cfg);
     }
 
-    protected String getHelpDescription() {
+    /**
+     * Override to display a different help text on "-h/--help"
+     *
+     * @return the help text
+     */
+    protected String makeHelpText() {
         return "gnunet-java tool";
     }
 
-    protected String getVersionDescription() {
+    /**
+     * Override to display a different version description on "-h/--help"
+     *
+     * @return
+     */
+    protected String makeVersionDescription() {
         return "development version of gnunet-java";
     }
 
     /**
-     * Start the Program as the initial Task of the Scheduler.
+     * Start the Program as the initial task of the Scheduler.
      */
-    public final void start() {
+    public void start() {
         if (showVersion) {
-            System.out.println(getVersionDescription());
+            System.out.println(makeVersionDescription());
         } else if (printHelp) {
-            System.out.println(getHelpDescription());
+            System.out.println(makeHelpText());
             System.out.print(optParser.getHelp());
         } else {
             Scheduler.run(new Scheduler.Task() {
                 public void run(Scheduler.RunContext c) {
-                    // kind of horrible hack: because of the default 
constructor, default member values are overwritten
-                    // in their constructor
+                    // the (default)constructor of any derived instances 
overwrites the call
+                    // to parse in the constructor, do it again here!
+                    // todo: this is too hacky, find better solution than 
parsing twice!
                     optParser.parse(args);
                     Program.this.run();
                 }

Modified: gnunet-java/src/org/gnunet/util/RelativeTimeMessage.java
===================================================================
--- gnunet-java/src/org/gnunet/util/RelativeTimeMessage.java    2012-04-21 
18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/util/RelativeTimeMessage.java    2012-04-21 
23:09:41 UTC (rev 21061)
@@ -3,6 +3,10 @@
 import org.gnunet.construct.Message;
 import org.gnunet.construct.UInt64;
 
+
+/**
+ * Representation of a RelativeTime object, to be sent over the network.
+ */
 public class RelativeTimeMessage implements Message {
 
     /**

Modified: gnunet-java/src/org/gnunet/util/Resolver.java
===================================================================
--- gnunet-java/src/org/gnunet/util/Resolver.java       2012-04-21 18:16:21 UTC 
(rev 21060)
+++ gnunet-java/src/org/gnunet/util/Resolver.java       2012-04-21 23:09:41 UTC 
(rev 21061)
@@ -2,9 +2,7 @@
 
 
 import org.gnunet.construct.*;
-import org.gnunet.exceptions.InterfaceViolationException;
-import org.gnunet.exceptions.InternalLogicError;
-import org.gnunet.exceptions.MessageFormatException;
+import org.gnunet.construct.ProtocolViolation;
 import org.gnunet.util.getopt.Option;
 import org.gnunet.util.getopt.OptionAction;
 import org.slf4j.Logger;
@@ -16,6 +14,12 @@
 import java.net.UnknownHostException;
 import java.util.LinkedList;
 
+
+/**
+ * Resolve hostnames asynchronously, using the gnunet resolver service if 
necessary.
+ * <p/>
+ * TODO: implement reverse lookup (already done in the C-API)
+ */
 public class Resolver {
     private static final Logger logger = LoggerFactory
             .getLogger(Resolver.class);
@@ -43,7 +47,7 @@
         public Address addr;
     }
 
-    public static interface Address extends MessageUnion { }
+    public static interface Address extends MessageUnion {}
 
     @UnionCase(GetMessage.DIRECTION_GET_IP)
     public static class TextualAddress implements Address {
@@ -71,7 +75,12 @@
     }
 
 
-    /* @Nullable */
+    /**
+     * Return the IPv4 InetAddress corresponding to ip
+     *
+     * @param ip the ip address, e.g. "127.0.0.1"
+     * @return the IPv4 InetAddress corresponding to ip, null if ip is not a 
IPv4 address.
+     */
     public InetAddress getInet4AddressFromString(String ip) {
         String[] components = ip.split(".");
         if (components.length != 4) {
@@ -92,6 +101,12 @@
         }
     }
 
+    /**
+     * Return the IPv6 InetAddress corresponding to ip
+     *
+     * @param ip the ip address, e.g. "::1"
+     * @return the IPv4 InetAddress corresponding to ip, null if ip is not a 
IPv4 address.
+     */
     public InetAddress getInet6AddressFromString(String ip) {
         String[] components = ip.split(":");
         if (components.length > 8) {
@@ -125,9 +140,9 @@
     /**
      * Get address from numeric textual IP address. May be IPv4 or IPv6
      *
+     * @param ip textual IP address
      * @return null if address is not numeric, the corresponding InetAddress 
object otherwise
      */
-    /* @Nullable */
     public InetAddress getInetAddressFromString(String ip) {
         // check for IPv4-address:
         InetAddress inAddr = getInet4AddressFromString(ip);
@@ -137,41 +152,36 @@
         return getInet4AddressFromString(ip);
     }
 
-
-    public interface HostnameCallback {
-        public void onHostname(String hostname);
-
-        public void onFinished();
-    }
-
+    /**
+     * Callbacks for hostname resolution
+     */
     public interface AddressCallback {
+        /**
+         * Called for every address the requested hostname resolves to.
+         *
+         * @param addr
+         */
         public void onAddress(InetAddress addr);
 
+        /**
+         * Called after every result (if any) has been passed to onAddress.
+         */
         public void onFinished();
 
+        /**
+         * Called when the resolve operation times out before returning every 
result.
+         */
         void onTimeout();
     }
 
 
-    private void connect(Configuration cfg) {
-        if (client != null) {
-            throw new InterfaceViolationException("connectStep called twice");
-        }
-
-    }
-
-    public InetAddress resolveHostnameLocal(String hostname) {
-        if (hostname.equals("localhost") || hostname.equals("ip6-localhost")) {
-            try {
-                return InetAddress.getByName(hostname);
-            } catch (UnknownHostException e) {
-                return null;
-            }
-        }
-        return getInetAddressFromString(hostname);
-    }
-
-
+    /**
+     * Configuration to use with the Resolver.
+     *
+     * Usually called by the entry points Program/Service.
+     *
+     * @param cfg
+     */
     public void setConfiguration(Configuration cfg) {
         this.cfg = cfg;
     }
@@ -179,14 +189,13 @@
     private void lazyConnect() {
         if (client == null) {
             if (cfg == null) {
-                throw new InterfaceViolationException("Resolver has no 
Configuration");
+                throw new AssertionError("Resolver has no Configuration");
             }
             client = new Client("resolver", cfg);
         }
     }
 
 
-
     private InetAddress getInet4Localhost() {
         try {
             return InetAddress.getByAddress(new byte[]{127, 0, 0, 1});
@@ -214,10 +223,10 @@
 
         public void cancel() {
             if (finished) {
-                throw new InterfaceViolationException("Resolve already 
finished");
+                throw new AssertionError("Resolve already finished");
             }
             if (canceled) {
-                throw new InterfaceViolationException("ResolveHandle canceled 
twice");
+                throw new AssertionError("ResolveHandle canceled twice");
             }
             if (queuedRequests.contains(this)) {
                 queuedRequests.remove(this);
@@ -237,6 +246,14 @@
 
     private boolean resolveActive = false;
 
+    /**
+     * Resolve the hostname 'hostname'.
+     *
+     * @param hostname
+     * @param timeout
+     * @param cb
+     * @return
+     */
     public ResolveHandle resolveHostname(String hostname, RelativeTime 
timeout, final AddressCallback cb) {
         final ResolveHandle rh = new ResolveHandle();
         rh.hostname = hostname;
@@ -291,7 +308,7 @@
 
     private void handleRequest(final ResolveHandle rh) {
         if (resolveActive) {
-            throw new InternalLogicError("resolveActive but new resolve 
started");
+            throw new AssertionError("resolveActive but new resolve started");
         }
 
         resolveActive = true;
@@ -316,11 +333,11 @@
 
         rh.transmitTask = client.notifyTransmitReady(
                 deadline.getRemaining(), true,
-                new MessageTransmitter() {
+                0, new MessageTransmitter() {
                     @Override
                     public void transmit(Connection.MessageSink sink) {
                         if (sink == null) {
-                                onTimeout(rh);
+                            onTimeout(rh);
                         }
                         sink.send(req);
                         rh.transmitTask = null;
@@ -338,13 +355,13 @@
                                         if (len == 4 || len == 16) {
                                             in_addr = 
InetAddress.getByAddress(gmsg.responseBody.addr);
                                         } else {
-                                            throw new 
MessageFormatException("malformed address message");
+                                            throw new 
ProtocolViolation("malformed address message");
                                         }
 
                                         rh.cb.onAddress(in_addr);
                                         rh.receiveTask = 
client.receive(deadline.getRemaining(), this);
                                     } catch (UnknownHostException e) {
-                                        throw new 
MessageFormatException("malformed address");
+                                        throw new ProtocolViolation("malformed 
address");
                                     }
                                 } else {
                                     resolveActive = false;
@@ -355,7 +372,7 @@
 
                             @Override
                             public void handleError() {
-                                    onTimeout(rh);
+                                onTimeout(rh);
                             }
                         });
 
@@ -369,7 +386,6 @@
     }
 
 
-
     private void onTimeout(ResolveHandle h) {
         resolveActive = false;
         h.cb.onTimeout();
@@ -385,6 +401,12 @@
     }
 
 
+    /**
+     * Return a textual representation of an InetAddress. Shortens IPv6 
addresses.
+     *
+     * @param addr
+     * @return
+     */
     public static String ipToString(InetAddress addr) {
         byte[] a = addr.getAddress();
         if (a.length == 4) {
@@ -442,6 +464,7 @@
                             next();
 
                         }
+
                         public void next() {
                             if (unprocessedArgs.length > next) {
                                 logger.info("resolving hostname '" + 
unprocessedArgs[next] + "'");
@@ -455,7 +478,7 @@
             }
 
             @Override
-            protected String getHelpDescription() {
+            protected String makeHelpText() {
                 return "tool for forward and reverse DNS lookup";
             }
         }.start();

Modified: gnunet-java/src/org/gnunet/util/RunaboutMessageReceiver.java
===================================================================
--- gnunet-java/src/org/gnunet/util/RunaboutMessageReceiver.java        
2012-04-21 18:16:21 UTC (rev 21060)
+++ gnunet-java/src/org/gnunet/util/RunaboutMessageReceiver.java        
2012-04-21 23:09:41 UTC (rev 21061)
@@ -2,6 +2,10 @@
 
 import org.grothoff.Runabout;
 
+/**
+ * An abstract base class for message receivers that want to use the runabout, 
dispatches
+ * messages to the appropriate visit method.
+ */
 public abstract class RunaboutMessageReceiver extends Runabout implements 
MessageReceiver  {
     public void process(GnunetMessage.Body msg) {
         this.visitAppropriate(msg);

Modified: gnunet-java/src/org/gnunet/util/Scheduler.java
===================================================================
--- gnunet-java/src/org/gnunet/util/Scheduler.java      2012-04-21 18:16:21 UTC 
(rev 21060)
+++ gnunet-java/src/org/gnunet/util/Scheduler.java      2012-04-21 23:09:41 UTC 
(rev 21061)
@@ -20,7 +20,6 @@
 
 package org.gnunet.util;
 
-import org.gnunet.exceptions.InterfaceViolationException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -106,7 +105,7 @@
             this.lifeness = liveness;
 
             if (timeout.getMilliseconds() < 0) {
-                throw new InterfaceViolationException("timeout must be (>=0)");
+                throw new AssertionError("timeout must be (>=0)");
             }
 
             this.deadline = timeout.toAbsolute();
@@ -425,6 +424,13 @@
     }
 
 
+    /**
+     * Add a task to run after the specified delay.
+     *
+     * @param delay time to wait until running the task
+     * @param task the task to run after delay
+     * @return the TaskIdentifier, can be used to cancel the task until it has 
been executed.
+     */
     public static TaskIdentifier addDelayed(RelativeTime delay, Task task) {
         return addSelect(Priority.KEEP, delay, null, null, task);
     }

Modified: gnunet-java/src/org/gnunet/util/Server.java
===================================================================
--- gnunet-java/src/org/gnunet/util/Server.java 2012-04-21 18:16:21 UTC (rev 
21060)
+++ gnunet-java/src/org/gnunet/util/Server.java 2012-04-21 23:09:41 UTC (rev 
21061)
@@ -4,29 +4,37 @@
 import org.grothoff.Runabout;
 
 import java.io.IOException;
+import java.lang.reflect.Method;
 import java.net.SocketAddress;
 import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.SocketChannel;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 
 public class Server {
 
 
-    private RelativeTime idleTimeout;
-    private boolean requireFound;
-    List<ServerSocketChannel> listenSockets;
-    List<ClientHandle> clients;
+    private final RelativeTime idleTimeout;
+    private final boolean requireFound;
+    private List<ServerSocketChannel> listenSockets;
+    private List<ClientHandle> clients;
 
+    private HashMap<Class, MessageRunabout> handlers;
 
+
     public class ClientHandle {
+        private RelativeTime clientTimeout;
+        private Connection connection;
 
-        private SocketChannel sock;
-
         private int referenceCount = 0;
+        private Connection.ReceiveHandle currentReceive;
 
-        public ClientHandle(SocketChannel accept) {
-
+        private ClientHandle(SocketChannel accept) {
+            connection = new Connection(accept);
+            clientTimeout = idleTimeout;
+            // start receiving
+            receiveDone(true);
         }
 
 
@@ -45,45 +53,62 @@
          *         GNUNET_CONNECTION_notify_transmit_ready_cancel.
          *         NULL if we are already going to notify someone else (busy)
          */
-        public void notifyTransmitReady(int size, RelativeTime timeout, 
MessageTransmitter transmitter) {
-
+        public Cancelable notifyTransmitReady(int size, RelativeTime timeout, 
MessageTransmitter transmitter) {
+            return connection.notifyTransmitReady(timeout, transmitter);
         }
 
         /**
          * Resume receiving from this client, we are done processing the
          * current request.  This function must be called from within each
-         * GNUNET_SERVER_MessageCallback (or its respective continuations).
+         * message handler (or its respective continuations).
          *
+         * The server does not automatically continue to receive messages to
+         * support flow control.
+         *
          * @param keepClient false if connection to the client should be closed
          */
         public void receiveDone(boolean keepClient) {
+            if (keepClient) {
+                currentReceive = connection.receive(RelativeTime.FOREVER, new 
MessageReceiver() {
+                    @Override
+                    public void process(GnunetMessage.Body msg) {
+                    }
 
+                    @Override
+                    public void handleError() {
+                    }
+                });
+            } else {
+                disconnect();
+            }
+
         }
 
+        /**
+         * Change the idle timeout of this particular client.
+         */
         public void setTimeout(RelativeTime newTimeout) {
-
         }
 
-        public void setFinishPendingWrites() {
-
-        }
-
         public void disconnect() {
-
+            connection.disconnect();
+            Server.this.clients.remove(this);
         }
 
+        /**
+         * Disable the warning the server issues if a message is not 
acknowledged
+         * in a timely fashion.  Use this call if a client is intentionally 
delayed
+         * for a while.  Only applies to the current message.
+         */
         public void disableReceiveDoneWarning() {
 
         }
-
-        public void injectMessage(/*msg*/) {
-
-        }
     }
 
 
     abstract class MessageRunabout extends Runabout {
         private ClientHandle currentSender;
+
         /**
          * Allows implementors of MessageRunabout to get the Client that sent 
the message
          * currently visited.
@@ -123,7 +148,6 @@
     }
 
 
-
     /**
      * Create a server listening on all specified addresses.
      *
@@ -147,15 +171,36 @@
         }
     }
 
+
+    /**
+     * Pass messages that the runabout can handle to it.
+     * There can only be one runabout per message type.
+     * (Discrepancy with the C-API, could be changed in the future)
+     *
+     * @param cb
+     */
     public void addHandler(MessageRunabout cb) {
+        Class rc = cb.getClass();
+        for (Method m : rc.getMethods()) {
+            if (!(m.getName().equals("visit") && m.getParameterTypes().length 
== 1)) {
+                continue;
+            }
+            Class msgClass = m.getParameterTypes()[0];
+            if (handlers.containsKey(msgClass)) {
+                throw new AssertionError("only one Runabout per message 
allowed");
+            }
+            handlers.put(msgClass, cb);
+        }
+    }
 
+    public interface DisconnectHandler {
+        void onDisconnect(ClientHandle clientHandle);
     }
 
-    public Cancelable notifyDisconnect(/* disco handler */) {
+    public Cancelable notifyDisconnect(DisconnectHandler disconnectHandler) {
         return null;
     }
 
-
     /**
      * Free resources held by this server.
      */

Modified: gnunet-java/src/org/gnunet/util/Service.java
===================================================================
--- gnunet-java/src/org/gnunet/util/Service.java        2012-04-21 18:16:21 UTC 
(rev 21060)
+++ gnunet-java/src/org/gnunet/util/Service.java        2012-04-21 23:09:41 UTC 
(rev 21061)
@@ -1,11 +1,18 @@
 package org.gnunet.util;
 
 
-public abstract class Service {
+/**
+ * Server the entry point class for every gnunet-java component providing 
services
+ * to other components.
+ *
+ */
+public abstract class Service extends Program {
     private Server s;
     
     public Service(String[] args) {
-        // load configuration, parse args, ...
+        super(args);
+        // now create the server:
+        // s = new Server()
     }
     
     public final Server getServer() {
@@ -13,10 +20,6 @@
         
     }
 
-    public final void start() {
-        // ...
-    }
-
     public final void stop() {
 
     }
@@ -25,4 +28,12 @@
      * Override to implement the behavior of the Program.
      */
     public abstract void run();
+
+    /**
+     * Start the Program as the initial Task of the Scheduler.
+     */
+    public void start() {
+        System.out.println("bla");
+        super.start();
+    }
 }

Modified: gnunet-java/src/org/gnunet/util/getopt/Parser.java
===================================================================
--- gnunet-java/src/org/gnunet/util/getopt/Parser.java  2012-04-21 18:16:21 UTC 
(rev 21060)
+++ gnunet-java/src/org/gnunet/util/getopt/Parser.java  2012-04-21 23:09:41 UTC 
(rev 21061)
@@ -1,8 +1,6 @@
 package org.gnunet.util.getopt;
 
 import org.gnunet.construct.ReflectUtil;
-import org.gnunet.exceptions.InterfaceViolationException;
-
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
 import java.util.*;
@@ -64,7 +62,7 @@
             Option opt = f.getAnnotation(Option.class);
             if (opt != null) {
                 if (opt.shortname().length() != 1) {
-                    throw new InterfaceViolationException("short name must be 
of length 1");
+                    throw new AssertionError("short name must be of length 1");
                 }
 
                 f.setAccessible(true);
@@ -106,19 +104,19 @@
             switch (option.action()) {
                 case SET:
                     if (!targetFieldType.equals(Boolean.TYPE)) {
-                        throw new InterfaceViolationException("action SET only 
valid on boolean member");
+                        throw new AssertionError("action SET only valid on 
boolean member");
                     }
                     targetField.set(targetObject, true);
                     break;
                 case RESET:
                     if (!targetFieldType.equals(Boolean.TYPE)) {
-                        throw new InterfaceViolationException("action RESET 
only valid on boolean member");
+                        throw new AssertionError("action RESET only valid on 
boolean member");
                     }
                     targetField.set(targetObject, false);
                     break;
                 case STORE_STRING:
                     if (!targetFieldType.equals(String.class)) {
-                        throw new InterfaceViolationException("action 
STORE_STRING only valid on boolean member");
+                        throw new AssertionError("action STORE_STRING only 
valid on boolean member");
                     }
                     if (right == null) {
                         argsList.removeFirst();
@@ -152,7 +150,7 @@
                     throw new UnsupportedOperationException("not yet 
implemented");
             }
         } catch (IllegalAccessException e) {
-            throw new InterfaceViolationException(
+            throw new AssertionError(
                     String.format("cannot acces member %s with @Option 
annotation", targetField.getName()));
         }
     }
@@ -162,19 +160,19 @@
             switch (option.action()) {
                 case SET:
                     if (!targetField.getType().equals(Boolean.TYPE)) {
-                        throw new InterfaceViolationException("action SET only 
valid on boolean member");
+                        throw new AssertionError("action SET only valid on 
boolean member");
                     }
                     targetField.set(targetObject, true);
                     break;
                 case RESET:
                     if (!targetField.getType().equals(Boolean.TYPE)) {
-                        throw new InterfaceViolationException("action RESET 
only valid on boolean member");
+                        throw new AssertionError("action RESET only valid on 
boolean member");
                     }
                     targetField.set(targetObject, false);
                     break;
                 case STORE_STRING:
                     if (!targetField.getType().equals(String.class)) {
-                        throw new InterfaceViolationException("action 
STORE_STRING only valid on boolean " +
+                        throw new AssertionError("action STORE_STRING only 
valid on boolean " +
                                 "member");
                     }
                     if (argsList.getFirst().length() == 2) { // -X

Modified: 
gnunet-java/test/org/gnunet/services/NetworkSizeEstimationServiceTest.java
===================================================================
--- gnunet-java/test/org/gnunet/services/NetworkSizeEstimationServiceTest.java  
2012-04-21 18:16:21 UTC (rev 21060)
+++ gnunet-java/test/org/gnunet/services/NetworkSizeEstimationServiceTest.java  
2012-04-21 23:09:41 UTC (rev 21061)
@@ -6,7 +6,7 @@
 import org.junit.Test;
 
 public class NetworkSizeEstimationServiceTest {
-    class TestSubscriber implements NetworkSizeEstimation.NSE_Subscriber {
+    class TestSubscriber implements NetworkSizeEstimation.Subscriber {
         public boolean success = false;
         NetworkSizeEstimation svc;
         @Override




reply via email to

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