diff options
author | Florian Dold <florian.dold@gmail.com> | 2014-03-11 01:24:03 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2014-03-11 01:24:03 +0000 |
commit | e2eecb019105d48e4afebe1bf57355b3450c8219 (patch) | |
tree | 74d8aee60cc6d336a3bb0445af8e091cc2351ecd /src/main/java/org | |
parent | 651cfb94264b0d12e8ed9afafab05f84d2201933 (diff) | |
download | gnunet-java-e2eecb019105d48e4afebe1bf57355b3450c8219.tar.gz gnunet-java-e2eecb019105d48e4afebe1bf57355b3450c8219.zip |
- simplify request containers
- statistics bugs
- fix missing annotation in consensus api
- work on voting
Diffstat (limited to 'src/main/java/org')
93 files changed, 703 insertions, 646 deletions
diff --git a/src/main/java/org/gnunet/arm/Arm.java b/src/main/java/org/gnunet/arm/Arm.java index 503413f..aee353b 100644 --- a/src/main/java/org/gnunet/arm/Arm.java +++ b/src/main/java/org/gnunet/arm/Arm.java | |||
@@ -53,7 +53,7 @@ public class Arm { | |||
53 | * further connection attempts. | 53 | * further connection attempts. |
54 | * | 54 | * |
55 | * @param serviceName name of the service | 55 | * @param serviceName name of the service |
56 | * @param resultHandler called with the result of the request | 56 | * @param resultHandler called with the result of the getRequestIdentifier |
57 | */ | 57 | */ |
58 | public void requestServiceStop(String serviceName, ResultHandler resultHandler) { | 58 | public void requestServiceStop(String serviceName, ResultHandler resultHandler) { |
59 | 59 | ||
diff --git a/src/main/java/org/gnunet/consensus/Consensus.java b/src/main/java/org/gnunet/consensus/Consensus.java index 9e58fac..ee3ec2a 100644 --- a/src/main/java/org/gnunet/consensus/Consensus.java +++ b/src/main/java/org/gnunet/consensus/Consensus.java | |||
@@ -89,7 +89,11 @@ public class Consensus { | |||
89 | AbsoluteTime startTime, AbsoluteTime deadline) { | 89 | AbsoluteTime startTime, AbsoluteTime deadline) { |
90 | client = new Client("consensus", cfg); | 90 | client = new Client("consensus", cfg); |
91 | client.installReceiver(new ConsensusMessageReceiver()); | 91 | client.installReceiver(new ConsensusMessageReceiver()); |
92 | String peersString = ""; | ||
93 | for (PeerIdentity pi : peers) | ||
94 | peersString += pi + ", "; | ||
92 | 95 | ||
96 | logger.info("starting consensus with {} peers given to consensus ({})", peers.length, peersString); | ||
93 | JoinMessage m = new JoinMessage(); | 97 | JoinMessage m = new JoinMessage(); |
94 | m.numPeers = peers.length; | 98 | m.numPeers = peers.length; |
95 | m.peers = peers; | 99 | m.peers = peers; |
diff --git a/src/main/java/org/gnunet/consensus/messages/ConcludeDoneMessage.java b/src/main/java/org/gnunet/consensus/messages/ConcludeDoneMessage.java index 9064e4b..62a2d9f 100644 --- a/src/main/java/org/gnunet/consensus/messages/ConcludeDoneMessage.java +++ b/src/main/java/org/gnunet/consensus/messages/ConcludeDoneMessage.java | |||
@@ -21,7 +21,6 @@ | |||
21 | package org.gnunet.consensus.messages; | 21 | package org.gnunet.consensus.messages; |
22 | 22 | ||
23 | 23 | ||
24 | import org.gnunet.construct.MessageUnion; | ||
25 | import org.gnunet.construct.UnionCase; | 24 | import org.gnunet.construct.UnionCase; |
26 | import org.gnunet.util.GnunetMessage; | 25 | import org.gnunet.util.GnunetMessage; |
27 | 26 | ||
diff --git a/src/main/java/org/gnunet/consensus/messages/ConcludeMessage.java b/src/main/java/org/gnunet/consensus/messages/ConcludeMessage.java index fb1c396..882d590 100644 --- a/src/main/java/org/gnunet/consensus/messages/ConcludeMessage.java +++ b/src/main/java/org/gnunet/consensus/messages/ConcludeMessage.java | |||
@@ -20,8 +20,8 @@ | |||
20 | 20 | ||
21 | package org.gnunet.consensus.messages; | 21 | package org.gnunet.consensus.messages; |
22 | 22 | ||
23 | import org.gnunet.construct.*; | 23 | import org.gnunet.construct.UnionCase; |
24 | import org.gnunet.util.*; | 24 | import org.gnunet.util.GnunetMessage; |
25 | 25 | ||
26 | /** | 26 | /** |
27 | * Notify the client of a new element. | 27 | * Notify the client of a new element. |
diff --git a/src/main/java/org/gnunet/consensus/messages/JoinMessage.java b/src/main/java/org/gnunet/consensus/messages/JoinMessage.java index 2529e0e..ab1a56b 100644 --- a/src/main/java/org/gnunet/consensus/messages/JoinMessage.java +++ b/src/main/java/org/gnunet/consensus/messages/JoinMessage.java | |||
@@ -37,6 +37,7 @@ public class JoinMessage implements GnunetMessage.Body { | |||
37 | public HashCode sessionId; | 37 | public HashCode sessionId; |
38 | @NestedMessage | 38 | @NestedMessage |
39 | public AbsoluteTimeMessage startTime; | 39 | public AbsoluteTimeMessage startTime; |
40 | @NestedMessage | ||
40 | public AbsoluteTimeMessage deadline; | 41 | public AbsoluteTimeMessage deadline; |
41 | @VariableSizeArray(lengthField = "numPeers") | 42 | @VariableSizeArray(lengthField = "numPeers") |
42 | public PeerIdentity[] peers; | 43 | public PeerIdentity[] peers; |
diff --git a/src/main/java/org/gnunet/consensus/messages/NewElementMessage.java b/src/main/java/org/gnunet/consensus/messages/NewElementMessage.java index 815c70a..4fc2413 100644 --- a/src/main/java/org/gnunet/consensus/messages/NewElementMessage.java +++ b/src/main/java/org/gnunet/consensus/messages/NewElementMessage.java | |||
@@ -20,7 +20,10 @@ | |||
20 | 20 | ||
21 | package org.gnunet.consensus.messages; | 21 | package org.gnunet.consensus.messages; |
22 | 22 | ||
23 | import org.gnunet.construct.*; | 23 | import org.gnunet.construct.FillWith; |
24 | import org.gnunet.construct.UInt16; | ||
25 | import org.gnunet.construct.UInt8; | ||
26 | import org.gnunet.construct.UnionCase; | ||
24 | import org.gnunet.util.GnunetMessage; | 27 | import org.gnunet.util.GnunetMessage; |
25 | 28 | ||
26 | /** | 29 | /** |
diff --git a/src/main/java/org/gnunet/construct/FrameSize.java b/src/main/java/org/gnunet/construct/FrameSize.java index 0533d0b..252f182 100644 --- a/src/main/java/org/gnunet/construct/FrameSize.java +++ b/src/main/java/org/gnunet/construct/FrameSize.java | |||
@@ -20,7 +20,10 @@ | |||
20 | 20 | ||
21 | package org.gnunet.construct; | 21 | package org.gnunet.construct; |
22 | 22 | ||
23 | import java.lang.annotation.*; | 23 | import java.lang.annotation.ElementType; |
24 | import java.lang.annotation.Retention; | ||
25 | import java.lang.annotation.RetentionPolicy; | ||
26 | import java.lang.annotation.Target; | ||
24 | 27 | ||
25 | /** | 28 | /** |
26 | * Marker for the field storing the size of the enclosing frame in bytes. | 29 | * Marker for the field storing the size of the enclosing frame in bytes. |
diff --git a/src/main/java/org/gnunet/construct/MessageIdAnnotationProcessor.java b/src/main/java/org/gnunet/construct/MessageIdAnnotationProcessor.java index 88ed11d..9f2e4a9 100644 --- a/src/main/java/org/gnunet/construct/MessageIdAnnotationProcessor.java +++ b/src/main/java/org/gnunet/construct/MessageIdAnnotationProcessor.java | |||
@@ -35,10 +35,11 @@ import javax.tools.FileObject; | |||
35 | import javax.tools.StandardLocation; | 35 | import javax.tools.StandardLocation; |
36 | import java.io.IOException; | 36 | import java.io.IOException; |
37 | import java.io.Writer; | 37 | import java.io.Writer; |
38 | import java.lang.Integer; | ||
39 | import java.text.DateFormat; | 38 | import java.text.DateFormat; |
40 | import java.text.SimpleDateFormat; | 39 | import java.text.SimpleDateFormat; |
41 | import java.util.*; | 40 | import java.util.Date; |
41 | import java.util.List; | ||
42 | import java.util.Set; | ||
42 | 43 | ||
43 | 44 | ||
44 | /** | 45 | /** |
diff --git a/src/main/java/org/gnunet/construct/ProtocolViolationException.java b/src/main/java/org/gnunet/construct/ProtocolViolationException.java index 9de46d4..73e091a 100644 --- a/src/main/java/org/gnunet/construct/ProtocolViolationException.java +++ b/src/main/java/org/gnunet/construct/ProtocolViolationException.java | |||
@@ -21,8 +21,6 @@ | |||
21 | package org.gnunet.construct; | 21 | package org.gnunet.construct; |
22 | 22 | ||
23 | 23 | ||
24 | import java.util.LinkedList; | ||
25 | |||
26 | /** | 24 | /** |
27 | * Thrown when a received message is invalid. | 25 | * Thrown when a received message is invalid. |
28 | * | 26 | * |
diff --git a/src/main/java/org/gnunet/construct/ReflectUtil.java b/src/main/java/org/gnunet/construct/ReflectUtil.java index b05a829..67bb6c2 100644 --- a/src/main/java/org/gnunet/construct/ReflectUtil.java +++ b/src/main/java/org/gnunet/construct/ReflectUtil.java | |||
@@ -21,7 +21,6 @@ | |||
21 | package org.gnunet.construct; | 21 | package org.gnunet.construct; |
22 | 22 | ||
23 | 23 | ||
24 | import java.lang.Integer; | ||
25 | import java.lang.reflect.Array; | 24 | import java.lang.reflect.Array; |
26 | import java.lang.reflect.Field; | 25 | import java.lang.reflect.Field; |
27 | import java.lang.reflect.InvocationTargetException; | 26 | import java.lang.reflect.InvocationTargetException; |
diff --git a/src/main/java/org/gnunet/construct/parsers/FillParser.java b/src/main/java/org/gnunet/construct/parsers/FillParser.java index 19ce252..9f63a07 100644 --- a/src/main/java/org/gnunet/construct/parsers/FillParser.java +++ b/src/main/java/org/gnunet/construct/parsers/FillParser.java | |||
@@ -22,6 +22,7 @@ package org.gnunet.construct.parsers; | |||
22 | 22 | ||
23 | import org.gnunet.construct.Message; | 23 | import org.gnunet.construct.Message; |
24 | import org.gnunet.construct.ReflectUtil; | 24 | import org.gnunet.construct.ReflectUtil; |
25 | |||
25 | import java.lang.reflect.Array; | 26 | import java.lang.reflect.Array; |
26 | import java.lang.reflect.Field; | 27 | import java.lang.reflect.Field; |
27 | import java.nio.ByteBuffer; | 28 | import java.nio.ByteBuffer; |
diff --git a/src/main/java/org/gnunet/construct/parsers/UnionParser.java b/src/main/java/org/gnunet/construct/parsers/UnionParser.java index e9fcc92..2424800 100644 --- a/src/main/java/org/gnunet/construct/parsers/UnionParser.java +++ b/src/main/java/org/gnunet/construct/parsers/UnionParser.java | |||
@@ -21,7 +21,6 @@ | |||
21 | package org.gnunet.construct.parsers; | 21 | package org.gnunet.construct.parsers; |
22 | 22 | ||
23 | import org.gnunet.construct.*; | 23 | import org.gnunet.construct.*; |
24 | import org.gnunet.construct.ProtocolViolationException; | ||
25 | 24 | ||
26 | import java.lang.reflect.Field; | 25 | import java.lang.reflect.Field; |
27 | import java.nio.ByteBuffer; | 26 | import java.nio.ByteBuffer; |
diff --git a/src/main/java/org/gnunet/construct/parsers/VariableSizeArrayParser.java b/src/main/java/org/gnunet/construct/parsers/VariableSizeArrayParser.java index fd55925..cf00c83 100644 --- a/src/main/java/org/gnunet/construct/parsers/VariableSizeArrayParser.java +++ b/src/main/java/org/gnunet/construct/parsers/VariableSizeArrayParser.java | |||
@@ -21,7 +21,6 @@ | |||
21 | package org.gnunet.construct.parsers; | 21 | package org.gnunet.construct.parsers; |
22 | 22 | ||
23 | import org.gnunet.construct.Message; | 23 | import org.gnunet.construct.Message; |
24 | import org.gnunet.construct.ProtocolViolationException; | ||
25 | import org.gnunet.construct.ReflectUtil; | 24 | import org.gnunet.construct.ReflectUtil; |
26 | 25 | ||
27 | import java.lang.reflect.Array; | 26 | import java.lang.reflect.Array; |
diff --git a/src/main/java/org/gnunet/construct/parsers/VariableSizeStringParser.java b/src/main/java/org/gnunet/construct/parsers/VariableSizeStringParser.java index 39dd7a4..9686066 100644 --- a/src/main/java/org/gnunet/construct/parsers/VariableSizeStringParser.java +++ b/src/main/java/org/gnunet/construct/parsers/VariableSizeStringParser.java | |||
@@ -44,7 +44,6 @@ import org.gnunet.construct.Message; | |||
44 | import org.gnunet.construct.ReflectUtil; | 44 | import org.gnunet.construct.ReflectUtil; |
45 | import org.gnunet.construct.StringTerminationType; | 45 | import org.gnunet.construct.StringTerminationType; |
46 | 46 | ||
47 | import java.lang.reflect.Array; | ||
48 | import java.lang.reflect.Field; | 47 | import java.lang.reflect.Field; |
49 | import java.nio.ByteBuffer; | 48 | import java.nio.ByteBuffer; |
50 | import java.util.List; | 49 | import java.util.List; |
diff --git a/src/main/java/org/gnunet/core/Core.java b/src/main/java/org/gnunet/core/Core.java index f209269..307b9a2 100644 --- a/src/main/java/org/gnunet/core/Core.java +++ b/src/main/java/org/gnunet/core/Core.java | |||
@@ -25,7 +25,8 @@ import org.gnunet.construct.Construct; | |||
25 | import org.gnunet.construct.MessageLoader; | 25 | import org.gnunet.construct.MessageLoader; |
26 | import org.gnunet.mq.Envelope; | 26 | import org.gnunet.mq.Envelope; |
27 | import org.gnunet.requests.MatchingRequestContainer; | 27 | import org.gnunet.requests.MatchingRequestContainer; |
28 | import org.gnunet.requests.RequestContainer; | 28 | import org.gnunet.requests.Request; |
29 | import org.gnunet.requests.RequestIdentifier; | ||
29 | import org.gnunet.util.*; | 30 | import org.gnunet.util.*; |
30 | import org.grothoff.Runabout; | 31 | import org.grothoff.Runabout; |
31 | import org.slf4j.Logger; | 32 | import org.slf4j.Logger; |
@@ -99,7 +100,7 @@ public class Core { | |||
99 | 100 | ||
100 | /** | 101 | /** |
101 | * Peers that we were notified about being connected to them. | 102 | * Peers that we were notified about being connected to them. |
102 | * Every connected peer is mapped to a generator for unique request IDs. | 103 | * Every connected peer is mapped to a generator for unique getRequestIdentifier IDs. |
103 | */ | 104 | */ |
104 | private HashMap<PeerIdentity, Integer> connectedPeers = Maps.newHashMap(); | 105 | private HashMap<PeerIdentity, Integer> connectedPeers = Maps.newHashMap(); |
105 | 106 | ||
@@ -108,7 +109,7 @@ public class Core { | |||
108 | */ | 109 | */ |
109 | private MatchingRequestContainer<RequestIdentification, NotifyTransmitReadyRequest> ntrRequests; | 110 | private MatchingRequestContainer<RequestIdentification, NotifyTransmitReadyRequest> ntrRequests; |
110 | 111 | ||
111 | public static class NotifyTransmitReadyRequest extends RequestContainer.Request { | 112 | public static class NotifyTransmitReadyRequest extends Request { |
112 | private final int size; | 113 | private final int size; |
113 | final public PeerIdentity target; | 114 | final public PeerIdentity target; |
114 | final public long priority; | 115 | final public long priority; |
@@ -136,7 +137,7 @@ public class Core { | |||
136 | return new Envelope(m); | 137 | return new Envelope(m); |
137 | } | 138 | } |
138 | 139 | ||
139 | public void cancel() { | 140 | public void onCancel() { |
140 | // do nothing | 141 | // do nothing |
141 | } | 142 | } |
142 | } | 143 | } |
@@ -200,7 +201,8 @@ public class Core { | |||
200 | public void visit(SendMessageReady m) { | 201 | public void visit(SendMessageReady m) { |
201 | logger.debug("got SendMessageReady"); | 202 | logger.debug("got SendMessageReady"); |
202 | RequestIdentification rid = new RequestIdentification(m.smrId, m.peer); | 203 | RequestIdentification rid = new RequestIdentification(m.smrId, m.peer); |
203 | NotifyTransmitReadyRequest req = ntrRequests.getRequest(rid); | 204 | RequestIdentifier<NotifyTransmitReadyRequest> reqId = ntrRequests.getRequestIdentifier(rid); |
205 | NotifyTransmitReadyRequest req = reqId.getRequest(); | ||
204 | 206 | ||
205 | final SendMessage sm = new SendMessage(); | 207 | final SendMessage sm = new SendMessage(); |
206 | sm.cork = 0; | 208 | sm.cork = 0; |
@@ -279,7 +281,7 @@ public class Core { | |||
279 | * @param target the identity of the receiver | 281 | * @param target the identity of the receiver |
280 | * @param size the size of the message we want to transmit | 282 | * @param size the size of the message we want to transmit |
281 | * @param transmitter called once the core service is ready to send message | 283 | * @param transmitter called once the core service is ready to send message |
282 | * @return a handle to cancel the notification | 284 | * @return a handle to onCancel the notification |
283 | */ | 285 | */ |
284 | public Cancelable notifyTransmitReady(int priority, RelativeTime maxdelay, | 286 | public Cancelable notifyTransmitReady(int priority, RelativeTime maxdelay, |
285 | PeerIdentity target, int size, final MessageTransmitter transmitter) { | 287 | PeerIdentity target, int size, final MessageTransmitter transmitter) { |
diff --git a/src/main/java/org/gnunet/core/NotifyInboundTrafficMessage.java b/src/main/java/org/gnunet/core/NotifyInboundTrafficMessage.java index 2bdd428..b00bd49 100644 --- a/src/main/java/org/gnunet/core/NotifyInboundTrafficMessage.java +++ b/src/main/java/org/gnunet/core/NotifyInboundTrafficMessage.java | |||
@@ -20,8 +20,10 @@ | |||
20 | 20 | ||
21 | package org.gnunet.core; | 21 | package org.gnunet.core; |
22 | 22 | ||
23 | import org.gnunet.construct.*; | 23 | import org.gnunet.construct.FillWith; |
24 | import org.gnunet.util.ATSInformation; | 24 | import org.gnunet.construct.NestedMessage; |
25 | import org.gnunet.construct.UInt8; | ||
26 | import org.gnunet.construct.UnionCase; | ||
25 | import org.gnunet.util.GnunetMessage; | 27 | import org.gnunet.util.GnunetMessage; |
26 | import org.gnunet.util.PeerIdentity; | 28 | import org.gnunet.util.PeerIdentity; |
27 | 29 | ||
diff --git a/src/main/java/org/gnunet/core/RequestIdentification.java b/src/main/java/org/gnunet/core/RequestIdentification.java index 4f6a734..2823153 100644 --- a/src/main/java/org/gnunet/core/RequestIdentification.java +++ b/src/main/java/org/gnunet/core/RequestIdentification.java | |||
@@ -1,6 +1,5 @@ | |||
1 | package org.gnunet.core; | 1 | package org.gnunet.core; |
2 | 2 | ||
3 | import org.gnunet.peerinfo.PeerInfo; | ||
4 | import org.gnunet.util.PeerIdentity; | 3 | import org.gnunet.util.PeerIdentity; |
5 | 4 | ||
6 | 5 | ||
diff --git a/src/main/java/org/gnunet/core/SendMessage.java b/src/main/java/org/gnunet/core/SendMessage.java index a0083ec..c3306ae 100644 --- a/src/main/java/org/gnunet/core/SendMessage.java +++ b/src/main/java/org/gnunet/core/SendMessage.java | |||
@@ -22,7 +22,6 @@ package org.gnunet.core; | |||
22 | 22 | ||
23 | import org.gnunet.construct.NestedMessage; | 23 | import org.gnunet.construct.NestedMessage; |
24 | import org.gnunet.construct.UInt32; | 24 | import org.gnunet.construct.UInt32; |
25 | import org.gnunet.construct.UInt64; | ||
26 | import org.gnunet.construct.UnionCase; | 25 | import org.gnunet.construct.UnionCase; |
27 | import org.gnunet.util.AbsoluteTimeMessage; | 26 | import org.gnunet.util.AbsoluteTimeMessage; |
28 | import org.gnunet.util.GnunetMessage; | 27 | import org.gnunet.util.GnunetMessage; |
diff --git a/src/main/java/org/gnunet/core/SendMessageReady.java b/src/main/java/org/gnunet/core/SendMessageReady.java index aa5bf44..ba28da8 100644 --- a/src/main/java/org/gnunet/core/SendMessageReady.java +++ b/src/main/java/org/gnunet/core/SendMessageReady.java | |||
@@ -36,14 +36,14 @@ public class SendMessageReady implements GnunetMessage.Body { | |||
36 | /** | 36 | /** |
37 | * How many bytes are allowed for transmission? | 37 | * How many bytes are allowed for transmission? |
38 | * Guaranteed to be at least as big as the requested size, | 38 | * Guaranteed to be at least as big as the requested size, |
39 | * or ZERO if the request is rejected (will timeout, | 39 | * or ZERO if the getRequestIdentifier is rejected (will timeout, |
40 | * peer disconnected, queue full, etc.). | 40 | * peer disconnected, queue full, etc.). |
41 | */ | 41 | */ |
42 | @UInt16 | 42 | @UInt16 |
43 | public int size; | 43 | public int size; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * smrId from the request. | 46 | * smrId from the getRequestIdentifier. |
47 | */ | 47 | */ |
48 | @UInt16 | 48 | @UInt16 |
49 | public int smrId; | 49 | public int smrId; |
diff --git a/src/main/java/org/gnunet/dht/ClientPutConfirmationMessage.java b/src/main/java/org/gnunet/dht/ClientPutConfirmationMessage.java index 45bbe60..abf6051 100644 --- a/src/main/java/org/gnunet/dht/ClientPutConfirmationMessage.java +++ b/src/main/java/org/gnunet/dht/ClientPutConfirmationMessage.java | |||
@@ -31,7 +31,7 @@ public class ClientPutConfirmationMessage implements GnunetMessage.Body { | |||
31 | @UInt32 | 31 | @UInt32 |
32 | public int reserved; | 32 | public int reserved; |
33 | /** | 33 | /** |
34 | * UID used to identify request with the response | 34 | * UID used to identify getRequestIdentifier with the response |
35 | */ | 35 | */ |
36 | @UInt64 | 36 | @UInt64 |
37 | public long uid; | 37 | public long uid; |
diff --git a/src/main/java/org/gnunet/dht/ClientPutMessage.java b/src/main/java/org/gnunet/dht/ClientPutMessage.java index 4b63e92..1d01be4 100644 --- a/src/main/java/org/gnunet/dht/ClientPutMessage.java +++ b/src/main/java/org/gnunet/dht/ClientPutMessage.java | |||
@@ -41,7 +41,7 @@ public class ClientPutMessage implements GnunetMessage.Body { | |||
41 | @UInt32 | 41 | @UInt32 |
42 | public int desiredReplicationLevel; | 42 | public int desiredReplicationLevel; |
43 | /** | 43 | /** |
44 | * UID used to identify request with the response | 44 | * UID used to identify getRequestIdentifier with the response |
45 | */ | 45 | */ |
46 | @UInt64 | 46 | @UInt64 |
47 | public long uid; | 47 | public long uid; |
diff --git a/src/main/java/org/gnunet/dht/DistributedHashTable.java b/src/main/java/org/gnunet/dht/DistributedHashTable.java index 10ac00e..0246992 100644 --- a/src/main/java/org/gnunet/dht/DistributedHashTable.java +++ b/src/main/java/org/gnunet/dht/DistributedHashTable.java | |||
@@ -23,7 +23,8 @@ package org.gnunet.dht; | |||
23 | import com.google.common.base.Charsets; | 23 | import com.google.common.base.Charsets; |
24 | import org.gnunet.mq.Envelope; | 24 | import org.gnunet.mq.Envelope; |
25 | import org.gnunet.requests.MatchingRequestContainer; | 25 | import org.gnunet.requests.MatchingRequestContainer; |
26 | import org.gnunet.requests.RequestContainer; | 26 | import org.gnunet.requests.Request; |
27 | import org.gnunet.requests.RequestIdentifier; | ||
27 | import org.gnunet.requests.SequentialRequestContainer; | 28 | import org.gnunet.requests.SequentialRequestContainer; |
28 | import org.gnunet.util.*; | 29 | import org.gnunet.util.*; |
29 | import org.gnunet.util.getopt.Argument; | 30 | import org.gnunet.util.getopt.Argument; |
@@ -31,7 +32,9 @@ import org.gnunet.util.getopt.ArgumentAction; | |||
31 | import org.slf4j.Logger; | 32 | import org.slf4j.Logger; |
32 | import org.slf4j.LoggerFactory; | 33 | import org.slf4j.LoggerFactory; |
33 | 34 | ||
34 | import java.util.*; | 35 | import java.util.EnumSet; |
36 | import java.util.List; | ||
37 | import java.util.Set; | ||
35 | 38 | ||
36 | /** | 39 | /** |
37 | * API for the gnunet dht service. | 40 | * API for the gnunet dht service. |
@@ -54,7 +57,7 @@ public class DistributedHashTable { | |||
54 | private MatchingRequestContainer<Long, GetRequest> getRequests; | 57 | private MatchingRequestContainer<Long, GetRequest> getRequests; |
55 | private SequentialRequestContainer<MonitorRequest> monitorRequests; | 58 | private SequentialRequestContainer<MonitorRequest> monitorRequests; |
56 | 59 | ||
57 | private class PutRequest extends RequestContainer.Request { | 60 | private class PutRequest extends Request { |
58 | public byte[] data; | 61 | public byte[] data; |
59 | public HashCode key; | 62 | public HashCode key; |
60 | public int replicationLevel; | 63 | public int replicationLevel; |
@@ -79,12 +82,12 @@ public class DistributedHashTable { | |||
79 | return new Envelope(cpm); | 82 | return new Envelope(cpm); |
80 | } | 83 | } |
81 | 84 | ||
82 | public void cancel() { | 85 | public void onCancel() { |
83 | } | 86 | } |
84 | } | 87 | } |
85 | 88 | ||
86 | 89 | ||
87 | private class GetRequest extends RequestContainer.Request { | 90 | private class GetRequest extends Request { |
88 | public long uid; | 91 | public long uid; |
89 | public HashCode key; | 92 | public HashCode key; |
90 | public ResultCallback cb; | 93 | public ResultCallback cb; |
@@ -106,12 +109,12 @@ public class DistributedHashTable { | |||
106 | gm.uniqueId = uid; | 109 | gm.uniqueId = uid; |
107 | return new Envelope(gm); | 110 | return new Envelope(gm); |
108 | } | 111 | } |
109 | public void cancel() { | 112 | public void onCancel() { |
110 | 113 | ||
111 | } | 114 | } |
112 | } | 115 | } |
113 | 116 | ||
114 | private class MonitorRequest extends RequestContainer.Request { | 117 | private class MonitorRequest extends Request { |
115 | public int blockType; | 118 | public int blockType; |
116 | public HashCode key; | 119 | public HashCode key; |
117 | public MonitorGetHandler getHandler; | 120 | public MonitorGetHandler getHandler; |
@@ -140,7 +143,7 @@ public class DistributedHashTable { | |||
140 | return new Envelope(mss); | 143 | return new Envelope(mss); |
141 | } | 144 | } |
142 | 145 | ||
143 | public void cancel() { | 146 | public void onCancel() { |
144 | // todo: use priority requests | 147 | // todo: use priority requests |
145 | MonitorRequest cancelRequest = new MonitorRequest(); | 148 | MonitorRequest cancelRequest = new MonitorRequest(); |
146 | cancelRequest.getHandler = null; | 149 | cancelRequest.getHandler = null; |
@@ -154,9 +157,9 @@ public class DistributedHashTable { | |||
154 | 157 | ||
155 | private class DHTMessageReceiver extends RunaboutMessageReceiver { | 158 | private class DHTMessageReceiver extends RunaboutMessageReceiver { |
156 | public void visit(ClientPutConfirmationMessage pcm) { | 159 | public void visit(ClientPutConfirmationMessage pcm) { |
157 | PutRequest thePutRequest = putRequests.getRequest(pcm.uid); | 160 | PutRequest thePutRequest = putRequests.getAndRetireRequest(pcm.uid); |
158 | if (thePutRequest == null) { | 161 | if (thePutRequest == null) { |
159 | logger.warn("request UID not found"); | 162 | logger.warn("getRequestIdentifier UID not found"); |
160 | return; | 163 | return; |
161 | } | 164 | } |
162 | if (thePutRequest.cont != null) { | 165 | if (thePutRequest.cont != null) { |
@@ -165,9 +168,9 @@ public class DistributedHashTable { | |||
165 | } | 168 | } |
166 | 169 | ||
167 | public void visit(ClientResultMessage rm) { | 170 | public void visit(ClientResultMessage rm) { |
168 | GetRequest theGetRequest = getRequests.getRequest(rm.uid); | 171 | GetRequest theGetRequest = getRequests.getAndRetireRequest(rm.uid); |
169 | if (theGetRequest == null) { | 172 | if (theGetRequest == null) { |
170 | logger.warn("request UID not found"); | 173 | logger.warn("getRequestIdentifier UID not found"); |
171 | return; | 174 | return; |
172 | } | 175 | } |
173 | theGetRequest.cb.handleResult(AbsoluteTime.fromNetwork(rm.expiration), rm.key, null, null, | 176 | theGetRequest.cb.handleResult(AbsoluteTime.fromNetwork(rm.expiration), rm.key, null, null, |
@@ -176,14 +179,14 @@ public class DistributedHashTable { | |||
176 | } | 179 | } |
177 | 180 | ||
178 | public void visit(MonitorGetMessage monitorGetMessage) { | 181 | public void visit(MonitorGetMessage monitorGetMessage) { |
179 | for (MonitorRequest monitorRequest : monitorRequests.iter()) { | 182 | for (RequestIdentifier<MonitorRequest> monitorRequest : monitorRequests.iter()) { |
180 | boolean typeOk = (monitorGetMessage.type == BlockType.ANY.val) | 183 | boolean typeOk = (monitorGetMessage.type == BlockType.ANY.val) |
181 | || (monitorGetMessage.type == monitorRequest.blockType); | 184 | || (monitorGetMessage.type == monitorRequest.getRequest().blockType); |
182 | boolean keyOk = monitorGetMessage.key.isAllZero() | 185 | boolean keyOk = monitorGetMessage.key.isAllZero() |
183 | || monitorGetMessage.key.equals(monitorRequest.key); | 186 | || monitorGetMessage.key.equals(monitorRequest.getRequest().key); |
184 | 187 | ||
185 | if (keyOk && typeOk && monitorRequest.getHandler != null) { | 188 | if (keyOk && typeOk && monitorRequest.getRequest().getHandler != null) { |
186 | monitorRequest.getHandler.onGet(monitorGetMessage.options, monitorGetMessage.type, | 189 | monitorRequest.getRequest().getHandler.onGet(monitorGetMessage.options, monitorGetMessage.type, |
187 | monitorGetMessage.hopCount, monitorGetMessage.desiredReplicationLevel, monitorGetMessage.getPath, | 190 | monitorGetMessage.hopCount, monitorGetMessage.desiredReplicationLevel, monitorGetMessage.getPath, |
188 | monitorGetMessage.key); | 191 | monitorGetMessage.key); |
189 | } | 192 | } |
@@ -191,14 +194,14 @@ public class DistributedHashTable { | |||
191 | } | 194 | } |
192 | 195 | ||
193 | public void visit(MonitorGetRespMessage monitorGetRespMessage) { | 196 | public void visit(MonitorGetRespMessage monitorGetRespMessage) { |
194 | for (MonitorRequest monitorRequest : monitorRequests.iter()) { | 197 | for (RequestIdentifier<MonitorRequest> monitorRequest : monitorRequests.iter()) { |
195 | boolean typeOk = (monitorGetRespMessage.type == BlockType.ANY.val) | 198 | boolean typeOk = (monitorGetRespMessage.type == BlockType.ANY.val) |
196 | || (monitorGetRespMessage.type == monitorRequest.blockType); | 199 | || (monitorGetRespMessage.type == monitorRequest.getRequest().blockType); |
197 | boolean keyOk = monitorGetRespMessage.key.isAllZero() | 200 | boolean keyOk = monitorGetRespMessage.key.isAllZero() |
198 | || monitorGetRespMessage.key.equals(monitorRequest.key); | 201 | || monitorGetRespMessage.key.equals(monitorRequest.getRequest().key); |
199 | 202 | ||
200 | if (keyOk && typeOk && monitorRequest.getResponseHandler != null) { | 203 | if (keyOk && typeOk && monitorRequest.getRequest().getResponseHandler != null) { |
201 | monitorRequest.getResponseHandler.onGetResponse( | 204 | monitorRequest.getRequest().getResponseHandler.onGetResponse( |
202 | monitorGetRespMessage.type, | 205 | monitorGetRespMessage.type, |
203 | monitorGetRespMessage.getPath, | 206 | monitorGetRespMessage.getPath, |
204 | monitorGetRespMessage.putPath, | 207 | monitorGetRespMessage.putPath, |
@@ -211,14 +214,14 @@ public class DistributedHashTable { | |||
211 | } | 214 | } |
212 | 215 | ||
213 | public void visit(MonitorPutMessage monitorPutMessage) { | 216 | public void visit(MonitorPutMessage monitorPutMessage) { |
214 | for (MonitorRequest monitorRequest : monitorRequests.iter()) { | 217 | for (RequestIdentifier<MonitorRequest> monitorRequest : monitorRequests.iter()) { |
215 | boolean typeOk = (monitorPutMessage.type == BlockType.ANY.val) | 218 | boolean typeOk = (monitorPutMessage.type == BlockType.ANY.val) |
216 | || (monitorPutMessage.type == monitorRequest.blockType); | 219 | || (monitorPutMessage.type == monitorRequest.getRequest().blockType); |
217 | boolean keyOk = monitorPutMessage.key.isAllZero() | 220 | boolean keyOk = monitorPutMessage.key.isAllZero() |
218 | || monitorPutMessage.key.equals(monitorRequest.key); | 221 | || monitorPutMessage.key.equals(monitorRequest.getRequest().key); |
219 | 222 | ||
220 | if (keyOk && typeOk && monitorRequest.putHandler != null) { | 223 | if (keyOk && typeOk && monitorRequest.getRequest().putHandler != null) { |
221 | monitorRequest.putHandler.onPut(monitorPutMessage.options, monitorPutMessage.type, | 224 | monitorRequest.getRequest().putHandler.onPut(monitorPutMessage.options, monitorPutMessage.type, |
222 | monitorPutMessage.hopCount, monitorPutMessage.expirationTime, | 225 | monitorPutMessage.hopCount, monitorPutMessage.expirationTime, |
223 | monitorPutMessage.putPath, monitorPutMessage.key, monitorPutMessage.data); | 226 | monitorPutMessage.putPath, monitorPutMessage.key, monitorPutMessage.data); |
224 | } | 227 | } |
@@ -274,14 +277,14 @@ public class DistributedHashTable { | |||
274 | /** | 277 | /** |
275 | * Request results from the DHT. | 278 | * Request results from the DHT. |
276 | * | 279 | * |
277 | * @param timeout timeout for the request | 280 | * @param timeout timeout for the getRequestIdentifier |
278 | * @param type which type of data do we want to query for? (the DHT does not support TYPE_ANY) | 281 | * @param type which type of data do we want to query for? (the DHT does not support TYPE_ANY) |
279 | * @param key the key we want to query | 282 | * @param key the key we want to query |
280 | * @param replication how many peers do we want to ask? | 283 | * @param replication how many peers do we want to ask? |
281 | * @param routeOptions extra routing options, null for default | 284 | * @param routeOptions extra routing options, null for default |
282 | * @param xquery extra query parameters, defaults to null | 285 | * @param xquery extra query parameters, defaults to null |
283 | * @param cb the callback object for results or failure indication | 286 | * @param cb the callback object for results or failure indication |
284 | * @return a handle to cancel the request | 287 | * @return a handle to onCancel the getRequestIdentifier |
285 | */ | 288 | */ |
286 | public Cancelable startGet(RelativeTime timeout, int type, HashCode key, | 289 | public Cancelable startGet(RelativeTime timeout, int type, HashCode key, |
287 | int replication, EnumSet<RouteOption> routeOptions, | 290 | int replication, EnumSet<RouteOption> routeOptions, |
@@ -320,7 +323,7 @@ public class DistributedHashTable { | |||
320 | } | 323 | } |
321 | 324 | ||
322 | public static void main(String[] args) { | 325 | public static void main(String[] args) { |
323 | new Program(args) { | 326 | new Program() { |
324 | @Argument(action = ArgumentAction.SET, | 327 | @Argument(action = ArgumentAction.SET, |
325 | shortname = "p", | 328 | shortname = "p", |
326 | longname = "put", | 329 | longname = "put", |
@@ -390,7 +393,7 @@ public class DistributedHashTable { | |||
390 | @Override | 393 | @Override |
391 | public void cont(boolean success) { | 394 | public void cont(boolean success) { |
392 | if (success) { | 395 | if (success) { |
393 | System.out.println("put request sent"); | 396 | System.out.println("put getRequestIdentifier sent"); |
394 | } else { | 397 | } else { |
395 | System.out.println("error"); | 398 | System.out.println("error"); |
396 | } | 399 | } |
@@ -444,6 +447,6 @@ public class DistributedHashTable { | |||
444 | }); | 447 | }); |
445 | } | 448 | } |
446 | } | 449 | } |
447 | }.start(); | 450 | }.start(args); |
448 | } | 451 | } |
449 | } | 452 | } |
diff --git a/src/main/java/org/gnunet/dht/MonitorGetMessage.java b/src/main/java/org/gnunet/dht/MonitorGetMessage.java index a3e6297..ba9bf44 100644 --- a/src/main/java/org/gnunet/dht/MonitorGetMessage.java +++ b/src/main/java/org/gnunet/dht/MonitorGetMessage.java | |||
@@ -40,7 +40,7 @@ public class MonitorGetMessage implements GnunetMessage.Body { | |||
40 | public int options; | 40 | public int options; |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * The type of data in the request. | 43 | * The type of data in the getRequestIdentifier. |
44 | */ | 44 | */ |
45 | @UInt32 | 45 | @UInt32 |
46 | public int type; | 46 | public int type; |
diff --git a/src/main/java/org/gnunet/dht/MonitorGetRespMessage.java b/src/main/java/org/gnunet/dht/MonitorGetRespMessage.java index 6a25440..c298328 100644 --- a/src/main/java/org/gnunet/dht/MonitorGetRespMessage.java +++ b/src/main/java/org/gnunet/dht/MonitorGetRespMessage.java | |||
@@ -56,7 +56,7 @@ public class MonitorGetRespMessage implements GnunetMessage.Body { | |||
56 | public AbsoluteTimeMessage expiration; | 56 | public AbsoluteTimeMessage expiration; |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * The key of the corresponding GET request. | 59 | * The key of the corresponding GET getRequestIdentifier. |
60 | */ | 60 | */ |
61 | @NestedMessage | 61 | @NestedMessage |
62 | public HashCode key; | 62 | public HashCode key; |
diff --git a/src/main/java/org/gnunet/dht/MonitorPutMessage.java b/src/main/java/org/gnunet/dht/MonitorPutMessage.java index cf6b1fd..7e242c7 100644 --- a/src/main/java/org/gnunet/dht/MonitorPutMessage.java +++ b/src/main/java/org/gnunet/dht/MonitorPutMessage.java | |||
@@ -38,7 +38,7 @@ public class MonitorPutMessage implements GnunetMessage.Body { | |||
38 | public int options; | 38 | public int options; |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * The type of data in the request. | 41 | * The type of data in the getRequestIdentifier. |
42 | */ | 42 | */ |
43 | @UInt32 | 43 | @UInt32 |
44 | public int type; | 44 | public int type; |
diff --git a/src/main/java/org/gnunet/dht/MonitorStartStop.java b/src/main/java/org/gnunet/dht/MonitorStartStop.java index b79ec3e..ffe5c9a 100644 --- a/src/main/java/org/gnunet/dht/MonitorStartStop.java +++ b/src/main/java/org/gnunet/dht/MonitorStartStop.java | |||
@@ -28,7 +28,7 @@ import org.gnunet.util.GnunetMessage; | |||
28 | import org.gnunet.util.HashCode; | 28 | import org.gnunet.util.HashCode; |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Message to request monitoring messages, clients --> DHT service. | 31 | * Message to getRequestIdentifier monitoring messages, clients --> DHT service. |
32 | */ | 32 | */ |
33 | @UnionCase(153) | 33 | @UnionCase(153) |
34 | public class MonitorStartStop implements GnunetMessage.Body { | 34 | public class MonitorStartStop implements GnunetMessage.Body { |
diff --git a/src/main/java/org/gnunet/dht/RouteOption.java b/src/main/java/org/gnunet/dht/RouteOption.java index b74b528..e6593b4 100644 --- a/src/main/java/org/gnunet/dht/RouteOption.java +++ b/src/main/java/org/gnunet/dht/RouteOption.java | |||
@@ -39,7 +39,7 @@ enum RouteOption { | |||
39 | */ | 39 | */ |
40 | RECORD_ROUTE(2), | 40 | RECORD_ROUTE(2), |
41 | /** | 41 | /** |
42 | * This is a 'FIND-PEER' request, so approximate results are fine. | 42 | * This is a 'FIND-PEER' getRequestIdentifier, so approximate results are fine. |
43 | */ | 43 | */ |
44 | FIND_PEER(4), | 44 | FIND_PEER(4), |
45 | /** | 45 | /** |
diff --git a/src/main/java/org/gnunet/gns/GNS.java b/src/main/java/org/gnunet/gns/GNS.java index 3abc86c..63cd750 100644 --- a/src/main/java/org/gnunet/gns/GNS.java +++ b/src/main/java/org/gnunet/gns/GNS.java | |||
@@ -24,8 +24,12 @@ import org.gnunet.gns.messages.ClientLookupMessage; | |||
24 | import org.gnunet.gns.messages.ClientLookupResultMessage; | 24 | import org.gnunet.gns.messages.ClientLookupResultMessage; |
25 | import org.gnunet.mq.Envelope; | 25 | import org.gnunet.mq.Envelope; |
26 | import org.gnunet.requests.MatchingRequestContainer; | 26 | import org.gnunet.requests.MatchingRequestContainer; |
27 | import org.gnunet.requests.RequestContainer; | 27 | import org.gnunet.requests.Request; |
28 | import org.gnunet.util.*; | 28 | import org.gnunet.requests.RequestIdentifier; |
29 | import org.gnunet.util.Cancelable; | ||
30 | import org.gnunet.util.Client; | ||
31 | import org.gnunet.util.Configuration; | ||
32 | import org.gnunet.util.RunaboutMessageReceiver; | ||
29 | import org.gnunet.util.crypto.EcdsaPrivateKey; | 33 | import org.gnunet.util.crypto.EcdsaPrivateKey; |
30 | import org.gnunet.util.crypto.EcdsaPublicKey; | 34 | import org.gnunet.util.crypto.EcdsaPublicKey; |
31 | import org.slf4j.Logger; | 35 | import org.slf4j.Logger; |
@@ -42,7 +46,7 @@ public class GNS { | |||
42 | */ | 46 | */ |
43 | private MatchingRequestContainer<Long, LookupRequest> lookupRequests; | 47 | private MatchingRequestContainer<Long, LookupRequest> lookupRequests; |
44 | 48 | ||
45 | private class LookupRequest extends RequestContainer.Request { | 49 | private class LookupRequest extends Request { |
46 | long uid; | 50 | long uid; |
47 | String name; | 51 | String name; |
48 | EcdsaPublicKey zone; | 52 | EcdsaPublicKey zone; |
@@ -85,12 +89,13 @@ public class GNS { | |||
85 | 89 | ||
86 | public class GNSMessageReceiver extends RunaboutMessageReceiver { | 90 | public class GNSMessageReceiver extends RunaboutMessageReceiver { |
87 | public void visit(ClientLookupResultMessage m) { | 91 | public void visit(ClientLookupResultMessage m) { |
88 | LookupRequest r = lookupRequests.pollRequest(m.id); | 92 | RequestIdentifier<LookupRequest> r = lookupRequests.getRequestIdentifier(m.id); |
89 | if (null == r) { | 93 | if (null == r) { |
90 | logger.warn("no matching request for lookup result"); | 94 | logger.warn("no matching getRequestIdentifier for lookup result"); |
91 | return; | 95 | return; |
92 | } | 96 | } |
93 | r.proc.process(m.records); | 97 | r.getRequest().proc.process(m.records); |
98 | r.retire(); | ||
94 | } | 99 | } |
95 | 100 | ||
96 | @Override | 101 | @Override |
@@ -132,7 +137,7 @@ public class GNS { | |||
132 | * shorten zone, we automatically add the respective zone | 137 | * shorten zone, we automatically add the respective zone |
133 | * under that name) | 138 | * under that name) |
134 | * @param proc function to call on result | 139 | * @param proc function to call on result |
135 | * @return handle to the queued request | 140 | * @return handle to the queued getRequestIdentifier |
136 | */ | 141 | */ |
137 | public Cancelable lookup(String name, | 142 | public Cancelable lookup(String name, |
138 | EcdsaPublicKey zone, | 143 | EcdsaPublicKey zone, |
diff --git a/src/main/java/org/gnunet/gns/Gns.java b/src/main/java/org/gnunet/gns/Gns.java index 3175be0..8dd1e9e 100644 --- a/src/main/java/org/gnunet/gns/Gns.java +++ b/src/main/java/org/gnunet/gns/Gns.java | |||
@@ -23,8 +23,9 @@ package org.gnunet.gns; | |||
23 | import org.gnunet.gns.callbacks.LookupResultProcessor; | 23 | import org.gnunet.gns.callbacks.LookupResultProcessor; |
24 | import org.gnunet.gns.messages.ClientLookupMessage; | 24 | import org.gnunet.gns.messages.ClientLookupMessage; |
25 | import org.gnunet.gns.messages.ClientLookupResultMessage; | 25 | import org.gnunet.gns.messages.ClientLookupResultMessage; |
26 | import org.gnunet.requests.FixedMessageRequest; | ||
26 | import org.gnunet.requests.MatchingRequestContainer; | 27 | import org.gnunet.requests.MatchingRequestContainer; |
27 | import org.gnunet.requests.SimpleRequest; | 28 | import org.gnunet.requests.RequestIdentifier; |
28 | import org.gnunet.util.*; | 29 | import org.gnunet.util.*; |
29 | import org.gnunet.util.crypto.EcdsaPrivateKey; | 30 | import org.gnunet.util.crypto.EcdsaPrivateKey; |
30 | import org.gnunet.util.crypto.EcdsaPublicKey; | 31 | import org.gnunet.util.crypto.EcdsaPublicKey; |
@@ -40,7 +41,7 @@ public class Gns { | |||
40 | /** | 41 | /** |
41 | * All pending and active lookup requests. | 42 | * All pending and active lookup requests. |
42 | */ | 43 | */ |
43 | private MatchingRequestContainer<Long, SimpleRequest<LookupResultProcessor>> lookupRequests; | 44 | private MatchingRequestContainer<Long, FixedMessageRequest<LookupResultProcessor>> lookupRequests; |
44 | 45 | ||
45 | /** | 46 | /** |
46 | * Request ID for lookup requests. | 47 | * Request ID for lookup requests. |
@@ -57,12 +58,12 @@ public class Gns { | |||
57 | 58 | ||
58 | public class GNSMessageReceiver extends RunaboutMessageReceiver { | 59 | public class GNSMessageReceiver extends RunaboutMessageReceiver { |
59 | public void visit(ClientLookupResultMessage m) { | 60 | public void visit(ClientLookupResultMessage m) { |
60 | SimpleRequest<LookupResultProcessor> r = lookupRequests.pollRequest(m.id); | 61 | RequestIdentifier<FixedMessageRequest<LookupResultProcessor>> r = lookupRequests.getRequestIdentifier(m.id); |
61 | if (null == r) { | 62 | if (null == r) { |
62 | logger.warn("no matching request for lookup result"); | 63 | logger.warn("no matching getRequestIdentifier for lookup result"); |
63 | return; | 64 | return; |
64 | } | 65 | } |
65 | r.getContext().process(m.records); | 66 | r.getRequest().getContext().process(m.records); |
66 | } | 67 | } |
67 | 68 | ||
68 | @Override | 69 | @Override |
@@ -87,7 +88,7 @@ public class Gns { | |||
87 | */ | 88 | */ |
88 | public Gns(Configuration cfg) { | 89 | public Gns(Configuration cfg) { |
89 | client = new Client("gns", cfg); | 90 | client = new Client("gns", cfg); |
90 | lookupRequests = new MatchingRequestContainer<Long, SimpleRequest<LookupResultProcessor>>(client); | 91 | lookupRequests = new MatchingRequestContainer<Long, FixedMessageRequest<LookupResultProcessor>>(client); |
91 | client.installReceiver(new GNSMessageReceiver()); | 92 | client.installReceiver(new GNSMessageReceiver()); |
92 | } | 93 | } |
93 | 94 | ||
@@ -104,7 +105,7 @@ public class Gns { | |||
104 | * shorten zone, we automatically add the respective zone | 105 | * shorten zone, we automatically add the respective zone |
105 | * under that name) | 106 | * under that name) |
106 | * @param proc function to call on result | 107 | * @param proc function to call on result |
107 | * @return handle to the queued request | 108 | * @return handle to the queued getRequestIdentifier |
108 | */ | 109 | */ |
109 | public Cancelable lookup(String name, | 110 | public Cancelable lookup(String name, |
110 | EcdsaPublicKey zone, | 111 | EcdsaPublicKey zone, |
@@ -126,7 +127,7 @@ public class Gns { | |||
126 | m.type = type; | 127 | m.type = type; |
127 | m.zone = zone; | 128 | m.zone = zone; |
128 | 129 | ||
129 | return lookupRequests.addRequest(m.id, new SimpleRequest<LookupResultProcessor>(m, proc)); | 130 | return lookupRequests.addRequest(m.id, new FixedMessageRequest<LookupResultProcessor>(m, proc)); |
130 | } | 131 | } |
131 | 132 | ||
132 | 133 | ||
diff --git a/src/main/java/org/gnunet/gns/GnsRecord.java b/src/main/java/org/gnunet/gns/GnsRecord.java index 946678c..cd1108f 100644 --- a/src/main/java/org/gnunet/gns/GnsRecord.java +++ b/src/main/java/org/gnunet/gns/GnsRecord.java | |||
@@ -34,7 +34,6 @@ import org.slf4j.LoggerFactory; | |||
34 | import java.lang.reflect.Field; | 34 | import java.lang.reflect.Field; |
35 | import java.lang.reflect.InvocationTargetException; | 35 | import java.lang.reflect.InvocationTargetException; |
36 | import java.lang.reflect.Method; | 36 | import java.lang.reflect.Method; |
37 | import java.util.HashMap; | ||
38 | import java.util.Map; | 37 | import java.util.Map; |
39 | 38 | ||
40 | public class GnsRecord implements Message { | 39 | public class GnsRecord implements Message { |
diff --git a/src/main/java/org/gnunet/gns/GnsTool.java b/src/main/java/org/gnunet/gns/GnsTool.java index 81cd6d3..b5879a1 100644 --- a/src/main/java/org/gnunet/gns/GnsTool.java +++ b/src/main/java/org/gnunet/gns/GnsTool.java | |||
@@ -10,7 +10,7 @@ import org.gnunet.util.getopt.ArgumentAction; | |||
10 | 10 | ||
11 | public class GnsTool { | 11 | public class GnsTool { |
12 | public static void main(String[] args) { | 12 | public static void main(String[] args) { |
13 | int ret = new Program(args) { | 13 | int ret = new Program() { |
14 | @Argument( | 14 | @Argument( |
15 | shortname = "u", | 15 | shortname = "u", |
16 | longname = "lookup", | 16 | longname = "lookup", |
@@ -75,7 +75,7 @@ public class GnsTool { | |||
75 | }); | 75 | }); |
76 | 76 | ||
77 | } | 77 | } |
78 | }.start(); | 78 | }.start(args); |
79 | System.exit(ret); | 79 | System.exit(ret); |
80 | } | 80 | } |
81 | } | 81 | } |
diff --git a/src/main/java/org/gnunet/gns/LookupResultProcessor.java b/src/main/java/org/gnunet/gns/LookupResultProcessor.java index 901b2d3..d3e0af0 100644 --- a/src/main/java/org/gnunet/gns/LookupResultProcessor.java +++ b/src/main/java/org/gnunet/gns/LookupResultProcessor.java | |||
@@ -22,7 +22,7 @@ package org.gnunet.gns; | |||
22 | 22 | ||
23 | 23 | ||
24 | /** | 24 | /** |
25 | * Processor for GNS request results. | 25 | * Processor for GNS getRequestIdentifier results. |
26 | */ | 26 | */ |
27 | public interface LookupResultProcessor { | 27 | public interface LookupResultProcessor { |
28 | /** | 28 | /** |
diff --git a/src/main/java/org/gnunet/gns/callbacks/LookupResultProcessor.java b/src/main/java/org/gnunet/gns/callbacks/LookupResultProcessor.java index daa6d3e..4b00c7e 100644 --- a/src/main/java/org/gnunet/gns/callbacks/LookupResultProcessor.java +++ b/src/main/java/org/gnunet/gns/callbacks/LookupResultProcessor.java | |||
@@ -23,7 +23,7 @@ package org.gnunet.gns.callbacks; | |||
23 | import org.gnunet.gns.GnsRecord; | 23 | import org.gnunet.gns.GnsRecord; |
24 | 24 | ||
25 | /** | 25 | /** |
26 | * Processor for GNS request results. | 26 | * Processor for GNS getRequestIdentifier results. |
27 | */ | 27 | */ |
28 | public interface LookupResultProcessor { | 28 | public interface LookupResultProcessor { |
29 | /** | 29 | /** |
diff --git a/src/main/java/org/gnunet/gns/messages/ClientLookupMessage.java b/src/main/java/org/gnunet/gns/messages/ClientLookupMessage.java index c8d7174..b91d377 100644 --- a/src/main/java/org/gnunet/gns/messages/ClientLookupMessage.java +++ b/src/main/java/org/gnunet/gns/messages/ClientLookupMessage.java | |||
@@ -31,7 +31,7 @@ import org.gnunet.util.crypto.EcdsaPublicKey; | |||
31 | @UnionCase(500) | 31 | @UnionCase(500) |
32 | public class ClientLookupMessage implements GnunetMessage.Body { | 32 | public class ClientLookupMessage implements GnunetMessage.Body { |
33 | /** | 33 | /** |
34 | * Unique identifier for this request (for key collisions). | 34 | * Unique identifier for this getRequestIdentifier (for key collisions). |
35 | */ | 35 | */ |
36 | @UInt32 | 36 | @UInt32 |
37 | public long id; | 37 | public long id; |
diff --git a/src/main/java/org/gnunet/gns/messages/ClientLookupResultMessage.java b/src/main/java/org/gnunet/gns/messages/ClientLookupResultMessage.java index f9a1ce2..d7d062d 100644 --- a/src/main/java/org/gnunet/gns/messages/ClientLookupResultMessage.java +++ b/src/main/java/org/gnunet/gns/messages/ClientLookupResultMessage.java | |||
@@ -40,17 +40,19 @@ | |||
40 | 40 | ||
41 | package org.gnunet.gns.messages; | 41 | package org.gnunet.gns.messages; |
42 | 42 | ||
43 | import org.gnunet.construct.*; | 43 | import org.gnunet.construct.UInt32; |
44 | import org.gnunet.construct.UnionCase; | ||
45 | import org.gnunet.construct.VariableSizeArray; | ||
44 | import org.gnunet.gns.GnsRecord; | 46 | import org.gnunet.gns.GnsRecord; |
45 | import org.gnunet.util.GnunetMessage; | 47 | import org.gnunet.util.GnunetMessage; |
46 | 48 | ||
47 | /** | 49 | /** |
48 | * Message GNS service to client as a response to a lookup request. | 50 | * Message GNS service to client as a response to a lookup getRequestIdentifier. |
49 | */ | 51 | */ |
50 | @UnionCase(501) | 52 | @UnionCase(501) |
51 | public class ClientLookupResultMessage implements GnunetMessage.Body { | 53 | public class ClientLookupResultMessage implements GnunetMessage.Body { |
52 | /** | 54 | /** |
53 | * Unique identifier for this request. | 55 | * Unique identifier for this getRequestIdentifier. |
54 | */ | 56 | */ |
55 | @UInt32 | 57 | @UInt32 |
56 | public long id; | 58 | public long id; |
diff --git a/src/main/java/org/gnunet/identity/Identity.java b/src/main/java/org/gnunet/identity/Identity.java index 495313c..ca94a20 100644 --- a/src/main/java/org/gnunet/identity/Identity.java +++ b/src/main/java/org/gnunet/identity/Identity.java | |||
@@ -24,7 +24,8 @@ package org.gnunet.identity; | |||
24 | import com.google.common.collect.Lists; | 24 | import com.google.common.collect.Lists; |
25 | import org.gnunet.identity.messages.*; | 25 | import org.gnunet.identity.messages.*; |
26 | import org.gnunet.mq.Envelope; | 26 | import org.gnunet.mq.Envelope; |
27 | import org.gnunet.requests.RequestContainer; | 27 | import org.gnunet.requests.Request; |
28 | import org.gnunet.requests.RequestIdentifier; | ||
28 | import org.gnunet.requests.SequentialRequestContainer; | 29 | import org.gnunet.requests.SequentialRequestContainer; |
29 | import org.gnunet.util.*; | 30 | import org.gnunet.util.*; |
30 | import org.gnunet.util.crypto.EcdsaPrivateKey; | 31 | import org.gnunet.util.crypto.EcdsaPrivateKey; |
@@ -124,7 +125,7 @@ public class Identity { | |||
124 | } | 125 | } |
125 | } | 126 | } |
126 | 127 | ||
127 | public abstract class IdentityRequest extends RequestContainer.Request { | 128 | public abstract class IdentityRequest extends Request { |
128 | 129 | ||
129 | public void onError(String errorMessage) { | 130 | public void onError(String errorMessage) { |
130 | throw new AssertionError("unexpected error message: " + errorMessage); | 131 | throw new AssertionError("unexpected error message: " + errorMessage); |
@@ -353,7 +354,8 @@ public class Identity { | |||
353 | } | 354 | } |
354 | 355 | ||
355 | public void visit(ResultCodeMessage m) { | 356 | public void visit(ResultCodeMessage m) { |
356 | IdentityRequest r = requests.getRequest(); | 357 | RequestIdentifier<IdentityRequest> rId = requests.getRequestIdentifier(); |
358 | IdentityRequest r = rId.getRequest(); | ||
357 | if (null == r) { | 359 | if (null == r) { |
358 | logger.warn("unsolicited result code message"); | 360 | logger.warn("unsolicited result code message"); |
359 | return; | 361 | return; |
@@ -363,11 +365,12 @@ public class Identity { | |||
363 | } else { | 365 | } else { |
364 | r.onResult(); | 366 | r.onResult(); |
365 | } | 367 | } |
366 | requests.next(); | 368 | rId.retire(); |
367 | } | 369 | } |
368 | 370 | ||
369 | public void visit(SetDefaultMessage m) { | 371 | public void visit(SetDefaultMessage m) { |
370 | IdentityRequest r = requests.getRequest(); | 372 | RequestIdentifier<IdentityRequest> rId = requests.getRequestIdentifier(); |
373 | IdentityRequest r = rId.getRequest(); | ||
371 | if (!(r instanceof GetDefaultRequest)) { | 374 | if (!(r instanceof GetDefaultRequest)) { |
372 | logger.error("unexpected 'default ego' response"); | 375 | logger.error("unexpected 'default ego' response"); |
373 | return; | 376 | return; |
@@ -376,6 +379,7 @@ public class Identity { | |||
376 | Ego ego = getEgoForKey(m.privateKey); | 379 | Ego ego = getEgoForKey(m.privateKey); |
377 | if (null != ego) | 380 | if (null != ego) |
378 | gdr.identityCallback.onEgo(ego); | 381 | gdr.identityCallback.onEgo(ego); |
382 | rId.retire(); | ||
379 | } | 383 | } |
380 | 384 | ||
381 | public void visit(final UpdateListMessage m) { | 385 | public void visit(final UpdateListMessage m) { |
diff --git a/src/main/java/org/gnunet/identity/messages/ResultCodeMessage.java b/src/main/java/org/gnunet/identity/messages/ResultCodeMessage.java index 12bd55b..717bbb4 100644 --- a/src/main/java/org/gnunet/identity/messages/ResultCodeMessage.java +++ b/src/main/java/org/gnunet/identity/messages/ResultCodeMessage.java | |||
@@ -100,7 +100,9 @@ | |||
100 | 100 | ||
101 | package org.gnunet.identity.messages; | 101 | package org.gnunet.identity.messages; |
102 | 102 | ||
103 | import org.gnunet.construct.*; | 103 | import org.gnunet.construct.UInt32; |
104 | import org.gnunet.construct.UnionCase; | ||
105 | import org.gnunet.construct.ZeroTerminatedString; | ||
104 | import org.gnunet.util.GnunetMessage; | 106 | import org.gnunet.util.GnunetMessage; |
105 | 107 | ||
106 | /** | 108 | /** |
diff --git a/src/main/java/org/gnunet/mesh/ClientConnectMessage.java b/src/main/java/org/gnunet/mesh/ClientConnectMessage.java index 7ef36ce..0a76ee1 100644 --- a/src/main/java/org/gnunet/mesh/ClientConnectMessage.java +++ b/src/main/java/org/gnunet/mesh/ClientConnectMessage.java | |||
@@ -1,6 +1,7 @@ | |||
1 | package org.gnunet.mesh; | 1 | package org.gnunet.mesh; |
2 | 2 | ||
3 | import org.gnunet.construct.*; | 3 | import org.gnunet.construct.IntegerFill; |
4 | import org.gnunet.construct.UnionCase; | ||
4 | import org.gnunet.util.GnunetMessage; | 5 | import org.gnunet.util.GnunetMessage; |
5 | 6 | ||
6 | /** | 7 | /** |
diff --git a/src/main/java/org/gnunet/mesh/ConnectHandler.java b/src/main/java/org/gnunet/mesh/ConnectHandler.java index 021e8f0..62275b0 100644 --- a/src/main/java/org/gnunet/mesh/ConnectHandler.java +++ b/src/main/java/org/gnunet/mesh/ConnectHandler.java | |||
@@ -1,6 +1,5 @@ | |||
1 | package org.gnunet.mesh; | 1 | package org.gnunet.mesh; |
2 | 2 | ||
3 | import org.gnunet.peerinfo.PeerInfo; | ||
4 | import org.gnunet.util.PeerIdentity; | 3 | import org.gnunet.util.PeerIdentity; |
5 | 4 | ||
6 | /** | 5 | /** |
diff --git a/src/main/java/org/gnunet/mesh/DataMessage.java b/src/main/java/org/gnunet/mesh/DataMessage.java index a5ced12..2f7f93f 100644 --- a/src/main/java/org/gnunet/mesh/DataMessage.java +++ b/src/main/java/org/gnunet/mesh/DataMessage.java | |||
@@ -1,8 +1,10 @@ | |||
1 | package org.gnunet.mesh; | 1 | package org.gnunet.mesh; |
2 | 2 | ||
3 | import org.gnunet.construct.*; | 3 | import org.gnunet.construct.FillWith; |
4 | import org.gnunet.construct.UInt32; | ||
5 | import org.gnunet.construct.UInt8; | ||
6 | import org.gnunet.construct.UnionCase; | ||
4 | import org.gnunet.util.GnunetMessage; | 7 | import org.gnunet.util.GnunetMessage; |
5 | import org.gnunet.util.PeerIdentity; | ||
6 | 8 | ||
7 | /** | 9 | /** |
8 | * ... | 10 | * ... |
diff --git a/src/main/java/org/gnunet/mesh/MeshRunabout.java b/src/main/java/org/gnunet/mesh/MeshRunabout.java index bd7819e..50dbe09 100644 --- a/src/main/java/org/gnunet/mesh/MeshRunabout.java +++ b/src/main/java/org/gnunet/mesh/MeshRunabout.java | |||
@@ -1,6 +1,5 @@ | |||
1 | package org.gnunet.mesh; | 1 | package org.gnunet.mesh; |
2 | 2 | ||
3 | import org.gnunet.util.PeerIdentity; | ||
4 | import org.grothoff.Runabout; | 3 | import org.grothoff.Runabout; |
5 | 4 | ||
6 | /** | 5 | /** |
diff --git a/src/main/java/org/gnunet/mesh/TunnelDestroyMessage.java b/src/main/java/org/gnunet/mesh/TunnelDestroyMessage.java index b6e2fc9..b2a4c4f 100644 --- a/src/main/java/org/gnunet/mesh/TunnelDestroyMessage.java +++ b/src/main/java/org/gnunet/mesh/TunnelDestroyMessage.java | |||
@@ -1,11 +1,9 @@ | |||
1 | package org.gnunet.mesh; | 1 | package org.gnunet.mesh; |
2 | 2 | ||
3 | import org.gnunet.construct.FixedSizeIntegerArray; | 3 | import org.gnunet.construct.FixedSizeIntegerArray; |
4 | import org.gnunet.construct.NestedMessage; | ||
5 | import org.gnunet.construct.UInt32; | 4 | import org.gnunet.construct.UInt32; |
6 | import org.gnunet.construct.UnionCase; | 5 | import org.gnunet.construct.UnionCase; |
7 | import org.gnunet.util.GnunetMessage; | 6 | import org.gnunet.util.GnunetMessage; |
8 | import org.gnunet.util.PeerIdentity; | ||
9 | 7 | ||
10 | /** | 8 | /** |
11 | * ... | 9 | * ... |
diff --git a/src/main/java/org/gnunet/mq/Envelope.java b/src/main/java/org/gnunet/mq/Envelope.java index d54af80..e800fee 100644 --- a/src/main/java/org/gnunet/mq/Envelope.java +++ b/src/main/java/org/gnunet/mq/Envelope.java | |||
@@ -26,10 +26,10 @@ public class Envelope implements Cancelable { | |||
26 | 26 | ||
27 | public void cancel() { | 27 | public void cancel() { |
28 | if (parentQueue == null) | 28 | if (parentQueue == null) |
29 | throw new AssertionError("can not cancel an unqueued message"); | 29 | throw new AssertionError("can not onCancel an unqueued message"); |
30 | } | 30 | } |
31 | 31 | ||
32 | /* pkg-private */ void invokeSentNotification() { | 32 | void invokeSentNotification() { |
33 | if (null != notifySentHandler) | 33 | if (null != notifySentHandler) |
34 | notifySentHandler.onSent(); | 34 | notifySentHandler.onSent(); |
35 | } | 35 | } |
diff --git a/src/main/java/org/gnunet/mq/MessageQueue.java b/src/main/java/org/gnunet/mq/MessageQueue.java index cdc6354..d7ecce7 100644 --- a/src/main/java/org/gnunet/mq/MessageQueue.java +++ b/src/main/java/org/gnunet/mq/MessageQueue.java | |||
@@ -88,7 +88,7 @@ public abstract class MessageQueue { | |||
88 | /** | 88 | /** |
89 | * Cancel sending an envelope. The envelope must be queued in this message queue. | 89 | * Cancel sending an envelope. The envelope must be queued in this message queue. |
90 | * | 90 | * |
91 | * @param ev the envelope to cancel | 91 | * @param ev the envelope to onCancel |
92 | */ | 92 | */ |
93 | /* pkg-private */ void cancelEnvelope(Envelope ev) { | 93 | /* pkg-private */ void cancelEnvelope(Envelope ev) { |
94 | if (null == currentEnvelope) | 94 | if (null == currentEnvelope) |
diff --git a/src/main/java/org/gnunet/nse/NetworkSizeEstimation.java b/src/main/java/org/gnunet/nse/NetworkSizeEstimation.java index 5fc7453..05f80f2 100644 --- a/src/main/java/org/gnunet/nse/NetworkSizeEstimation.java +++ b/src/main/java/org/gnunet/nse/NetworkSizeEstimation.java | |||
@@ -83,7 +83,7 @@ public class NetworkSizeEstimation { | |||
83 | 83 | ||
84 | 84 | ||
85 | /** | 85 | /** |
86 | * A handle for a subscription to the network size estimation service, may be used to cancel the | 86 | * A handle for a subscription to the network size estimation service, may be used to onCancel the |
87 | * subscription. | 87 | * subscription. |
88 | */ | 88 | */ |
89 | public class Subscription implements Cancelable { | 89 | public class Subscription implements Cancelable { |
@@ -112,7 +112,7 @@ public class NetworkSizeEstimation { | |||
112 | * Subscribe for updates from the service. | 112 | * Subscribe for updates from the service. |
113 | * | 113 | * |
114 | * @param s callback for updates | 114 | * @param s callback for updates |
115 | * @return a subscription handle that may be used to cancel the subscription | 115 | * @return a subscription handle that may be used to onCancel the subscription |
116 | */ | 116 | */ |
117 | public Cancelable subscribe(Subscriber s) { | 117 | public Cancelable subscribe(Subscriber s) { |
118 | subscribers.add(s); | 118 | subscribers.add(s); |
@@ -141,7 +141,7 @@ public class NetworkSizeEstimation { | |||
141 | } | 141 | } |
142 | 142 | ||
143 | public static void main(String[] args) { | 143 | public static void main(String[] args) { |
144 | new Program(args) { | 144 | new Program() { |
145 | @Argument(action = ArgumentAction.SET, | 145 | @Argument(action = ArgumentAction.SET, |
146 | shortname = "w", | 146 | shortname = "w", |
147 | longname = "watch", | 147 | longname = "watch", |
@@ -162,6 +162,6 @@ public class NetworkSizeEstimation { | |||
162 | }; | 162 | }; |
163 | svc.subscribe(subscriber); | 163 | svc.subscribe(subscriber); |
164 | } | 164 | } |
165 | }.start(); | 165 | }.start(args); |
166 | } | 166 | } |
167 | } | 167 | } |
diff --git a/src/main/java/org/gnunet/nse/UpdateMessage.java b/src/main/java/org/gnunet/nse/UpdateMessage.java index 5c64a54..c83b740 100644 --- a/src/main/java/org/gnunet/nse/UpdateMessage.java +++ b/src/main/java/org/gnunet/nse/UpdateMessage.java | |||
@@ -1,7 +1,9 @@ | |||
1 | package org.gnunet.nse; | 1 | package org.gnunet.nse; |
2 | 2 | ||
3 | import org.gnunet.construct.*; | ||
4 | import org.gnunet.construct.DoubleValue; | 3 | import org.gnunet.construct.DoubleValue; |
4 | import org.gnunet.construct.NestedMessage; | ||
5 | import org.gnunet.construct.UInt32; | ||
6 | import org.gnunet.construct.UnionCase; | ||
5 | import org.gnunet.util.AbsoluteTimeMessage; | 7 | import org.gnunet.util.AbsoluteTimeMessage; |
6 | import org.gnunet.util.GnunetMessage; | 8 | import org.gnunet.util.GnunetMessage; |
7 | 9 | ||
diff --git a/src/main/java/org/gnunet/peerinfo/ListAllPeersMessage.java b/src/main/java/org/gnunet/peerinfo/ListAllPeersMessage.java index 7d175ca..f1cbd7e 100644 --- a/src/main/java/org/gnunet/peerinfo/ListAllPeersMessage.java +++ b/src/main/java/org/gnunet/peerinfo/ListAllPeersMessage.java | |||
@@ -20,11 +20,9 @@ | |||
20 | 20 | ||
21 | package org.gnunet.peerinfo; | 21 | package org.gnunet.peerinfo; |
22 | 22 | ||
23 | import org.gnunet.construct.NestedMessage; | ||
24 | import org.gnunet.construct.UInt32; | 23 | import org.gnunet.construct.UInt32; |
25 | import org.gnunet.construct.UnionCase; | 24 | import org.gnunet.construct.UnionCase; |
26 | import org.gnunet.util.GnunetMessage; | 25 | import org.gnunet.util.GnunetMessage; |
27 | import org.gnunet.util.PeerIdentity; | ||
28 | 26 | ||
29 | /** | 27 | /** |
30 | * Message requesting a listing of all known peers, | 28 | * Message requesting a listing of all known peers, |
diff --git a/src/main/java/org/gnunet/peerinfo/PeerInfo.java b/src/main/java/org/gnunet/peerinfo/PeerInfo.java index ea099ac..2304c5d 100644 --- a/src/main/java/org/gnunet/peerinfo/PeerInfo.java +++ b/src/main/java/org/gnunet/peerinfo/PeerInfo.java | |||
@@ -22,7 +22,7 @@ package org.gnunet.peerinfo; | |||
22 | 22 | ||
23 | import org.gnunet.hello.HelloMessage; | 23 | import org.gnunet.hello.HelloMessage; |
24 | import org.gnunet.mq.Envelope; | 24 | import org.gnunet.mq.Envelope; |
25 | import org.gnunet.requests.RequestContainer; | 25 | import org.gnunet.requests.Request; |
26 | import org.gnunet.requests.SequentialRequestContainer; | 26 | import org.gnunet.requests.SequentialRequestContainer; |
27 | import org.gnunet.util.*; | 27 | import org.gnunet.util.*; |
28 | import org.slf4j.Logger; | 28 | import org.slf4j.Logger; |
@@ -47,7 +47,7 @@ public class PeerInfo { | |||
47 | */ | 47 | */ |
48 | private SequentialRequestContainer<PeerIterateRequest> iterateRequests; | 48 | private SequentialRequestContainer<PeerIterateRequest> iterateRequests; |
49 | 49 | ||
50 | private class PeerIterateRequest extends RequestContainer.Request { | 50 | private class PeerIterateRequest extends Request { |
51 | public PeerIdentity peer; | 51 | public PeerIdentity peer; |
52 | public PeerProcessor peerProcessor; | 52 | public PeerProcessor peerProcessor; |
53 | public boolean friendOnly; | 53 | public boolean friendOnly; |
@@ -72,17 +72,16 @@ public class PeerInfo { | |||
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | public void cancel() { | 75 | public void onCancel() { |
76 | canceled = true; | 76 | canceled = true; |
77 | } | 77 | } |
78 | } | 78 | } |
79 | 79 | ||
80 | private class PeerInfoMessageReceiver extends RunaboutMessageReceiver { | 80 | private class PeerInfoMessageReceiver extends RunaboutMessageReceiver { |
81 | public void visit(InfoEnd infoEnd) { | 81 | public void visit(InfoEnd infoEnd) { |
82 | PeerIterateRequest r = iterateRequests.getRequest(); | 82 | PeerIterateRequest r = iterateRequests.getAndRetireRequest(); |
83 | if (!r.canceled) | 83 | if (!r.canceled) |
84 | r.peerProcessor.onEnd(); | 84 | r.peerProcessor.onEnd(); |
85 | iterateRequests.next(); | ||
86 | } | 85 | } |
87 | public void visit(InfoMessage infoMessage) { | 86 | public void visit(InfoMessage infoMessage) { |
88 | PeerIterateRequest r = iterateRequests.getRequest(); | 87 | PeerIterateRequest r = iterateRequests.getRequest(); |
@@ -102,9 +101,6 @@ public class PeerInfo { | |||
102 | client = new Client("peerinfo", cfg); | 101 | client = new Client("peerinfo", cfg); |
103 | client.installReceiver(new PeerInfoMessageReceiver()); | 102 | client.installReceiver(new PeerInfoMessageReceiver()); |
104 | iterateRequests = new SequentialRequestContainer<PeerIterateRequest>(client); | 103 | iterateRequests = new SequentialRequestContainer<PeerIterateRequest>(client); |
105 | // Make sure that new requests are only sent once the old request has finished. | ||
106 | // Otherwise, the peerinfo service would send the answers interleaved. | ||
107 | iterateRequests.setOverlap(false); | ||
108 | } | 104 | } |
109 | 105 | ||
110 | /** | 106 | /** |
@@ -136,7 +132,7 @@ public class PeerInfo { | |||
136 | } | 132 | } |
137 | 133 | ||
138 | public static void main(String... args) { | 134 | public static void main(String... args) { |
139 | new Program(args) { | 135 | new Program() { |
140 | @Override | 136 | @Override |
141 | public void run() { | 137 | public void run() { |
142 | final PeerInfo peerInfo = new PeerInfo(getConfiguration()); | 138 | final PeerInfo peerInfo = new PeerInfo(getConfiguration()); |
@@ -153,6 +149,6 @@ public class PeerInfo { | |||
153 | } | 149 | } |
154 | }); | 150 | }); |
155 | } | 151 | } |
156 | }.start(); | 152 | }.start(args); |
157 | } | 153 | } |
158 | } | 154 | } |
diff --git a/src/main/java/org/gnunet/requests/MatchingRequestContainer.java b/src/main/java/org/gnunet/requests/MatchingRequestContainer.java index b2c671e..04b17fd 100644 --- a/src/main/java/org/gnunet/requests/MatchingRequestContainer.java +++ b/src/main/java/org/gnunet/requests/MatchingRequestContainer.java | |||
@@ -1,3 +1,24 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2014 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | |||
1 | package org.gnunet.requests; | 22 | package org.gnunet.requests; |
2 | 23 | ||
3 | import com.google.common.collect.Maps; | 24 | import com.google.common.collect.Maps; |
@@ -8,13 +29,13 @@ import java.util.Map; | |||
8 | 29 | ||
9 | 30 | ||
10 | /** | 31 | /** |
11 | * Container for requests that are responded to with a matching request identification | 32 | * Container for requests that are responded to with a matching getRequestIdentifier identification |
12 | */ | 33 | */ |
13 | public class MatchingRequestContainer<K, T extends RequestContainer.Request> extends RequestContainer { | 34 | public class MatchingRequestContainer<K, T extends Request> extends RequestContainer { |
14 | /** | 35 | /** |
15 | * All queued requests. | 36 | * All queued requests. |
16 | */ | 37 | */ |
17 | private Map<K,T> requests = Maps.newHashMap(); | 38 | private Map<K,Identifier> requests = Maps.newHashMap(); |
18 | 39 | ||
19 | /** | 40 | /** |
20 | * Message queue to send to requests over. | 41 | * Message queue to send to requests over. |
@@ -25,48 +46,48 @@ public class MatchingRequestContainer<K, T extends RequestContainer.Request> ext | |||
25 | this.mq = mq; | 46 | this.mq = mq; |
26 | } | 47 | } |
27 | 48 | ||
49 | private class Identifier extends SimpleRequestIdentifier<T> { | ||
50 | final K key; | ||
51 | |||
52 | public Identifier(T request, K key) { | ||
53 | super(request); | ||
54 | this.key = key; | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | public void retire() { | ||
59 | super.retire(); | ||
60 | requests.remove(key); | ||
61 | } | ||
62 | } | ||
63 | |||
28 | public Cancelable addRequest(K key, final T request) { | 64 | public Cancelable addRequest(K key, final T request) { |
29 | if (requests.containsKey(key)) | 65 | if (requests.containsKey(key)) |
30 | throw new AssertionError("key already present in request container"); | 66 | throw new AssertionError("key already present in getRequestIdentifier container"); |
31 | requests.put(key, request); | 67 | Identifier identifier = new Identifier(request, key); |
32 | mq.send(request.assembleRequest()); | 68 | requests.put(key, identifier); |
33 | return new Cancelable() { | 69 | identifier.send(mq); |
34 | @Override | 70 | return identifier; |
35 | public void cancel() { | ||
36 | setRequestCancelled(request); | ||
37 | if (isRequestTransmitting(request)) { | ||
38 | cancelRequestTransmission(request); | ||
39 | } else { | ||
40 | request.cancel(); | ||
41 | } | ||
42 | } | ||
43 | }; | ||
44 | } | 71 | } |
45 | 72 | ||
46 | @Override | 73 | @Override |
47 | public void restart() { | 74 | public void restart() { |
48 | Map<K,T> requestsOld = requests; | 75 | Map<K, Identifier> requestsOld = requests; |
49 | requests = Maps.newHashMap(); | 76 | requests = Maps.newHashMap(); |
50 | for (Map.Entry<K,T> e : requestsOld.entrySet()) { | 77 | for (Map.Entry<K,Identifier> e : requestsOld.entrySet()) { |
51 | if (!isRequestCancelled(e.getValue())) { | 78 | addRequest(e.getKey(), e.getValue().getRequest()); |
52 | setRequestTransmitting(e.getValue(), false); | ||
53 | addRequest(e.getKey(), e.getValue()); | ||
54 | } | ||
55 | } | 79 | } |
56 | } | 80 | } |
57 | 81 | ||
58 | public T getRequest(K key) { | 82 | public RequestIdentifier<T> getRequestIdentifier(K key) { |
59 | return requests.get(key); | 83 | return requests.get(key); |
60 | } | 84 | } |
61 | 85 | ||
62 | /** | 86 | public T getAndRetireRequest(K key) { |
63 | * Retrieve the request matching the given key, and remove it. | 87 | RequestIdentifier<T> i = getRequestIdentifier(key); |
64 | * Return null if there is no matching request. | 88 | if (null == i) |
65 | * | 89 | return null; |
66 | * @param key key to look for | 90 | i.retire(); |
67 | * @return request, or null | 91 | return i.getRequest(); |
68 | */ | ||
69 | public T pollRequest(K key) { | ||
70 | return requests.remove(key); | ||
71 | } | 92 | } |
72 | } | 93 | } |
diff --git a/src/main/java/org/gnunet/requests/RequestContainer.java b/src/main/java/org/gnunet/requests/RequestContainer.java index 8fc631e..9c7fb48 100644 --- a/src/main/java/org/gnunet/requests/RequestContainer.java +++ b/src/main/java/org/gnunet/requests/RequestContainer.java | |||
@@ -1,90 +1,31 @@ | |||
1 | package org.gnunet.requests; | 1 | /* |
2 | 2 | This file is part of GNUnet. | |
3 | (C) 2014 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
3 | 20 | ||
4 | import org.gnunet.mq.Envelope; | 21 | package org.gnunet.requests; |
5 | import org.gnunet.util.Cancelable; | ||
6 | 22 | ||
7 | /** | 23 | /** |
8 | * Container for requests to a service. | 24 | * Container for requests to a service. |
9 | */ | 25 | */ |
10 | public abstract class RequestContainer { | 26 | public abstract class RequestContainer { |
11 | /** | 27 | /** |
12 | * Do we allow sending pending requests while | 28 | * Re-send all active and pending requests. |
13 | * other requests are still active (true), or do we send | ||
14 | * requests one-by-one (false)? | ||
15 | */ | ||
16 | protected boolean overlap = true; | ||
17 | |||
18 | /** | ||
19 | * A request that can be put in a request container. | ||
20 | */ | ||
21 | public abstract static class Request { | ||
22 | private boolean transmitting; | ||
23 | private boolean canceled; | ||
24 | private Cancelable cancelRequest; | ||
25 | |||
26 | /** | ||
27 | * Create an envelope for executing the request. | ||
28 | * | ||
29 | * @return Envelope to be sent to the service with the request message. | ||
30 | */ | ||
31 | public abstract Envelope assembleRequest(); | ||
32 | |||
33 | /** | ||
34 | * Implement cancellation logic for requests. | ||
35 | * Only called when the request has already been sent to the service. | ||
36 | * | ||
37 | * By default, canceling a request throws an exception. | ||
38 | */ | ||
39 | public void cancel() { | ||
40 | throw new AssertionError("request of type " + this.getClass() + " can not be canceled (not implemented)"); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | /** | ||
45 | * Re-send all requests in the queue that have not been canceled. | ||
46 | */ | 29 | */ |
47 | public abstract void restart(); | 30 | public abstract void restart(); |
48 | |||
49 | /** | ||
50 | * Allow or disallow requests to be send while other requests in the queue have not been completed. | ||
51 | * | ||
52 | * @param overlap true to allow overlapped requests, false to disallow them | ||
53 | */ | ||
54 | public void setOverlap(boolean overlap) { | ||
55 | this.overlap = overlap; | ||
56 | } | ||
57 | |||
58 | /** | ||
59 | * Check if the given request is transmitting, that is, the request | ||
60 | * is waiting to be sent to the service. | ||
61 | * | ||
62 | * @param r request | ||
63 | * @return whether the request is still being transmitted | ||
64 | */ | ||
65 | protected boolean isRequestTransmitting(Request r) { | ||
66 | return r.transmitting; | ||
67 | } | ||
68 | |||
69 | protected void setRequestTransmitting(Request r, boolean transmitting) { | ||
70 | r.transmitting = transmitting; | ||
71 | } | ||
72 | |||
73 | protected void setRequestTransmissionCancel(Request request, Cancelable cancel) { | ||
74 | request.cancelRequest = cancel; | ||
75 | } | ||
76 | |||
77 | protected void cancelRequestTransmission(Request r) { | ||
78 | r.cancelRequest.cancel(); | ||
79 | r.cancelRequest = null; | ||
80 | } | ||
81 | |||
82 | protected void setRequestCancelled(Request r) { | ||
83 | r.canceled = true; | ||
84 | } | ||
85 | |||
86 | protected boolean isRequestCancelled(Request r) { | ||
87 | return r.canceled; | ||
88 | } | ||
89 | |||
90 | } | 31 | } |
diff --git a/src/main/java/org/gnunet/requests/SequentialRequestContainer.java b/src/main/java/org/gnunet/requests/SequentialRequestContainer.java index 037055f..c343812 100644 --- a/src/main/java/org/gnunet/requests/SequentialRequestContainer.java +++ b/src/main/java/org/gnunet/requests/SequentialRequestContainer.java | |||
@@ -1,86 +1,153 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2014 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
1 | package org.gnunet.requests; | 21 | package org.gnunet.requests; |
2 | 22 | ||
3 | import org.gnunet.mq.Envelope; | ||
4 | import org.gnunet.mq.MessageQueue; | 23 | import org.gnunet.mq.MessageQueue; |
5 | import org.gnunet.mq.NotifySentHandler; | ||
6 | import org.gnunet.util.Cancelable; | ||
7 | 24 | ||
8 | import java.util.LinkedList; | 25 | import java.util.LinkedList; |
9 | 26 | ||
10 | /** | 27 | /** |
11 | * Container for requests that are responded to in sequential order. | 28 | * Container for requests that are responded to in sequential order. |
12 | */ | 29 | */ |
13 | public class SequentialRequestContainer<T extends RequestContainer.Request> extends RequestContainer { | 30 | public class SequentialRequestContainer<T extends Request> extends RequestContainer { |
14 | private LinkedList<T> requests = new LinkedList<T>(); | 31 | /** |
15 | private MessageQueue mq; | 32 | * Allow overlapping requests. |
33 | */ | ||
34 | private boolean overlap; | ||
35 | /** | ||
36 | * Request in our queue with information about them. | ||
37 | */ | ||
38 | private LinkedList<Identifier> requests = new LinkedList<Identifier>(); | ||
39 | /** | ||
40 | * Message queue that is used to send envelopes. | ||
41 | */ | ||
42 | private final MessageQueue mq; | ||
16 | 43 | ||
17 | int requestsActive = 0; | 44 | /** |
45 | * Number of active requests. | ||
46 | */ | ||
47 | private int requestsActive = 0; | ||
18 | 48 | ||
19 | public SequentialRequestContainer(MessageQueue mq) { | 49 | /** |
50 | * Create a sequential request container that sends messages with the given | ||
51 | * message queue. | ||
52 | * | ||
53 | * @param mq message queue to send messages with | ||
54 | * @param overlap allow sending requests while other request have not yet completed | ||
55 | */ | ||
56 | public SequentialRequestContainer(MessageQueue mq, boolean overlap) { | ||
20 | this.mq = mq; | 57 | this.mq = mq; |
58 | this.overlap = overlap; | ||
59 | } | ||
60 | /** | ||
61 | * Create a sequential request container that sends messages with the given | ||
62 | * message queue. Do not allow other requests to be send while the current request | ||
63 | * is still active. | ||
64 | * | ||
65 | * @param mq message queue to send messages with | ||
66 | */ | ||
67 | public SequentialRequestContainer(MessageQueue mq) { | ||
68 | this(mq, false); | ||
69 | } | ||
70 | /** | ||
71 | * Get the current request's identifier. | ||
72 | * | ||
73 | * @return current request | ||
74 | */ | ||
75 | public RequestIdentifier<T> getRequestIdentifier() { | ||
76 | return requests.peekFirst(); | ||
21 | } | 77 | } |
22 | 78 | ||
79 | /** | ||
80 | * Get the current request and retire it. | ||
81 | * If there is no current request, null will be returned. | ||
82 | * | ||
83 | * @return current request | ||
84 | */ | ||
85 | public T getAndRetireRequest() { | ||
86 | RequestIdentifier<T> i = getRequestIdentifier(); | ||
87 | if (null == i) | ||
88 | return null; | ||
89 | i.retire(); | ||
90 | return i.getRequest(); | ||
91 | } | ||
92 | |||
93 | public Iterable<RequestIdentifier<T>> iter() { | ||
94 | return (Iterable) requests; | ||
95 | } | ||
96 | |||
97 | /** | ||
98 | * Get the current request. | ||
99 | * | ||
100 | * @return the current request. | ||
101 | */ | ||
23 | public T getRequest() { | 102 | public T getRequest() { |
24 | return requests.getFirst(); | 103 | RequestIdentifier<T> i = getRequestIdentifier(); |
104 | if (null == i) | ||
105 | return null; | ||
106 | return i.getRequest(); | ||
25 | } | 107 | } |
26 | 108 | ||
27 | public void next() { | 109 | /** |
28 | if (requestsActive == 0 || requests.isEmpty()) | 110 | * A request identifier in a sequential request container. |
29 | throw new AssertionError(); | 111 | */ |
30 | requestsActive--; | 112 | private class Identifier extends SimpleRequestIdentifier<T> { |
31 | requests.removeFirst(); | 113 | public Identifier(T request) { |
32 | if (requestsActive == 0 && !requests.isEmpty()) { | 114 | super(request); |
33 | Request r = requests.getFirst(); | 115 | } |
34 | setRequestTransmitting(r, true); | 116 | |
35 | Envelope ev = r.assembleRequest(); | 117 | @Override |
36 | setRequestTransmissionCancel(r, ev); | 118 | public void retire() { |
37 | mq.send(r.assembleRequest()); | 119 | super.retire(); |
38 | requestsActive++; | 120 | if (requestsActive == 0 || requests.isEmpty()) |
121 | throw new AssertionError(); | ||
122 | boolean found = requests.remove(this); | ||
123 | if (!found) | ||
124 | throw new AssertionError("request not in queue"); | ||
125 | requestsActive--; | ||
126 | Identifier next = requests.peekFirst(); | ||
127 | if (null == next || next.queued) | ||
128 | return; | ||
129 | if (requestsActive == 0 || overlap) | ||
130 | next.send(mq); | ||
39 | } | 131 | } |
40 | } | 132 | } |
41 | 133 | ||
42 | public Cancelable addRequest(final T request) { | 134 | public RequestIdentifier<T> addRequest(final T request) { |
43 | requests.addLast(request); | 135 | final Identifier identifier = new Identifier(request); |
136 | requests.addLast(identifier); | ||
137 | // only send immediately if we are allowed to | ||
44 | if (overlap || requestsActive == 0) { | 138 | if (overlap || requestsActive == 0) { |
45 | requestsActive++; | 139 | identifier.send(mq); |
46 | setRequestTransmitting(request, true); | 140 | requestsActive += 1; |
47 | Envelope ev = request.assembleRequest(); | ||
48 | ev.notifySent(new NotifySentHandler() { | ||
49 | @Override | ||
50 | public void onSent() { | ||
51 | setRequestTransmitting(request, false); | ||
52 | } | ||
53 | }); | ||
54 | setRequestTransmissionCancel(request, ev); | ||
55 | mq.send(request.assembleRequest()); | ||
56 | } | 141 | } |
57 | return new Cancelable() { | 142 | return identifier; |
58 | @Override | ||
59 | public void cancel() { | ||
60 | setRequestCancelled(request); | ||
61 | if (isRequestTransmitting(request)) { | ||
62 | cancelRequestTransmission(request); | ||
63 | } else { | ||
64 | request.cancel(); | ||
65 | } | ||
66 | } | ||
67 | }; | ||
68 | } | 143 | } |
69 | 144 | ||
70 | @Override | 145 | @Override |
71 | public void restart() { | 146 | public void restart() { |
72 | LinkedList<T> requestsOld = requests; | 147 | LinkedList<Identifier> requestsOld = requests; |
73 | requests = new LinkedList<T>(); | 148 | requests = new LinkedList<Identifier>(); |
74 | for (T r : requestsOld) { | 149 | for (Identifier r : requestsOld) { |
75 | if (!isRequestCancelled(r)) { | 150 | addRequest(r.getRequest()); |
76 | setRequestTransmitting(r, false); | ||
77 | addRequest(r); | ||
78 | } | ||
79 | } | 151 | } |
80 | } | 152 | } |
81 | |||
82 | |||
83 | public Iterable<T> iter() { | ||
84 | return requests; | ||
85 | } | ||
86 | } | 153 | } |
diff --git a/src/main/java/org/gnunet/requests/package-info.java b/src/main/java/org/gnunet/requests/package-info.java index 892a606..b4fd674 100644 --- a/src/main/java/org/gnunet/requests/package-info.java +++ b/src/main/java/org/gnunet/requests/package-info.java | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2011, 2012 Christian Grothoff (and other contributing authors) | 3 | (C) 2014 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -18,7 +18,6 @@ | |||
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | |||
22 | /** | 21 | /** |
23 | * General mechanism for queueing requests to a service. | 22 | * General mechanism for queueing requests to a service. |
24 | */ | 23 | */ |
diff --git a/src/main/java/org/gnunet/secretsharing/Ciphertext.java b/src/main/java/org/gnunet/secretsharing/Ciphertext.java index b940f21..d60e8ce 100644 --- a/src/main/java/org/gnunet/secretsharing/Ciphertext.java +++ b/src/main/java/org/gnunet/secretsharing/Ciphertext.java | |||
@@ -28,7 +28,7 @@ import org.gnunet.util.Strings; | |||
28 | import java.math.BigInteger; | 28 | import java.math.BigInteger; |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * ElGamal ciphertext | 31 | * ElGamal ciphertext. |
32 | */ | 32 | */ |
33 | public class Ciphertext implements Message { | 33 | public class Ciphertext implements Message { |
34 | @FixedSizeIntegerArray(signed = true, bitSize = 8, length = Parameters.elgamalBits / 8) | 34 | @FixedSizeIntegerArray(signed = true, bitSize = 8, length = Parameters.elgamalBits / 8) |
@@ -82,4 +82,17 @@ public class Ciphertext implements Message { | |||
82 | Parameters.elgamalBits); | 82 | Parameters.elgamalBits); |
83 | return ciphertext; | 83 | return ciphertext; |
84 | } | 84 | } |
85 | |||
86 | /** | ||
87 | * Get the ciphertext that is the identity for multiplication. | ||
88 | * | ||
89 | * @return multiplicative identity ciphertext | ||
90 | */ | ||
91 | public static Ciphertext identity() { | ||
92 | Ciphertext ciphertext = new Ciphertext(); | ||
93 | ciphertext.allocate(); | ||
94 | ciphertext.c_1 = BigIntegers.serializeUnsigned(BigInteger.ONE, Parameters.elgamalBits); | ||
95 | ciphertext.c_2 = BigIntegers.serializeUnsigned(BigInteger.ONE, Parameters.elgamalBits); | ||
96 | return ciphertext; | ||
97 | } | ||
85 | } | 98 | } |
diff --git a/src/main/java/org/gnunet/secretsharing/KeyGeneration.java b/src/main/java/org/gnunet/secretsharing/KeyGeneration.java index 8b9a759..72d13b1 100644 --- a/src/main/java/org/gnunet/secretsharing/KeyGeneration.java +++ b/src/main/java/org/gnunet/secretsharing/KeyGeneration.java | |||
@@ -76,7 +76,7 @@ public class KeyGeneration { | |||
76 | } | 76 | } |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * Disconnect from the secretsharing service and cancel the operation. | 79 | * Disconnect from the secretsharing service and onCancel the operation. |
80 | * The SecretReadyCallback will not be called after calling disconnect. | 80 | * The SecretReadyCallback will not be called after calling disconnect. |
81 | */ | 81 | */ |
82 | public void disconnect() { | 82 | public void disconnect() { |
diff --git a/src/main/java/org/gnunet/secretsharing/Plaintext.java b/src/main/java/org/gnunet/secretsharing/Plaintext.java index c2eacc2..fc4ac14 100644 --- a/src/main/java/org/gnunet/secretsharing/Plaintext.java +++ b/src/main/java/org/gnunet/secretsharing/Plaintext.java | |||
@@ -20,7 +20,6 @@ | |||
20 | 20 | ||
21 | package org.gnunet.secretsharing; | 21 | package org.gnunet.secretsharing; |
22 | 22 | ||
23 | import com.google.common.base.Preconditions; | ||
24 | import org.gnunet.construct.FixedSizeIntegerArray; | 23 | import org.gnunet.construct.FixedSizeIntegerArray; |
25 | import org.gnunet.construct.Message; | 24 | import org.gnunet.construct.Message; |
26 | import org.gnunet.util.BigIntegers; | 25 | import org.gnunet.util.BigIntegers; |
@@ -42,13 +41,13 @@ public class Plaintext implements Message { | |||
42 | 41 | ||
43 | public long bruteForceDiscreteLog(final long l) { | 42 | public long bruteForceDiscreteLog(final long l) { |
44 | BigInteger needle = new BigInteger(1, bits); | 43 | BigInteger needle = new BigInteger(1, bits); |
45 | for (long i = -l; i < l; i++) { | 44 | for (long i = -l; i <= l; i++) { |
46 | BigInteger val; | 45 | BigInteger val; |
47 | val = Parameters.elgamalG.modPow(BigInteger.valueOf(l), Parameters.elgamalP); | 46 | val = Parameters.elgamalG.modPow(BigInteger.valueOf(l), Parameters.elgamalP); |
48 | if (val.equals(needle)) | 47 | if (val.equals(needle)) |
49 | return i; | 48 | return i; |
50 | } | 49 | } |
51 | throw new ArithmeticException("discrete log has no solution in given range"); | 50 | throw new ArithmeticException(String.format("discrete log has no solution in range [%s, %s]", -l, l)); |
52 | } | 51 | } |
53 | 52 | ||
54 | public Ciphertext encrypt(ThresholdPublicKey publicKey) { | 53 | public Ciphertext encrypt(ThresholdPublicKey publicKey) { |
diff --git a/src/main/java/org/gnunet/secretsharing/messages/ClientDecryptMessage.java b/src/main/java/org/gnunet/secretsharing/messages/ClientDecryptMessage.java index 1dc0981..bfe2efc 100644 --- a/src/main/java/org/gnunet/secretsharing/messages/ClientDecryptMessage.java +++ b/src/main/java/org/gnunet/secretsharing/messages/ClientDecryptMessage.java | |||
@@ -28,7 +28,7 @@ import org.gnunet.util.AbsoluteTimeMessage; | |||
28 | import org.gnunet.util.GnunetMessage; | 28 | import org.gnunet.util.GnunetMessage; |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Sent by the client to the service to request the cooperative decryption of a | 31 | * Sent by the client to the service to getRequestIdentifier the cooperative decryption of a |
32 | * ciphertext. | 32 | * ciphertext. |
33 | */ | 33 | */ |
34 | @UnionCase(781) | 34 | @UnionCase(781) |
diff --git a/src/main/java/org/gnunet/secretsharing/messages/GenerateMessage.java b/src/main/java/org/gnunet/secretsharing/messages/GenerateMessage.java index b1ce6b2..135b254 100644 --- a/src/main/java/org/gnunet/secretsharing/messages/GenerateMessage.java +++ b/src/main/java/org/gnunet/secretsharing/messages/GenerateMessage.java | |||
@@ -26,7 +26,10 @@ import org.gnunet.construct.NestedMessage; | |||
26 | import org.gnunet.construct.UInt16; | 26 | import org.gnunet.construct.UInt16; |
27 | import org.gnunet.construct.UnionCase; | 27 | import org.gnunet.construct.UnionCase; |
28 | import org.gnunet.construct.VariableSizeArray; | 28 | import org.gnunet.construct.VariableSizeArray; |
29 | import org.gnunet.util.*; | 29 | import org.gnunet.util.AbsoluteTimeMessage; |
30 | import org.gnunet.util.GnunetMessage; | ||
31 | import org.gnunet.util.HashCode; | ||
32 | import org.gnunet.util.PeerIdentity; | ||
30 | 33 | ||
31 | 34 | ||
32 | @UnionCase(780) | 35 | @UnionCase(780) |
diff --git a/src/main/java/org/gnunet/statistics/GetRequest.java b/src/main/java/org/gnunet/statistics/GetRequest.java index 8f421b1..42ca0bb 100644 --- a/src/main/java/org/gnunet/statistics/GetRequest.java +++ b/src/main/java/org/gnunet/statistics/GetRequest.java | |||
@@ -1,16 +1,13 @@ | |||
1 | package org.gnunet.statistics; | 1 | package org.gnunet.statistics; |
2 | 2 | ||
3 | import org.gnunet.mq.Envelope; | 3 | import org.gnunet.mq.Envelope; |
4 | import org.gnunet.mq.MessageQueue; | 4 | import org.gnunet.requests.Request; |
5 | import org.gnunet.requests.RequestContainer; | 5 | import org.gnunet.statistics.messages.GetMessage; |
6 | 6 | ||
7 | /** | 7 | class GetRequest extends Request { |
8 | */ | ||
9 | public class GetRequest extends RequestContainer.Request { | ||
10 | private final String subsystem; | 8 | private final String subsystem; |
11 | private final String name; | 9 | private final String name; |
12 | public final StatisticsReceiver receiver; | 10 | public final StatisticsReceiver receiver; |
13 | private RequestContainer parent; | ||
14 | 11 | ||
15 | public GetRequest(String subsystem, String name, StatisticsReceiver receiver) { | 12 | public GetRequest(String subsystem, String name, StatisticsReceiver receiver) { |
16 | this.subsystem = subsystem; | 13 | this.subsystem = subsystem; |
@@ -27,5 +24,6 @@ public class GetRequest extends RequestContainer.Request { | |||
27 | } | 24 | } |
28 | 25 | ||
29 | public void cancel() { | 26 | public void cancel() { |
27 | // nothing we can do here (statistics service has no message to cancel requests) | ||
30 | } | 28 | } |
31 | } | 29 | } |
diff --git a/src/main/java/org/gnunet/statistics/Statistics.java b/src/main/java/org/gnunet/statistics/Statistics.java index d06b627..d8b8f3e 100644 --- a/src/main/java/org/gnunet/statistics/Statistics.java +++ b/src/main/java/org/gnunet/statistics/Statistics.java | |||
@@ -18,19 +18,17 @@ | |||
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | ||
22 | * The stuff below does nothing whatsoever, first milestone of | ||
23 | * this project is to implement the StatisticsService api | ||
24 | * | ||
25 | */ | ||
26 | |||
27 | package org.gnunet.statistics; | 21 | package org.gnunet.statistics; |
28 | 22 | ||
29 | import org.gnunet.requests.MatchingRequestContainer; | 23 | import org.gnunet.requests.MatchingRequestContainer; |
24 | import org.gnunet.requests.RequestIdentifier; | ||
30 | import org.gnunet.requests.SequentialRequestContainer; | 25 | import org.gnunet.requests.SequentialRequestContainer; |
26 | import org.gnunet.requests.TimeoutHandler; | ||
27 | import org.gnunet.statistics.messages.GetResponseEndMessage; | ||
28 | import org.gnunet.statistics.messages.GetResponseMessage; | ||
29 | import org.gnunet.statistics.messages.SetMessage; | ||
30 | import org.gnunet.statistics.messages.WatchResponseMessage; | ||
31 | import org.gnunet.util.*; | 31 | import org.gnunet.util.*; |
32 | import org.gnunet.util.getopt.Argument; | ||
33 | import org.gnunet.util.getopt.ArgumentAction; | ||
34 | import org.slf4j.Logger; | 32 | import org.slf4j.Logger; |
35 | import org.slf4j.LoggerFactory; | 33 | import org.slf4j.LoggerFactory; |
36 | 34 | ||
@@ -48,39 +46,68 @@ public class Statistics { | |||
48 | /** | 46 | /** |
49 | * Client connecting us to the statistics service. | 47 | * Client connecting us to the statistics service. |
50 | */ | 48 | */ |
51 | private final Client client; | 49 | private Client client; |
52 | 50 | ||
53 | SequentialRequestContainer<SetRequest> setRequests; | 51 | /** |
54 | SequentialRequestContainer<GetRequest> getRequests; | 52 | * All request to the service for getting a value. |
55 | MatchingRequestContainer<Long,WatchRequest> watchRequests; | 53 | */ |
54 | private final SequentialRequestContainer<GetRequest> getRequests; | ||
56 | 55 | ||
56 | /** | ||
57 | * All requests to the service for watching a value. | ||
58 | */ | ||
59 | private final MatchingRequestContainer<Long,WatchRequest> watchRequests; | ||
60 | |||
61 | /** | ||
62 | * Do we wait for the final 'TestMessage' from the service and | ||
63 | * do not accept any new requests? | ||
64 | */ | ||
57 | private boolean destroyRequested; | 65 | private boolean destroyRequested; |
58 | 66 | ||
59 | private long wid = 0; | 67 | /** |
68 | * Next unused ID to identity watch requests/responses. | ||
69 | */ | ||
70 | private long nextWatchId = 0; | ||
71 | |||
72 | /** | ||
73 | * Timeout when waiting for the TestMessage after destruction of | ||
74 | * this statistics handle has been requested. | ||
75 | */ | ||
76 | private Scheduler.TaskIdentifier destroyTimeout; | ||
60 | 77 | ||
78 | /** | ||
79 | * Messages from the statistics service are dispatched to an instance of this class. | ||
80 | */ | ||
61 | public class StatisticsMessageReceiver extends RunaboutMessageReceiver { | 81 | public class StatisticsMessageReceiver extends RunaboutMessageReceiver { |
62 | public void visit(GetResponseMessage m) { | 82 | public void visit(GetResponseMessage m) { |
63 | GetRequest r = getRequests.getRequest(); | 83 | RequestIdentifier<GetRequest> r = getRequests.getRequestIdentifier(); |
64 | if (r != null) | 84 | if (r != null) |
65 | r.receiver.onReceive(m.subsystemName, m.statisticName, m.value); | 85 | r.getRequest().receiver.onReceive(m.subsystemName, m.statisticName, m.value); |
66 | } | 86 | } |
67 | 87 | ||
68 | public void visit(GetResponseEndMessage m) { | 88 | public void visit(@SuppressWarnings("UnusedParameters") GetResponseEndMessage m) { |
69 | GetRequest r = getRequests.getRequest(); | 89 | RequestIdentifier<GetRequest> r = getRequests.getRequestIdentifier(); |
70 | if (r != null) | 90 | if (r != null) { |
71 | r.receiver.onDone(); | 91 | r.retire(); |
72 | //noinspection ConstantConditions | 92 | r.getRequest().receiver.onDone(); |
73 | if (getRequests != null) | 93 | } |
74 | getRequests.next(); | ||
75 | } | 94 | } |
76 | 95 | ||
77 | public void visit(TestMessage m) { | 96 | public void visit(@SuppressWarnings("UnusedParameters") TestMessage m) { |
78 | System.out.println("got back TEST message"); | 97 | // The TestMessage indicates that the statistics service received all our |
98 | // messages, we can disconnect. | ||
99 | if (null != destroyTimeout) { | ||
100 | destroyTimeout.cancel(); | ||
101 | destroyTimeout = null; | ||
102 | } else { | ||
103 | logger.error("protocol violation: destroy timeout is 'null' but got test message"); | ||
104 | } | ||
79 | client.disconnect(); | 105 | client.disconnect(); |
80 | } | 106 | } |
81 | 107 | ||
82 | public void visit(WatchResponseMessage wrm) { | 108 | public void visit(WatchResponseMessage wrm) { |
83 | WatchRequest r = watchRequests.getRequest((long) wrm.wid); | 109 | RequestIdentifier<WatchRequest> ri = watchRequests.getRequestIdentifier((long) wrm.wid); |
110 | WatchRequest r = ri.getRequest(); | ||
84 | if (r != null) { | 111 | if (r != null) { |
85 | r.watcher.onReceive(r.subsystem, r.name, wrm.value); | 112 | r.watcher.onReceive(r.subsystem, r.name, wrm.value); |
86 | } | 113 | } |
@@ -88,12 +115,19 @@ public class Statistics { | |||
88 | 115 | ||
89 | @Override | 116 | @Override |
90 | public void handleError() { | 117 | public void handleError() { |
118 | if (null == client) | ||
119 | throw new AssertionError(); | ||
91 | if (!destroyRequested) { | 120 | if (!destroyRequested) { |
92 | client.reconnect(); | 121 | client.reconnect(); |
93 | getRequests.restart(); | 122 | getRequests.restart(); |
94 | setRequests.restart(); | ||
95 | watchRequests.restart(); | 123 | watchRequests.restart(); |
96 | } | 124 | } |
125 | // if everything is shutting down, maybe the statistics service | ||
126 | // was shut down, and can't respond with the TestMessage anymore. | ||
127 | if (null != destroyTimeout) { | ||
128 | destroyTimeout.cancel(); | ||
129 | destroyTimeout = null; | ||
130 | } | ||
97 | } | 131 | } |
98 | } | 132 | } |
99 | 133 | ||
@@ -101,26 +135,32 @@ public class Statistics { | |||
101 | client = new Client("statistics", cfg); | 135 | client = new Client("statistics", cfg); |
102 | client.installReceiver(new StatisticsMessageReceiver()); | 136 | client.installReceiver(new StatisticsMessageReceiver()); |
103 | getRequests = new SequentialRequestContainer<GetRequest>(client); | 137 | getRequests = new SequentialRequestContainer<GetRequest>(client); |
104 | setRequests = new SequentialRequestContainer<SetRequest>(client); | ||
105 | watchRequests = new MatchingRequestContainer<Long, WatchRequest>(client); | 138 | watchRequests = new MatchingRequestContainer<Long, WatchRequest>(client); |
106 | } | 139 | } |
107 | 140 | ||
108 | /** | 141 | /** |
109 | * Retrieve values from statistics. | 142 | * Retrieve values from statistics. |
110 | * Only one instance of this request may be active simultaneously. | 143 | * Only one instance of this getRequestIdentifier may be active simultaneously. |
111 | * Upon cancellation | 144 | * Upon cancellation |
112 | * | 145 | * |
113 | * @param timeout time after we give up and call receiver.onTimeout | 146 | * @param timeout time after we give up and call receiver.onTimeout |
114 | * @param subsystem the subsystem of interest | 147 | * @param subsystem the subsystem of interest |
115 | * @param name name of the statistics value belongs to | 148 | * @param name name of the statistics value belongs to |
116 | * @param receiver callback | 149 | * @param receiver callback |
117 | * @return handle to cancel the request | 150 | * @return handle to onCancel the getRequestIdentifier |
118 | */ | 151 | */ |
119 | public Cancelable get(RelativeTime timeout, final String subsystem, final String name, | 152 | public Cancelable get(RelativeTime timeout, final String subsystem, final String name, |
120 | final StatisticsReceiver receiver) { | 153 | final StatisticsReceiver receiver) { |
121 | if (destroyRequested) | 154 | if (destroyRequested || client == null) |
122 | throw new AssertionError("already destroyed"); | 155 | throw new AssertionError("already destroyed"); |
123 | return getRequests.addRequest(new GetRequest(subsystem, name, receiver)); | 156 | RequestIdentifier<GetRequest> identifier = getRequests.addRequest(new GetRequest(subsystem, name, receiver)); |
157 | identifier.setTimeout(timeout, new TimeoutHandler() { | ||
158 | @Override | ||
159 | public void onTimeout() { | ||
160 | receiver.onTimeout(); | ||
161 | } | ||
162 | }); | ||
163 | return identifier; | ||
124 | } | 164 | } |
125 | 165 | ||
126 | /** | 166 | /** |
@@ -129,12 +169,17 @@ public class Statistics { | |||
129 | * @param name name of the entry | 169 | * @param name name of the entry |
130 | * @param value desired value | 170 | * @param value desired value |
131 | * @param persist keep value even if the statistics service restarts | 171 | * @param persist keep value even if the statistics service restarts |
132 | * @return a handle to cancel the request | ||
133 | */ | 172 | */ |
134 | public Cancelable set(final String subsystem, final String name, final long value, boolean persist) { | 173 | public void set(final String subsystem, final String name, final long value, boolean persist) { |
135 | if (destroyRequested) | 174 | if (destroyRequested || client == null) |
136 | throw new AssertionError("already destroyed"); | 175 | throw new AssertionError("already destroyed"); |
137 | return setRequests.addRequest(new SetRequest(subsystem, name, value, false, persist)); | 176 | SetMessage m = new SetMessage(); |
177 | m.statisticName = name; | ||
178 | m.subsystemName = subsystem; | ||
179 | m.value = value; | ||
180 | if (persist) | ||
181 | m.flags |= SetMessage.SETFLAG_PERSIST; | ||
182 | client.send(m); | ||
138 | } | 183 | } |
139 | 184 | ||
140 | /** | 185 | /** |
@@ -143,12 +188,18 @@ public class Statistics { | |||
143 | * @param name name of the entry | 188 | * @param name name of the entry |
144 | * @param delta relative difference to the old value | 189 | * @param delta relative difference to the old value |
145 | * @param persist keep value even if the statistics service restarts | 190 | * @param persist keep value even if the statistics service restarts |
146 | * @return a handle to cancel the request | ||
147 | */ | 191 | */ |
148 | public Cancelable update(final String subsystem, final String name, final long delta, boolean persist) { | 192 | public void update(final String subsystem, final String name, final long delta, boolean persist) { |
149 | if (destroyRequested) | 193 | if (destroyRequested || null == client) |
150 | throw new AssertionError("already destroyed"); | 194 | throw new AssertionError("already destroyed"); |
151 | return setRequests.addRequest(new SetRequest(subsystem, name, delta, true, persist)); | 195 | SetMessage m = new SetMessage(); |
196 | m.statisticName = name; | ||
197 | m.subsystemName = subsystem; | ||
198 | m.value = delta; | ||
199 | if (persist) | ||
200 | m.flags |= SetMessage.SETFLAG_PERSIST; | ||
201 | m.flags |= SetMessage.SETFLAG_RELATIVE; | ||
202 | client.send(m); | ||
152 | } | 203 | } |
153 | 204 | ||
154 | /** | 205 | /** |
@@ -157,154 +208,48 @@ public class Statistics { | |||
157 | * @param subsystem the subsystem to watch | 208 | * @param subsystem the subsystem to watch |
158 | * @param name the value to watch | 209 | * @param name the value to watch |
159 | * @param watcher the object that receives the updates | 210 | * @param watcher the object that receives the updates |
160 | * @return a handle to cancel the request | 211 | * @return a handle to onCancel the getRequestIdentifier |
161 | */ | 212 | */ |
162 | public Cancelable watch(final String subsystem, final String name, StatisticsWatcher watcher) { | 213 | public Cancelable watch(final String subsystem, final String name, StatisticsWatcher watcher) { |
163 | if (destroyRequested) | 214 | if (destroyRequested || null == client) |
164 | throw new AssertionError("already destroyed"); | 215 | throw new AssertionError("already destroyed"); |
165 | WatchRequest r = new WatchRequest(subsystem, name, watcher); | 216 | WatchRequest r = new WatchRequest(subsystem, name, watcher); |
166 | return watchRequests.addRequest(wid++, r); | 217 | return watchRequests.addRequest(nextWatchId++, r); |
167 | } | 218 | } |
168 | 219 | ||
220 | |||
169 | /** | 221 | /** |
170 | * Destroy handle to the statistics service. Always finishes writing pending values. | 222 | * Destroy handle to the statistics service. Always finishes writing pending values. |
171 | */ | 223 | */ |
172 | public void destroy() { | 224 | public void destroy() { |
173 | destroyRequested = true; | 225 | destroy(true); |
174 | client.send(new TestMessage()); | ||
175 | // wait until the service responds | ||
176 | // TODO: or timeout | ||
177 | System.out.println("destroying statistics"); | ||
178 | } | 226 | } |
179 | 227 | ||
180 | |||
181 | /** | 228 | /** |
182 | * Statistics command line utility entry point | 229 | * Destroy handle to the statistics service. Always finishes writing pending values. |
183 | * | 230 | * |
184 | * @param args command line arguments | 231 | * @param syncFirst Wait until the statistics service has received all our updates. |
185 | */ | 232 | */ |
186 | public static void main(String[] args) { | 233 | public void destroy(boolean syncFirst) { |
187 | new Program(args) { | 234 | if (destroyRequested) |
188 | @Argument( | 235 | throw new AssertionError("already destroyed"); |
189 | shortname = "x", | 236 | destroyRequested = true; |
190 | longname = "set", | 237 | logger.debug("destroying statistics"); |
191 | action = ArgumentAction.SET, | 238 | if (!syncFirst || !client.isConnected()) { |
192 | description = "watch a value") | 239 | client.disconnect(); |
193 | boolean set; | 240 | client = null; |
194 | @Argument( | 241 | return; |
195 | shortname = "w", | 242 | } |
196 | longname = "watch", | 243 | client.send(new TestMessage()); |
197 | action = ArgumentAction.SET, | 244 | // wait until the service responds or a timeout occurs |
198 | description = "set a value") | 245 | destroyTimeout = Scheduler.addDelayed(RelativeTime.fromSeconds(5), new Scheduler.Task() { |
199 | boolean watch; | ||
200 | @Argument( | ||
201 | shortname = "n", | ||
202 | longname = "name", | ||
203 | action = ArgumentAction.STORE_STRING, | ||
204 | argumentName = "NAME", | ||
205 | description = "statistics name") | ||
206 | String statisticsName = ""; | ||
207 | @Argument( | ||
208 | shortname = "s", | ||
209 | longname = "subsystem", | ||
210 | argumentName = "SUBSYS", | ||
211 | action = ArgumentAction.STORE_STRING, | ||
212 | description = "subsystem name") | ||
213 | String subsystemName = ""; | ||
214 | @Argument( | ||
215 | shortname = "p", | ||
216 | longname = "persistent", | ||
217 | action = ArgumentAction.SET, | ||
218 | description = "set value persistently (used with -x)") | ||
219 | boolean persistent = false; | ||
220 | @Argument( | ||
221 | shortname = "r", | ||
222 | longname = "relative", | ||
223 | action = ArgumentAction.SET, | ||
224 | description = "set value relative to old value (used with -x)") | ||
225 | boolean relative = false; | ||
226 | |||
227 | @Override | 246 | @Override |
228 | protected String makeHelpText() { | 247 | public void run(Scheduler.RunContext ctx) { |
229 | return "Get, set and watch GNUnet's statistics."; | 248 | if (null == client) |
230 | } | ||
231 | |||
232 | public void run() { | ||
233 | final Statistics statistics = new Statistics(cfg); | ||
234 | |||
235 | if (set && watch) { | ||
236 | System.err.println("--watch/-w and --set/-s cannot be used together"); | ||
237 | return; | ||
238 | } | ||
239 | |||
240 | if (set) { | ||
241 | if (subsystemName.isEmpty() || statisticsName.isEmpty()) { | ||
242 | System.err.println("both subsystem and name must be given for --set/-x"); | ||
243 | return; | ||
244 | } | ||
245 | if (unprocessedArgs.length != 1) { | ||
246 | System.err.println("must specify exactly one value to set"); | ||
247 | return; | ||
248 | } | ||
249 | long value; | ||
250 | try { | ||
251 | value = Long.parseLong(unprocessedArgs[0]); | ||
252 | } catch (NumberFormatException e) { | ||
253 | System.err.println("invalid value (not a long)"); | ||
254 | return; | ||
255 | } | ||
256 | if (relative) | ||
257 | statistics.update(subsystemName, statisticsName, value, persistent); | ||
258 | else | ||
259 | statistics.set(subsystemName, statisticsName, value, persistent); | ||
260 | statistics.destroy(); | ||
261 | return; | 249 | return; |
262 | } | 250 | client.disconnect(); |
263 | 251 | client = null; | |
264 | if (unprocessedArgs.length != 0) { | ||
265 | System.err.println("dumping statistics does not take any positional parameters"); | ||
266 | return; | ||
267 | } | ||
268 | |||
269 | if (watch) { | ||
270 | if (subsystemName.isEmpty() || statisticsName.isEmpty()) { | ||
271 | System.err.println("both subsystem and name must be given for --watch/-w"); | ||
272 | return; | ||
273 | } | ||
274 | statistics.watch(subsystemName, statisticsName, | ||
275 | new StatisticsWatcher() { | ||
276 | @Override | ||
277 | public void onReceive(String subsystem, String name, long value) { | ||
278 | System.out.println(subsystem + "(" + name + ") = " + value); | ||
279 | } | ||
280 | |||
281 | @Override | ||
282 | public void onTimeout() { | ||
283 | System.err.println("timeout"); | ||
284 | } | ||
285 | } | ||
286 | ); | ||
287 | } else { | ||
288 | statistics.get(RelativeTime.SECOND, subsystemName, statisticsName, | ||
289 | new StatisticsReceiver() { | ||
290 | @Override | ||
291 | public void onReceive(String subsystem, String name, long value) { | ||
292 | System.out.println(subsystem + "(" + name + ") = " + value); | ||
293 | } | ||
294 | |||
295 | @Override | ||
296 | public void onTimeout() { | ||
297 | System.err.println("timeout"); | ||
298 | } | ||
299 | |||
300 | @Override | ||
301 | public void onDone() { | ||
302 | statistics.destroy(); | ||
303 | } | ||
304 | } | ||
305 | ); | ||
306 | } | ||
307 | } | 252 | } |
308 | }.start(); | 253 | }); |
309 | } | 254 | } |
310 | } | 255 | } |
diff --git a/src/main/java/org/gnunet/statistics/StatisticsWatcher.java b/src/main/java/org/gnunet/statistics/StatisticsWatcher.java index b6c5f9e..11328b7 100644 --- a/src/main/java/org/gnunet/statistics/StatisticsWatcher.java +++ b/src/main/java/org/gnunet/statistics/StatisticsWatcher.java | |||
@@ -2,5 +2,4 @@ package org.gnunet.statistics; | |||
2 | 2 | ||
3 | public interface StatisticsWatcher { | 3 | public interface StatisticsWatcher { |
4 | public void onReceive(String subsystem, String name, long value); | 4 | public void onReceive(String subsystem, String name, long value); |
5 | public void onTimeout(); | ||
6 | } | 5 | } |
diff --git a/src/main/java/org/gnunet/statistics/WatchRequest.java b/src/main/java/org/gnunet/statistics/WatchRequest.java index 49e1615..784aa5e 100644 --- a/src/main/java/org/gnunet/statistics/WatchRequest.java +++ b/src/main/java/org/gnunet/statistics/WatchRequest.java | |||
@@ -1,15 +1,14 @@ | |||
1 | package org.gnunet.statistics; | 1 | package org.gnunet.statistics; |
2 | 2 | ||
3 | import org.gnunet.mq.Envelope; | 3 | import org.gnunet.mq.Envelope; |
4 | import org.gnunet.mq.MessageQueue; | 4 | import org.gnunet.requests.Request; |
5 | import org.gnunet.requests.RequestContainer; | 5 | import org.gnunet.statistics.messages.WatchMessage; |
6 | 6 | ||
7 | /** | 7 | |
8 | */ | 8 | class WatchRequest extends Request { |
9 | public class WatchRequest extends RequestContainer.Request { | 9 | public final String subsystem; |
10 | public String subsystem; | 10 | public final String name; |
11 | public String name; | 11 | public final StatisticsWatcher watcher; |
12 | public StatisticsWatcher watcher; | ||
13 | 12 | ||
14 | public WatchRequest(String subsystem, String name, StatisticsWatcher watcher) { | 13 | public WatchRequest(String subsystem, String name, StatisticsWatcher watcher) { |
15 | this.subsystem = subsystem; | 14 | this.subsystem = subsystem; |
@@ -25,7 +24,9 @@ public class WatchRequest extends RequestContainer.Request { | |||
25 | return new Envelope(m); | 24 | return new Envelope(m); |
26 | } | 25 | } |
27 | 26 | ||
27 | @Override | ||
28 | public void cancel() { | 28 | public void cancel() { |
29 | 29 | // do nothing, incoming changes with the watch id of this request | |
30 | // will simply be ignured | ||
30 | } | 31 | } |
31 | } | 32 | } |
diff --git a/src/main/java/org/gnunet/statistics/package-info.java b/src/main/java/org/gnunet/statistics/package-info.java index fce59e7..6d3cb6f 100644 --- a/src/main/java/org/gnunet/statistics/package-info.java +++ b/src/main/java/org/gnunet/statistics/package-info.java | |||
@@ -19,6 +19,6 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * API for the gnunet statistics service. | 22 | * API for the GNUnet statistics service. |
23 | */ | 23 | */ |
24 | package org.gnunet.statistics; | 24 | package org.gnunet.statistics; |
diff --git a/src/main/java/org/gnunet/testbed/Controller.java b/src/main/java/org/gnunet/testbed/Controller.java index 1e78e2a..da3143b 100644 --- a/src/main/java/org/gnunet/testbed/Controller.java +++ b/src/main/java/org/gnunet/testbed/Controller.java | |||
@@ -21,7 +21,8 @@ package org.gnunet.testbed; | |||
21 | 21 | ||
22 | import org.gnunet.mq.Envelope; | 22 | import org.gnunet.mq.Envelope; |
23 | import org.gnunet.requests.MatchingRequestContainer; | 23 | import org.gnunet.requests.MatchingRequestContainer; |
24 | import org.gnunet.requests.RequestContainer; | 24 | import org.gnunet.requests.Request; |
25 | import org.gnunet.requests.RequestIdentifier; | ||
25 | import org.gnunet.testbed.callbacks.*; | 26 | import org.gnunet.testbed.callbacks.*; |
26 | import org.gnunet.testbed.messages.*; | 27 | import org.gnunet.testbed.messages.*; |
27 | import org.gnunet.util.*; | 28 | import org.gnunet.util.*; |
@@ -82,7 +83,7 @@ public class Controller { | |||
82 | */ | 83 | */ |
83 | private MatchingRequestContainer<Long,OperationRequest> requests; | 84 | private MatchingRequestContainer<Long,OperationRequest> requests; |
84 | 85 | ||
85 | abstract class OperationRequest extends RequestContainer.Request { | 86 | abstract class OperationRequest extends Request { |
86 | protected final long operationId; | 87 | protected final long operationId; |
87 | public OperationRequest() { | 88 | public OperationRequest() { |
88 | operationId = (((long) host.id) << 32) | (long) operationCounter++; | 89 | operationId = (((long) host.id) << 32) | (long) operationCounter++; |
@@ -121,7 +122,7 @@ public class Controller { | |||
121 | m.peerId = peerId; | 122 | m.peerId = peerId; |
122 | m.compressedConfig = ccfg.compressedData; | 123 | m.compressedConfig = ccfg.compressedData; |
123 | m.configSize = ccfg.getUncompressedSize(); | 124 | m.configSize = ccfg.getUncompressedSize(); |
124 | System.out.println("create request with opid " + m.operationId); | 125 | System.out.println("create getRequestIdentifier with opid " + m.operationId); |
125 | return new Envelope(m); | 126 | return new Envelope(m); |
126 | } | 127 | } |
127 | } | 128 | } |
@@ -139,7 +140,7 @@ public class Controller { | |||
139 | m.operationId = operationId; | 140 | m.operationId = operationId; |
140 | m.peerId = peerId; | 141 | m.peerId = peerId; |
141 | 142 | ||
142 | System.out.println("destroy request with opid " + m.operationId); | 143 | System.out.println("destroy getRequestIdentifier with opid " + m.operationId); |
143 | return new Envelope(m); | 144 | return new Envelope(m); |
144 | } | 145 | } |
145 | } | 146 | } |
@@ -263,9 +264,10 @@ public class Controller { | |||
263 | 264 | ||
264 | public class ControllerMessageReceiver extends RunaboutMessageReceiver { | 265 | public class ControllerMessageReceiver extends RunaboutMessageReceiver { |
265 | public void visit(PeerEventMessage m) { | 266 | public void visit(PeerEventMessage m) { |
266 | RequestContainer.Request r = requests.getRequest(m.operationId); | 267 | RequestIdentifier<OperationRequest> rId = requests.getRequestIdentifier(m.operationId); |
268 | OperationRequest r = rId.getRequest(); | ||
267 | if (null == r) { | 269 | if (null == r) { |
268 | logger.error("no matching peer event request for op id %s", m.operationId); | 270 | logger.error("no matching peer event getRequestIdentifier for op id %s", m.operationId); |
269 | return; | 271 | return; |
270 | } | 272 | } |
271 | if (r instanceof PeerStartRequest && m.eventType == EventTypes.PEER_START) { | 273 | if (r instanceof PeerStartRequest && m.eventType == EventTypes.PEER_START) { |
@@ -275,14 +277,15 @@ public class Controller { | |||
275 | PeerStopRequest psr = (PeerStopRequest) r; | 277 | PeerStopRequest psr = (PeerStopRequest) r; |
276 | psr.peerChurnCallback.onChurnSuccess(); | 278 | psr.peerChurnCallback.onChurnSuccess(); |
277 | } else { | 279 | } else { |
278 | logger.error("unexpected peer event message, event type %s and request %s", | 280 | logger.error("unexpected peer event message, event type %s and getRequestIdentifier %s", |
279 | m.eventType, r); | 281 | m.eventType, r); |
280 | } | 282 | } |
281 | } | 283 | } |
282 | public void visit(PeerCreateSuccessMessage m) { | 284 | public void visit(PeerCreateSuccessMessage m) { |
283 | RequestContainer.Request r = requests.getRequest(m.operationId); | 285 | RequestIdentifier<OperationRequest> rId = requests.getRequestIdentifier(m.operationId); |
286 | OperationRequest r = rId.getRequest(); | ||
284 | if (!(r instanceof PeerCreateRequest)) { | 287 | if (!(r instanceof PeerCreateRequest)) { |
285 | logger.warn("response to peer create request does not match"); | 288 | logger.warn("response to peer create getRequestIdentifier does not match"); |
286 | return; | 289 | return; |
287 | } | 290 | } |
288 | PeerCreateRequest pcr = (PeerCreateRequest) r; | 291 | PeerCreateRequest pcr = (PeerCreateRequest) r; |
@@ -290,13 +293,14 @@ public class Controller { | |||
290 | pcr.cb.onPeerCreated(p); | 293 | pcr.cb.onPeerCreated(p); |
291 | } | 294 | } |
292 | public void visit(PeerInformationMessage m) { | 295 | public void visit(PeerInformationMessage m) { |
293 | RequestContainer.Request r = requests.getRequest(m.operationId); | 296 | RequestIdentifier<OperationRequest> rId = requests.getRequestIdentifier(m.operationId); |
297 | OperationRequest r = rId.getRequest(); | ||
294 | if (null == r) { | 298 | if (null == r) { |
295 | logger.error("unexpected peer information message (opid={})", m.operationId); | 299 | logger.error("unexpected peer information message (opid={})", m.operationId); |
296 | return; | 300 | return; |
297 | } | 301 | } |
298 | if (!(r instanceof PeerInformationRequest)) { | 302 | if (!(r instanceof PeerInformationRequest)) { |
299 | logger.warn("response to peer create request does not match"); | 303 | logger.warn("response to peer create getRequestIdentifier does not match"); |
300 | return; | 304 | return; |
301 | } | 305 | } |
302 | PeerInformationRequest pir = (PeerInformationRequest) r; | 306 | PeerInformationRequest pir = (PeerInformationRequest) r; |
@@ -304,14 +308,15 @@ public class Controller { | |||
304 | pir.cb.onSuccess(m.peerIdentity, ccfg.decompress()); | 308 | pir.cb.onSuccess(m.peerIdentity, ccfg.decompress()); |
305 | } | 309 | } |
306 | public void visit(GenericOperationSuccessMessage m) { | 310 | public void visit(GenericOperationSuccessMessage m) { |
307 | OperationRequest r = requests.getRequest(m.operationId); | 311 | RequestIdentifier<OperationRequest> rId = requests.getRequestIdentifier(m.operationId); |
312 | OperationRequest r = rId.getRequest(); | ||
308 | if (null == r) { | 313 | if (null == r) { |
309 | logger.error("unexpected generic success message (opid={})", m.operationId); | 314 | logger.error("unexpected generic success message (opid={})", m.operationId); |
310 | return; | 315 | return; |
311 | } | 316 | } |
312 | if (!(r instanceof GenericOperationRequest)) { | 317 | if (!(r instanceof GenericOperationRequest)) { |
313 | logger.error(String.format( | 318 | logger.error(String.format( |
314 | "got GenericOperationSuccessMessage as response to request '%s', opid %s; event type %s", | 319 | "got GenericOperationSuccessMessage as response to getRequestIdentifier '%s', opid %s; event type %s", |
315 | r.getClass(), m.operationId, m.eventType)); | 320 | r.getClass(), m.operationId, m.eventType)); |
316 | return; | 321 | return; |
317 | } | 322 | } |
@@ -319,7 +324,8 @@ public class Controller { | |||
319 | gr.onSuccess(); | 324 | gr.onSuccess(); |
320 | } | 325 | } |
321 | public void visit(ConnectionEventMessage m) { | 326 | public void visit(ConnectionEventMessage m) { |
322 | OperationRequest r = requests.getRequest(m.operationId); | 327 | RequestIdentifier<OperationRequest> rId = requests.getRequestIdentifier(m.operationId); |
328 | OperationRequest r = rId.getRequest(); | ||
323 | if (null == r) { | 329 | if (null == r) { |
324 | logger.error("unexpected connection event message (opid={})", m.operationId); | 330 | logger.error("unexpected connection event message (opid={})", m.operationId); |
325 | return; | 331 | return; |
@@ -408,7 +414,7 @@ public class Controller { | |||
408 | /** | 414 | /** |
409 | * Create a link from slave controller to delegated controller. Whenever the | 415 | * Create a link from slave controller to delegated controller. Whenever the |
410 | * master controller is asked to start a peer at the delegated controller the | 416 | * master controller is asked to start a peer at the delegated controller the |
411 | * request will be routed towards slave controller (if a route exists). The | 417 | * getRequestIdentifier will be routed towards slave controller (if a route exists). The |
412 | * slave controller will then route it to the delegated controller. The | 418 | * slave controller will then route it to the delegated controller. The |
413 | * configuration of the delegated controller is given and is used to either | 419 | * configuration of the delegated controller is given and is used to either |
414 | * create the delegated controller or to connect to an existing controller. Note | 420 | * create the delegated controller or to connect to an existing controller. Note |
@@ -445,7 +451,7 @@ public class Controller { | |||
445 | * @param cc the completion callback to call to inform the status of | 451 | * @param cc the completion callback to call to inform the status of |
446 | * registration. After calling this callback the registration handle | 452 | * registration. After calling this callback the registration handle |
447 | * will be invalid. Cannot be NULL | 453 | * will be invalid. Cannot be NULL |
448 | * @return handle to the host registration which can be used to cancel the | 454 | * @return handle to the host registration which can be used to onCancel the |
449 | * registration; NULL if another registration handle is present and | 455 | * registration; NULL if another registration handle is present and |
450 | * is not cancelled | 456 | * is not cancelled |
451 | */ | 457 | */ |
@@ -475,7 +481,7 @@ public class Controller { | |||
475 | * Start this peer | 481 | * Start this peer |
476 | * | 482 | * |
477 | * @param peerChurnCallback completion callback | 483 | * @param peerChurnCallback completion callback |
478 | * @return handle to cancel the operation | 484 | * @return handle to onCancel the operation |
479 | */ | 485 | */ |
480 | public Cancelable start(PeerChurnCallback peerChurnCallback) { | 486 | public Cancelable start(PeerChurnCallback peerChurnCallback) { |
481 | PeerStartRequest r = new PeerStartRequest(this, peerChurnCallback); | 487 | PeerStartRequest r = new PeerStartRequest(this, peerChurnCallback); |
@@ -486,7 +492,7 @@ public class Controller { | |||
486 | * Stop this peer | 492 | * Stop this peer |
487 | * | 493 | * |
488 | * @param peerChurnCallback completion callback | 494 | * @param peerChurnCallback completion callback |
489 | * @return handle to cancel the operation | 495 | * @return handle to onCancel the operation |
490 | */ | 496 | */ |
491 | public Cancelable stop(PeerChurnCallback peerChurnCallback) { | 497 | public Cancelable stop(PeerChurnCallback peerChurnCallback) { |
492 | PeerStopRequest r = new PeerStopRequest(this, peerChurnCallback); | 498 | PeerStopRequest r = new PeerStopRequest(this, peerChurnCallback); |
@@ -530,7 +536,7 @@ public class Controller { | |||
530 | * | 536 | * |
531 | * @param otherPeer peer to connect this peer to | 537 | * @param otherPeer peer to connect this peer to |
532 | * @param cb callback object to signal completion or failure | 538 | * @param cb callback object to signal completion or failure |
533 | * @return token to cancel the request | 539 | * @return token to onCancel the getRequestIdentifier |
534 | * | 540 | * |
535 | */ | 541 | */ |
536 | public Cancelable connectOverlay(Peer otherPeer, OperationCompletionCallback cb) { | 542 | public Cancelable connectOverlay(Peer otherPeer, OperationCompletionCallback cb) { |
@@ -541,7 +547,7 @@ public class Controller { | |||
541 | 547 | ||
542 | /** | 548 | /** |
543 | * Connect to a service offered by the given peer. Will ensure that | 549 | * Connect to a service offered by the given peer. Will ensure that |
544 | * the request is queued to not overwhelm our ability to create and | 550 | * the getRequestIdentifier is queued to not overwhelm our ability to create and |
545 | * maintain connections with other systems. The actual service | 551 | * maintain connections with other systems. The actual service |
546 | * handle is then returned via the 'op_result' member in the event | 552 | * handle is then returned via the 'op_result' member in the event |
547 | * callback. The 'ca' callback is used to create the connection | 553 | * callback. The 'ca' callback is used to create the connection |
diff --git a/src/main/java/org/gnunet/testing/TestingServer.java b/src/main/java/org/gnunet/testing/TestingServer.java index 97b6bc0..8cda836 100644 --- a/src/main/java/org/gnunet/testing/TestingServer.java +++ b/src/main/java/org/gnunet/testing/TestingServer.java | |||
@@ -5,7 +5,6 @@ import org.gnunet.util.RelativeTime; | |||
5 | import org.gnunet.util.Server; | 5 | import org.gnunet.util.Server; |
6 | 6 | ||
7 | import java.io.IOException; | 7 | import java.io.IOException; |
8 | import java.net.InetAddress; | ||
9 | import java.net.InetSocketAddress; | 8 | import java.net.InetSocketAddress; |
10 | import java.net.SocketAddress; | 9 | import java.net.SocketAddress; |
11 | import java.nio.channels.ServerSocketChannel; | 10 | import java.nio.channels.ServerSocketChannel; |
diff --git a/src/main/java/org/gnunet/testing/TestingSetup.java b/src/main/java/org/gnunet/testing/TestingSetup.java index 6f8d578..276480b 100644 --- a/src/main/java/org/gnunet/testing/TestingSetup.java +++ b/src/main/java/org/gnunet/testing/TestingSetup.java | |||
@@ -21,7 +21,6 @@ | |||
21 | package org.gnunet.testing; | 21 | package org.gnunet.testing; |
22 | 22 | ||
23 | import org.gnunet.util.Program; | 23 | import org.gnunet.util.Program; |
24 | import org.gnunet.util.RelativeTime; | ||
25 | 24 | ||
26 | /** | 25 | /** |
27 | * A testing setup is responsible for configuring the loggers during testing, and can | 26 | * A testing setup is responsible for configuring the loggers during testing, and can |
diff --git a/src/main/java/org/gnunet/transport/Transport.java b/src/main/java/org/gnunet/transport/Transport.java index 6a3da02..eba3678 100644 --- a/src/main/java/org/gnunet/transport/Transport.java +++ b/src/main/java/org/gnunet/transport/Transport.java | |||
@@ -5,7 +5,6 @@ import org.gnunet.mq.Envelope; | |||
5 | import org.gnunet.mq.NotifySentHandler; | 5 | import org.gnunet.mq.NotifySentHandler; |
6 | import org.gnunet.transport.callbacks.HelloUpdateCallback; | 6 | import org.gnunet.transport.callbacks.HelloUpdateCallback; |
7 | import org.gnunet.transport.callbacks.OfferHelloContinuation; | 7 | import org.gnunet.transport.callbacks.OfferHelloContinuation; |
8 | import org.gnunet.transport.callbacks.PeerIterateCallback; | ||
9 | import org.gnunet.transport.callbacks.TryConnectCallback; | 8 | import org.gnunet.transport.callbacks.TryConnectCallback; |
10 | import org.gnunet.transport.messages.RequestConnectMessage; | 9 | import org.gnunet.transport.messages.RequestConnectMessage; |
11 | import org.gnunet.transport.messages.StartMessage; | 10 | import org.gnunet.transport.messages.StartMessage; |
@@ -40,7 +39,7 @@ public class Transport { | |||
40 | private List<GetHelloHolder> getHelloHolderList = new LinkedList<GetHelloHolder>(); | 39 | private List<GetHelloHolder> getHelloHolderList = new LinkedList<GetHelloHolder>(); |
41 | 40 | ||
42 | /** | 41 | /** |
43 | * Wrapper to give each get hello request a unique identity. | 42 | * Wrapper to give each get hello getRequestIdentifier a unique identity. |
44 | */ | 43 | */ |
45 | private class GetHelloHolder { | 44 | private class GetHelloHolder { |
46 | HelloUpdateCallback cb; | 45 | HelloUpdateCallback cb; |
@@ -89,9 +88,9 @@ public class Transport { | |||
89 | * the given peer. | 88 | * the given peer. |
90 | * | 89 | * |
91 | * @param target who we should try to connect to | 90 | * @param target who we should try to connect to |
92 | * @param cb callback to be called when request was transmitted to transport | 91 | * @param cb callback to be called when getRequestIdentifier was transmitted to transport |
93 | * service | 92 | * service |
94 | * @return a handle to cancel the operation | 93 | * @return a handle to onCancel the operation |
95 | */ | 94 | */ |
96 | Cancelable tryConnect(PeerIdentity target, final TryConnectCallback cb) { | 95 | Cancelable tryConnect(PeerIdentity target, final TryConnectCallback cb) { |
97 | RequestConnectMessage m = new RequestConnectMessage(); | 96 | RequestConnectMessage m = new RequestConnectMessage(); |
@@ -119,7 +118,7 @@ public class Transport { | |||
119 | * Obtain the HELLO message for this peer. | 118 | * Obtain the HELLO message for this peer. |
120 | * | 119 | * |
121 | * @param rec function to call with the HELLO | 120 | * @param rec function to call with the HELLO |
122 | * @return handle to cancel the operation | 121 | * @return handle to onCancel the operation |
123 | */ | 122 | */ |
124 | Cancelable getHello(final HelloUpdateCallback rec) { | 123 | Cancelable getHello(final HelloUpdateCallback rec) { |
125 | if (myHello != null) { | 124 | if (myHello != null) { |
diff --git a/src/main/java/org/gnunet/transport/callbacks/PeerAddressListCallback.java b/src/main/java/org/gnunet/transport/callbacks/PeerAddressListCallback.java index 4e3d5ac..12b6d97 100644 --- a/src/main/java/org/gnunet/transport/callbacks/PeerAddressListCallback.java +++ b/src/main/java/org/gnunet/transport/callbacks/PeerAddressListCallback.java | |||
@@ -42,7 +42,6 @@ package org.gnunet.transport.callbacks; | |||
42 | 42 | ||
43 | 43 | ||
44 | import org.gnunet.transport.HelloAddress; | 44 | import org.gnunet.transport.HelloAddress; |
45 | import org.gnunet.util.PeerIdentity; | ||
46 | 45 | ||
47 | public interface PeerAddressListCallback { | 46 | public interface PeerAddressListCallback { |
48 | void onPeerAddress(HelloAddress helloAddress); | 47 | void onPeerAddress(HelloAddress helloAddress); |
diff --git a/src/main/java/org/gnunet/transport/messages/AddressIterateMessage.java b/src/main/java/org/gnunet/transport/messages/AddressIterateMessage.java index 85460e3..c3be994 100644 --- a/src/main/java/org/gnunet/transport/messages/AddressIterateMessage.java +++ b/src/main/java/org/gnunet/transport/messages/AddressIterateMessage.java | |||
@@ -4,7 +4,6 @@ package org.gnunet.transport.messages; | |||
4 | import org.gnunet.construct.NestedMessage; | 4 | import org.gnunet.construct.NestedMessage; |
5 | import org.gnunet.construct.UInt32; | 5 | import org.gnunet.construct.UInt32; |
6 | import org.gnunet.construct.UnionCase; | 6 | import org.gnunet.construct.UnionCase; |
7 | import org.gnunet.util.AbsoluteTime; | ||
8 | import org.gnunet.util.AbsoluteTimeMessage; | 7 | import org.gnunet.util.AbsoluteTimeMessage; |
9 | import org.gnunet.util.GnunetMessage; | 8 | import org.gnunet.util.GnunetMessage; |
10 | import org.gnunet.util.PeerIdentity; | 9 | import org.gnunet.util.PeerIdentity; |
diff --git a/src/main/java/org/gnunet/transport/messages/AddressIterateResponseMessage.java b/src/main/java/org/gnunet/transport/messages/AddressIterateResponseMessage.java index 69f9fd4..dfa4b97 100644 --- a/src/main/java/org/gnunet/transport/messages/AddressIterateResponseMessage.java +++ b/src/main/java/org/gnunet/transport/messages/AddressIterateResponseMessage.java | |||
@@ -20,12 +20,9 @@ | |||
20 | 20 | ||
21 | package org.gnunet.transport.messages; | 21 | package org.gnunet.transport.messages; |
22 | 22 | ||
23 | import org.gnunet.construct.IntegerFill; | ||
24 | import org.gnunet.construct.NestedMessage; | 23 | import org.gnunet.construct.NestedMessage; |
25 | import org.gnunet.construct.UInt32; | ||
26 | import org.gnunet.construct.UnionCase; | 24 | import org.gnunet.construct.UnionCase; |
27 | import org.gnunet.util.GnunetMessage; | 25 | import org.gnunet.util.GnunetMessage; |
28 | import org.gnunet.util.PeerIdentity; | ||
29 | 26 | ||
30 | @UnionCase(383) | 27 | @UnionCase(383) |
31 | public class AddressIterateResponseMessage implements GnunetMessage.Body { | 28 | public class AddressIterateResponseMessage implements GnunetMessage.Body { |
diff --git a/src/main/java/org/gnunet/util/AbsoluteTime.java b/src/main/java/org/gnunet/util/AbsoluteTime.java index 07dd816..b6ab811 100644 --- a/src/main/java/org/gnunet/util/AbsoluteTime.java +++ b/src/main/java/org/gnunet/util/AbsoluteTime.java | |||
@@ -278,7 +278,7 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
278 | } | 278 | } |
279 | 279 | ||
280 | public String toFancyString() { | 280 | public String toFancyString() { |
281 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); | 281 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
282 | return sdf.format(new Date(getMilliseconds())); | 282 | return sdf.format(new Date(getMilliseconds())); |
283 | } | 283 | } |
284 | 284 | ||
diff --git a/src/main/java/org/gnunet/util/Client.java b/src/main/java/org/gnunet/util/Client.java index 02e59aa..5ca60ce 100644 --- a/src/main/java/org/gnunet/util/Client.java +++ b/src/main/java/org/gnunet/util/Client.java | |||
@@ -77,7 +77,7 @@ public class Client extends MessageQueue { | |||
77 | private boolean notifyTransmitReadyDelayed; | 77 | private boolean notifyTransmitReadyDelayed; |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * When notifyTransmitReadyDelayed is true, This can be used to cancel the task | 80 | * When notifyTransmitReadyDelayed is true, This can be used to onCancel the task |
81 | * waiting for the connection to be established. | 81 | * waiting for the connection to be established. |
82 | */ | 82 | */ |
83 | private Cancelable delayedNotifyTransmitHandle; | 83 | private Cancelable delayedNotifyTransmitHandle; |
@@ -91,7 +91,7 @@ public class Client extends MessageQueue { | |||
91 | private boolean receiverActive; | 91 | private boolean receiverActive; |
92 | 92 | ||
93 | /** | 93 | /** |
94 | * Handle to cancel the message currently submitted in the queue, | 94 | * Handle to onCancel the message currently submitted in the queue, |
95 | */ | 95 | */ |
96 | private Cancelable currentSubmit; | 96 | private Cancelable currentSubmit; |
97 | private Scheduler.TaskIdentifier receiverLifenessTask; | 97 | private Scheduler.TaskIdentifier receiverLifenessTask; |
@@ -163,9 +163,9 @@ public class Client extends MessageQueue { | |||
163 | * for example because the protocol is stateless | 163 | * for example because the protocol is stateless |
164 | * @param size size of the message we want to transmit, can be an upper bound | 164 | * @param size size of the message we want to transmit, can be an upper bound |
165 | * @param transmitter the MessageTransmitter object to call once the client is ready to transmit or | 165 | * @param transmitter the MessageTransmitter object to call once the client is ready to transmit or |
166 | * 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 | 166 | * when the timeout is over. Guaranteed to be called *after* notifyTransmitReady has returned. @return a handle that can be used to onCancel the transmit getRequestIdentifier |
167 | * | 167 | * |
168 | * @return a handle to cancel the notification | 168 | * @return a handle to onCancel the notification |
169 | */ | 169 | */ |
170 | public Cancelable notifyTransmitReady(final RelativeTime timeout, | 170 | public Cancelable notifyTransmitReady(final RelativeTime timeout, |
171 | final boolean autoRetry, int size, final MessageTransmitter transmitter) { | 171 | final boolean autoRetry, int size, final MessageTransmitter transmitter) { |
@@ -230,7 +230,7 @@ public class Client extends MessageQueue { | |||
230 | * @param timeout when should we give up sending the message, and call cont.cont(false) | 230 | * @param timeout when should we give up sending the message, and call cont.cont(false) |
231 | * @param message the message to send | 231 | * @param message the message to send |
232 | * @param cont called when the message has been sent successfully or on error | 232 | * @param cont called when the message has been sent successfully or on error |
233 | * @return a handle to cancel sending the message | 233 | * @return a handle to onCancel sending the message |
234 | */ | 234 | */ |
235 | public Cancelable transmitWhenReady(final RelativeTime timeout, final GnunetMessage.Body message, final Continuation cont) { | 235 | public Cancelable transmitWhenReady(final RelativeTime timeout, final GnunetMessage.Body message, final Continuation cont) { |
236 | return notifyTransmitReady(timeout, false, 0, new MessageTransmitter() { | 236 | return notifyTransmitReady(timeout, false, 0, new MessageTransmitter() { |
@@ -256,7 +256,7 @@ public class Client extends MessageQueue { | |||
256 | * | 256 | * |
257 | * @param message the message to send | 257 | * @param message the message to send |
258 | * @param cont called when the message has been sent successfully or on error | 258 | * @param cont called when the message has been sent successfully or on error |
259 | * @return a handle to cancel sending the message | 259 | * @return a handle to onCancel sending the message |
260 | */ | 260 | */ |
261 | public Cancelable transmitWhenReady(final GnunetMessage.Body message, final Continuation cont) { | 261 | public Cancelable transmitWhenReady(final GnunetMessage.Body message, final Continuation cont) { |
262 | return transmitWhenReady(RelativeTime.FOREVER, message, cont); | 262 | return transmitWhenReady(RelativeTime.FOREVER, message, cont); |
@@ -270,12 +270,9 @@ public class Client extends MessageQueue { | |||
270 | } | 270 | } |
271 | 271 | ||
272 | /** | 272 | /** |
273 | * Disconnect from the service. Cancel all pending receive/transmit requests. | 273 | * Disconnect from the service. Cancels all pending receive/transmit requests. |
274 | */ | 274 | */ |
275 | public void disconnect() { | 275 | public void disconnect() { |
276 | if (notifyTransmitReadyDelayed) { | ||
277 | logger.error("disconnecting while notifyTransmitReady is pending"); | ||
278 | } | ||
279 | connection.disconnect(); | 276 | connection.disconnect(); |
280 | connection = null; | 277 | connection = null; |
281 | if (receiverLifenessTask != null) { | 278 | if (receiverLifenessTask != null) { |
diff --git a/src/main/java/org/gnunet/util/Connection.java b/src/main/java/org/gnunet/util/Connection.java index 9e136a8..cce32a4 100644 --- a/src/main/java/org/gnunet/util/Connection.java +++ b/src/main/java/org/gnunet/util/Connection.java | |||
@@ -141,12 +141,12 @@ public class Connection { | |||
141 | } | 141 | } |
142 | 142 | ||
143 | /** | 143 | /** |
144 | * Represents a request for transmission. | 144 | * Represents a getRequestIdentifier for transmission. |
145 | */ | 145 | */ |
146 | public interface TransmitHandle extends Cancelable { | 146 | public interface TransmitHandle extends Cancelable { |
147 | /** | 147 | /** |
148 | * Cancel a request for the transmit ready notification. | 148 | * Cancel a getRequestIdentifier for the transmit ready notification. |
149 | * This does *not* cancel a transmission that already has been started. | 149 | * This does *not* onCancel a transmission that already has been started. |
150 | */ | 150 | */ |
151 | public void cancel(); | 151 | public void cancel(); |
152 | } | 152 | } |
@@ -298,7 +298,7 @@ public class Connection { | |||
298 | } | 298 | } |
299 | // timeout is forever, because there is no way to directly limit the transmission time | 299 | // timeout is forever, because there is no way to directly limit the transmission time |
300 | // of a message, only the max. wait time before transmission. | 300 | // of a message, only the max. wait time before transmission. |
301 | // cancel must be called on the transmitTask if we disconnect | 301 | // onCancel must be called on the transmitTask if we disconnect |
302 | Scheduler.TaskConfiguration tc = new Scheduler.TaskConfiguration(RelativeTime.FOREVER, this); | 302 | Scheduler.TaskConfiguration tc = new Scheduler.TaskConfiguration(RelativeTime.FOREVER, this); |
303 | tc.addSelectEvent(connectionChannel, SelectionKey.OP_WRITE); | 303 | tc.addSelectEvent(connectionChannel, SelectionKey.OP_WRITE); |
304 | this.transmitTask = tc.schedule(); | 304 | this.transmitTask = tc.schedule(); |
@@ -549,7 +549,7 @@ public class Connection { | |||
549 | * @param timeout after how long should we give up (and call transmitter.transmit(null)) | 549 | * @param timeout after how long should we give up (and call transmitter.transmit(null)) |
550 | * @param transmitter the MessageTransmitter object to call once the client is ready to transmit or | 550 | * @param transmitter the MessageTransmitter object to call once the client is ready to transmit or |
551 | * when the timeout is over. Guaranteed to be called *after* notifyTransmitReady has returned. | 551 | * when the timeout is over. Guaranteed to be called *after* notifyTransmitReady has returned. |
552 | * @return a handle that can be used to cancel the transmit request, null if request could be satisfied immediately | 552 | * @return a handle that can be used to onCancel the transmit getRequestIdentifier, null if getRequestIdentifier could be satisfied immediately |
553 | */ | 553 | */ |
554 | public TransmitHandle notifyTransmitReady(int size, RelativeTime timeout, final MessageTransmitter transmitter) { | 554 | public TransmitHandle notifyTransmitReady(int size, RelativeTime timeout, final MessageTransmitter transmitter) { |
555 | if (disconnected) { | 555 | if (disconnected) { |
@@ -557,7 +557,7 @@ public class Connection { | |||
557 | } | 557 | } |
558 | if (nextTransmitHelper != null) { | 558 | if (nextTransmitHelper != null) { |
559 | throw new AssertionError( | 559 | throw new AssertionError( |
560 | "previous transmit request must have completed before calling notifyTransmitReady again"); | 560 | "previous transmit getRequestIdentifier must have completed before calling notifyTransmitReady again"); |
561 | } | 561 | } |
562 | 562 | ||
563 | if (timeout.getMicroseconds() <= 0) { | 563 | if (timeout.getMicroseconds() <= 0) { |
@@ -593,7 +593,7 @@ public class Connection { | |||
593 | * @param cont continuation to call | 593 | * @param cont continuation to call |
594 | * @return | 594 | * @return |
595 | */ | 595 | */ |
596 | /* package-protected */ Cancelable notifyConnected(RelativeTime timeout, final Continuation cont) { | 596 | Cancelable notifyConnected(RelativeTime timeout, final Continuation cont) { |
597 | if (notifyConnectedTimeout != null) { | 597 | if (notifyConnectedTimeout != null) { |
598 | throw new AssertionError(); | 598 | throw new AssertionError(); |
599 | } | 599 | } |
@@ -621,6 +621,10 @@ public class Connection { | |||
621 | logger.error("disconnect called twice"); | 621 | logger.error("disconnect called twice"); |
622 | } | 622 | } |
623 | disconnected = true; | 623 | disconnected = true; |
624 | if (notifyConnectedTimeout != null) { | ||
625 | notifyConnectedTimeout.cancel(); | ||
626 | notifyConnectedTimeout = null; | ||
627 | } | ||
624 | if (receiveTaskId != null) { | 628 | if (receiveTaskId != null) { |
625 | receiveTaskId.cancel(); | 629 | receiveTaskId.cancel(); |
626 | receiveTaskId = null; | 630 | receiveTaskId = null; |
diff --git a/src/main/java/org/gnunet/util/Helper.java b/src/main/java/org/gnunet/util/Helper.java index 8256ab9..1462cf2 100644 --- a/src/main/java/org/gnunet/util/Helper.java +++ b/src/main/java/org/gnunet/util/Helper.java | |||
@@ -26,7 +26,6 @@ import org.gnunet.mq.MessageQueue; | |||
26 | import org.slf4j.Logger; | 26 | import org.slf4j.Logger; |
27 | import org.slf4j.LoggerFactory; | 27 | import org.slf4j.LoggerFactory; |
28 | 28 | ||
29 | import java.io.ByteArrayOutputStream; | ||
30 | import java.io.IOError; | 29 | import java.io.IOError; |
31 | import java.io.IOException; | 30 | import java.io.IOException; |
32 | import java.nio.ByteBuffer; | 31 | import java.nio.ByteBuffer; |
diff --git a/src/main/java/org/gnunet/util/MessageStreamTokenizer.java b/src/main/java/org/gnunet/util/MessageStreamTokenizer.java index a2da4c9..9beb632 100644 --- a/src/main/java/org/gnunet/util/MessageStreamTokenizer.java +++ b/src/main/java/org/gnunet/util/MessageStreamTokenizer.java | |||
@@ -26,12 +26,8 @@ import org.gnunet.construct.ProtocolViolationException; | |||
26 | import org.slf4j.Logger; | 26 | import org.slf4j.Logger; |
27 | import org.slf4j.LoggerFactory; | 27 | import org.slf4j.LoggerFactory; |
28 | 28 | ||
29 | import java.io.IOError; | ||
30 | import java.io.IOException; | 29 | import java.io.IOException; |
31 | import java.nio.ByteBuffer; | 30 | import java.nio.ByteBuffer; |
32 | import java.nio.channels.Channel; | ||
33 | import java.nio.channels.ClosedChannelException; | ||
34 | import java.nio.channels.Pipe; | ||
35 | import java.nio.channels.ReadableByteChannel; | 31 | import java.nio.channels.ReadableByteChannel; |
36 | 32 | ||
37 | /** | 33 | /** |
diff --git a/src/main/java/org/gnunet/util/MessageTransmitter.java b/src/main/java/org/gnunet/util/MessageTransmitter.java index 54a6555..2b63c8c 100644 --- a/src/main/java/org/gnunet/util/MessageTransmitter.java +++ b/src/main/java/org/gnunet/util/MessageTransmitter.java | |||
@@ -35,9 +35,9 @@ public interface MessageTransmitter { | |||
35 | 35 | ||
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Called when the transmit request could not be fullfilled. | 38 | * Called when the transmit getRequestIdentifier could not be fullfilled. |
39 | * | 39 | * |
40 | * After transmit has been called, handleError will not be called anymore (until the next transmit request) | 40 | * After transmit has been called, handleError will not be called anymore (until the next transmit getRequestIdentifier) |
41 | */ | 41 | */ |
42 | void handleError(); | 42 | void handleError(); |
43 | } | 43 | } |
diff --git a/src/main/java/org/gnunet/util/Program.java b/src/main/java/org/gnunet/util/Program.java index faacbe1..31b4924 100644 --- a/src/main/java/org/gnunet/util/Program.java +++ b/src/main/java/org/gnunet/util/Program.java | |||
@@ -73,30 +73,18 @@ public abstract class Program { | |||
73 | action = ArgumentAction.STORE_STRING) | 73 | action = ArgumentAction.STORE_STRING) |
74 | public String logFile; | 74 | public String logFile; |
75 | 75 | ||
76 | 76 | /** | |
77 | * Positional arguments, excluding those that have been processed | ||
78 | * by the command line parser. | ||
79 | */ | ||
77 | protected String[] unprocessedArgs; | 80 | protected String[] unprocessedArgs; |
78 | 81 | ||
79 | private final String[] args; | ||
80 | |||
81 | private int returnValue = 0; | ||
82 | |||
83 | |||
84 | /** | 82 | /** |
85 | * A program with the desired environment for a GNUnet utility. | 83 | * Return value for the program. |
86 | * While executing, the scheduler is guaranteed to run, command arguments are parsed, | 84 | * We prefer setting the return value, as System.exit(...) does bad things sometimes. |
87 | * the default configuration is loaded and the DNS Resolver is initialized. | 85 | * (In JUnit test cases, for instance) |
88 | * | ||
89 | * @param args array of command line arguments to parse. used to automatically load additional settings | ||
90 | * and configure log levels. | ||
91 | */ | 86 | */ |
92 | public Program(String... args) { | 87 | private int returnValue = 0; |
93 | this.args = args; | ||
94 | |||
95 | /* | ||
96 | * Remember: We can't parse command line arguments here, as java's initialization order | ||
97 | * dictates that member variables of subclasses are initialized *after* the superclass constructor (here). | ||
98 | */ | ||
99 | } | ||
100 | 88 | ||
101 | /** | 89 | /** |
102 | * Configure logging with the given log level and log file. | 90 | * Configure logging with the given log level and log file. |
@@ -202,7 +190,7 @@ public abstract class Program { | |||
202 | * is invoked inside a scheduler task or not | 190 | * is invoked inside a scheduler task or not |
203 | * @return the exit value of the program | 191 | * @return the exit value of the program |
204 | */ | 192 | */ |
205 | public final int start(boolean withScheduler) { | 193 | public final int start(boolean withScheduler, String... args) { |
206 | Parser optParser = new Parser(this); | 194 | Parser optParser = new Parser(this); |
207 | unprocessedArgs = optParser.parse(args); | 195 | unprocessedArgs = optParser.parse(args); |
208 | 196 | ||
@@ -246,8 +234,8 @@ public abstract class Program { | |||
246 | * | 234 | * |
247 | * @return the exit value of the program | 235 | * @return the exit value of the program |
248 | */ | 236 | */ |
249 | public final int start() { | 237 | public final int start(String... args) { |
250 | return start(true); | 238 | return start(true, args); |
251 | } | 239 | } |
252 | 240 | ||
253 | 241 | ||
@@ -256,7 +244,7 @@ public abstract class Program { | |||
256 | * | 244 | * |
257 | * @return the exit value of the program | 245 | * @return the exit value of the program |
258 | */ | 246 | */ |
259 | public final int startWithoutScheduler() { | 247 | public final int startWithoutScheduler(String... args) { |
260 | return start(false); | 248 | return start(false, args); |
261 | } | 249 | } |
262 | } | 250 | } |
diff --git a/src/main/java/org/gnunet/util/RelativeTime.java b/src/main/java/org/gnunet/util/RelativeTime.java index fec8f80..188d9ac 100644 --- a/src/main/java/org/gnunet/util/RelativeTime.java +++ b/src/main/java/org/gnunet/util/RelativeTime.java | |||
@@ -236,4 +236,9 @@ public final class RelativeTime implements Comparable<RelativeTime> { | |||
236 | public long getSeconds() { | 236 | public long getSeconds() { |
237 | return rel_value_us / (1000 * 1000); | 237 | return rel_value_us / (1000 * 1000); |
238 | } | 238 | } |
239 | |||
240 | public static RelativeTime fromSeconds(long i) { | ||
241 | RelativeTime relativeTime = new RelativeTime(i * 1000 * 1000); | ||
242 | return relativeTime; | ||
243 | } | ||
239 | } | 244 | } |
diff --git a/src/main/java/org/gnunet/util/Resolver.java b/src/main/java/org/gnunet/util/Resolver.java index 3ddcfa4..f6c2e00 100644 --- a/src/main/java/org/gnunet/util/Resolver.java +++ b/src/main/java/org/gnunet/util/Resolver.java | |||
@@ -22,7 +22,6 @@ package org.gnunet.util; | |||
22 | 22 | ||
23 | import com.google.common.net.InetAddresses; | 23 | import com.google.common.net.InetAddresses; |
24 | import org.gnunet.construct.*; | 24 | import org.gnunet.construct.*; |
25 | import org.gnunet.construct.ProtocolViolationException; | ||
26 | import org.gnunet.util.getopt.Argument; | 25 | import org.gnunet.util.getopt.Argument; |
27 | import org.gnunet.util.getopt.ArgumentAction; | 26 | import org.gnunet.util.getopt.ArgumentAction; |
28 | import org.slf4j.Logger; | 27 | import org.slf4j.Logger; |
@@ -196,7 +195,7 @@ public class Resolver { | |||
196 | * @param hostname hostname to resolve | 195 | * @param hostname hostname to resolve |
197 | * @param timeout timeout, calls cb.onTimeout on expiratoin | 196 | * @param timeout timeout, calls cb.onTimeout on expiratoin |
198 | * @param cb callback | 197 | * @param cb callback |
199 | * @return a handle to cancel the request, null if request could be satisfied immediately | 198 | * @return a handle to onCancel the getRequestIdentifier, null if getRequestIdentifier could be satisfied immediately |
200 | */ | 199 | */ |
201 | public Cancelable resolveHostname(String hostname, RelativeTime timeout, final AddressCallback cb) { | 200 | public Cancelable resolveHostname(String hostname, RelativeTime timeout, final AddressCallback cb) { |
202 | // try if hostname is numeric IP or loopback | 201 | // try if hostname is numeric IP or loopback |
@@ -352,7 +351,7 @@ public class Resolver { | |||
352 | 351 | ||
353 | 352 | ||
354 | public static void main(final String[] argv) { | 353 | public static void main(final String[] argv) { |
355 | new Program(argv) { | 354 | new Program() { |
356 | @Argument(shortname = "r", longname = "reverse", | 355 | @Argument(shortname = "r", longname = "reverse", |
357 | description = "do reverse dns lookup", | 356 | description = "do reverse dns lookup", |
358 | action = ArgumentAction.SET) | 357 | action = ArgumentAction.SET) |
@@ -411,6 +410,6 @@ public class Resolver { | |||
411 | protected String makeHelpText() { | 410 | protected String makeHelpText() { |
412 | return "tool for forward and reverse DNS lookup"; | 411 | return "tool for forward and reverse DNS lookup"; |
413 | } | 412 | } |
414 | }.start(); | 413 | }.start(argv); |
415 | } | 414 | } |
416 | } | 415 | } |
diff --git a/src/main/java/org/gnunet/util/Scheduler.java b/src/main/java/org/gnunet/util/Scheduler.java index 10b4bcf..ef801dd 100644 --- a/src/main/java/org/gnunet/util/Scheduler.java +++ b/src/main/java/org/gnunet/util/Scheduler.java | |||
@@ -214,7 +214,7 @@ public class Scheduler { | |||
214 | } | 214 | } |
215 | } | 215 | } |
216 | for (TaskIdentifier tt : executableTasks) { | 216 | for (TaskIdentifier tt : executableTasks) { |
217 | // cancel subscriptions to other events, we can execute now! | 217 | // onCancel subscriptions to other events, we can execute now! |
218 | tt.deregister(); | 218 | tt.deregister(); |
219 | queueReady(tt); | 219 | queueReady(tt); |
220 | } | 220 | } |
@@ -548,7 +548,7 @@ public class Scheduler { | |||
548 | @Override | 548 | @Override |
549 | public void cancel() { | 549 | public void cancel() { |
550 | if (hasRun) { | 550 | if (hasRun) { |
551 | throw new AssertionError("can't cancel task that already ran"); | 551 | throw new AssertionError("can't onCancel task that already ran"); |
552 | } | 552 | } |
553 | if (isCanceled) { | 553 | if (isCanceled) { |
554 | throw new AssertionError("task canceled twice"); | 554 | throw new AssertionError("task canceled twice"); |
@@ -557,7 +557,7 @@ public class Scheduler { | |||
557 | scheduler.pending.remove(this); | 557 | scheduler.pending.remove(this); |
558 | } | 558 | } |
559 | 559 | ||
560 | public void deregister() { | 560 | private void deregister() { |
561 | if (subscriptions != null) { | 561 | if (subscriptions != null) { |
562 | subscriptions.stop(this); | 562 | subscriptions.stop(this); |
563 | } | 563 | } |
@@ -578,7 +578,7 @@ public class Scheduler { | |||
578 | private SchedulerInstance scheduler; | 578 | private SchedulerInstance scheduler; |
579 | 579 | ||
580 | /** | 580 | /** |
581 | * Create a TaskIdentifier. | 581 | * Create a TaskConfiguration. |
582 | * | 582 | * |
583 | * @param delay when will the task be run? | 583 | * @param delay when will the task be run? |
584 | * may be null to indicate that this task may not be run | 584 | * may be null to indicate that this task may not be run |
@@ -593,7 +593,7 @@ public class Scheduler { | |||
593 | this.deadline = delay.toAbsolute(); | 593 | this.deadline = delay.toAbsolute(); |
594 | } | 594 | } |
595 | 595 | ||
596 | TaskConfiguration(RelativeTime delay, Task task) { | 596 | public TaskConfiguration(RelativeTime delay, Task task) { |
597 | this(threadScheduler.get(), delay, task); | 597 | this(threadScheduler.get(), delay, task); |
598 | } | 598 | } |
599 | 599 | ||
@@ -624,6 +624,10 @@ public class Scheduler { | |||
624 | subscriptions = new Subscriptions(scheduler.selector); | 624 | subscriptions = new Subscriptions(scheduler.selector); |
625 | subscriptions.add(channel, event); | 625 | subscriptions.add(channel, event); |
626 | } | 626 | } |
627 | |||
628 | public void setLifeness(boolean b) { | ||
629 | this.lifeness = b; | ||
630 | } | ||
627 | } | 631 | } |
628 | 632 | ||
629 | /** | 633 | /** |
@@ -651,7 +655,7 @@ public class Scheduler { | |||
651 | * | 655 | * |
652 | * @param delay time to wait until running the task | 656 | * @param delay time to wait until running the task |
653 | * @param task the task to run after delay | 657 | * @param task the task to run after delay |
654 | * @return the TaskIdentifier, can be used to cancel the task until it has been executed. | 658 | * @return the TaskIdentifier, can be used to onCancel the task until it has been executed. |
655 | */ | 659 | */ |
656 | public static TaskIdentifier addDelayed(RelativeTime delay, Task task) { | 660 | public static TaskIdentifier addDelayed(RelativeTime delay, Task task) { |
657 | TaskConfiguration tid = new TaskConfiguration(delay, task); | 661 | TaskConfiguration tid = new TaskConfiguration(delay, task); |
@@ -817,4 +821,11 @@ public class Scheduler { | |||
817 | fpt.start(); | 821 | fpt.start(); |
818 | return new FilePipe(fpt); | 822 | return new FilePipe(fpt); |
819 | } | 823 | } |
824 | |||
825 | public static void debugPrintPendingTasks() { | ||
826 | System.err.println("pending tasks:"); | ||
827 | for (TaskIdentifier i : threadScheduler.get().pending) { | ||
828 | System.err.println(i.task.getClass()); | ||
829 | } | ||
830 | } | ||
820 | } | 831 | } |
diff --git a/src/main/java/org/gnunet/util/Server.java b/src/main/java/org/gnunet/util/Server.java index 4d783a1..ccf977e 100644 --- a/src/main/java/org/gnunet/util/Server.java +++ b/src/main/java/org/gnunet/util/Server.java | |||
@@ -20,7 +20,6 @@ | |||
20 | 20 | ||
21 | package org.gnunet.util; | 21 | package org.gnunet.util; |
22 | 22 | ||
23 | import org.gnunet.construct.Construct; | ||
24 | import org.grothoff.Runabout; | 23 | import org.grothoff.Runabout; |
25 | import org.slf4j.Logger; | 24 | import org.slf4j.Logger; |
26 | import org.slf4j.LoggerFactory; | 25 | import org.slf4j.LoggerFactory; |
@@ -160,7 +159,7 @@ public class Server { | |||
160 | * @param timeout after how long should we give up (and call | 159 | * @param timeout after how long should we give up (and call |
161 | * notify with buf NULL and size 0)? | 160 | * notify with buf NULL and size 0)? |
162 | * @param transmitter callback | 161 | * @param transmitter callback |
163 | * @return a handle to cancel the notification | 162 | * @return a handle to onCancel the notification |
164 | */ | 163 | */ |
165 | public Cancelable notifyTransmitReady(int size, RelativeTime timeout, MessageTransmitter transmitter) { | 164 | public Cancelable notifyTransmitReady(int size, RelativeTime timeout, MessageTransmitter transmitter) { |
166 | return connection.notifyTransmitReady(size, timeout, transmitter); | 165 | return connection.notifyTransmitReady(size, timeout, transmitter); |
@@ -172,7 +171,7 @@ public class Server { | |||
172 | * @param timeout when should we give up sending the message, and call cont.cont(false) | 171 | * @param timeout when should we give up sending the message, and call cont.cont(false) |
173 | * @param message the message to send | 172 | * @param message the message to send |
174 | * @param cont called when the message has been sent successfully or on error | 173 | * @param cont called when the message has been sent successfully or on error |
175 | * @return a handle to cancel sending the message | 174 | * @return a handle to onCancel sending the message |
176 | */ | 175 | */ |
177 | public Cancelable transmitWhenReady(final RelativeTime timeout, final GnunetMessage.Body message, final Continuation cont) { | 176 | public Cancelable transmitWhenReady(final RelativeTime timeout, final GnunetMessage.Body message, final Continuation cont) { |
178 | return notifyTransmitReady(0, timeout, new MessageTransmitter() { | 177 | return notifyTransmitReady(0, timeout, new MessageTransmitter() { |
@@ -195,7 +194,7 @@ public class Server { | |||
195 | 194 | ||
196 | /** | 195 | /** |
197 | * Resume receiving from this client, we are done processing the | 196 | * Resume receiving from this client, we are done processing the |
198 | * current request. This function must be called from within each | 197 | * current getRequestIdentifier. This function must be called from within each |
199 | * message handler (or its respective continuations). | 198 | * message handler (or its respective continuations). |
200 | * <p/> | 199 | * <p/> |
201 | * The server does not automatically continue to receive messages to | 200 | * The server does not automatically continue to receive messages to |
diff --git a/src/main/java/org/gnunet/util/Service.java b/src/main/java/org/gnunet/util/Service.java index a150089..af7529e 100644 --- a/src/main/java/org/gnunet/util/Service.java +++ b/src/main/java/org/gnunet/util/Service.java | |||
@@ -24,7 +24,8 @@ package org.gnunet.util; | |||
24 | import org.slf4j.Logger; | 24 | import org.slf4j.Logger; |
25 | import org.slf4j.LoggerFactory; | 25 | import org.slf4j.LoggerFactory; |
26 | 26 | ||
27 | import java.io.*; | 27 | import java.io.File; |
28 | import java.io.IOException; | ||
28 | import java.net.InetAddress; | 29 | import java.net.InetAddress; |
29 | import java.net.InetSocketAddress; | 30 | import java.net.InetSocketAddress; |
30 | import java.net.SocketAddress; | 31 | import java.net.SocketAddress; |
@@ -56,7 +57,6 @@ public abstract class Service extends Program { | |||
56 | private Pipe.SourceChannel sigpipeChannel; | 57 | private Pipe.SourceChannel sigpipeChannel; |
57 | 58 | ||
58 | public Service(String serviceName, RelativeTime idleTimeout, boolean requireFound, String[] args) { | 59 | public Service(String serviceName, RelativeTime idleTimeout, boolean requireFound, String[] args) { |
59 | super(args); | ||
60 | this.serviceName = serviceName; | 60 | this.serviceName = serviceName; |
61 | this.idleTimeout = idleTimeout; | 61 | this.idleTimeout = idleTimeout; |
62 | this.requireFound = requireFound; | 62 | this.requireFound = requireFound; |
diff --git a/src/main/java/org/gnunet/util/crypto/Ed25519.java b/src/main/java/org/gnunet/util/crypto/Ed25519.java index 673d86d..e335c99 100644 --- a/src/main/java/org/gnunet/util/crypto/Ed25519.java +++ b/src/main/java/org/gnunet/util/crypto/Ed25519.java | |||
@@ -24,7 +24,6 @@ package org.gnunet.util.crypto; | |||
24 | import java.math.BigInteger; | 24 | import java.math.BigInteger; |
25 | import java.security.MessageDigest; | 25 | import java.security.MessageDigest; |
26 | import java.security.NoSuchAlgorithmException; | 26 | import java.security.NoSuchAlgorithmException; |
27 | import java.util.Arrays; | ||
28 | 27 | ||
29 | /** | 28 | /** |
30 | * Java-only implementation of arithmetic on DJBs Ed25519. | 29 | * Java-only implementation of arithmetic on DJBs Ed25519. |
diff --git a/src/main/java/org/gnunet/util/getopt/Parser.java b/src/main/java/org/gnunet/util/getopt/Parser.java index 135e6f8..cd1603a 100644 --- a/src/main/java/org/gnunet/util/getopt/Parser.java +++ b/src/main/java/org/gnunet/util/getopt/Parser.java | |||
@@ -21,6 +21,7 @@ | |||
21 | package org.gnunet.util.getopt; | 21 | package org.gnunet.util.getopt; |
22 | 22 | ||
23 | import org.gnunet.construct.ReflectUtil; | 23 | import org.gnunet.construct.ReflectUtil; |
24 | |||
24 | import java.lang.reflect.Field; | 25 | import java.lang.reflect.Field; |
25 | import java.util.*; | 26 | import java.util.*; |
26 | 27 | ||
diff --git a/src/main/java/org/gnunet/voting/Ballot.java b/src/main/java/org/gnunet/voting/Ballot.java index 10bf25a..92ec7da 100644 --- a/src/main/java/org/gnunet/voting/Ballot.java +++ b/src/main/java/org/gnunet/voting/Ballot.java | |||
@@ -28,8 +28,14 @@ import com.google.common.collect.HashBiMap; | |||
28 | import com.google.common.collect.Maps; | 28 | import com.google.common.collect.Maps; |
29 | import com.google.common.primitives.Longs; | 29 | import com.google.common.primitives.Longs; |
30 | import org.gnunet.secretsharing.ThresholdPublicKey; | 30 | import org.gnunet.secretsharing.ThresholdPublicKey; |
31 | import org.gnunet.util.*; | 31 | import org.gnunet.util.AbsoluteTime; |
32 | import org.gnunet.util.crypto.*; | 32 | import org.gnunet.util.Configuration; |
33 | import org.gnunet.util.HashCode; | ||
34 | import org.gnunet.util.PeerIdentity; | ||
35 | import org.gnunet.util.crypto.EcdsaPrivateKey; | ||
36 | import org.gnunet.util.crypto.EcdsaPublicKey; | ||
37 | import org.gnunet.util.crypto.EcdsaSignature; | ||
38 | import org.gnunet.util.crypto.EddsaSignature; | ||
33 | import org.gnunet.voting.messages.KeyQueryResponseMessage; | 39 | import org.gnunet.voting.messages.KeyQueryResponseMessage; |
34 | 40 | ||
35 | import java.security.MessageDigest; | 41 | import java.security.MessageDigest; |
@@ -263,13 +269,13 @@ public class Ballot { | |||
263 | } | 269 | } |
264 | confirmationSigs.put(e.getKey(), sig); | 270 | confirmationSigs.put(e.getKey(), sig); |
265 | } | 271 | } |
266 | encryptedVote = EncryptedVote.parseFromConfiguration(cfg); | ||
267 | Optional<String> optVoterPub = cfg.getValueString("vote", "VOTER_PUB"); | 272 | Optional<String> optVoterPub = cfg.getValueString("vote", "VOTER_PUB"); |
268 | if (optVoterPub.isPresent()) { | 273 | if (optVoterPub.isPresent()) { |
269 | voterPub = EcdsaPublicKey.fromString(optVoterPub.get()); | 274 | voterPub = EcdsaPublicKey.fromString(optVoterPub.get()); |
270 | if (null == voterPub) { | 275 | if (null == voterPub) { |
271 | throw new InvalidBallotException("voter public key present but invalid"); | 276 | throw new InvalidBallotException("voter public key present but invalid"); |
272 | } | 277 | } |
278 | encryptedVote = EncryptedVote.parseFromConfiguration(cfg, voterPub); | ||
273 | } | 279 | } |
274 | 280 | ||
275 | startTime = getTime(cfg, "START"); | 281 | startTime = getTime(cfg, "START"); |
@@ -302,8 +308,8 @@ public class Ballot { | |||
302 | m.signedGuidKey = new KeyQueryResponseMessage.BallotPublicKey(); | 308 | m.signedGuidKey = new KeyQueryResponseMessage.BallotPublicKey(); |
303 | m.signedGuidKey.ballotGuid = getBallotGuid(); | 309 | m.signedGuidKey.ballotGuid = getBallotGuid(); |
304 | m.signedGuidKey.publicKey = ThresholdPublicKey.fromString(e.getValue()); | 310 | m.signedGuidKey.publicKey = ThresholdPublicKey.fromString(e.getValue()); |
311 | thresholdPublicKeys.put(alias, m); | ||
305 | } | 312 | } |
306 | |||
307 | } | 313 | } |
308 | 314 | ||
309 | /** | 315 | /** |
@@ -355,7 +361,7 @@ public class Ballot { | |||
355 | if (counts.containsKey(pk)) { | 361 | if (counts.containsKey(pk)) { |
356 | counts.put(pk, counts.get(pk) + 1); | 362 | counts.put(pk, counts.get(pk) + 1); |
357 | } else { | 363 | } else { |
358 | counts.put(pk, 0); | 364 | counts.put(pk, 1); |
359 | } | 365 | } |
360 | } | 366 | } |
361 | int maxCount = 0; | 367 | int maxCount = 0; |
@@ -390,11 +396,9 @@ public class Ballot { | |||
390 | i++; | 396 | i++; |
391 | } | 397 | } |
392 | voterPub = voterPrivateKey.getPublicKey(); | 398 | voterPub = voterPrivateKey.getPublicKey(); |
393 | if (choiceId < 0 || choiceId > 1) { | 399 | encryptedVote = EncryptedVote.fromChoice(choiceId, thresholdPublicKey, voterPrivateKey, voterPub); |
394 | throw new InvalidBallotException(String.format("choice '%s' not valid", choice)); | 400 | System.out.println("voter encrypted vote, ciphertext: " + encryptedVote.v.toString()); |
395 | } | 401 | System.out.println("threshold key (of voter): " + thresholdPublicKey.toString()); |
396 | |||
397 | encryptedVote = EncryptedVote.fromChoice(choiceId, thresholdPublicKey, voterPrivateKey); | ||
398 | } | 402 | } |
399 | 403 | ||
400 | /** | 404 | /** |
@@ -442,9 +446,7 @@ public class Ballot { | |||
442 | if (null != groupCert) { | 446 | if (null != groupCert) { |
443 | groupCert.writeBallotConfig(cfg); | 447 | groupCert.writeBallotConfig(cfg); |
444 | } | 448 | } |
445 | System.out.println("thresh set when writing: " + thresholdPublicKeys.size()); | ||
446 | for (Map.Entry<String,KeyQueryResponseMessage> e : thresholdPublicKeys.entrySet()) { | 449 | for (Map.Entry<String,KeyQueryResponseMessage> e : thresholdPublicKeys.entrySet()) { |
447 | System.out.println("writing tresh"); | ||
448 | cfg.setValueString("threshold-pubkeys", e.getKey(), | 450 | cfg.setValueString("threshold-pubkeys", e.getKey(), |
449 | e.getValue().signedGuidKey.publicKey.toString()); | 451 | e.getValue().signedGuidKey.publicKey.toString()); |
450 | cfg.setValueString("threshold-pubkey-sigs", e.getKey(), | 452 | cfg.setValueString("threshold-pubkey-sigs", e.getKey(), |
@@ -560,6 +562,15 @@ public class Ballot { | |||
560 | } else { | 562 | } else { |
561 | buf.append("no voter\n"); | 563 | buf.append("no voter\n"); |
562 | } | 564 | } |
565 | if (thresholdPublicKeys != null && thresholdPublicKeys.size() != 0) { | ||
566 | buf.append("Authorities with threshold public key:\n"); | ||
567 | for (String s : thresholdPublicKeys.keySet()) { | ||
568 | buf.append(s); | ||
569 | buf.append("\n"); | ||
570 | } | ||
571 | } else { | ||
572 | buf.append("no threshold public keys"); | ||
573 | } | ||
563 | return buf.toString(); | 574 | return buf.toString(); |
564 | } | 575 | } |
565 | 576 | ||
diff --git a/src/main/java/org/gnunet/voting/BallotTool.java b/src/main/java/org/gnunet/voting/BallotTool.java index c0767a4..d03e0ea 100644 --- a/src/main/java/org/gnunet/voting/BallotTool.java +++ b/src/main/java/org/gnunet/voting/BallotTool.java | |||
@@ -112,9 +112,9 @@ public class BallotTool extends Program { | |||
112 | 112 | ||
113 | @Argument( | 113 | @Argument( |
114 | shortname = "k", | 114 | shortname = "k", |
115 | longname = "request-key", | 115 | longname = "getRequestIdentifier-key", |
116 | action = ArgumentAction.SET, | 116 | action = ArgumentAction.SET, |
117 | description = "request the threshold public key from authorities") | 117 | description = "getRequestIdentifier the threshold public key from authorities") |
118 | boolean requestKey = false; | 118 | boolean requestKey = false; |
119 | 119 | ||
120 | @Argument( | 120 | @Argument( |
@@ -348,7 +348,8 @@ public class BallotTool extends Program { | |||
348 | } | 348 | } |
349 | ThresholdPublicKey thresholdPublicKey = ballot.getMajorityThresholdPublicKey(); | 349 | ThresholdPublicKey thresholdPublicKey = ballot.getMajorityThresholdPublicKey(); |
350 | if (null == thresholdPublicKey) { | 350 | if (null == thresholdPublicKey) { |
351 | System.err.println("no threshold public key in ballot"); | 351 | System.err.println(String.format("no majority threshold public key in ballot (got keys of %s authorities)", |
352 | (ballot.thresholdPublicKeys == null) ? 0 : ballot.thresholdPublicKeys.size())); | ||
352 | setReturnValue(1); | 353 | setReturnValue(1); |
353 | return; | 354 | return; |
354 | } | 355 | } |
@@ -364,7 +365,7 @@ public class BallotTool extends Program { | |||
364 | } | 365 | } |
365 | Random r = new Random(); | 366 | Random r = new Random(); |
366 | PeerIdentity authority = remainingAuthorities.get(r.nextInt(remainingAuthorities.size())); | 367 | PeerIdentity authority = remainingAuthorities.get(r.nextInt(remainingAuthorities.size())); |
367 | System.out.println("submitting to authority" + authority.toString()); | 368 | System.out.println("submitting to authority " + authority.toString()); |
368 | currentAuthority = authority; | 369 | currentAuthority = authority; |
369 | mesh = new Mesh(cfg, new BallotTunnelEndHandler(), new SubmitReceiver()); | 370 | mesh = new Mesh(cfg, new BallotTunnelEndHandler(), new SubmitReceiver()); |
370 | tunnel = mesh.createTunnel(authority, TallyAuthorityDaemon.MESH_PORT, true, true, null); | 371 | tunnel = mesh.createTunnel(authority, TallyAuthorityDaemon.MESH_PORT, true, true, null); |
@@ -471,14 +472,9 @@ public class BallotTool extends Program { | |||
471 | doCommands(); | 472 | doCommands(); |
472 | } | 473 | } |
473 | } | 474 | } |
474 | |||
475 | private BallotTool(String[] args) { | ||
476 | super(args); | ||
477 | } | ||
478 | |||
479 | public static void main(String args[]) { | 475 | public static void main(String args[]) { |
480 | Program tool = new BallotTool(args); | 476 | Program tool = new BallotTool(); |
481 | int ret = tool.start(); | 477 | int ret = tool.start(args); |
482 | System.exit(ret); | 478 | System.exit(ret); |
483 | } | 479 | } |
484 | } | 480 | } |
diff --git a/src/main/java/org/gnunet/voting/CertifyGroupTool.java b/src/main/java/org/gnunet/voting/CertifyGroupTool.java index ec82eba..37dcd05 100644 --- a/src/main/java/org/gnunet/voting/CertifyGroupTool.java +++ b/src/main/java/org/gnunet/voting/CertifyGroupTool.java | |||
@@ -74,13 +74,9 @@ public class CertifyGroupTool extends Program { | |||
74 | "The resulting certificate file written to standard output."; | 74 | "The resulting certificate file written to standard output."; |
75 | } | 75 | } |
76 | 76 | ||
77 | private CertifyGroupTool(String... args) { | ||
78 | super(args); | ||
79 | } | ||
80 | |||
81 | public static void main(String args[]) { | 77 | public static void main(String args[]) { |
82 | CertifyGroupTool tool = new CertifyGroupTool(args); | 78 | CertifyGroupTool tool = new CertifyGroupTool(); |
83 | int ret = tool.start(); | 79 | int ret = tool.start(args); |
84 | System.exit(ret); | 80 | System.exit(ret); |
85 | } | 81 | } |
86 | 82 | ||
diff --git a/src/main/java/org/gnunet/voting/EncryptedVote.java b/src/main/java/org/gnunet/voting/EncryptedVote.java index bf13a66..6fa0d1f 100644 --- a/src/main/java/org/gnunet/voting/EncryptedVote.java +++ b/src/main/java/org/gnunet/voting/EncryptedVote.java | |||
@@ -28,37 +28,80 @@ import org.gnunet.secretsharing.Ciphertext; | |||
28 | import org.gnunet.secretsharing.Plaintext; | 28 | import org.gnunet.secretsharing.Plaintext; |
29 | import org.gnunet.secretsharing.ThresholdPublicKey; | 29 | import org.gnunet.secretsharing.ThresholdPublicKey; |
30 | import org.gnunet.util.Configuration; | 30 | import org.gnunet.util.Configuration; |
31 | import org.gnunet.util.Strings; | ||
32 | import org.gnunet.util.crypto.EcdsaPrivateKey; | 31 | import org.gnunet.util.crypto.EcdsaPrivateKey; |
32 | import org.gnunet.util.crypto.EcdsaPublicKey; | ||
33 | import org.gnunet.voting.simulation.Voter; | ||
34 | import org.omg.CORBA.DynAnyPackage.Invalid; | ||
33 | 35 | ||
34 | import java.math.BigInteger; | 36 | import java.math.BigInteger; |
35 | 37 | ||
36 | public class EncryptedVote implements Message { | 38 | public class EncryptedVote implements Message { |
37 | // TODO: zero knowledge proof | 39 | @NestedMessage |
38 | // TODO: signature | 40 | public Ciphertext v; |
41 | |||
39 | 42 | ||
40 | @NestedMessage | 43 | @NestedMessage |
41 | Ciphertext v; | 44 | public EcdsaPublicKey voterPublicKey; |
45 | |||
46 | @Override | ||
47 | public boolean equals(Object o) { | ||
48 | if (this == o) return true; | ||
49 | if (o == null || getClass() != o.getClass()) return false; | ||
50 | |||
51 | EncryptedVote that = (EncryptedVote) o; | ||
52 | |||
53 | if (v != null ? !v.equals(that.v) : that.v != null) return false; | ||
54 | if (voterPublicKey != null ? !voterPublicKey.equals(that.voterPublicKey) : that.voterPublicKey != null) | ||
55 | return false; | ||
56 | |||
57 | return true; | ||
58 | } | ||
59 | |||
60 | @Override | ||
61 | public int hashCode() { | ||
62 | int result = v != null ? v.hashCode() : 0; | ||
63 | result = 31 * result + (voterPublicKey != null ? voterPublicKey.hashCode() : 0); | ||
64 | return result; | ||
65 | } | ||
66 | |||
42 | 67 | ||
43 | public static EncryptedVote parseFromConfiguration(Configuration cfg) { | 68 | /** |
69 | * Construct an EncryptedVote by parsing it from the configuration. | ||
70 | * The voter public key must be passed separately. | ||
71 | * | ||
72 | * @param cfg configuration | ||
73 | * @param voterPublicKey public key of the voter | ||
74 | * @return the encrypted vote | ||
75 | */ | ||
76 | public static EncryptedVote parseFromConfiguration(Configuration cfg, EcdsaPublicKey voterPublicKey) { | ||
44 | Optional<String> optVal = cfg.getValueString("vote", "ENCRYPTED_VOTE_VAL"); | 77 | Optional<String> optVal = cfg.getValueString("vote", "ENCRYPTED_VOTE_VAL"); |
45 | if (!optVal.isPresent()) { | 78 | if (!optVal.isPresent()) { |
46 | return null; | 79 | return null; |
47 | } | 80 | } |
48 | EncryptedVote encryptedVote = new EncryptedVote(); | 81 | EncryptedVote encryptedVote = new EncryptedVote(); |
82 | encryptedVote.voterPublicKey = voterPublicKey; | ||
49 | encryptedVote.v = Ciphertext.fromString(optVal.get()); | 83 | encryptedVote.v = Ciphertext.fromString(optVal.get()); |
50 | return encryptedVote; | 84 | return encryptedVote; |
51 | } | 85 | } |
52 | 86 | // TODO: zero knowledge proof | |
53 | public void writeToConfiguration(Configuration cfg) { | 87 | // TODO: signature |
54 | cfg.setValueString("vote", "ENCRYPTED_VOTE_VAL", v.toString()); } | ||
55 | 88 | ||
56 | public static EncryptedVote fromChoice(int choiceId, ThresholdPublicKey thresholdPublicKey, | 89 | public static EncryptedVote fromChoice(int choiceId, ThresholdPublicKey thresholdPublicKey, |
57 | EcdsaPrivateKey voterPrivateKey) { | 90 | EcdsaPrivateKey voterPrivateKey, EcdsaPublicKey voterPublicKey) { |
91 | // for now, we only support one choice! | ||
92 | if (choiceId < 0 || choiceId > 1) { | ||
93 | throw new InvalidBallotException(String.format("choice '%s' not valid", choiceId)); | ||
94 | } | ||
95 | int choiceExp = (choiceId == 1) ? 1 : -1; | ||
58 | // FIXME: can we use 'g', or should we use another generator? | 96 | // FIXME: can we use 'g', or should we use another generator? |
59 | Plaintext p = Plaintext.generate(BigInteger.valueOf(choiceId)); | 97 | Plaintext p = Plaintext.generate(BigInteger.valueOf(choiceExp)); |
60 | EncryptedVote encryptedVote = new EncryptedVote(); | 98 | EncryptedVote encryptedVote = new EncryptedVote(); |
61 | encryptedVote.v = p.encrypt(thresholdPublicKey); | 99 | encryptedVote.v = p.encrypt(thresholdPublicKey); |
100 | encryptedVote.voterPublicKey = voterPublicKey; | ||
62 | return encryptedVote; | 101 | return encryptedVote; |
63 | } | 102 | } |
103 | |||
104 | public void writeToConfiguration(Configuration cfg) { | ||
105 | cfg.setValueString("vote", "ENCRYPTED_VOTE_VAL", v.toString()); | ||
106 | } | ||
64 | } | 107 | } |
diff --git a/src/main/java/org/gnunet/voting/GroupCert.java b/src/main/java/org/gnunet/voting/GroupCert.java index 296aae7..6899faa 100644 --- a/src/main/java/org/gnunet/voting/GroupCert.java +++ b/src/main/java/org/gnunet/voting/GroupCert.java | |||
@@ -27,7 +27,6 @@ import org.gnunet.util.Configuration; | |||
27 | import org.gnunet.util.crypto.EcdsaPrivateKey; | 27 | import org.gnunet.util.crypto.EcdsaPrivateKey; |
28 | import org.gnunet.util.crypto.EcdsaPublicKey; | 28 | import org.gnunet.util.crypto.EcdsaPublicKey; |
29 | import org.gnunet.util.crypto.EcdsaSignature; | 29 | import org.gnunet.util.crypto.EcdsaSignature; |
30 | import org.gnunet.util.crypto.EddsaSignature; | ||
31 | 30 | ||
32 | /** | 31 | /** |
33 | * Group certificate. Attests to the fact that a voter (identified | 32 | * Group certificate. Attests to the fact that a voter (identified |
diff --git a/src/main/java/org/gnunet/voting/TallyAuthorityDaemon.java b/src/main/java/org/gnunet/voting/TallyAuthorityDaemon.java index 6fa6b8e..e3a1d8e 100644 --- a/src/main/java/org/gnunet/voting/TallyAuthorityDaemon.java +++ b/src/main/java/org/gnunet/voting/TallyAuthorityDaemon.java | |||
@@ -25,9 +25,6 @@ import org.gnunet.consensus.Consensus; | |||
25 | import org.gnunet.consensus.ConsensusCallback; | 25 | import org.gnunet.consensus.ConsensusCallback; |
26 | import org.gnunet.consensus.ConsensusElement; | 26 | import org.gnunet.consensus.ConsensusElement; |
27 | import org.gnunet.construct.Construct; | 27 | import org.gnunet.construct.Construct; |
28 | import org.gnunet.construct.Message; | ||
29 | import org.gnunet.construct.NestedMessage; | ||
30 | import org.gnunet.construct.UInt32; | ||
31 | import org.gnunet.mesh.Mesh; | 28 | import org.gnunet.mesh.Mesh; |
32 | import org.gnunet.mesh.MeshRunabout; | 29 | import org.gnunet.mesh.MeshRunabout; |
33 | import org.gnunet.secretsharing.*; | 30 | import org.gnunet.secretsharing.*; |
@@ -35,13 +32,17 @@ import org.gnunet.secretsharing.callbacks.DecryptCallback; | |||
35 | import org.gnunet.secretsharing.callbacks.SecretReadyCallback; | 32 | import org.gnunet.secretsharing.callbacks.SecretReadyCallback; |
36 | import org.gnunet.testbed.CompressedConfig; | 33 | import org.gnunet.testbed.CompressedConfig; |
37 | import org.gnunet.util.*; | 34 | import org.gnunet.util.*; |
38 | import org.gnunet.util.crypto.*; | 35 | import org.gnunet.util.crypto.EcdsaPublicKey; |
36 | import org.gnunet.util.crypto.EddsaPrivateKey; | ||
37 | import org.gnunet.util.crypto.EddsaPublicKey; | ||
38 | import org.gnunet.util.crypto.EddsaSignature; | ||
39 | import org.gnunet.voting.messages.*; | 39 | import org.gnunet.voting.messages.*; |
40 | import org.slf4j.Logger; | 40 | import org.slf4j.Logger; |
41 | import org.slf4j.LoggerFactory; | 41 | import org.slf4j.LoggerFactory; |
42 | 42 | ||
43 | import java.math.BigInteger; | 43 | import java.util.HashMap; |
44 | import java.util.*; | 44 | import java.util.HashSet; |
45 | import java.util.Set; | ||
45 | 46 | ||
46 | 47 | ||
47 | /** | 48 | /** |
@@ -114,7 +115,7 @@ public class TallyAuthorityDaemon extends Program { | |||
114 | /** | 115 | /** |
115 | * Product of all encrypted votes (mod q), used to compute the final tally. | 116 | * Product of all encrypted votes (mod q), used to compute the final tally. |
116 | */ | 117 | */ |
117 | Ciphertext voteProduct; | 118 | Ciphertext voteProduct = Ciphertext.identity(); |
118 | 119 | ||
119 | /** | 120 | /** |
120 | * Maping from choice to number of votes for that choice. | 121 | * Maping from choice to number of votes for that choice. |
@@ -142,7 +143,16 @@ public class TallyAuthorityDaemon extends Program { | |||
142 | public void onElement(ConsensusElement element) { | 143 | public void onElement(ConsensusElement element) { |
143 | System.out.println("got element from consensus"); | 144 | System.out.println("got element from consensus"); |
144 | EncryptedVote vote = Construct.parseAs(element.data, EncryptedVote.class); | 145 | EncryptedVote vote = Construct.parseAs(element.data, EncryptedVote.class); |
146 | System.out.println("got vote from consensus, ciphertext: " + vote.v.toString()); | ||
147 | if (electionState.countedVoters.contains(vote.voterPublicKey)) { | ||
148 | // Complain. FIXME: keep lexically largest vote, so ballot is unambigous | ||
149 | logger.error("voter {} voted twice", vote.voterPublicKey); | ||
150 | return; | ||
151 | } | ||
145 | electionState.voteProduct = electionState.voteProduct.multiply(vote.v); | 152 | electionState.voteProduct = electionState.voteProduct.multiply(vote.v); |
153 | electionState.countedVoters.add(vote.voterPublicKey); | ||
154 | |||
155 | System.out.println("threshold key (of this authority): " + electionState.share.publicKey.toString()); | ||
146 | } | 156 | } |
147 | 157 | ||
148 | @Override | 158 | @Override |
@@ -286,6 +296,8 @@ public class TallyAuthorityDaemon extends Program { | |||
286 | logger.info("concluding in {}", b.closingTime.getRemaining().getSeconds()); | 296 | logger.info("concluding in {}", b.closingTime.getRemaining().getSeconds()); |
287 | Scheduler.addDelayed(b.closingTime.getRemaining(), t); | 297 | Scheduler.addDelayed(b.closingTime.getRemaining(), t); |
288 | } | 298 | } |
299 | System.out.println("authority threshold: " + electionState.ballot.threshold); | ||
300 | System.out.println("authority num_peers: " + electionState.ballot.authorities.size()); | ||
289 | // we hash the GUID a second time, so that there's no | 301 | // we hash the GUID a second time, so that there's no |
290 | // collision with the consensus (as secretsharing also uses consensus internally) | 302 | // collision with the consensus (as secretsharing also uses consensus internally) |
291 | electionState.keyGeneration = new KeyGeneration( | 303 | electionState.keyGeneration = new KeyGeneration( |
@@ -365,15 +377,15 @@ public class TallyAuthorityDaemon extends Program { | |||
365 | } | 377 | } |
366 | } | 378 | } |
367 | 379 | ||
368 | public TallyAuthorityDaemon(String[] args) { | 380 | public TallyAuthorityDaemon() { |
369 | super(args); | ||
370 | authorityPrivateKey = EddsaPrivateKey.createRandom(); | 381 | authorityPrivateKey = EddsaPrivateKey.createRandom(); |
371 | authorityPublicKey = authorityPrivateKey.getPublicKey(); | 382 | authorityPublicKey = authorityPrivateKey.getPublicKey(); |
372 | } | 383 | } |
373 | 384 | ||
374 | public static void main(String[] args) { | 385 | public static void main(String[] args) { |
375 | TallyAuthorityDaemon daemon = new TallyAuthorityDaemon(args); | 386 | TallyAuthorityDaemon daemon = new TallyAuthorityDaemon(); |
376 | daemon.start(); | 387 | int ret = daemon.start(args); |
388 | System.exit(ret); | ||
377 | } | 389 | } |
378 | 390 | ||
379 | @Override | 391 | @Override |
diff --git a/src/main/java/org/gnunet/voting/messages/ResultQueryResponseMessage.java b/src/main/java/org/gnunet/voting/messages/ResultQueryResponseMessage.java index 96ad4b5..8a1b0e3 100644 --- a/src/main/java/org/gnunet/voting/messages/ResultQueryResponseMessage.java +++ b/src/main/java/org/gnunet/voting/messages/ResultQueryResponseMessage.java | |||
@@ -1,9 +1,9 @@ | |||
1 | package org.gnunet.voting.messages; | 1 | package org.gnunet.voting.messages; |
2 | 2 | ||
3 | 3 | ||
4 | import org.gnunet.construct.*; | 4 | import org.gnunet.construct.IntegerFill; |
5 | import org.gnunet.construct.UnionCase; | ||
5 | import org.gnunet.util.GnunetMessage; | 6 | import org.gnunet.util.GnunetMessage; |
6 | import org.gnunet.util.HashCode; | ||
7 | 7 | ||
8 | @UnionCase(42006) | 8 | @UnionCase(42006) |
9 | public class ResultQueryResponseMessage implements GnunetMessage.Body { | 9 | public class ResultQueryResponseMessage implements GnunetMessage.Body { |
diff --git a/src/main/java/org/gnunet/voting/messages/SubmitMessage.java b/src/main/java/org/gnunet/voting/messages/SubmitMessage.java index 342aa0b..4f131e3 100644 --- a/src/main/java/org/gnunet/voting/messages/SubmitMessage.java +++ b/src/main/java/org/gnunet/voting/messages/SubmitMessage.java | |||
@@ -1,12 +1,12 @@ | |||
1 | package org.gnunet.voting.messages; | 1 | package org.gnunet.voting.messages; |
2 | 2 | ||
3 | import org.gnunet.construct.NestedMessage; | 3 | import org.gnunet.construct.NestedMessage; |
4 | import org.gnunet.construct.UInt32; | ||
5 | import org.gnunet.construct.UnionCase; | 4 | import org.gnunet.construct.UnionCase; |
6 | import org.gnunet.util.*; | 5 | import org.gnunet.util.AbsoluteTimeMessage; |
6 | import org.gnunet.util.GnunetMessage; | ||
7 | import org.gnunet.util.HashCode; | ||
7 | import org.gnunet.util.crypto.EcdsaPublicKey; | 8 | import org.gnunet.util.crypto.EcdsaPublicKey; |
8 | import org.gnunet.util.crypto.EcdsaSignature; | 9 | import org.gnunet.util.crypto.EcdsaSignature; |
9 | import org.gnunet.util.crypto.EddsaSignature; | ||
10 | import org.gnunet.voting.EncryptedVote; | 10 | import org.gnunet.voting.EncryptedVote; |
11 | 11 | ||
12 | /** | 12 | /** |
diff --git a/src/main/java/org/gnunet/voting/simulation/CryptoUtil.java b/src/main/java/org/gnunet/voting/simulation/CryptoUtil.java index 87ecd9f..b8ab04d 100644 --- a/src/main/java/org/gnunet/voting/simulation/CryptoUtil.java +++ b/src/main/java/org/gnunet/voting/simulation/CryptoUtil.java | |||
@@ -3,7 +3,6 @@ package org.gnunet.voting.simulation; | |||
3 | import java.math.BigInteger; | 3 | import java.math.BigInteger; |
4 | import java.security.MessageDigest; | 4 | import java.security.MessageDigest; |
5 | import java.security.NoSuchAlgorithmException; | 5 | import java.security.NoSuchAlgorithmException; |
6 | import java.security.SecureRandom; | ||
7 | import java.util.Random; | 6 | import java.util.Random; |
8 | 7 | ||
9 | /** | 8 | /** |
diff --git a/src/main/java/org/gnunet/voting/simulation/VotingParameters.java b/src/main/java/org/gnunet/voting/simulation/VotingParameters.java index 87bfeac..0086578 100644 --- a/src/main/java/org/gnunet/voting/simulation/VotingParameters.java +++ b/src/main/java/org/gnunet/voting/simulation/VotingParameters.java | |||
@@ -176,7 +176,7 @@ public class VotingParameters { | |||
176 | } | 176 | } |
177 | 177 | ||
178 | public static void main(String... args) { | 178 | public static void main(String... args) { |
179 | new Program(args) { | 179 | new Program() { |
180 | @Argument( | 180 | @Argument( |
181 | shortname = "b", | 181 | shortname = "b", |
182 | longname = "bits", | 182 | longname = "bits", |
@@ -199,7 +199,7 @@ public class VotingParameters { | |||
199 | System.out.println("q: 0x0" + vp.getQ().toString(16)); | 199 | System.out.println("q: 0x0" + vp.getQ().toString(16)); |
200 | System.out.println("g: 0x0" + vp.getG().toString(16)); | 200 | System.out.println("g: 0x0" + vp.getG().toString(16)); |
201 | } | 201 | } |
202 | }.startWithoutScheduler(); | 202 | }.startWithoutScheduler(args); |
203 | } | 203 | } |
204 | 204 | ||
205 | } | 205 | } |