diff options
author | Florian Dold <florian.dold@gmail.com> | 2013-08-13 21:49:15 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2013-08-13 21:49:15 +0000 |
commit | 8dd31db2eae90764bac5ddcc7ab4ed25e9d39817 (patch) | |
tree | 3f2547234c59ee69dae409cc94fb5e51a542d993 /src | |
parent | e4a01152171e4186e4718c4c9c92842fccf6d8a1 (diff) | |
download | gnunet-java-8dd31db2eae90764bac5ddcc7ab4ed25e9d39817.tar.gz gnunet-java-8dd31db2eae90764bac5ddcc7ab4ed25e9d39817.zip |
- mq,mesh,consensus,millisecond time
Diffstat (limited to 'src')
-rw-r--r-- | src/org/gnunet/consensus/ConcludeDoneMessage.java | 3 | ||||
-rw-r--r-- | src/org/gnunet/consensus/Consensus.java | 20 | ||||
-rw-r--r-- | src/org/gnunet/construct/MsgMap.txt | 11 | ||||
-rw-r--r-- | src/org/gnunet/mesh/Mesh.java | 24 | ||||
-rw-r--r-- | src/org/gnunet/mq/ClientMessageQueue.java | 4 | ||||
-rw-r--r-- | src/org/gnunet/util/AbsoluteTime.java | 55 | ||||
-rw-r--r-- | src/org/gnunet/util/AbsoluteTimeMessage.java | 2 | ||||
-rw-r--r-- | src/org/gnunet/util/Configuration.java | 6 | ||||
-rw-r--r-- | src/org/gnunet/util/Connection.java | 2 | ||||
-rw-r--r-- | src/org/gnunet/util/RelativeTime.java | 56 | ||||
-rw-r--r-- | src/org/gnunet/util/RelativeTimeMessage.java | 2 | ||||
-rw-r--r-- | src/org/gnunet/util/Scheduler.java | 10 |
12 files changed, 118 insertions, 77 deletions
diff --git a/src/org/gnunet/consensus/ConcludeDoneMessage.java b/src/org/gnunet/consensus/ConcludeDoneMessage.java index 3b016cf..51757aa 100644 --- a/src/org/gnunet/consensus/ConcludeDoneMessage.java +++ b/src/org/gnunet/consensus/ConcludeDoneMessage.java | |||
@@ -1,6 +1,7 @@ | |||
1 | package org.gnunet.consensus; | 1 | package org.gnunet.consensus; |
2 | 2 | ||
3 | 3 | ||
4 | import org.gnunet.construct.MessageUnion; | ||
4 | import org.gnunet.construct.UnionCase; | 5 | import org.gnunet.construct.UnionCase; |
5 | 6 | ||
6 | /** | 7 | /** |
@@ -8,5 +9,5 @@ import org.gnunet.construct.UnionCase; | |||
8 | * Direction: service -> client | 9 | * Direction: service -> client |
9 | */ | 10 | */ |
10 | @UnionCase(525) | 11 | @UnionCase(525) |
11 | public class ConcludeDoneMessage { | 12 | public class ConcludeDoneMessage implements MessageUnion { |
12 | } | 13 | } |
diff --git a/src/org/gnunet/consensus/Consensus.java b/src/org/gnunet/consensus/Consensus.java index e6fab01..2047454 100644 --- a/src/org/gnunet/consensus/Consensus.java +++ b/src/org/gnunet/consensus/Consensus.java | |||
@@ -85,6 +85,12 @@ public class Consensus { | |||
85 | this.newElementCallback = newElementCallback; | 85 | this.newElementCallback = newElementCallback; |
86 | } | 86 | } |
87 | 87 | ||
88 | /** | ||
89 | * Insert an element into the consensus set. | ||
90 | * | ||
91 | * @param element element to insert in the consnesus | ||
92 | * @param idc called when the element has been sent to the service | ||
93 | */ | ||
88 | public void insertElement (ConsensusElement element, final InsertDoneCallback idc) { | 94 | public void insertElement (ConsensusElement element, final InsertDoneCallback idc) { |
89 | InsertElementMessage m = new InsertElementMessage(); | 95 | InsertElementMessage m = new InsertElementMessage(); |
90 | m.element_data = element.data; | 96 | m.element_data = element.data; |
@@ -99,17 +105,27 @@ public class Consensus { | |||
99 | client_mq.send(ev); | 105 | client_mq.send(ev); |
100 | } | 106 | } |
101 | 107 | ||
108 | /** | ||
109 | * We are done with inserting new elements into the consensus; | ||
110 | * try to conclude the consensus within a given time window. | ||
111 | * After conclude has been called, no further elements may be | ||
112 | * inserted by the client. | ||
113 | * @param concludeCallback called when the consensus has concluded | ||
114 | */ | ||
102 | public void conclude(ConcludeCallback concludeCallback) { | 115 | public void conclude(ConcludeCallback concludeCallback) { |
103 | if (null == concludeCallback) | 116 | if (null == concludeCallback) |
104 | throw new AssertionError("conclude with empty callback"); | 117 | throw new AssertionError("conclude with empty callback"); |
105 | if (null != this.concludeCallback) | 118 | if (null != this.concludeCallback) |
106 | throw new AssertionError("called conclude twice"); | 119 | throw new AssertionError("called conclude twice"); |
107 | this.concludeCallback = concludeCallback; | 120 | this.concludeCallback = concludeCallback; |
121 | ConcludeMessage m = new ConcludeMessage(); | ||
122 | client_mq.send(m); | ||
108 | } | 123 | } |
109 | 124 | ||
110 | /** | 125 | /** |
111 | * Destroy a consensus handle (free all state associated with | 126 | * Destroy a consensus handle. |
112 | * it, no longer call any of the callbacks). | 127 | * Free all state associated with |
128 | * it, no longer call any of the callbacks. | ||
113 | */ | 129 | */ |
114 | public void destroy() { | 130 | public void destroy() { |
115 | client_mq.destroy(); | 131 | client_mq.destroy(); |
diff --git a/src/org/gnunet/construct/MsgMap.txt b/src/org/gnunet/construct/MsgMap.txt index 30e7077..7f3d2f4 100644 --- a/src/org/gnunet/construct/MsgMap.txt +++ b/src/org/gnunet/construct/MsgMap.txt | |||
@@ -1,7 +1,6 @@ | |||
1 | org.gnunet.util.Resolver$Address|0=org.gnunet.util.Resolver$TextualAddress | 1 | org.gnunet.util.Resolver$Address|0=org.gnunet.util.Resolver$TextualAddress |
2 | org.gnunet.util.Resolver$Address|1=org.gnunet.util.Resolver$NumericAddress | 2 | org.gnunet.util.Resolver$Address|1=org.gnunet.util.Resolver$NumericAddress |
3 | org.gnunet.util.GnunetMessage$Body|68=org.gnunet.core.DisconnectNotifyMessage | 3 | org.gnunet.util.GnunetMessage$Body|68=org.gnunet.core.DisconnectNotifyMessage |
4 | org.gnunet.util.GnunetMessage$Body|275=org.gnunet.mesh.PeerAddMessage | ||
5 | org.gnunet.util.GnunetMessage$Body|274=org.gnunet.mesh.TunnelDestroyMessage | 4 | org.gnunet.util.GnunetMessage$Body|274=org.gnunet.mesh.TunnelDestroyMessage |
6 | org.gnunet.util.GnunetMessage$Body|1=org.gnunet.util.TestMessage | 5 | org.gnunet.util.GnunetMessage$Body|1=org.gnunet.util.TestMessage |
7 | org.gnunet.util.GnunetMessage$Body|70=org.gnunet.core.NotifyInboundTrafficMessage | 6 | org.gnunet.util.GnunetMessage$Body|70=org.gnunet.core.NotifyInboundTrafficMessage |
@@ -12,10 +11,8 @@ org.gnunet.util.GnunetMessage$Body|64=org.gnunet.core.InitMessage | |||
12 | org.gnunet.util.GnunetMessage$Body|4=org.gnunet.util.Resolver$GetMessage | 11 | org.gnunet.util.GnunetMessage$Body|4=org.gnunet.util.Resolver$GetMessage |
13 | org.gnunet.util.GnunetMessage$Body|65=org.gnunet.core.InitReplyMessage | 12 | org.gnunet.util.GnunetMessage$Body|65=org.gnunet.core.InitReplyMessage |
14 | org.gnunet.util.GnunetMessage$Body|5=org.gnunet.util.Resolver$ResolverResponse | 13 | org.gnunet.util.GnunetMessage$Body|5=org.gnunet.util.Resolver$ResolverResponse |
15 | org.gnunet.util.GnunetMessage$Body|277=org.gnunet.mesh.ConnectPeerByTypeMessage | ||
16 | org.gnunet.util.GnunetMessage$Body|143=org.gnunet.dht.ClientGetMessage | 14 | org.gnunet.util.GnunetMessage$Body|143=org.gnunet.dht.ClientGetMessage |
17 | org.gnunet.util.GnunetMessage$Body|67=org.gnunet.core.ConnectNotifyMessage | 15 | org.gnunet.util.GnunetMessage$Body|67=org.gnunet.core.ConnectNotifyMessage |
18 | org.gnunet.util.GnunetMessage$Body|276=org.gnunet.mesh.PeerDeleteMessage | ||
19 | org.gnunet.util.GnunetMessage$Body|142=org.gnunet.dht.ClientPutMessage | 16 | org.gnunet.util.GnunetMessage$Body|142=org.gnunet.dht.ClientPutMessage |
20 | org.gnunet.util.GnunetMessage$Body|76=org.gnunet.core.SendMessage | 17 | org.gnunet.util.GnunetMessage$Body|76=org.gnunet.core.SendMessage |
21 | org.gnunet.util.GnunetMessage$Body|286=org.gnunet.mesh.LocalAckMessage | 18 | org.gnunet.util.GnunetMessage$Body|286=org.gnunet.mesh.LocalAckMessage |
@@ -23,10 +20,8 @@ org.gnunet.util.GnunetMessage$Body|74=org.gnunet.core.SendMessageRequest | |||
23 | org.gnunet.util.GnunetMessage$Body|75=org.gnunet.core.SendMessageReady | 20 | org.gnunet.util.GnunetMessage$Body|75=org.gnunet.core.SendMessageReady |
24 | org.gnunet.util.GnunetMessage$Body|153=org.gnunet.dht.MonitorStartStop | 21 | org.gnunet.util.GnunetMessage$Body|153=org.gnunet.dht.MonitorStartStop |
25 | org.gnunet.util.GnunetMessage$Body|155=org.gnunet.dht.ClientPutConfirmationMessage | 22 | org.gnunet.util.GnunetMessage$Body|155=org.gnunet.dht.ClientPutConfirmationMessage |
26 | org.gnunet.util.GnunetMessage$Body|262=org.gnunet.mesh.OriginMessage | ||
27 | org.gnunet.util.GnunetMessage$Body|323=org.gnunet.nse.UpdateMessage | 23 | org.gnunet.util.GnunetMessage$Body|323=org.gnunet.nse.UpdateMessage |
28 | org.gnunet.util.GnunetMessage$Body|260=org.gnunet.mesh.DataMessage | 24 | org.gnunet.util.GnunetMessage$Body|260=org.gnunet.mesh.DataMessage |
29 | org.gnunet.util.GnunetMessage$Body|261=org.gnunet.mesh.MulticastMessage | ||
30 | org.gnunet.util.GnunetMessage$Body|321=org.gnunet.nse.StartMessage | 25 | org.gnunet.util.GnunetMessage$Body|321=org.gnunet.nse.StartMessage |
31 | org.gnunet.util.GnunetMessage$Body|144=org.gnunet.dht.ClientGetStopMessage | 26 | org.gnunet.util.GnunetMessage$Body|144=org.gnunet.dht.ClientGetStopMessage |
32 | org.gnunet.util.GnunetMessage$Body|145=org.gnunet.dht.ClientResultMessage | 27 | org.gnunet.util.GnunetMessage$Body|145=org.gnunet.dht.ClientResultMessage |
@@ -43,5 +38,9 @@ org.gnunet.util.GnunetMessage$Body|168=org.gnunet.statistics.SetMessage | |||
43 | org.gnunet.util.GnunetMessage$Body|374=org.gnunet.transport.RequestConnectMessage | 38 | org.gnunet.util.GnunetMessage$Body|374=org.gnunet.transport.RequestConnectMessage |
44 | org.gnunet.util.GnunetMessage$Body|173=org.gnunet.statistics.WatchResponseMessage | 39 | org.gnunet.util.GnunetMessage$Body|173=org.gnunet.statistics.WatchResponseMessage |
45 | org.gnunet.util.GnunetMessage$Body|172=org.gnunet.statistics.WatchMessage | 40 | org.gnunet.util.GnunetMessage$Body|172=org.gnunet.statistics.WatchMessage |
41 | org.gnunet.util.GnunetMessage$Body|524=org.gnunet.consensus.ConcludeMessage | ||
42 | org.gnunet.util.GnunetMessage$Body|521=org.gnunet.consensus.InsertElementMessage | ||
43 | org.gnunet.util.GnunetMessage$Body|523=org.gnunet.consensus.NewElementMessage | ||
46 | org.gnunet.util.GnunetMessage$Body|360=org.gnunet.transport.StartMessage | 44 | org.gnunet.util.GnunetMessage$Body|360=org.gnunet.transport.StartMessage |
47 | # generated 2013/04/14 22:27:05 | 45 | org.gnunet.construct.MessageUnion|525=org.gnunet.consensus.ConcludeDoneMessage |
46 | # generated 2013/08/13 20:15:12 | ||
diff --git a/src/org/gnunet/mesh/Mesh.java b/src/org/gnunet/mesh/Mesh.java index 091cb17..b272b0b 100644 --- a/src/org/gnunet/mesh/Mesh.java +++ b/src/org/gnunet/mesh/Mesh.java | |||
@@ -116,6 +116,7 @@ public class Mesh { | |||
116 | * @param <T> type of context data for the tunnel | 116 | * @param <T> type of context data for the tunnel |
117 | */ | 117 | */ |
118 | public class Tunnel<T> extends MessageQueue { | 118 | public class Tunnel<T> extends MessageQueue { |
119 | private T context; | ||
119 | private final int opt; | 120 | private final int opt; |
120 | public final PeerIdentity peer; | 121 | public final PeerIdentity peer; |
121 | public final int port; | 122 | public final int port; |
@@ -194,8 +195,16 @@ public class Mesh { | |||
194 | client_mq.send(mesh_ev); | 195 | client_mq.send(mesh_ev); |
195 | ack_count -= 1; | 196 | ack_count -= 1; |
196 | } | 197 | } |
197 | } | ||
198 | 198 | ||
199 | public T getContext() { | ||
200 | return context; | ||
201 | } | ||
202 | |||
203 | public void setContext(T newContext) { | ||
204 | context = newContext; | ||
205 | } | ||
206 | |||
207 | } | ||
199 | 208 | ||
200 | private class MeshMessageReceiver extends RunaboutMessageReceiver { | 209 | private class MeshMessageReceiver extends RunaboutMessageReceiver { |
201 | public void visit(TunnelCreateMessage m) { | 210 | public void visit(TunnelCreateMessage m) { |
@@ -235,11 +244,19 @@ public class Mesh { | |||
235 | 244 | ||
236 | @Override | 245 | @Override |
237 | public void handleError() { | 246 | public void handleError() { |
238 | // todo: re-establish all tunnels | 247 | if (tunnelEndHandler != null) { |
248 | for (Tunnel t : tunnelMap.values()) { | ||
249 | tunnelEndHandler.onTunnelEnd(t); | ||
250 | } | ||
251 | } | ||
252 | tunnelMap.clear(); | ||
253 | client.reconnect(); | ||
254 | ClientConnectMessage ccm = new ClientConnectMessage(); | ||
255 | ccm.apps_list = ports; | ||
256 | client_mq.send(ccm); | ||
239 | } | 257 | } |
240 | } | 258 | } |
241 | 259 | ||
242 | |||
243 | /** | 260 | /** |
244 | * Connect to the mesh service. | 261 | * Connect to the mesh service. |
245 | * | 262 | * |
@@ -263,7 +280,6 @@ public class Mesh { | |||
263 | client_mq.send(ccm); | 280 | client_mq.send(ccm); |
264 | } | 281 | } |
265 | 282 | ||
266 | |||
267 | /** | 283 | /** |
268 | * Disconnect from the mesh service. | 284 | * Disconnect from the mesh service. |
269 | * All tunnels will be destroyed. | 285 | * All tunnels will be destroyed. |
diff --git a/src/org/gnunet/mq/ClientMessageQueue.java b/src/org/gnunet/mq/ClientMessageQueue.java index bfb0466..b3fccc7 100644 --- a/src/org/gnunet/mq/ClientMessageQueue.java +++ b/src/org/gnunet/mq/ClientMessageQueue.java | |||
@@ -11,18 +11,15 @@ public class ClientMessageQueue extends MessageQueue { | |||
11 | private final Client client; | 11 | private final Client client; |
12 | private final RunaboutMessageReceiver receiver; | 12 | private final RunaboutMessageReceiver receiver; |
13 | 13 | ||
14 | |||
15 | public ClientMessageQueue(Client client, RunaboutMessageReceiver receiver) { | 14 | public ClientMessageQueue(Client client, RunaboutMessageReceiver receiver) { |
16 | this.client = client; | 15 | this.client = client; |
17 | this.receiver = receiver; | 16 | this.receiver = receiver; |
18 | } | 17 | } |
19 | 18 | ||
20 | |||
21 | public ClientMessageQueue(Client client) { | 19 | public ClientMessageQueue(Client client) { |
22 | this(client, null); | 20 | this(client, null); |
23 | } | 21 | } |
24 | 22 | ||
25 | |||
26 | @Override | 23 | @Override |
27 | protected void sendImmediate(final Envelope ev) { | 24 | protected void sendImmediate(final Envelope ev) { |
28 | int size = Construct.getSize(ev.message); | 25 | int size = Construct.getSize(ev.message); |
@@ -40,7 +37,6 @@ public class ClientMessageQueue extends MessageQueue { | |||
40 | }); | 37 | }); |
41 | } | 38 | } |
42 | 39 | ||
43 | |||
44 | @Override | 40 | @Override |
45 | public void destroy() { | 41 | public void destroy() { |
46 | 42 | ||
diff --git a/src/org/gnunet/util/AbsoluteTime.java b/src/org/gnunet/util/AbsoluteTime.java index cea0366..06f41ac 100644 --- a/src/org/gnunet/util/AbsoluteTime.java +++ b/src/org/gnunet/util/AbsoluteTime.java | |||
@@ -41,6 +41,11 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
41 | public final static AbsoluteTime FOREVER = new AbsoluteTime(Long.MAX_VALUE); | 41 | public final static AbsoluteTime FOREVER = new AbsoluteTime(Long.MAX_VALUE); |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Absolute time value in microseconds. | ||
45 | */ | ||
46 | private final long abs_value_us; | ||
47 | |||
48 | /** | ||
44 | * Gets the current time. | 49 | * Gets the current time. |
45 | * | 50 | * |
46 | * @return the current time | 51 | * @return the current time |
@@ -49,10 +54,8 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
49 | return new AbsoluteTime(System.currentTimeMillis()); | 54 | return new AbsoluteTime(System.currentTimeMillis()); |
50 | } | 55 | } |
51 | 56 | ||
52 | private final long abs_value; | 57 | public AbsoluteTime(final long abs_value_us) { |
53 | 58 | this.abs_value_us = abs_value_us; | |
54 | public AbsoluteTime(final long abs_value) { | ||
55 | this.abs_value = abs_value; | ||
56 | } | 59 | } |
57 | 60 | ||
58 | /** | 61 | /** |
@@ -62,14 +65,14 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
62 | * @return {@literal this + duration} | 65 | * @return {@literal this + duration} |
63 | */ | 66 | */ |
64 | public AbsoluteTime add(RelativeTime duration) { | 67 | public AbsoluteTime add(RelativeTime duration) { |
65 | if (abs_value == Long.MAX_VALUE | 68 | if (abs_value_us == Long.MAX_VALUE |
66 | || duration.isForever()) { | 69 | || duration.isForever()) { |
67 | return AbsoluteTime.FOREVER; | 70 | return AbsoluteTime.FOREVER; |
68 | } | 71 | } |
69 | if (abs_value + duration.getMilliseconds() < abs_value) { | 72 | if (abs_value_us + duration.getMicroseconds() < abs_value_us) { |
70 | return AbsoluteTime.FOREVER; | 73 | return AbsoluteTime.FOREVER; |
71 | } | 74 | } |
72 | return new AbsoluteTime(abs_value + duration.getMilliseconds()); | 75 | return new AbsoluteTime(abs_value_us + duration.getMicroseconds()); |
73 | } | 76 | } |
74 | 77 | ||
75 | /** | 78 | /** |
@@ -93,7 +96,7 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
93 | return RelativeTime.FOREVER; | 96 | return RelativeTime.FOREVER; |
94 | } | 97 | } |
95 | final RelativeTime dur = start.getDuration(); | 98 | final RelativeTime dur = start.getDuration(); |
96 | final double exp = dur.getMilliseconds() * total | 99 | final double exp = dur.getMicroseconds() * total |
97 | / (double) finished; | 100 | / (double) finished; |
98 | return new RelativeTime((long) exp); | 101 | return new RelativeTime((long) exp); |
99 | } | 102 | } |
@@ -112,7 +115,7 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
112 | */ | 115 | */ |
113 | @Override | 116 | @Override |
114 | public int hashCode() { | 117 | public int hashCode() { |
115 | return (int) this.abs_value; | 118 | return (int) this.abs_value_us; |
116 | } | 119 | } |
117 | 120 | ||
118 | /** | 121 | /** |
@@ -120,10 +123,10 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
120 | */ | 123 | */ |
121 | @Override | 124 | @Override |
122 | public int compareTo(AbsoluteTime other) { | 125 | public int compareTo(AbsoluteTime other) { |
123 | if (this.abs_value < other.abs_value) { | 126 | if (this.abs_value_us < other.abs_value_us) { |
124 | return -1; | 127 | return -1; |
125 | } | 128 | } |
126 | if (this.abs_value > other.abs_value) { | 129 | if (this.abs_value_us > other.abs_value_us) { |
127 | return 1; | 130 | return 1; |
128 | } | 131 | } |
129 | return 0; | 132 | return 0; |
@@ -137,7 +140,7 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
137 | if (this.isForever()) { | 140 | if (this.isForever()) { |
138 | return "AbsoluteTime(FOREVER)"; | 141 | return "AbsoluteTime(FOREVER)"; |
139 | } | 142 | } |
140 | return "AbsoluteTime("+this.abs_value+")"; | 143 | return "AbsoluteTime("+this.abs_value_us +")"; |
141 | } | 144 | } |
142 | 145 | ||
143 | 146 | ||
@@ -146,7 +149,7 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
146 | * @return true if NOW is greater than the given time, false otherwise | 149 | * @return true if NOW is greater than the given time, false otherwise |
147 | */ | 150 | */ |
148 | public boolean isDue() { | 151 | public boolean isDue() { |
149 | return this.abs_value < now().abs_value; | 152 | return this.abs_value_us < now().abs_value_us; |
150 | } | 153 | } |
151 | 154 | ||
152 | /** | 155 | /** |
@@ -155,7 +158,7 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
155 | * @return this==FOREVER | 158 | * @return this==FOREVER |
156 | */ | 159 | */ |
157 | public boolean isForever() { | 160 | public boolean isForever() { |
158 | return this.abs_value == Long.MAX_VALUE; | 161 | return this.abs_value_us == Long.MAX_VALUE; |
159 | } | 162 | } |
160 | 163 | ||
161 | /** | 164 | /** |
@@ -165,10 +168,10 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
165 | * @return this - other | 168 | * @return this - other |
166 | */ | 169 | */ |
167 | public RelativeTime getDifference(final AbsoluteTime other) { | 170 | public RelativeTime getDifference(final AbsoluteTime other) { |
168 | if (other.abs_value == Long.MAX_VALUE) { | 171 | if (other.abs_value_us == Long.MAX_VALUE) { |
169 | return RelativeTime.FOREVER; | 172 | return RelativeTime.FOREVER; |
170 | } | 173 | } |
171 | return new RelativeTime(abs_value - other.abs_value); | 174 | return new RelativeTime(abs_value_us - other.abs_value_us); |
172 | } | 175 | } |
173 | 176 | ||
174 | /** | 177 | /** |
@@ -178,7 +181,7 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
178 | * @return this - now | 181 | * @return this - now |
179 | */ | 182 | */ |
180 | public RelativeTime getDuration() { | 183 | public RelativeTime getDuration() { |
181 | assert abs_value != Long.MAX_VALUE; | 184 | assert abs_value_us != Long.MAX_VALUE; |
182 | return getDifference(AbsoluteTime.now()); | 185 | return getDifference(AbsoluteTime.now()); |
183 | } | 186 | } |
184 | 187 | ||
@@ -187,8 +190,8 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
187 | * | 190 | * |
188 | * @return the absolute time in milliseconds | 191 | * @return the absolute time in milliseconds |
189 | */ | 192 | */ |
190 | public long getMilliseconds() { | 193 | public long getMicroseconds() { |
191 | return abs_value; | 194 | return abs_value_us; |
192 | } | 195 | } |
193 | 196 | ||
194 | /** | 197 | /** |
@@ -197,7 +200,7 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
197 | * @return this - now | 200 | * @return this - now |
198 | */ | 201 | */ |
199 | public RelativeTime getRemaining() { | 202 | public RelativeTime getRemaining() { |
200 | if (abs_value == Long.MAX_VALUE) { | 203 | if (abs_value_us == Long.MAX_VALUE) { |
201 | return RelativeTime.FOREVER; | 204 | return RelativeTime.FOREVER; |
202 | } | 205 | } |
203 | return getDifference(AbsoluteTime.now()); | 206 | return getDifference(AbsoluteTime.now()); |
@@ -210,7 +213,7 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
210 | * @return max(this,other) | 213 | * @return max(this,other) |
211 | */ | 214 | */ |
212 | public AbsoluteTime max(final AbsoluteTime other) { | 215 | public AbsoluteTime max(final AbsoluteTime other) { |
213 | return abs_value >= other.abs_value ? this : other; | 216 | return abs_value_us >= other.abs_value_us ? this : other; |
214 | 217 | ||
215 | } | 218 | } |
216 | 219 | ||
@@ -221,7 +224,7 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
221 | * @return min(this,other) | 224 | * @return min(this,other) |
222 | */ | 225 | */ |
223 | public AbsoluteTime min(final AbsoluteTime other) { | 226 | public AbsoluteTime min(final AbsoluteTime other) { |
224 | return abs_value <= other.abs_value ? this : other; | 227 | return abs_value_us <= other.abs_value_us ? this : other; |
225 | } | 228 | } |
226 | 229 | ||
227 | /** | 230 | /** |
@@ -231,13 +234,13 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
231 | * @return this - duration | 234 | * @return this - duration |
232 | */ | 235 | */ |
233 | public AbsoluteTime subtract(final RelativeTime duration) { | 236 | public AbsoluteTime subtract(final RelativeTime duration) { |
234 | if (abs_value <= duration.getMilliseconds()) { | 237 | if (abs_value_us <= duration.getMicroseconds()) { |
235 | return AbsoluteTime.ZERO; | 238 | return AbsoluteTime.ZERO; |
236 | } | 239 | } |
237 | if (abs_value == Long.MAX_VALUE) { | 240 | if (abs_value_us == Long.MAX_VALUE) { |
238 | return this; | 241 | return this; |
239 | } | 242 | } |
240 | return new AbsoluteTime(abs_value - duration.getMilliseconds()); | 243 | return new AbsoluteTime(abs_value_us - duration.getMicroseconds()); |
241 | } | 244 | } |
242 | 245 | ||
243 | /** | 246 | /** |
@@ -261,6 +264,6 @@ public class AbsoluteTime implements Comparable<AbsoluteTime> { | |||
261 | } | 264 | } |
262 | 265 | ||
263 | public Date toDate() { | 266 | public Date toDate() { |
264 | return new Date(abs_value); | 267 | return new Date(abs_value_us); |
265 | } | 268 | } |
266 | } | 269 | } |
diff --git a/src/org/gnunet/util/AbsoluteTimeMessage.java b/src/org/gnunet/util/AbsoluteTimeMessage.java index 8ddcc9b..f46d577 100644 --- a/src/org/gnunet/util/AbsoluteTimeMessage.java +++ b/src/org/gnunet/util/AbsoluteTimeMessage.java | |||
@@ -41,7 +41,7 @@ public class AbsoluteTimeMessage implements Message { | |||
41 | if (t.equals(AbsoluteTime.FOREVER)) { | 41 | if (t.equals(AbsoluteTime.FOREVER)) { |
42 | this.value__ = -1; | 42 | this.value__ = -1; |
43 | } else { | 43 | } else { |
44 | this.value__ = t.getMilliseconds(); | 44 | this.value__ = t.getMicroseconds(); |
45 | } | 45 | } |
46 | } | 46 | } |
47 | } | 47 | } |
diff --git a/src/org/gnunet/util/Configuration.java b/src/org/gnunet/util/Configuration.java index ed12ff3..5cf950c 100644 --- a/src/org/gnunet/util/Configuration.java +++ b/src/org/gnunet/util/Configuration.java | |||
@@ -250,8 +250,12 @@ public class Configuration { | |||
250 | 250 | ||
251 | while (it.hasNext()) { | 251 | while (it.hasNext()) { |
252 | String line = it.next(); | 252 | String line = it.next(); |
253 | String[] split_line = line.split("#"); | ||
254 | if (split_line.length == 0) | ||
255 | continue; | ||
256 | |||
253 | // strip comment | 257 | // strip comment |
254 | line = line.split("#")[0]; | 258 | line = split_line[0]; |
255 | Matcher m; | 259 | Matcher m; |
256 | 260 | ||
257 | if ((m = tag.matcher(line)).matches()) { | 261 | if ((m = tag.matcher(line)).matches()) { |
diff --git a/src/org/gnunet/util/Connection.java b/src/org/gnunet/util/Connection.java index 8e0c401..f969cbe 100644 --- a/src/org/gnunet/util/Connection.java +++ b/src/org/gnunet/util/Connection.java | |||
@@ -596,7 +596,7 @@ public class Connection { | |||
596 | "previous transmit request must have completed before calling notifyTransmitReady again"); | 596 | "previous transmit request must have completed before calling notifyTransmitReady again"); |
597 | } | 597 | } |
598 | 598 | ||
599 | if (timeout.getMilliseconds() <= 0) { | 599 | if (timeout.getMicroseconds() <= 0) { |
600 | throw new AssertionError("notifyTransmitReady timeout must be positive"); | 600 | throw new AssertionError("notifyTransmitReady timeout must be positive"); |
601 | } | 601 | } |
602 | 602 | ||
diff --git a/src/org/gnunet/util/RelativeTime.java b/src/org/gnunet/util/RelativeTime.java index 7b45bb0..0faedfc 100644 --- a/src/org/gnunet/util/RelativeTime.java +++ b/src/org/gnunet/util/RelativeTime.java | |||
@@ -32,7 +32,8 @@ public final class RelativeTime implements Comparable<RelativeTime> { | |||
32 | private static final Logger logger = LoggerFactory | 32 | private static final Logger logger = LoggerFactory |
33 | .getLogger(RelativeTime.class); | 33 | .getLogger(RelativeTime.class); |
34 | 34 | ||
35 | public static final RelativeTime MILLISECOND = new RelativeTime(1); | 35 | public static final RelativeTime MICROSECOND = new RelativeTime(1); |
36 | public static final RelativeTime MILLISECOND = MICROSECOND.multiply(1000); | ||
36 | public static final RelativeTime SECOND = MILLISECOND.multiply(1000); | 37 | public static final RelativeTime SECOND = MILLISECOND.multiply(1000); |
37 | public static final RelativeTime MINUTE = SECOND.multiply(60); | 38 | public static final RelativeTime MINUTE = SECOND.multiply(60); |
38 | public static final RelativeTime HOUR = MINUTE.multiply(60); | 39 | public static final RelativeTime HOUR = MINUTE.multiply(60); |
@@ -44,7 +45,10 @@ public final class RelativeTime implements Comparable<RelativeTime> { | |||
44 | public static final RelativeTime ZERO = new RelativeTime(0); | 45 | public static final RelativeTime ZERO = new RelativeTime(0); |
45 | public static final RelativeTime FOREVER = new RelativeTime(Long.MAX_VALUE); | 46 | public static final RelativeTime FOREVER = new RelativeTime(Long.MAX_VALUE); |
46 | 47 | ||
47 | private final long rel_value; | 48 | /** |
49 | * Time offset in microseconds. | ||
50 | */ | ||
51 | private final long rel_value_us; | ||
48 | 52 | ||
49 | /** | 53 | /** |
50 | * Create a new RelativeTime value, with a given time in milliseconds. | 54 | * Create a new RelativeTime value, with a given time in milliseconds. |
@@ -52,7 +56,7 @@ public final class RelativeTime implements Comparable<RelativeTime> { | |||
52 | * @param abs_value time in milliseconds | 56 | * @param abs_value time in milliseconds |
53 | */ | 57 | */ |
54 | public RelativeTime(final long abs_value) { | 58 | public RelativeTime(final long abs_value) { |
55 | this.rel_value = abs_value; | 59 | this.rel_value_us = abs_value; |
56 | } | 60 | } |
57 | 61 | ||
58 | /** | 62 | /** |
@@ -64,13 +68,13 @@ public final class RelativeTime implements Comparable<RelativeTime> { | |||
64 | * @return this + other | 68 | * @return this + other |
65 | */ | 69 | */ |
66 | public RelativeTime add(final RelativeTime other) { | 70 | public RelativeTime add(final RelativeTime other) { |
67 | if (this.rel_value == Long.MAX_VALUE | 71 | if (this.rel_value_us == Long.MAX_VALUE |
68 | || other.rel_value == Long.MAX_VALUE) { | 72 | || other.rel_value_us == Long.MAX_VALUE) { |
69 | return RelativeTime.FOREVER; | 73 | return RelativeTime.FOREVER; |
70 | } | 74 | } |
71 | final long new_rel_value = this.rel_value + other.rel_value; | 75 | final long new_rel_value = this.rel_value_us + other.rel_value_us; |
72 | // check for numeric overflow | 76 | // check for numeric overflow |
73 | if (new_rel_value < this.rel_value) { | 77 | if (new_rel_value < this.rel_value_us) { |
74 | logger.warn("time overflow"); | 78 | logger.warn("time overflow"); |
75 | return RelativeTime.FOREVER; | 79 | return RelativeTime.FOREVER; |
76 | } | 80 | } |
@@ -85,10 +89,10 @@ public final class RelativeTime implements Comparable<RelativeTime> { | |||
85 | * @return FOREVER if this=FOREVER or factor=0; otherwise this/factor | 89 | * @return FOREVER if this=FOREVER or factor=0; otherwise this/factor |
86 | */ | 90 | */ |
87 | public RelativeTime divide(final int factor) { | 91 | public RelativeTime divide(final int factor) { |
88 | if (factor == 0 || this.rel_value == Long.MAX_VALUE) { | 92 | if (factor == 0 || this.rel_value_us == Long.MAX_VALUE) { |
89 | return RelativeTime.FOREVER; | 93 | return RelativeTime.FOREVER; |
90 | } | 94 | } |
91 | return new RelativeTime(this.rel_value / factor); | 95 | return new RelativeTime(this.rel_value_us / factor); |
92 | } | 96 | } |
93 | 97 | ||
94 | /** | 98 | /** |
@@ -96,8 +100,8 @@ public final class RelativeTime implements Comparable<RelativeTime> { | |||
96 | * | 100 | * |
97 | * @return the amount of time in milliseconds | 101 | * @return the amount of time in milliseconds |
98 | */ | 102 | */ |
99 | public long getMilliseconds() { | 103 | public long getMicroseconds() { |
100 | return rel_value; | 104 | return rel_value_us; |
101 | } | 105 | } |
102 | 106 | ||
103 | /** | 107 | /** |
@@ -106,7 +110,7 @@ public final class RelativeTime implements Comparable<RelativeTime> { | |||
106 | * @return max(t1, t2) | 110 | * @return max(t1, t2) |
107 | */ | 111 | */ |
108 | public static RelativeTime max(RelativeTime t1, RelativeTime t2) { | 112 | public static RelativeTime max(RelativeTime t1, RelativeTime t2) { |
109 | return t1.rel_value >= t2.rel_value ? t1 : t2; | 113 | return t1.rel_value_us >= t2.rel_value_us ? t1 : t2; |
110 | } | 114 | } |
111 | 115 | ||
112 | /** | 116 | /** |
@@ -115,7 +119,7 @@ public final class RelativeTime implements Comparable<RelativeTime> { | |||
115 | * @return min(this, other) | 119 | * @return min(this, other) |
116 | */ | 120 | */ |
117 | public static RelativeTime min(RelativeTime t1, RelativeTime t2) { | 121 | public static RelativeTime min(RelativeTime t1, RelativeTime t2) { |
118 | return t1.rel_value <= t2.rel_value ? t1 : t2; | 122 | return t1.rel_value_us <= t2.rel_value_us ? t1 : t2; |
119 | } | 123 | } |
120 | 124 | ||
121 | /** | 125 | /** |
@@ -127,9 +131,9 @@ public final class RelativeTime implements Comparable<RelativeTime> { | |||
127 | if (factor == 0) { | 131 | if (factor == 0) { |
128 | return RelativeTime.ZERO; | 132 | return RelativeTime.ZERO; |
129 | } | 133 | } |
130 | final long ret = this.rel_value * factor; | 134 | final long ret = this.rel_value_us * factor; |
131 | // check for numeric overflow | 135 | // check for numeric overflow |
132 | if (ret / factor != rel_value) { | 136 | if (ret / factor != rel_value_us) { |
133 | logger.warn("time overflow"); | 137 | logger.warn("time overflow"); |
134 | return RelativeTime.FOREVER; | 138 | return RelativeTime.FOREVER; |
135 | } | 139 | } |
@@ -145,12 +149,12 @@ public final class RelativeTime implements Comparable<RelativeTime> { | |||
145 | * this=FOREVER, this-other otherwise | 149 | * this=FOREVER, this-other otherwise |
146 | */ | 150 | */ |
147 | public RelativeTime subtract(final RelativeTime other) { | 151 | public RelativeTime subtract(final RelativeTime other) { |
148 | if (this.rel_value >= other.rel_value) { | 152 | if (this.rel_value_us >= other.rel_value_us) { |
149 | return RelativeTime.ZERO; | 153 | return RelativeTime.ZERO; |
150 | } else if (this.rel_value == Long.MAX_VALUE) { | 154 | } else if (this.rel_value_us == Long.MAX_VALUE) { |
151 | return this; | 155 | return this; |
152 | } else { | 156 | } else { |
153 | return new RelativeTime(this.rel_value - other.rel_value); | 157 | return new RelativeTime(this.rel_value_us - other.rel_value_us); |
154 | } | 158 | } |
155 | } | 159 | } |
156 | 160 | ||
@@ -165,24 +169,24 @@ public final class RelativeTime implements Comparable<RelativeTime> { | |||
165 | } | 169 | } |
166 | 170 | ||
167 | public boolean isForever() { | 171 | public boolean isForever() { |
168 | return rel_value == FOREVER.rel_value; | 172 | return rel_value_us == FOREVER.rel_value_us; |
169 | } | 173 | } |
170 | 174 | ||
171 | public boolean equals(Object o) { | 175 | public boolean equals(Object o) { |
172 | return (o instanceof RelativeTime) && ((RelativeTime) o).rel_value == rel_value; | 176 | return (o instanceof RelativeTime) && ((RelativeTime) o).rel_value_us == rel_value_us; |
173 | } | 177 | } |
174 | 178 | ||
175 | @Override | 179 | @Override |
176 | public int hashCode() { | 180 | public int hashCode() { |
177 | return (int) this.rel_value; | 181 | return (int) this.rel_value_us; |
178 | } | 182 | } |
179 | 183 | ||
180 | @Override | 184 | @Override |
181 | public int compareTo(RelativeTime other) { | 185 | public int compareTo(RelativeTime other) { |
182 | if (this.rel_value < other.rel_value) { | 186 | if (this.rel_value_us < other.rel_value_us) { |
183 | return -1; | 187 | return -1; |
184 | } | 188 | } |
185 | if (this.rel_value > other.rel_value) { | 189 | if (this.rel_value_us > other.rel_value_us) { |
186 | return 1; | 190 | return 1; |
187 | } | 191 | } |
188 | return 0; | 192 | return 0; |
@@ -193,16 +197,16 @@ public final class RelativeTime implements Comparable<RelativeTime> { | |||
193 | if (this.isForever()) { | 197 | if (this.isForever()) { |
194 | return "RelativeTime(FOREVER)"; | 198 | return "RelativeTime(FOREVER)"; |
195 | } | 199 | } |
196 | return "RelativeTime("+this.rel_value+")"; | 200 | return "RelativeTime("+this.rel_value_us +")"; |
197 | } | 201 | } |
198 | 202 | ||
199 | 203 | ||
200 | 204 | ||
201 | 205 | ||
202 | public RelativeTimeMessage toNetwork() { | 206 | public RelativeTimeMessage toNetwork() { |
203 | long rval = this.rel_value; | 207 | long rval = this.rel_value_us; |
204 | assert rval >= 0; | 208 | assert rval >= 0; |
205 | if (rval == FOREVER.rel_value) { | 209 | if (rval == FOREVER.rel_value_us) { |
206 | rval = -1L; /* 0xFFFFFFFFFFFFFFFF for network format! */ | 210 | rval = -1L; /* 0xFFFFFFFFFFFFFFFF for network format! */ |
207 | } | 211 | } |
208 | return new RelativeTimeMessage(rval); | 212 | return new RelativeTimeMessage(rval); |
diff --git a/src/org/gnunet/util/RelativeTimeMessage.java b/src/org/gnunet/util/RelativeTimeMessage.java index 9488441..ac4e66c 100644 --- a/src/org/gnunet/util/RelativeTimeMessage.java +++ b/src/org/gnunet/util/RelativeTimeMessage.java | |||
@@ -48,7 +48,7 @@ public class RelativeTimeMessage implements Message { | |||
48 | if (t.equals(RelativeTime.FOREVER)) { | 48 | if (t.equals(RelativeTime.FOREVER)) { |
49 | this.value__ = -1; | 49 | this.value__ = -1; |
50 | } else { | 50 | } else { |
51 | this.value__ = t.getMilliseconds(); | 51 | this.value__ = t.getMicroseconds(); |
52 | } | 52 | } |
53 | } | 53 | } |
54 | 54 | ||
diff --git a/src/org/gnunet/util/Scheduler.java b/src/org/gnunet/util/Scheduler.java index 3680261..6998633 100644 --- a/src/org/gnunet/util/Scheduler.java +++ b/src/org/gnunet/util/Scheduler.java | |||
@@ -384,7 +384,7 @@ public class Scheduler { | |||
384 | break; | 384 | break; |
385 | } | 385 | } |
386 | RelativeTime remaining = t.deadline.getRemaining(); | 386 | RelativeTime remaining = t.deadline.getRemaining(); |
387 | if (remaining.getMilliseconds() <= 0) { | 387 | if (remaining.getMicroseconds() <= 0) { |
388 | t.deregister(); | 388 | t.deregister(); |
389 | t.ctx.reasons = EnumSet.of(Reason.TIMEOUT); | 389 | t.ctx.reasons = EnumSet.of(Reason.TIMEOUT); |
390 | queueReady(t); | 390 | queueReady(t); |
@@ -408,12 +408,12 @@ public class Scheduler { | |||
408 | private static void handleSelect(RelativeTime timeout) { | 408 | private static void handleSelect(RelativeTime timeout) { |
409 | try { | 409 | try { |
410 | // selector.select(0) would block indefinitely (counter-intuitive, java's fault) | 410 | // selector.select(0) would block indefinitely (counter-intuitive, java's fault) |
411 | if (timeout.getMilliseconds() == 0) { | 411 | if (timeout.getMicroseconds() == 0) { |
412 | selector.selectNow(); | 412 | selector.selectNow(); |
413 | } else if (timeout.isForever()) { | 413 | } else if (timeout.isForever()) { |
414 | selector.select(0); | 414 | selector.select(0); |
415 | } else { | 415 | } else { |
416 | selector.select(timeout.getMilliseconds()); | 416 | selector.select(timeout.getMicroseconds()); |
417 | } | 417 | } |
418 | } catch (IOException e) { | 418 | } catch (IOException e) { |
419 | throw new IOError(e); | 419 | throw new IOError(e); |
@@ -461,6 +461,7 @@ public class Scheduler { | |||
461 | * @param initialTask the initial task to run immediately | 461 | * @param initialTask the initial task to run immediately |
462 | */ | 462 | */ |
463 | public static void run(Task initialTask) { | 463 | public static void run(Task initialTask) { |
464 | logger.info("running scheduler"); | ||
464 | if (scheduler_running) { | 465 | if (scheduler_running) { |
465 | throw new AssertionError("Scheduler already running"); | 466 | throw new AssertionError("Scheduler already running"); |
466 | } | 467 | } |
@@ -468,6 +469,7 @@ public class Scheduler { | |||
468 | try { | 469 | try { |
469 | run_unchecked(initialTask); | 470 | run_unchecked(initialTask); |
470 | } finally { | 471 | } finally { |
472 | logger.info("cleaning up after scheduler ran"); | ||
471 | // ensure that after run returns, the scheduler is in its initial state, | 473 | // ensure that after run returns, the scheduler is in its initial state, |
472 | // even though there was an exception (e.g. after a test case that expects an exception) | 474 | // even though there was an exception (e.g. after a test case that expects an exception) |
473 | scheduler_running = false; | 475 | scheduler_running = false; |
@@ -495,7 +497,7 @@ public class Scheduler { | |||
495 | // the gnunet main loop | 497 | // the gnunet main loop |
496 | while (checkLiveness()) { | 498 | while (checkLiveness()) { |
497 | RelativeTime nextTimeout = handleTimeouts(); | 499 | RelativeTime nextTimeout = handleTimeouts(); |
498 | if (nextTimeout.getMilliseconds() < 0) { | 500 | if (nextTimeout.getMicroseconds() < 0) { |
499 | logger.warn("negative timeout for select"); | 501 | logger.warn("negative timeout for select"); |
500 | } | 502 | } |
501 | 503 | ||