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/gnunet/util | |
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/gnunet/util')
-rw-r--r-- | src/main/java/org/gnunet/util/AbsoluteTime.java | 2 | ||||
-rw-r--r-- | src/main/java/org/gnunet/util/Client.java | 17 | ||||
-rw-r--r-- | src/main/java/org/gnunet/util/Connection.java | 18 | ||||
-rw-r--r-- | src/main/java/org/gnunet/util/Helper.java | 1 | ||||
-rw-r--r-- | src/main/java/org/gnunet/util/MessageStreamTokenizer.java | 4 | ||||
-rw-r--r-- | src/main/java/org/gnunet/util/MessageTransmitter.java | 4 | ||||
-rw-r--r-- | src/main/java/org/gnunet/util/Program.java | 38 | ||||
-rw-r--r-- | src/main/java/org/gnunet/util/RelativeTime.java | 5 | ||||
-rw-r--r-- | src/main/java/org/gnunet/util/Resolver.java | 7 | ||||
-rw-r--r-- | src/main/java/org/gnunet/util/Scheduler.java | 23 | ||||
-rw-r--r-- | src/main/java/org/gnunet/util/Server.java | 7 | ||||
-rw-r--r-- | src/main/java/org/gnunet/util/Service.java | 4 | ||||
-rw-r--r-- | src/main/java/org/gnunet/util/crypto/Ed25519.java | 1 | ||||
-rw-r--r-- | src/main/java/org/gnunet/util/getopt/Parser.java | 1 |
14 files changed, 65 insertions, 67 deletions
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 | ||