aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/gnunet/core
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2013-08-27 17:16:18 +0000
committerFlorian Dold <florian.dold@gmail.com>2013-08-27 17:16:18 +0000
commita942ffadee0fe9fd385decdf818ad6baae8c99b3 (patch)
treed500fbdba7379631b0591a19417c7c3f3df29194 /src/main/java/org/gnunet/core
parent6be9a1ed1b7847c795cb700e3e0bd87824fc0573 (diff)
downloadgnunet-java-a942ffadee0fe9fd385decdf818ad6baae8c99b3.tar.gz
gnunet-java-a942ffadee0fe9fd385decdf818ad6baae8c99b3.zip
- adapted source tree structure to gradle/maven conventions
- added gradle wrapper - fixes to adapt to GNUnet changes (new time unit, ...) - helper process in util - started implementing testbed - skeleton for voting tools - use new mq api - implemented some more transport api - mesh
Diffstat (limited to 'src/main/java/org/gnunet/core')
-rw-r--r--src/main/java/org/gnunet/core/ConnectHandler.java30
-rw-r--r--src/main/java/org/gnunet/core/ConnectNotifyMessage.java54
-rw-r--r--src/main/java/org/gnunet/core/Core.java347
-rw-r--r--src/main/java/org/gnunet/core/DisconnectHandler.java30
-rw-r--r--src/main/java/org/gnunet/core/DisconnectNotifyMessage.java46
-rw-r--r--src/main/java/org/gnunet/core/HeaderNotify.java30
-rw-r--r--src/main/java/org/gnunet/core/InitCallback.java30
-rw-r--r--src/main/java/org/gnunet/core/InitMessage.java45
-rw-r--r--src/main/java/org/gnunet/core/InitReplyMessage.java39
-rw-r--r--src/main/java/org/gnunet/core/MessageNotify.java28
-rw-r--r--src/main/java/org/gnunet/core/NotifyInboundTrafficMessage.java47
-rw-r--r--src/main/java/org/gnunet/core/NotifyOutboundTrafficMessage.java58
-rw-r--r--src/main/java/org/gnunet/core/RequestIdentification.java35
-rw-r--r--src/main/java/org/gnunet/core/SendMessage.java71
-rw-r--r--src/main/java/org/gnunet/core/SendMessageReady.java56
-rw-r--r--src/main/java/org/gnunet/core/SendMessageRequest.java73
-rw-r--r--src/main/java/org/gnunet/core/package-info.java24
17 files changed, 1043 insertions, 0 deletions
diff --git a/src/main/java/org/gnunet/core/ConnectHandler.java b/src/main/java/org/gnunet/core/ConnectHandler.java
new file mode 100644
index 0000000..a36d798
--- /dev/null
+++ b/src/main/java/org/gnunet/core/ConnectHandler.java
@@ -0,0 +1,30 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 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
21package org.gnunet.core;
22
23import org.gnunet.util.PeerIdentity;
24
25/**
26 * Called when a new peer (with a compatible set of messages) connects to core
27 */
28public interface ConnectHandler {
29 void onConnect(PeerIdentity peerIdentity);
30}
diff --git a/src/main/java/org/gnunet/core/ConnectNotifyMessage.java b/src/main/java/org/gnunet/core/ConnectNotifyMessage.java
new file mode 100644
index 0000000..4eafe02
--- /dev/null
+++ b/src/main/java/org/gnunet/core/ConnectNotifyMessage.java
@@ -0,0 +1,54 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 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
21package org.gnunet.core;
22
23import org.gnunet.construct.*;
24import org.gnunet.util.GnunetMessage;
25import org.gnunet.util.PeerIdentity;
26
27/**
28 * Message sent by the service to clients to notify them
29 * about a peer connecting.
30 */
31@UnionCase(67)
32public class ConnectNotifyMessage implements GnunetMessage.Body {
33 /**
34 * Number of ATS key-value pairs that follow this struct
35 * (excluding the 0-terminator).
36 */
37 @UInt32
38 public long atsCount;
39
40 /**
41 * Identity of the connecting peer.
42 */
43 @NestedMessage
44 public PeerIdentity peer;
45
46
47 @FillWith @UInt8
48 public byte[] atsInfo;
49
50
51 //@FillWith
52 //public ATSInformation[] atsInformation;
53
54}
diff --git a/src/main/java/org/gnunet/core/Core.java b/src/main/java/org/gnunet/core/Core.java
new file mode 100644
index 0000000..2895e41
--- /dev/null
+++ b/src/main/java/org/gnunet/core/Core.java
@@ -0,0 +1,347 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 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
21package org.gnunet.core;
22
23import com.google.common.collect.Maps;
24import org.gnunet.construct.Construct;
25import org.gnunet.construct.MessageLoader;
26import org.gnunet.mq.Envelope;
27import org.gnunet.requests.MatchingRequestContainer;
28import org.gnunet.requests.RequestContainer;
29import org.gnunet.util.*;
30import org.grothoff.Runabout;
31import org.slf4j.Logger;
32import org.slf4j.LoggerFactory;
33
34import java.util.HashMap;
35
36
37/**
38 * API for the gnunet core service.
39 * <p/>
40 * Sends messages to connected peers.
41 */
42public class Core {
43 /**
44 * Logger for org.gnunet.Core.
45 */
46 private static final Logger logger = LoggerFactory
47 .getLogger(Core.class);
48
49 /**
50 * Client for connecting to the core service
51 */
52 private final Client client;
53
54 /*
55 * set to null once connected for the first time
56 */
57 private InitCallback initCallback;
58
59 /*
60 * Callback for traffic notifications. null if not interested.
61 */
62 private HeaderNotify notifyOutboundHeaders;
63
64 /*
65 * Callback for traffic notifications. null if not interested.
66 */
67 private HeaderNotify notifyInboundHeaders;
68
69 /*
70 * Callback for traffic notifications. null if not interested.
71 */
72 private MessageNotify notifyOutboundMessages;
73
74 /*
75 * Callback for traffic notifications. null if not interested.
76 */
77 private MessageNotify notifyInboundMessages;
78
79 /*
80 * Callbacks for connect events
81 */
82 private ConnectHandler connectHandler;
83
84 /**
85 * Callback for disconnect events.
86 */
87 private DisconnectHandler disconnectHandler;
88
89 /**
90 * Messages we are interested in.
91 * Per default we are interested in all messages => specific interest set is empty.
92 */
93 private int[] interested = new int[0];
94
95 /**
96 * Handler for the messages we are interested in.
97 */
98 private Runabout messageHandler;
99
100 /**
101 * Peers that we were notified about being connected to them.
102 * Every connected peer is mapped to a generator for unique request IDs.
103 */
104 private HashMap<PeerIdentity, Integer> connectedPeers = Maps.newHashMap();
105
106 /**
107 * Request container for notify transmit requests.
108 */
109 private MatchingRequestContainer<RequestIdentification, NotifyTransmitReadyRequest> ntr_requests;
110
111 public static class NotifyTransmitReadyRequest extends RequestContainer.Request {
112 private final int size;
113 final public PeerIdentity target;
114 final public long priority;
115 public int smrId;
116 final public MessageTransmitter transmitter;
117 final public AbsoluteTime deadline;
118
119 public NotifyTransmitReadyRequest(int priority, int size, PeerIdentity target, RelativeTime timeout, MessageTransmitter transmitter) {
120 this.deadline = timeout.toAbsolute();
121 this.priority = priority;
122 this.size = size;
123 this.target = target;
124 this.transmitter = transmitter;
125 }
126
127 @Override
128 public Envelope assembleRequest() {
129 SendMessageRequest m = new SendMessageRequest();
130 m.peer = target;
131 m.smrId = smrId;
132 m.priority = priority;
133 m.size = size;
134 m.deadline = deadline.asMessage();
135 return new Envelope(m);
136 }
137
138 public void cancel() {
139 // do nothing
140 }
141 }
142
143
144 public final class CoreReceiver extends RunaboutMessageReceiver {
145 public void visit(InitReplyMessage m) {
146 PeerIdentity myIdentity = m.myIdentity;
147 connectedPeers.put(myIdentity, 1);
148
149 if (initCallback != null) {
150 initCallback.onInit(m.myIdentity);
151 initCallback = null;
152 }
153 }
154
155 public void visit(ConnectNotifyMessage m) {
156 if (connectHandler != null) {
157 connectHandler.onConnect(m.peer);
158 }
159 }
160
161 public void visit(DisconnectNotifyMessage m) {
162 if (disconnectHandler != null) {
163 disconnectHandler.onDisconnect(m.peer);
164 }
165 }
166
167 public void visit(NotifyInboundTrafficMessage m) {
168 boolean found = false;
169 if (notifyInboundHeaders != null) {
170 notifyInboundHeaders.notify(m.payloadHeader);
171 }
172 if (notifyInboundMessages != null) {
173 // todo: call corresponding notify on notifyInboundMessages
174 }
175
176 for (int i : interested) {
177 if (i == m.payloadHeader.messageType) {
178 found = true;
179 break;
180 }
181 }
182 if (found) {
183 Class bodyClass = MessageLoader.getUnionClass(GnunetMessage.Body.class, m.payloadHeader.messageType);
184 @SuppressWarnings("unchecked")
185 GnunetMessage.Body b = (GnunetMessage.Body) Construct.parseAs(m.payloadBody, bodyClass);
186 messageHandler.visitAppropriate(b);
187 }
188 }
189
190 public void visit(NotifyOutboundTrafficMessage m) {
191 if (notifyOutboundHeaders != null) {
192 notifyOutboundHeaders.notify(m.payloadHeader);
193 }
194 if (notifyOutboundMessages != null) {
195 // todo
196 }
197 }
198
199 public void visit(SendMessageReady m) {
200 RequestIdentification rid = new RequestIdentification(m.smrId, m.peer);
201 NotifyTransmitReadyRequest req = ntr_requests.getRequest(rid);
202
203 final SendMessage sm = new SendMessage();
204 sm.cork = 0;
205 sm.peer = req.target;
206 sm.priority = req.priority;
207 sm.deadline = req.deadline.asMessage();
208
209 req.transmitter.transmit(new Connection.MessageSink() {
210 boolean sent;
211 @Override
212 public void send(GnunetMessage.Body m) {
213 if (sent) {
214 throw new AssertionError("sending multiple messages not supported");
215 }
216 sm.payloadMessage = GnunetMessage.fromBody(m);
217 sent = true;
218 }
219 });
220
221
222 if (sm.payloadMessage == null)
223 throw new AssertionError();
224
225 client.send(sm);
226 }
227
228 @Override
229 public void visitDefault(Object o) {
230 logger.warn("received unexpected message from core: {}", o.getClass());
231 }
232
233 @Override
234 public void handleError() {
235 if (disconnectHandler != null) {
236 for (PeerIdentity e : connectedPeers.keySet()) {
237 disconnectHandler.onDisconnect(e);
238 }
239 }
240 connectedPeers.clear();
241 }
242 }
243
244 public Core(Configuration cfg) {
245 client = new Client("core", cfg);
246 client.installReceiver(new CoreReceiver());
247 ntr_requests = new MatchingRequestContainer<RequestIdentification, NotifyTransmitReadyRequest>(client);
248 }
249
250 /**
251 * Send to the service which messages are we interested in.
252 *
253 * @param initCallback called after the init message has been sent
254 */
255 public void init(InitCallback initCallback) {
256 this.initCallback = initCallback;
257 InitMessage initMessage = new InitMessage();
258
259 initMessage.interested = interested;
260 initMessage.options = 0;
261
262 for (int i : interested) {
263 logger.debug("we are interested in " + i);
264 }
265 client.sendPrefered(initMessage);
266 }
267
268 /**
269 * Ask the core to call "notify" once it is ready to transmit the
270 * given number of bytes to the specified "target". Must only be
271 * called after a connection to the respective peer has been
272 * established (and the client has been informed about this).
273 *
274 * @param priority how important is the message?
275 * @param maxdelay how long can the message wait?
276 * @param target the identity of the receiver
277 * @param size the size of the message we want to transmit
278 * @param transmitter called once the core service is ready to send message
279 * @return a handle to cancel the notification
280 */
281 public Cancelable notifyTransmitReady(int priority, RelativeTime maxdelay,
282 PeerIdentity target, int size, final MessageTransmitter transmitter) {
283 if (!connectedPeers.containsKey(target)) {
284 throw new AssertionError("notifyTransmitReady called for unconnected peer");
285 }
286 int id = connectedPeers.get(target);
287 connectedPeers.put(target, id+1);
288 NotifyTransmitReadyRequest notifyRequest = new NotifyTransmitReadyRequest(priority, size, target, maxdelay, transmitter);
289 notifyRequest.smrId = id;
290 RequestIdentification rid = new RequestIdentification(notifyRequest.smrId, target);
291 return ntr_requests.addRequest(rid, notifyRequest);
292 }
293
294 /**
295 * Observe outgoing message headers from core.
296 * @param h callback
297 */
298 public void observeOutboundHeaders(HeaderNotify h) {
299 this.notifyOutboundHeaders = h;
300 }
301
302 public void observeInboundHeaders(HeaderNotify h) {
303 this.notifyInboundHeaders = h;
304 }
305
306 public void observeInboundMessages(MessageNotify h) {
307 this.notifyInboundMessages = h;
308 }
309
310 public void observeOutboundMessages(MessageNotify h) {
311 this.notifyOutboundMessages = h;
312 }
313
314 public void observeConnect(ConnectHandler connectHandler) {
315 this.connectHandler = connectHandler;
316 }
317
318 public void observeDisconnect(DisconnectHandler disconnectHandler) {
319 this.disconnectHandler = disconnectHandler;
320 }
321
322 /**
323 * Handle all incoming messages with the specified runabout.
324 * Has to be called before init, as the service has to know which messages we
325 * are interested in.
326 */
327 public void setMessageHandler(Runabout runabout) {
328 if (messageHandler != null) {
329 throw new AssertionError("Core can have only on message handler");
330 }
331 if (client.isConnected()) {
332 // todo: shouldn't we just reconnect?
333 throw new AssertionError("can set message handler only if not yet connected");
334 }
335 messageHandler = runabout;
336 interested = RunaboutUtil.getRunaboutMessageTypes(runabout);
337 }
338
339 /**
340 * Disconnect from the core service. This function can only
341 * be called *after* all pending notifyTransmitReady
342 * requests have been explicitly cancelled.
343 */
344 public void disconnect() {
345 client.disconnect();
346 }
347}
diff --git a/src/main/java/org/gnunet/core/DisconnectHandler.java b/src/main/java/org/gnunet/core/DisconnectHandler.java
new file mode 100644
index 0000000..c7ca407
--- /dev/null
+++ b/src/main/java/org/gnunet/core/DisconnectHandler.java
@@ -0,0 +1,30 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 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
21package org.gnunet.core;
22
23import org.gnunet.util.PeerIdentity;
24
25/**
26 * Called when a peer disconnects from the core.
27 */
28public interface DisconnectHandler {
29 void onDisconnect(PeerIdentity peerIdentity);
30}
diff --git a/src/main/java/org/gnunet/core/DisconnectNotifyMessage.java b/src/main/java/org/gnunet/core/DisconnectNotifyMessage.java
new file mode 100644
index 0000000..e4c3209
--- /dev/null
+++ b/src/main/java/org/gnunet/core/DisconnectNotifyMessage.java
@@ -0,0 +1,46 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 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
21package org.gnunet.core;
22
23import org.gnunet.construct.NestedMessage;
24import org.gnunet.construct.UInt32;
25import org.gnunet.construct.UnionCase;
26import org.gnunet.util.GnunetMessage;
27import org.gnunet.util.PeerIdentity;
28
29/**
30 * Message sent by the service to clients to notify them
31 * about a peer disconnecting.
32 */
33@UnionCase(68)
34public class DisconnectNotifyMessage implements GnunetMessage.Body {
35 /**
36 * Always zero.
37 */
38 @UInt32
39 public int reserved;
40
41 /**
42 * Identity of the connecting peer.
43 */
44 @NestedMessage
45 public PeerIdentity peer;
46}
diff --git a/src/main/java/org/gnunet/core/HeaderNotify.java b/src/main/java/org/gnunet/core/HeaderNotify.java
new file mode 100644
index 0000000..4f536e3
--- /dev/null
+++ b/src/main/java/org/gnunet/core/HeaderNotify.java
@@ -0,0 +1,30 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 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
21package org.gnunet.core;
22
23import org.gnunet.util.GnunetMessage;
24
25/**
26 *
27 */
28public interface HeaderNotify {
29 void notify(GnunetMessage.Header header);
30}
diff --git a/src/main/java/org/gnunet/core/InitCallback.java b/src/main/java/org/gnunet/core/InitCallback.java
new file mode 100644
index 0000000..889f8cf
--- /dev/null
+++ b/src/main/java/org/gnunet/core/InitCallback.java
@@ -0,0 +1,30 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 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
21package org.gnunet.core;
22
23import org.gnunet.util.PeerIdentity;
24
25/**
26 * Called once the handshake with core was successful.
27 */
28public interface InitCallback {
29 void onInit(PeerIdentity myIdentity);
30}
diff --git a/src/main/java/org/gnunet/core/InitMessage.java b/src/main/java/org/gnunet/core/InitMessage.java
new file mode 100644
index 0000000..5546088
--- /dev/null
+++ b/src/main/java/org/gnunet/core/InitMessage.java
@@ -0,0 +1,45 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 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
21package org.gnunet.core;
22
23import org.gnunet.construct.IntegerFill;
24import org.gnunet.construct.UInt32;
25import org.gnunet.construct.UnionCase;
26import org.gnunet.util.GnunetMessage;
27
28
29@UnionCase(64)
30public class InitMessage implements GnunetMessage.Body {
31 /*
32 * Options used to tell core what kind of traffic notify messages we are interested in.
33 */
34 private final static int
35 OPTION_FULL_INBOUND = 8,
36 OPTION_HDR_INBOUND = 16,
37 OPTION_FULL_OUTBOUND = 32,
38 OPTION_HDR_OUTBOUND = 64;
39
40 @UInt32
41 public long options;
42
43 @IntegerFill(signed = false, bitSize = 16)
44 public int[] interested;
45}
diff --git a/src/main/java/org/gnunet/core/InitReplyMessage.java b/src/main/java/org/gnunet/core/InitReplyMessage.java
new file mode 100644
index 0000000..02e8eef
--- /dev/null
+++ b/src/main/java/org/gnunet/core/InitReplyMessage.java
@@ -0,0 +1,39 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 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
21package org.gnunet.core;
22
23import org.gnunet.construct.NestedMessage;
24import org.gnunet.construct.UInt32;
25import org.gnunet.construct.UnionCase;
26import org.gnunet.util.GnunetMessage;
27import org.gnunet.util.PeerIdentity;
28
29
30@UnionCase(65)
31public class InitReplyMessage implements GnunetMessage.Body {
32 @UInt32
33 public int reserved = 0;
34 /**
35 * pubkey of the local peer
36 */
37 @NestedMessage
38 public PeerIdentity myIdentity;
39}
diff --git a/src/main/java/org/gnunet/core/MessageNotify.java b/src/main/java/org/gnunet/core/MessageNotify.java
new file mode 100644
index 0000000..b14ce29
--- /dev/null
+++ b/src/main/java/org/gnunet/core/MessageNotify.java
@@ -0,0 +1,28 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 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
21package org.gnunet.core;
22
23import org.gnunet.util.GnunetMessage;
24
25
26public interface MessageNotify {
27 void notify(GnunetMessage messageBody);
28}
diff --git a/src/main/java/org/gnunet/core/NotifyInboundTrafficMessage.java b/src/main/java/org/gnunet/core/NotifyInboundTrafficMessage.java
new file mode 100644
index 0000000..2bdd428
--- /dev/null
+++ b/src/main/java/org/gnunet/core/NotifyInboundTrafficMessage.java
@@ -0,0 +1,47 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 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
21package org.gnunet.core;
22
23import org.gnunet.construct.*;
24import org.gnunet.util.ATSInformation;
25import org.gnunet.util.GnunetMessage;
26import org.gnunet.util.PeerIdentity;
27
28
29@UnionCase(70)
30public class NotifyInboundTrafficMessage implements GnunetMessage.Body {
31 /**
32 * Identity of the receiver or sender.
33 */
34 @NestedMessage
35 public PeerIdentity peer;
36
37 @NestedMessage(newFrame = true)
38 public GnunetMessage.Header payloadHeader;
39
40 /**
41 * The (optional) message body corresponding to payloadHeader.
42 * Not typed as GnunetMessage.Body because the message type may not be known by this
43 * peer.
44 */
45 @FillWith @UInt8
46 public byte[] payloadBody;
47}
diff --git a/src/main/java/org/gnunet/core/NotifyOutboundTrafficMessage.java b/src/main/java/org/gnunet/core/NotifyOutboundTrafficMessage.java
new file mode 100644
index 0000000..900f8be
--- /dev/null
+++ b/src/main/java/org/gnunet/core/NotifyOutboundTrafficMessage.java
@@ -0,0 +1,58 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 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
21package org.gnunet.core;
22
23import org.gnunet.construct.*;
24import org.gnunet.util.ATSInformation;
25import org.gnunet.util.GnunetMessage;
26import org.gnunet.util.PeerIdentity;
27
28
29@UnionCase(71)
30public class NotifyOutboundTrafficMessage implements GnunetMessage.Body {
31 /**
32 * Number of ATS key-value pairs that follow this struct
33 * (excluding the 0-terminator).
34 */
35 @UInt32
36 public long ats_count;
37
38 /**
39 * Identity of the receiver or sender.
40 */
41 @NestedMessage
42 public PeerIdentity peer;
43
44 @VariableSizeArray(lengthField = "ats_count")
45 public ATSInformation[] atsRest;
46
47 @NestedMessage(newFrame = true)
48 public GnunetMessage.Header payloadHeader;
49
50 /**
51 * The (optional) message body corresponding to payloadHeader.
52 * Not typed as GnunetMessage.Body because the message type may not be known by this
53 * peer.
54 */
55 @FillWith @UInt8
56 public byte[] payloadBody;
57
58}
diff --git a/src/main/java/org/gnunet/core/RequestIdentification.java b/src/main/java/org/gnunet/core/RequestIdentification.java
new file mode 100644
index 0000000..4f6a734
--- /dev/null
+++ b/src/main/java/org/gnunet/core/RequestIdentification.java
@@ -0,0 +1,35 @@
1package org.gnunet.core;
2
3import org.gnunet.peerinfo.PeerInfo;
4import org.gnunet.util.PeerIdentity;
5
6
7final class RequestIdentification {
8 public final int requestIdentifier;
9 public final PeerIdentity peerIdentity;
10
11 public RequestIdentification(int requestIdentifier, PeerIdentity peerIdentity) {
12 this.requestIdentifier = requestIdentifier;
13 this.peerIdentity = peerIdentity;
14 }
15
16 @Override
17 public boolean equals(Object o) {
18 if (this == o) return true;
19 if (o == null || getClass() != o.getClass()) return false;
20
21 RequestIdentification that = (RequestIdentification) o;
22
23 if (requestIdentifier != that.requestIdentifier) return false;
24 if (!peerIdentity.equals(that.peerIdentity)) return false;
25
26 return true;
27 }
28
29 @Override
30 public int hashCode() {
31 int result = requestIdentifier;
32 result = 31 * result + peerIdentity.hashCode();
33 return result;
34 }
35}
diff --git a/src/main/java/org/gnunet/core/SendMessage.java b/src/main/java/org/gnunet/core/SendMessage.java
new file mode 100644
index 0000000..e4c6215
--- /dev/null
+++ b/src/main/java/org/gnunet/core/SendMessage.java
@@ -0,0 +1,71 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 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
21package org.gnunet.core;
22
23import org.gnunet.construct.NestedMessage;
24import org.gnunet.construct.UInt32;
25import org.gnunet.construct.UInt64;
26import org.gnunet.construct.UnionCase;
27import org.gnunet.util.AbsoluteTimeMessage;
28import org.gnunet.util.GnunetMessage;
29import org.gnunet.util.PeerIdentity;
30
31/**
32 * Client asking core to transmit a particular message to a particular
33 * target (response to GNUNET_MESSAGE_TYPE_CORE_SEND_READY).
34 */
35@UnionCase(76)
36public class SendMessage implements GnunetMessage.Body {
37 /**
38 * How important is this message?
39 */
40 @UInt32
41 public long priority;
42
43 /**
44 * By what time would the sender really like to see this
45 * message transmitted?
46 */
47 @NestedMessage
48 public AbsoluteTimeMessage deadline;
49
50 /**
51 * Identity of the intended receiver.
52 */
53 @NestedMessage
54 public PeerIdentity peer;
55
56 /**
57 * GNUNET_YES if corking is allowed, GNUNET_NO if not.
58 */
59 @UInt32
60 public int cork;
61
62 /**
63 * Always 0.
64 */
65 @UInt64
66 public int reserved;
67
68 @NestedMessage(newFrame = true)
69 public GnunetMessage payloadMessage;
70
71}
diff --git a/src/main/java/org/gnunet/core/SendMessageReady.java b/src/main/java/org/gnunet/core/SendMessageReady.java
new file mode 100644
index 0000000..aa5bf44
--- /dev/null
+++ b/src/main/java/org/gnunet/core/SendMessageReady.java
@@ -0,0 +1,56 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 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
21package org.gnunet.core;
22
23import org.gnunet.construct.NestedMessage;
24import org.gnunet.construct.UInt16;
25import org.gnunet.construct.UnionCase;
26import org.gnunet.util.GnunetMessage;
27import org.gnunet.util.PeerIdentity;
28
29/**
30 * Core notifying client that it is allowed to now
31 * transmit a message to the given target
32 * (response to GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST).
33 */
34@UnionCase(75)
35public class SendMessageReady implements GnunetMessage.Body {
36 /**
37 * How many bytes are allowed for transmission?
38 * Guaranteed to be at least as big as the requested size,
39 * or ZERO if the request is rejected (will timeout,
40 * peer disconnected, queue full, etc.).
41 */
42 @UInt16
43 public int size;
44
45 /**
46 * smrId from the request.
47 */
48 @UInt16
49 public int smrId;
50
51 /**
52 * Identity of the intended target.
53 */
54 @NestedMessage
55 public PeerIdentity peer;
56}
diff --git a/src/main/java/org/gnunet/core/SendMessageRequest.java b/src/main/java/org/gnunet/core/SendMessageRequest.java
new file mode 100644
index 0000000..7a95127
--- /dev/null
+++ b/src/main/java/org/gnunet/core/SendMessageRequest.java
@@ -0,0 +1,73 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 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
21package org.gnunet.core;
22
23import org.gnunet.construct.NestedMessage;
24import org.gnunet.construct.UInt16;
25import org.gnunet.construct.UInt32;
26import org.gnunet.construct.UnionCase;
27import org.gnunet.util.AbsoluteTimeMessage;
28import org.gnunet.util.GnunetMessage;
29import org.gnunet.util.PeerIdentity;
30
31/**
32 * Client notifying core about the maximum-priority
33 * message it has in the queue for a particular target.
34 */
35@UnionCase(74)
36public class SendMessageRequest implements GnunetMessage.Body {
37 /**
38 * How important is this message?
39 */
40 @UInt32
41 public long priority;
42
43 /**
44 * By what time would the sender really like to see this
45 * message transmitted?
46 */
47 @NestedMessage
48 public AbsoluteTimeMessage deadline;
49
50 /**
51 * Identity of the intended target.
52 */
53 @NestedMessage
54 public PeerIdentity peer;
55
56 /**
57 * How large is the client's message queue for this peer?
58 */
59 @UInt32
60 public byte reserved;
61
62 /**
63 * How large is the message?
64 */
65 @UInt16
66 public int size;
67
68 /**
69 * Counter for this peer to match SMRs to replies.
70 */
71 @UInt16
72 public int smrId;
73}
diff --git a/src/main/java/org/gnunet/core/package-info.java b/src/main/java/org/gnunet/core/package-info.java
new file mode 100644
index 0000000..64e5d59
--- /dev/null
+++ b/src/main/java/org/gnunet/core/package-info.java
@@ -0,0 +1,24 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 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/**
22 * API for the gnunet core service.
23 */
24package org.gnunet.core;