From d33161cddda663720ea93c483ed6e3e7511e995b Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 7 Apr 2014 00:26:06 +0000 Subject: docs / fixed fixme in crypto --- src/main/java/org/gnunet/core/ConnectHandler.java | 4 ++ src/main/java/org/gnunet/core/Core.java | 40 ++++++++++++- .../java/org/gnunet/core/DisconnectHandler.java | 5 ++ src/main/java/org/gnunet/core/HeaderNotify.java | 6 +- src/main/java/org/gnunet/core/InitCallback.java | 6 ++ src/main/java/org/gnunet/core/MessageNotify.java | 8 +++ .../org/gnunet/core/PeerIdentityContinuation.java | 8 +++ src/main/java/org/gnunet/core/package-info.java | 2 +- .../java/org/gnunet/dht/DistributedHashTable.java | 41 +++++++++----- .../java/org/gnunet/dht/MonitorGetHandler.java | 14 ++++- .../org/gnunet/dht/MonitorGetResponseHandler.java | 13 +++++ .../java/org/gnunet/dht/MonitorPutHandler.java | 4 +- src/main/java/org/gnunet/gns/Gns.java | 3 + src/main/java/org/gnunet/gns/GnsRecord.java | 3 + src/main/java/org/gnunet/gns/GnsTool.java | 3 + src/main/java/org/gnunet/gns/RecordFlags.java | 4 +- src/main/java/org/gnunet/identity/Identity.java | 65 ++++++++++++++++++++++ src/main/java/org/gnunet/mesh/Mesh.java | 63 ++++++++++----------- src/main/java/org/gnunet/nse/package-info.java | 2 +- src/main/java/org/gnunet/peerinfo/PeerInfo.java | 12 ++++ .../java/org/gnunet/peerinfo/PeerProcessor.java | 10 ++++ src/main/java/org/gnunet/requests/Request.java | 2 +- .../requests/SequentialRequestContainer.java | 9 +++ .../gnunet/requests/SimpleRequestIdentifier.java | 3 - .../java/org/gnunet/requests/TimeoutHandler.java | 2 +- .../java/org/gnunet/statistics/Statistics.java | 27 +++++++-- .../org/gnunet/statistics/StatisticsReceiver.java | 21 ++++++- .../org/gnunet/statistics/StatisticsWatcher.java | 10 ++++ .../gnunet/testbed/ControllerStatusCallback.java | 12 ++++ .../gnunet/testbed/HostRegistrationCompletion.java | 5 +- .../testbed/OperationCompletionCallback.java | 12 ++++ src/main/java/org/gnunet/util/Connection.java | 2 +- .../org/gnunet/util/crypto/EcdsaSignature.java | 9 ++- .../org/gnunet/util/crypto/EddsaSignature.java | 6 +- .../java/org/gnunet/util/crypto/package-info.java | 2 +- src/main/java/org/gnunet/voting/BallotTool.java | 20 +++---- .../org/gnunet/voting/TallyAuthorityDaemon.java | 4 +- .../java/org/gnunet/construct/SendMessageTest.java | 2 +- src/test/java/org/gnunet/mesh/MeshTest.java | 10 ++-- .../gnunet/secretsharing/SecretsharingTest.java | 3 +- 40 files changed, 381 insertions(+), 96 deletions(-) (limited to 'src') diff --git a/src/main/java/org/gnunet/core/ConnectHandler.java b/src/main/java/org/gnunet/core/ConnectHandler.java index a36d798..4291acd 100644 --- a/src/main/java/org/gnunet/core/ConnectHandler.java +++ b/src/main/java/org/gnunet/core/ConnectHandler.java @@ -26,5 +26,9 @@ import org.gnunet.util.PeerIdentity; * Called when a new peer (with a compatible set of messages) connects to core */ public interface ConnectHandler { + /** + * Called when a new peer (with a compatible set of messages) connects to core + * @param peerIdentity identity of the connecting peer + */ void onConnect(PeerIdentity peerIdentity); } diff --git a/src/main/java/org/gnunet/core/Core.java b/src/main/java/org/gnunet/core/Core.java index a4adb32..83e712b 100644 --- a/src/main/java/org/gnunet/core/Core.java +++ b/src/main/java/org/gnunet/core/Core.java @@ -23,6 +23,7 @@ package org.gnunet.core; import com.google.common.collect.Maps; import org.gnunet.construct.Construct; import org.gnunet.construct.MessageLoader; +import org.gnunet.core.messages.*; import org.gnunet.mq.Envelope; import org.gnunet.requests.MatchingRequestContainer; import org.gnunet.requests.Request; @@ -36,7 +37,7 @@ import java.util.HashMap; /** - * API for the gnunet core service. + * API for the GNUnet core service. *

* Sends messages to connected peers. */ @@ -246,6 +247,11 @@ public class Core { } } + /** + * Establish a connection to the core service. + * + * @param cfg configuration to use + */ public Core(Configuration cfg) { client = new Client("core", cfg); client.installReceiver(new CoreReceiver()); @@ -301,8 +307,8 @@ public class Core { * Helper function to retrieve the peer identity with the given configuration via CORE. * Should not be used unless there is no other means to obtain the peer identity. * - * @param cfg - * @param cont + * @param cfg configuration to use + * @param cont continuation, called with the peer identity once available */ public static void withPeerIdentity(Configuration cfg, final PeerIdentityContinuation cont) { final Core core = new Core(cfg); @@ -317,28 +323,54 @@ public class Core { /** * Observe outgoing message headers from core. + * * @param h callback */ public void observeOutboundHeaders(HeaderNotify h) { this.notifyOutboundHeaders = h; } + /** + * Observe inbound headers from core. + * + * @param h callback + */ public void observeInboundHeaders(HeaderNotify h) { this.notifyInboundHeaders = h; } + /** + * Observe inbound messages from core. + * + * @param h callback + */ public void observeInboundMessages(MessageNotify h) { this.notifyInboundMessages = h; } + /** + * Observe outbound messages from core. + * + * @param h callback + */ public void observeOutboundMessages(MessageNotify h) { this.notifyOutboundMessages = h; } + /** + * Observe core connections + * + * @param connectHandler callback + */ public void observeConnect(ConnectHandler connectHandler) { this.connectHandler = connectHandler; } + /** + * Observe core disconnections. + * + * @param disconnectHandler callback + */ public void observeDisconnect(DisconnectHandler disconnectHandler) { this.disconnectHandler = disconnectHandler; } @@ -347,6 +379,8 @@ public class Core { * Handle all incoming messages with the specified runabout. * Has to be called before init, as the service has to know which messages we * are interested in. + * + * @param runabout the runabout that will handle received messages */ public void setMessageHandler(Runabout runabout) { if (messageHandler != null) { diff --git a/src/main/java/org/gnunet/core/DisconnectHandler.java b/src/main/java/org/gnunet/core/DisconnectHandler.java index c7ca407..e0fe08b 100644 --- a/src/main/java/org/gnunet/core/DisconnectHandler.java +++ b/src/main/java/org/gnunet/core/DisconnectHandler.java @@ -26,5 +26,10 @@ import org.gnunet.util.PeerIdentity; * Called when a peer disconnects from the core. */ public interface DisconnectHandler { + /** + * Called when a peer disconnects from the core. + * + * @param peerIdentity identity of the peer that disconnected + */ void onDisconnect(PeerIdentity peerIdentity); } diff --git a/src/main/java/org/gnunet/core/HeaderNotify.java b/src/main/java/org/gnunet/core/HeaderNotify.java index 4f536e3..353c576 100644 --- a/src/main/java/org/gnunet/core/HeaderNotify.java +++ b/src/main/java/org/gnunet/core/HeaderNotify.java @@ -23,8 +23,12 @@ package org.gnunet.core; import org.gnunet.util.GnunetMessage; /** - * + * Called to notify the client about a header. */ public interface HeaderNotify { + /** + * Called to notify the client about a header. + * @param header the header + */ void notify(GnunetMessage.Header header); } diff --git a/src/main/java/org/gnunet/core/InitCallback.java b/src/main/java/org/gnunet/core/InitCallback.java index 889f8cf..7b3548f 100644 --- a/src/main/java/org/gnunet/core/InitCallback.java +++ b/src/main/java/org/gnunet/core/InitCallback.java @@ -26,5 +26,11 @@ import org.gnunet.util.PeerIdentity; * Called once the handshake with core was successful. */ public interface InitCallback { + /** + * Called once the handshake with core was successful. + * + * @param myIdentity the identity of the peer that runs + * the core service we connected to + */ void onInit(PeerIdentity myIdentity); } diff --git a/src/main/java/org/gnunet/core/MessageNotify.java b/src/main/java/org/gnunet/core/MessageNotify.java index b14ce29..7244884 100644 --- a/src/main/java/org/gnunet/core/MessageNotify.java +++ b/src/main/java/org/gnunet/core/MessageNotify.java @@ -23,6 +23,14 @@ package org.gnunet.core; import org.gnunet.util.GnunetMessage; +/** + * Notify the client about a message. + */ public interface MessageNotify { + /** + * Notify the client about a message. + * + * @param messageBody the received message + */ void notify(GnunetMessage messageBody); } diff --git a/src/main/java/org/gnunet/core/PeerIdentityContinuation.java b/src/main/java/org/gnunet/core/PeerIdentityContinuation.java index e29af45..2e9ada6 100644 --- a/src/main/java/org/gnunet/core/PeerIdentityContinuation.java +++ b/src/main/java/org/gnunet/core/PeerIdentityContinuation.java @@ -2,6 +2,14 @@ package org.gnunet.core; import org.gnunet.util.PeerIdentity; +/** + * Continuation that receives the peer's identity. + */ public interface PeerIdentityContinuation { + /** + * Called with the peer identity. + * + * @param peerIdentity the peer identity + */ public void cont(PeerIdentity peerIdentity); } diff --git a/src/main/java/org/gnunet/core/package-info.java b/src/main/java/org/gnunet/core/package-info.java index 7feb82c..d078d72 100644 --- a/src/main/java/org/gnunet/core/package-info.java +++ b/src/main/java/org/gnunet/core/package-info.java @@ -19,6 +19,6 @@ */ /** - * API for the GNUnet CORE service. + * Communication with connected peers. */ package org.gnunet.core; diff --git a/src/main/java/org/gnunet/dht/DistributedHashTable.java b/src/main/java/org/gnunet/dht/DistributedHashTable.java index 0246992..27bac92 100644 --- a/src/main/java/org/gnunet/dht/DistributedHashTable.java +++ b/src/main/java/org/gnunet/dht/DistributedHashTable.java @@ -21,6 +21,7 @@ package org.gnunet.dht; import com.google.common.base.Charsets; +import org.gnunet.dht.messages.*; import org.gnunet.mq.Envelope; import org.gnunet.requests.MatchingRequestContainer; import org.gnunet.requests.Request; @@ -37,7 +38,7 @@ import java.util.List; import java.util.Set; /** - * API for the gnunet dht service. + * API for the GNUnet dht service. *

* Stores data under a key, distributed across the network. *

@@ -230,6 +231,7 @@ public class DistributedHashTable { @Override public void handleError() { + // FIXME } } @@ -256,12 +258,10 @@ public class DistributedHashTable { * @param routeOptions additional options * @param type type of the data to store * @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, Set routeOptions, - int type, AbsoluteTime expiration, - RelativeTime timeout, final Continuation cont) { + int type, AbsoluteTime expiration, final Continuation cont) { PutRequest pr = new PutRequest(); pr.key = key; pr.data = data; @@ -296,10 +296,21 @@ public class DistributedHashTable { getRequest.type = type; getRequest.replication = type; getRequest.xquery = xquery; + getRequest.replication = replication; return getRequests.addRequest(getRequest.uid, getRequest); } + /** + * Start monitoring certain types of requests. + * + * @param blockType block type of requests we're interested in + * @param key key we're interested in + * @param getHandler listener for get requests + * @param getResponseHandler listener for get responses + * @param putHandler listener for put requests + * @return a handle to cancel the monitoring + */ public Cancelable startMonitor(int blockType, HashCode key, MonitorGetHandler getHandler, MonitorGetResponseHandler getResponseHandler, MonitorPutHandler putHandler) { @@ -389,17 +400,17 @@ public class DistributedHashTable { dht.put(new HashCode(key), data.getBytes(), replication, EnumSet.of(RouteOption.NONE), BlockType.TEST.val, AbsoluteTime.now().add(RelativeTime.HOUR), - RelativeTime.SECOND, new Continuation() { - @Override - public void cont(boolean success) { - if (success) { - System.out.println("put getRequestIdentifier sent"); - } else { - System.out.println("error"); - } - dht.destroy(); - } - }); + new Continuation() { + @Override + public void cont(boolean success) { + if (success) { + System.out.println("put getRequestIdentifier sent"); + } else { + System.out.println("error"); + } + dht.destroy(); + } + }); } else if (monitor) { final DistributedHashTable dht = new DistributedHashTable(cfg); dht.startMonitor(BlockType.TEST.val, null, diff --git a/src/main/java/org/gnunet/dht/MonitorGetHandler.java b/src/main/java/org/gnunet/dht/MonitorGetHandler.java index d3f5d5f..d2ce36f 100644 --- a/src/main/java/org/gnunet/dht/MonitorGetHandler.java +++ b/src/main/java/org/gnunet/dht/MonitorGetHandler.java @@ -23,8 +23,20 @@ package org.gnunet.dht; import org.gnunet.util.HashCode; import org.gnunet.util.PeerIdentity; - +/** + * Listener for monitoring get requests. + */ public interface MonitorGetHandler { + /** + * Called when a get request happens. + * + * @param options options of the request + * @param type type of the request + * @param hopCount hop count of the request + * @param desiredReplicationLevel desired replication level for the request + * @param getPath path of the get request + * @param key key for the request + */ void onGet(int options, int type, int hopCount, int desiredReplicationLevel, PeerIdentity[] getPath, HashCode key); } diff --git a/src/main/java/org/gnunet/dht/MonitorGetResponseHandler.java b/src/main/java/org/gnunet/dht/MonitorGetResponseHandler.java index ff03cce..c0710c9 100644 --- a/src/main/java/org/gnunet/dht/MonitorGetResponseHandler.java +++ b/src/main/java/org/gnunet/dht/MonitorGetResponseHandler.java @@ -25,7 +25,20 @@ import org.gnunet.util.HashCode; import org.gnunet.util.PeerIdentity; +/** + * Listener for monitoring get responses. + */ public interface MonitorGetResponseHandler { + /** + * Called when a get response happens. + * + * @param type + * @param getPath + * @param putPath + * @param expiration + * @param key + * @param data + */ void onGetResponse(int type, PeerIdentity[] getPath, PeerIdentity[] putPath, AbsoluteTimeMessage expiration, HashCode key, byte[] data); } diff --git a/src/main/java/org/gnunet/dht/MonitorPutHandler.java b/src/main/java/org/gnunet/dht/MonitorPutHandler.java index 0abb79b..1fac89e 100644 --- a/src/main/java/org/gnunet/dht/MonitorPutHandler.java +++ b/src/main/java/org/gnunet/dht/MonitorPutHandler.java @@ -24,7 +24,9 @@ import org.gnunet.util.AbsoluteTimeMessage; import org.gnunet.util.HashCode; import org.gnunet.util.PeerIdentity; - +/** + * + */ public interface MonitorPutHandler { void onPut(int options, int type, int hop_count, AbsoluteTimeMessage expirationTime, PeerIdentity[] putPath, HashCode key, byte[] data); diff --git a/src/main/java/org/gnunet/gns/Gns.java b/src/main/java/org/gnunet/gns/Gns.java index 2b10296..0e64ae0 100644 --- a/src/main/java/org/gnunet/gns/Gns.java +++ b/src/main/java/org/gnunet/gns/Gns.java @@ -130,6 +130,9 @@ public class Gns { } + /** + * Disconnect from the GNS service. + */ public void disconnect() { client.disconnect(); client = null; diff --git a/src/main/java/org/gnunet/gns/GnsRecord.java b/src/main/java/org/gnunet/gns/GnsRecord.java index cd1108f..657d4e7 100644 --- a/src/main/java/org/gnunet/gns/GnsRecord.java +++ b/src/main/java/org/gnunet/gns/GnsRecord.java @@ -36,6 +36,9 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Map; +/** + * A GNS record. + */ public class GnsRecord implements Message { private static final Logger logger = LoggerFactory .getLogger(GnsRecord.class); diff --git a/src/main/java/org/gnunet/gns/GnsTool.java b/src/main/java/org/gnunet/gns/GnsTool.java index 624a5fe..0d33dc1 100644 --- a/src/main/java/org/gnunet/gns/GnsTool.java +++ b/src/main/java/org/gnunet/gns/GnsTool.java @@ -7,6 +7,9 @@ import org.gnunet.util.Program; import org.gnunet.util.getopt.Argument; import org.gnunet.util.getopt.ArgumentAction; +/** + * Command line tool for GNS. + */ public class GnsTool { public static void main(String[] args) { int ret = new Program() { diff --git a/src/main/java/org/gnunet/gns/RecordFlags.java b/src/main/java/org/gnunet/gns/RecordFlags.java index 58a9141..10c43b9 100644 --- a/src/main/java/org/gnunet/gns/RecordFlags.java +++ b/src/main/java/org/gnunet/gns/RecordFlags.java @@ -20,7 +20,9 @@ package org.gnunet.gns; - +/** + * Flags for GNS records. + */ public interface RecordFlags { /** * No special options. diff --git a/src/main/java/org/gnunet/identity/Identity.java b/src/main/java/org/gnunet/identity/Identity.java index ca94a20..7273ef6 100644 --- a/src/main/java/org/gnunet/identity/Identity.java +++ b/src/main/java/org/gnunet/identity/Identity.java @@ -35,6 +35,9 @@ import org.slf4j.LoggerFactory; import java.util.List; +/** + * Make requests to the identity service. + */ public class Identity { private static final Logger logger = LoggerFactory .getLogger(Identity.class); @@ -46,6 +49,15 @@ public class Identity { private static Ego anonymousEgo; + /** + * Look up the given ego name. + * + * @param configuration configuration to use for connecting to + * the identity service + * @param egoName ego name to look up + * @param identityCallback handler for lookup result + * @return a handle to cancel the lookup + */ public static Cancelable lookup(Configuration configuration, final String egoName, final IdentityCallback identityCallback) { final Identity myIdentity = new Identity(); @@ -106,20 +118,47 @@ public class Identity { return cancellationToken; } + /** + * An ego. + */ public static class Ego { private String name; private EcdsaPrivateKey privateKey; + /** + * Create an ego with the given name and private key. + * + * @param egoName the ego name + * @param privateKey the ego's private key + */ public Ego(String egoName, EcdsaPrivateKey privateKey) { this.name = egoName; this.privateKey = privateKey; } + + /** + * Get the ego's private key. + * + * @return the ego's private key + */ public EcdsaPrivateKey getPrivateKey() { return privateKey; } + + /** + * Compute the ego's public key from its private key. + * + * @return the ego's public key + */ public EcdsaPublicKey getPublicKey() { return privateKey.getPublicKey(); } + + /** + * Get the ego's name. + * + * @return the ego's name + */ public String getName() { return name; } @@ -261,6 +300,12 @@ public class Identity { } } + /** + * Get the anonymous ego. The anonymous ego has a publicly + * known private key. + * + * @return the anonymous ego + */ public static Ego getAnonymousEgo() { if (anonymousEgo == null) { anonymousEgo = new Ego(null, EcdsaPrivateKey.getAnonymous()); @@ -269,10 +314,20 @@ public class Identity { } + /** + * Create a handle that can connect to the identity service. + * Nothing will happen until calling connect. + */ public Identity() { // do nothing } + /** + * Connect to the identity service. + * + * @param configuration configuration to use + * @param identityListCallback + */ public void connect(Configuration configuration, IdentityListCallback identityListCallback) { this.configuration = configuration; this.client = new Client("identity", configuration); @@ -283,6 +338,13 @@ public class Identity { client.send(m); } + /** + * Get the default ego for a service + * + * @param serviceName name of the service + * @param identityCallback callback that receives the default ego + * @return a handle to cancel the operation + */ public Cancelable get(String serviceName, IdentityCallback identityCallback) { return requests.addRequest(new GetDefaultRequest(serviceName, identityCallback)); } @@ -298,6 +360,9 @@ public class Identity { return requests.addRequest(new SetDefaultRequest(serviceName, ego)); } + /** + * Disconnect from the identity service. + */ public void disconnect() { client.disconnect(); client = null; diff --git a/src/main/java/org/gnunet/mesh/Mesh.java b/src/main/java/org/gnunet/mesh/Mesh.java index 32f9ba0..ede7761 100644 --- a/src/main/java/org/gnunet/mesh/Mesh.java +++ b/src/main/java/org/gnunet/mesh/Mesh.java @@ -77,7 +77,7 @@ public class Mesh { /** * Called whenever a tunnel was destroyed. */ - private TunnelEndHandler tunnelEndHandler; + private ChannelEndHandler channelEndHandler; /** * Message handler for messages received through @@ -108,10 +108,8 @@ public class Mesh { /** * A tunnel to a remote peer. - * @param type of context data for the tunnel */ - public class Channel extends MessageQueue { - private T context; + public class Channel extends MessageQueue { private final int opt; final PeerIdentity peer; final int port; @@ -129,13 +127,12 @@ public class Mesh { * Create a new tunnel (we're initiator and will be allowed to add/remove peers * and to broadcast). * - * @param context tunnel context * @param peer peer identity the tunnel should go to * @param port Port number. * @param nobuffer Flag for disabling buffering on relay nodes. * @param reliable Flag for end-to-end reliability. */ - public Channel(PeerIdentity peer, int port, boolean nobuffer, boolean reliable, T context) { + public Channel(PeerIdentity peer, int port, boolean nobuffer, boolean reliable) { this(peer, 0, port, nobuffer, reliable); TunnelCreateMessage tcm = new TunnelCreateMessage(); tcm.otherEnd = peer; @@ -225,14 +222,6 @@ public class Mesh { envelopeCanceler = null; } - public T getContext() { - return context; - } - - public void setContext(T newContext) { - context = newContext; - } - void handleAck() { ackCount++; logger.debug("got ack for tunnel id " + tunnelId); @@ -287,7 +276,7 @@ public class Mesh { t.destroyedByService = true; logger.debug("tunnel destroyed by service"); t.destroy(); - tunnelEndHandler.onChannelEnd(t); + channelEndHandler.onChannelEnd(t); } public void visit(RejectMessage m) { @@ -300,15 +289,15 @@ public class Mesh { t.destroyedByService = true; logger.debug("tunnel destroyed by service (nack/reject)"); t.destroy(); - tunnelEndHandler.onChannelEnd(t); + channelEndHandler.onChannelEnd(t); } @Override public void handleError() { logger.warn("lost connection to mesh service, reconnecting"); - if (null != tunnelEndHandler) { + if (null != channelEndHandler) { for (Channel t : tunnelMap.values()) { - tunnelEndHandler.onChannelEnd(t); + channelEndHandler.onChannelEnd(t); } } tunnelMap.clear(); @@ -324,17 +313,17 @@ public class Mesh { * * @param cfg configuration to use * @param inboundChannelHandler called when an inbound channel is established - * @param tunnelEndHandler called when a tunnel is destroyed (either by the client calling Tunnel.destroy(), + * @param channelEndHandler called when a tunnel is destroyed (either by the client calling Tunnel.destroy(), * or by the service) * @param messageReceiver runabout for messages we are interested in * @param ports ports to listen on */ public Mesh(Configuration cfg, InboundChannelHandler inboundChannelHandler, - TunnelEndHandler tunnelEndHandler, MeshRunabout messageReceiver, int... ports) { - if (null == tunnelEndHandler) { + ChannelEndHandler channelEndHandler, MeshRunabout messageReceiver, int... ports) { + if (null == channelEndHandler) { throw new AssertionError("tunnel end handler may not be null"); } - this.tunnelEndHandler = tunnelEndHandler; + this.channelEndHandler = channelEndHandler; this.messageReceiver = messageReceiver; this.ports = ports; this.inboundChannelHandler = inboundChannelHandler; @@ -352,14 +341,14 @@ public class Mesh { } /** - * Connect to the mesh service. Use this constructor if you are not interested in inbound tunnels. + * Connect to the mesh service. Use this constructor if you are not interested in inbound channels. * * @param cfg configuration to use - * @param tunnelEndHandler called when a tunnel is destroyed (either by the client calling Tunnel.destroy(), + * @param channelEndHandler called when a tunnel is destroyed (either by the client calling Channel.destroy(), * or by the service) */ - public Mesh(Configuration cfg, TunnelEndHandler tunnelEndHandler, MeshRunabout messageReceiver) { - this(cfg, null, tunnelEndHandler, messageReceiver); + public Mesh(Configuration cfg, ChannelEndHandler channelEndHandler, MeshRunabout messageReceiver) { + this(cfg, null, channelEndHandler, messageReceiver); } /** @@ -367,20 +356,26 @@ public class Mesh { * and don't want to receive messages. * * @param cfg configuration to use - * @param tunnelEndHandler called when a tunnel is destroyed (either by the client calling Tunnel.destroy(), + * @param channelEndHandler called when a tunnel is destroyed (either by the client calling Tunnel.destroy(), * or by the service) */ - public Mesh(Configuration cfg, TunnelEndHandler tunnelEndHandler) { - this(cfg, null, tunnelEndHandler, null); + public Mesh(Configuration cfg, ChannelEndHandler channelEndHandler) { + this(cfg, null, channelEndHandler, null); } - public Channel createTunnel(PeerIdentity peer, int port, boolean nobuffer, boolean reliable, T initialContext) { - return new Channel(peer, port, nobuffer, reliable, initialContext); - } - public Channel createTunnel(PeerIdentity peer, int port, boolean nobuffer, boolean reliable) { + /** + * Create a channel to a peer over the given port, with the given options. + * + * @param peer peer to create a channel to + * @param port port to use + * @param nobuffer true if messages should be buffered + * @param reliable true if transmission should be reliable + * @return a channel + */ + public Channel createChannel(PeerIdentity peer, int port, boolean nobuffer, boolean reliable) { logger.debug("creating tunnel to peer {} over port {}", peer.toString(), port); - return new Channel(peer, port, nobuffer, reliable, null); + return new Channel(peer, port, nobuffer, reliable); } /** diff --git a/src/main/java/org/gnunet/nse/package-info.java b/src/main/java/org/gnunet/nse/package-info.java index 3bbc064..45618ba 100644 --- a/src/main/java/org/gnunet/nse/package-info.java +++ b/src/main/java/org/gnunet/nse/package-info.java @@ -19,6 +19,6 @@ */ /** - * API for the gnunet nse service. + * Retrieve network size estimates. */ package org.gnunet.nse; diff --git a/src/main/java/org/gnunet/peerinfo/PeerInfo.java b/src/main/java/org/gnunet/peerinfo/PeerInfo.java index 43c0597..dcd3cc0 100644 --- a/src/main/java/org/gnunet/peerinfo/PeerInfo.java +++ b/src/main/java/org/gnunet/peerinfo/PeerInfo.java @@ -22,6 +22,10 @@ package org.gnunet.peerinfo; import org.gnunet.hello.HelloMessage; import org.gnunet.mq.Envelope; +import org.gnunet.peerinfo.messages.InfoEnd; +import org.gnunet.peerinfo.messages.InfoMessage; +import org.gnunet.peerinfo.messages.ListAllPeersMessage; +import org.gnunet.peerinfo.messages.ListPeerMessage; import org.gnunet.requests.Request; import org.gnunet.requests.SequentialRequestContainer; import org.gnunet.util.*; @@ -97,6 +101,11 @@ public class PeerInfo { } + /** + * Create a connection to the peerinfo service. + * + * @param cfg configuration to use + */ public PeerInfo(Configuration cfg) { client = new Client("peerinfo", cfg); client.installReceiver(new PeerInfoMessageReceiver()); @@ -127,6 +136,9 @@ public class PeerInfo { return iterateRequests.addRequest(r); } + /** + * Disconnect from the peerinfo service. + */ public void disconnect() { client.disconnect(); } diff --git a/src/main/java/org/gnunet/peerinfo/PeerProcessor.java b/src/main/java/org/gnunet/peerinfo/PeerProcessor.java index b096c37..3a76425 100644 --- a/src/main/java/org/gnunet/peerinfo/PeerProcessor.java +++ b/src/main/java/org/gnunet/peerinfo/PeerProcessor.java @@ -7,6 +7,16 @@ import org.gnunet.util.PeerIdentity; * Callback class to receive known peers and their HELLOs. */ public interface PeerProcessor { + /** + * Process a peer and its hello + * + * @param peerIdentity the peer + * @param hello the hello of the peer + */ public void onPeer(PeerIdentity peerIdentity, HelloMessage hello); + + /** + * Called to indicate the end of a peer list. + */ public void onEnd(); } diff --git a/src/main/java/org/gnunet/requests/Request.java b/src/main/java/org/gnunet/requests/Request.java index 53fb3db..80a59ff 100644 --- a/src/main/java/org/gnunet/requests/Request.java +++ b/src/main/java/org/gnunet/requests/Request.java @@ -84,7 +84,7 @@ import org.gnunet.mq.Envelope; import org.gnunet.util.Cancelable; /** - * A getRequestIdentifier that can be put in a getRequestIdentifier container. + * A request that can be put in a request container. */ public abstract class Request implements Cancelable { /** diff --git a/src/main/java/org/gnunet/requests/SequentialRequestContainer.java b/src/main/java/org/gnunet/requests/SequentialRequestContainer.java index c343812..07a662f 100644 --- a/src/main/java/org/gnunet/requests/SequentialRequestContainer.java +++ b/src/main/java/org/gnunet/requests/SequentialRequestContainer.java @@ -131,6 +131,12 @@ public class SequentialRequestContainer extends RequestContai } } + /** + * Add a request to the queue + * + * @param request the request to add + * @return a handle that represents the queued request + */ public RequestIdentifier addRequest(final T request) { final Identifier identifier = new Identifier(request); requests.addLast(identifier); @@ -142,6 +148,9 @@ public class SequentialRequestContainer extends RequestContai return identifier; } + /** + * Re-send all active requests. + */ @Override public void restart() { LinkedList requestsOld = requests; diff --git a/src/main/java/org/gnunet/requests/SimpleRequestIdentifier.java b/src/main/java/org/gnunet/requests/SimpleRequestIdentifier.java index 5963ce8..7132472 100644 --- a/src/main/java/org/gnunet/requests/SimpleRequestIdentifier.java +++ b/src/main/java/org/gnunet/requests/SimpleRequestIdentifier.java @@ -18,10 +18,8 @@ Boston, MA 02111-1307, USA. */ - package org.gnunet.requests; - import org.gnunet.mq.Envelope; import org.gnunet.mq.MessageQueue; import org.gnunet.mq.NotifySentHandler; @@ -29,7 +27,6 @@ import org.gnunet.util.Cancelable; import org.gnunet.util.RelativeTime; import org.gnunet.util.Scheduler; - abstract class SimpleRequestIdentifier implements RequestIdentifier { private final T request; /** diff --git a/src/main/java/org/gnunet/requests/TimeoutHandler.java b/src/main/java/org/gnunet/requests/TimeoutHandler.java index eca067e..f9715de 100644 --- a/src/main/java/org/gnunet/requests/TimeoutHandler.java +++ b/src/main/java/org/gnunet/requests/TimeoutHandler.java @@ -21,7 +21,7 @@ package org.gnunet.requests; /** - * Callback object for handling getRequestIdentifier timeouts. + * Callback object for handling request timeouts. */ public interface TimeoutHandler { void onTimeout(); diff --git a/src/main/java/org/gnunet/statistics/Statistics.java b/src/main/java/org/gnunet/statistics/Statistics.java index d8b8f3e..d642962 100644 --- a/src/main/java/org/gnunet/statistics/Statistics.java +++ b/src/main/java/org/gnunet/statistics/Statistics.java @@ -131,6 +131,11 @@ public class Statistics { } } + /** + * Create a connection to the statistics service. + * + * @param cfg configuration to use + */ public Statistics(Configuration cfg) { client = new Client("statistics", cfg); client.installReceiver(new StatisticsMessageReceiver()); @@ -139,9 +144,7 @@ public class Statistics { } /** - * Retrieve values from statistics. - * Only one instance of this getRequestIdentifier may be active simultaneously. - * Upon cancellation + * Retrieve a statistics value of a subsystem. * * @param timeout time after we give up and call receiver.onTimeout * @param subsystem the subsystem of interest @@ -163,6 +166,19 @@ public class Statistics { return identifier; } + /** + * Retrieve all statistics value of a subsystem. + * + * @param timeout time after we give up and call receiver.onTimeout + * @param subsystem the subsystem of interest + * @param receiver callback + * @return handle to onCancel the getRequestIdentifier + */ + public Cancelable get(RelativeTime timeout, final String subsystem, + final StatisticsReceiver receiver) { + return get(timeout, subsystem, "", receiver); + } + /** * Sets a statistics value asynchronously. * @@ -226,9 +242,10 @@ public class Statistics { } /** - * Destroy handle to the statistics service. Always finishes writing pending values. + * Destroy handle to the statistics service. * - * @param syncFirst Wait until the statistics service has received all our updates. + * @param syncFirst If true, wait until the statistics service has received all our updates. + * If false, pending updates may be lost. */ public void destroy(boolean syncFirst) { if (destroyRequested) diff --git a/src/main/java/org/gnunet/statistics/StatisticsReceiver.java b/src/main/java/org/gnunet/statistics/StatisticsReceiver.java index 0c25acc..d30a93e 100644 --- a/src/main/java/org/gnunet/statistics/StatisticsReceiver.java +++ b/src/main/java/org/gnunet/statistics/StatisticsReceiver.java @@ -21,9 +21,28 @@ package org.gnunet.statistics; - +/** + * Handler for statistics results. + */ public interface StatisticsReceiver { + /** + * Called when having received a statistics value from the service. + * + * @param subsystem subsystem of the value + * @param name name of the value + * @param value the value + */ public void onReceive(String subsystem, String name, long value); + + /** + * Called when a statistics request times out. Never called + * for watchers. + */ public void onTimeout(); + + /** + * Called when all values for the request have been received. + * Never called for watchers. + */ public void onDone(); } diff --git a/src/main/java/org/gnunet/statistics/StatisticsWatcher.java b/src/main/java/org/gnunet/statistics/StatisticsWatcher.java index 11328b7..5fdd6bc 100644 --- a/src/main/java/org/gnunet/statistics/StatisticsWatcher.java +++ b/src/main/java/org/gnunet/statistics/StatisticsWatcher.java @@ -1,5 +1,15 @@ package org.gnunet.statistics; +/** + * Listener for statistics changes. + */ public interface StatisticsWatcher { + /** + * Called when receiving a change notification for a statistics value. + * + * @param subsystem subsystem of the value that changed + * @param name name of the value that changed + * @param value new value + */ public void onReceive(String subsystem, String name, long value); } diff --git a/src/main/java/org/gnunet/testbed/ControllerStatusCallback.java b/src/main/java/org/gnunet/testbed/ControllerStatusCallback.java index ba9e56f..2d4930c 100644 --- a/src/main/java/org/gnunet/testbed/ControllerStatusCallback.java +++ b/src/main/java/org/gnunet/testbed/ControllerStatusCallback.java @@ -3,7 +3,19 @@ package org.gnunet.testbed; import org.gnunet.util.Configuration; +/** + * Listener for controller status changes. + */ public interface ControllerStatusCallback { + /** + * Called on successful startup. + * + * @param cfg configuration + */ void onStartupSuccess(Configuration cfg); + + /** + * Called on failed startup. + */ void onStartupFailure(); } diff --git a/src/main/java/org/gnunet/testbed/HostRegistrationCompletion.java b/src/main/java/org/gnunet/testbed/HostRegistrationCompletion.java index 72196ca..e0f46fe 100644 --- a/src/main/java/org/gnunet/testbed/HostRegistrationCompletion.java +++ b/src/main/java/org/gnunet/testbed/HostRegistrationCompletion.java @@ -1,4 +1,7 @@ package org.gnunet.testbed; -public class HostRegistrationCompletion { +/** + * (not yet implemented) + */ +public interface HostRegistrationCompletion { } diff --git a/src/main/java/org/gnunet/testbed/OperationCompletionCallback.java b/src/main/java/org/gnunet/testbed/OperationCompletionCallback.java index cc1cfa1..b1e974b 100644 --- a/src/main/java/org/gnunet/testbed/OperationCompletionCallback.java +++ b/src/main/java/org/gnunet/testbed/OperationCompletionCallback.java @@ -1,7 +1,19 @@ package org.gnunet.testbed; +/** + * Called on completed operation or error. + */ public interface OperationCompletionCallback { + /** + * Called on completed operation. + */ void onCompletion(); + + /** + * Called on error. + * + * @param emsg error message + */ void onError(String emsg); } diff --git a/src/main/java/org/gnunet/util/Connection.java b/src/main/java/org/gnunet/util/Connection.java index d735b27..3f87180 100644 --- a/src/main/java/org/gnunet/util/Connection.java +++ b/src/main/java/org/gnunet/util/Connection.java @@ -592,7 +592,7 @@ public class Connection { * * @param timeout timeout * @param cont continuation to call - * @return + * @return a handle to cancel the notification */ Cancelable notifyConnected(RelativeTime timeout, final Continuation cont) { if (notifyConnectedTimeout != null) { diff --git a/src/main/java/org/gnunet/util/crypto/EcdsaSignature.java b/src/main/java/org/gnunet/util/crypto/EcdsaSignature.java index 9e01a6f..28dfb3e 100644 --- a/src/main/java/org/gnunet/util/crypto/EcdsaSignature.java +++ b/src/main/java/org/gnunet/util/crypto/EcdsaSignature.java @@ -80,9 +80,16 @@ public class EcdsaSignature implements Message { HashCode h = HashCode.hash(m); BigInteger z = new BigInteger(1, h.data); BigInteger sCoeff = Ed25519.decodeScalar(s); + + if (sCoeff.equals(BigInteger.ZERO) || sCoeff.compareTo(Ed25519.l) >= 0) { + return false; + } + BigInteger rCoeff = Ed25519.decodeScalar(r); + if (rCoeff.equals(BigInteger.ZERO) || rCoeff.compareTo(Ed25519.l) >= 0) { + return false; + } - // FIXME: check range of s and r BigInteger w = sCoeff.modInverse(Ed25519.l); BigInteger u1 = z.multiply(w).mod(Ed25519.l); BigInteger u2 = rCoeff.multiply(w).mod(Ed25519.l); diff --git a/src/main/java/org/gnunet/util/crypto/EddsaSignature.java b/src/main/java/org/gnunet/util/crypto/EddsaSignature.java index ff78908..c9be7e5 100644 --- a/src/main/java/org/gnunet/util/crypto/EddsaSignature.java +++ b/src/main/java/org/gnunet/util/crypto/EddsaSignature.java @@ -61,9 +61,9 @@ public class EddsaSignature implements Message { /** * Verify the signature on a message with given purpose. * - * @param m - * @param publicKey - * @return + * @param m the message signed by this signature + * @param publicKey public key of the signer + * @return true if the signature is valid, false otherwise */ public boolean verifyRaw(byte[] m, EddsaPublicKey publicKey) { Ed25519 R = Ed25519.decode(r); diff --git a/src/main/java/org/gnunet/util/crypto/package-info.java b/src/main/java/org/gnunet/util/crypto/package-info.java index 9e79056..8262249 100644 --- a/src/main/java/org/gnunet/util/crypto/package-info.java +++ b/src/main/java/org/gnunet/util/crypto/package-info.java @@ -20,6 +20,6 @@ /** - * Cryptographic primitives for. + * Cryptographic primitives. */ package org.gnunet.util.crypto; diff --git a/src/main/java/org/gnunet/voting/BallotTool.java b/src/main/java/org/gnunet/voting/BallotTool.java index f5b4009..05b8e5a 100644 --- a/src/main/java/org/gnunet/voting/BallotTool.java +++ b/src/main/java/org/gnunet/voting/BallotTool.java @@ -28,7 +28,7 @@ import org.gnunet.identity.Identity; import org.gnunet.identity.IdentityCallback; import org.gnunet.mesh.Mesh; import org.gnunet.mesh.MeshRunabout; -import org.gnunet.mesh.TunnelEndHandler; +import org.gnunet.mesh.ChannelEndHandler; import org.gnunet.secretsharing.ThresholdPublicKey; import org.gnunet.testbed.CompressedConfig; import org.gnunet.util.*; @@ -161,7 +161,7 @@ public class BallotTool extends Program { private RelativeTime tunnelReconnectBackoff = RelativeTime.STD_BACKOFF; - public class BallotTunnelEndHandler implements TunnelEndHandler { + public class BallotChannelEndHandler implements ChannelEndHandler { @Override public void onChannelEnd(final Mesh.Channel channel) { // FIXME: just re-running 'doCommands' is a bit of a hack @@ -320,8 +320,8 @@ public class BallotTool extends Program { Random r = new Random(); currentAuthority = remainingAuthorities.get(r.nextInt(remainingAuthorities.size())); System.out.println("registering ballot with authority " + currentAuthority.toString()); - mesh = new Mesh(getConfiguration(), new BallotTunnelEndHandler(), new BallotRegisterReceiver()); - channel = mesh.createTunnel(currentAuthority, TallyAuthorityDaemon.MESH_PORT, true, true); + mesh = new Mesh(getConfiguration(), new BallotChannelEndHandler(), new BallotRegisterReceiver()); + channel = mesh.createChannel(currentAuthority, TallyAuthorityDaemon.MESH_PORT, true, true); BallotRegisterRequestMessage m = new BallotRegisterRequestMessage(); CompressedConfig ccfg = new CompressedConfig(ballot.toConfiguration()); m.compressedBallotConfig = ccfg.compressedData; @@ -365,8 +365,8 @@ public class BallotTool extends Program { PeerIdentity authority = remainingAuthorities.get(r.nextInt(remainingAuthorities.size())); System.out.println("submitting to authority " + authority.toString()); currentAuthority = authority; - mesh = new Mesh(cfg, new BallotTunnelEndHandler(), new SubmitReceiver()); - channel = mesh.createTunnel(authority, TallyAuthorityDaemon.MESH_PORT, true, true, null); + mesh = new Mesh(cfg, new BallotChannelEndHandler(), new SubmitReceiver()); + channel = mesh.createChannel(authority, TallyAuthorityDaemon.MESH_PORT, true, true); SubmitMessage m = new SubmitMessage(); if (ballot.voterPub == null) { throw new InvalidBallotException("no voter in ballot"); @@ -399,8 +399,8 @@ public class BallotTool extends Program { Random r = new Random(); currentAuthority = remainingAuthorities.get(r.nextInt(remainingAuthorities.size())); System.out.println("querying authority " + currentAuthority.toString()); - mesh = new Mesh(cfg, new BallotTunnelEndHandler(), new QueryReceiver()); - channel = mesh.createTunnel(currentAuthority, TallyAuthorityDaemon.MESH_PORT, true, true, null); + mesh = new Mesh(cfg, new BallotChannelEndHandler(), new QueryReceiver()); + channel = mesh.createChannel(currentAuthority, TallyAuthorityDaemon.MESH_PORT, true, true); ResultQueryMessage m = new ResultQueryMessage(); m.ballotGuid = ballot.getBallotGuid(); channel.send(m); @@ -415,8 +415,8 @@ public class BallotTool extends Program { Random r = new Random(); currentAuthority = remainingAuthorities.get(r.nextInt(remainingAuthorities.size())); System.out.println("asking authority for key " + currentAuthority.toString()); - mesh = new Mesh(cfg, new BallotTunnelEndHandler(), new PublicKeyReceiver()); - channel = mesh.createTunnel(currentAuthority, TallyAuthorityDaemon.MESH_PORT, true, true, null); + mesh = new Mesh(cfg, new BallotChannelEndHandler(), new PublicKeyReceiver()); + channel = mesh.createChannel(currentAuthority, TallyAuthorityDaemon.MESH_PORT, true, true); KeyQueryMessage m = new KeyQueryMessage(); m.ballotGuid = ballot.getBallotGuid(); channel.send(m); diff --git a/src/main/java/org/gnunet/voting/TallyAuthorityDaemon.java b/src/main/java/org/gnunet/voting/TallyAuthorityDaemon.java index 1d4a42d..af96871 100644 --- a/src/main/java/org/gnunet/voting/TallyAuthorityDaemon.java +++ b/src/main/java/org/gnunet/voting/TallyAuthorityDaemon.java @@ -27,7 +27,7 @@ import org.gnunet.consensus.ConsensusElement; import org.gnunet.construct.Construct; import org.gnunet.mesh.Mesh; import org.gnunet.mesh.MeshRunabout; -import org.gnunet.mesh.TunnelEndHandler; +import org.gnunet.mesh.ChannelEndHandler; import org.gnunet.secretsharing.*; import org.gnunet.testbed.CompressedConfig; import org.gnunet.util.*; @@ -391,7 +391,7 @@ public class TallyAuthorityDaemon extends Program { @Override public void run() { logger.info("running tally daemon"); - mesh = new Mesh(getConfiguration(), null, new TunnelEndHandler() { + mesh = new Mesh(getConfiguration(), null, new ChannelEndHandler() { @Override public void onChannelEnd(Mesh.Channel channel) { logger.warn("on channel end"); diff --git a/src/test/java/org/gnunet/construct/SendMessageTest.java b/src/test/java/org/gnunet/construct/SendMessageTest.java index b95cc78..e83df02 100644 --- a/src/test/java/org/gnunet/construct/SendMessageTest.java +++ b/src/test/java/org/gnunet/construct/SendMessageTest.java @@ -1,6 +1,6 @@ package org.gnunet.construct; -import org.gnunet.core.SendMessage; +import org.gnunet.core.messages.SendMessage; import org.gnunet.util.AbsoluteTime; import org.gnunet.util.GnunetMessage; import org.gnunet.util.PeerIdentity; diff --git a/src/test/java/org/gnunet/mesh/MeshTest.java b/src/test/java/org/gnunet/mesh/MeshTest.java index d840b88..9287148 100644 --- a/src/test/java/org/gnunet/mesh/MeshTest.java +++ b/src/test/java/org/gnunet/mesh/MeshTest.java @@ -23,12 +23,12 @@ public class MeshTest extends TestingFixture { } } - public static class MyTunnelEndHandler implements TunnelEndHandler { + public static class MyChannelEndHandler implements ChannelEndHandler { Mesh mesh1; PeerIdentity peerIdentity; @Override public void onChannelEnd(Mesh.Channel channel) { - Mesh.Channel myChannel = mesh1.createTunnel(peerIdentity, 42, false, true, null); + Mesh.Channel myChannel = mesh1.createChannel(peerIdentity, 42, false, true, null); myChannel.send(new TestMessage()); } } @@ -50,7 +50,7 @@ public class MeshTest extends TestingFixture { public void cont(PeerIdentity peerIdentity) { System.out.println("got peer identity from core"); // - MyTunnelEndHandler teh = new MyTunnelEndHandler(); + MyChannelEndHandler teh = new MyChannelEndHandler(); // first mesh handle, used to send the message final Mesh mesh1 = new Mesh(cfg, teh); teh.mesh1 = mesh1; @@ -61,7 +61,7 @@ public class MeshTest extends TestingFixture { public void onInboundTunnel(Mesh.Channel tunnel, PeerIdentity initiator) { System.out.println("got inbound channel " + initiator); } - }, new TunnelEndHandler() { + }, new ChannelEndHandler() { @Override public void onChannelEnd(Mesh.Channel tunnel) { System.out.println("channel end handler called"); @@ -69,7 +69,7 @@ public class MeshTest extends TestingFixture { }, mh, 42); mh.m1 = mesh1; mh.m2 = mesh2; - Mesh.Channel channel = mesh1.createTunnel(peerIdentity, 42, false, true, null); + Mesh.Channel channel = mesh1.createChannel(peerIdentity, 42, false, true, null); channel.send(new TestMessage()); } }); diff --git a/src/test/java/org/gnunet/secretsharing/SecretsharingTest.java b/src/test/java/org/gnunet/secretsharing/SecretsharingTest.java index 696f0a5..c9c611c 100644 --- a/src/test/java/org/gnunet/secretsharing/SecretsharingTest.java +++ b/src/test/java/org/gnunet/secretsharing/SecretsharingTest.java @@ -20,16 +20,15 @@ package org.gnunet.secretsharing; - import org.gnunet.testing.TestingSubsystem; import org.gnunet.util.*; import org.junit.Assert; import org.junit.Test; +import org.junit.experimental.categories.Category; import java.math.BigInteger; public class SecretsharingTest { - @Test public void test_secretsharing_single_generate() { Program.configureLogging("debug"); -- cgit v1.2.3