diff options
-rw-r--r-- | ISSUES | 84 | ||||
-rw-r--r-- | src/main/java/org/gnunet/gns/GNS.java | 145 | ||||
-rw-r--r-- | src/main/java/org/gnunet/gns/GnsRecord.java | 86 | ||||
-rw-r--r-- | src/main/java/org/gnunet/gns/LookupResultProcessor.java | 34 | ||||
-rw-r--r-- | src/main/java/org/gnunet/gns/messages/ClientLookupMessage.java | 73 | ||||
-rw-r--r-- | src/main/java/org/gnunet/gns/messages/ClientLookupResultMessage.java | 66 | ||||
-rw-r--r-- | src/main/java/org/gnunet/requests/MatchingRequestContainer.java | 7 | ||||
-rw-r--r-- | src/main/java/org/gnunet/requests/RequestContainer.java | 31 |
8 files changed, 480 insertions, 46 deletions
@@ -1,58 +1,50 @@ | |||
1 | * even though my talk was quite horrible, I got to know | 1 | secretsharing |
2 | some TOR people, who need distributed _nonce_ generation (which requires byz-consensus ...) | 2 | * plaintexts: |
3 | * due to the (sub-)group we chose, not every bit pattern is a valid | ||
4 | message | ||
5 | * => GNUNET_SECRETSHARING_message_generate (...) | ||
3 | 6 | ||
4 | * in the current protocol, a rushing adversary may still _influence_ (but not determine) | 7 | secretsharing working, both keygen and decryption |
5 | the public key, will that be a problem? | 8 | * debugging was a pain ... |
6 | * the same "attack" as on tor's nonce generation scheme | ||
7 | 9 | ||
8 | * secretsharing DKG and cooperative decryption implemented and working | 10 | libgcrypt: |
9 | * ... but not robust yet (signatures!) | 11 | The following code does not terminate. |
10 | * ... and without the ZKP that requires the gauss lattice reduction | ||
11 | 12 | ||
12 | * how is work on multicast going, and is there any chance that | 13 | gcry_mpi_set_ui (x, 0); |
13 | gradecast could fit into there? | 14 | gcry_mpi_sub_ui (x, x, 1); |
15 | gcry_mpi_set_ui (p, 17); | ||
16 | gcry_mpi_invm (x, x, p); | ||
14 | 17 | ||
15 | * Distributed Key Generation and Its Applications, Aniket Pundlik Kate, 2010 | 18 | ... which was very "nice" to spot because |
16 | * a PhD thesis that discusses the first DKG protocol useable for "the internet", | 19 | gcry_mpi_dump prints -1 as "01" ... |
17 | but does never mention / cite Fouque and Stern | ||
18 | 20 | ||
19 | * neither the documentation nor the C tutorial mention when to use GNUNET_PACKED, | 21 | * it's kind of hard to trust any gcry_mpi_* op that involves |
20 | and its relation to GNUNET_NETWORK_STRUCT_* | 22 | any kind of negative value .... |
21 | 23 | ||
22 | * why is the purpose size uint32_t? | 24 | * it's not documented what powm does when the exponent is negative, but the inverse |
23 | * that bit me ... | 25 | does not exist! |
26 | * invm at least returns an error flag ... | ||
24 | 27 | ||
25 | * currently i'm printing MPIs wrong in some places | ||
26 | 28 | ||
27 | * dependencies: secretsharing_common.c / is it ok to | 29 | secretsharing: |
28 | include gnunet_secretsharing_service.h in the service itself? | 30 | * problem with valgrind+testbed: slows stuff down, serialized due to testbed |
29 | * well according to other services it is ... | 31 | * consensi get out of sync, but are started at the very beginning |
32 | * proposal: also specify start time for DKG, | ||
33 | crypto setup is done *before* start time (of consensus) | ||
30 | 34 | ||
31 | * there now is GNUNET_new_array | 35 | paillier is now in util! |
32 | 36 | ||
33 | * crashing services after tests are not reported | 37 | next: implement ZKPs |
34 | 38 | ||
35 | * consensus now properly requires an absolute time deadline | ||
36 | |||
37 | * gnunet-java has gnunet-elgamal, which I used to generate keys | ||
38 | |||
39 | dold@dold-x1c:~/repos/gnunet-java$ ./bin/gnunet-elgamal -C 32 -b 1024 | ||
40 | Generating parameters with bitlength 1024 and certainty 32 | ||
41 | p: 0x08a347d3d69e8b2dd7d1b12a08dfbccbebf4ca6f4269a0814e158a34312964d946b3ef228823172bcf30fc08f772774cb404f9bc002a6f66b09a79d810d67c4f8cb3bedc6060e3c8ef874b1b64df716c7d2b002da880e269438d5a776e6b5f253c8df56a16b1c7ce58def07c03db48238aadfc52a354a27ed285b0c1675cad3f3 | ||
42 | q: 0x0451a3e9eb4f4596ebe8d895046fde65f5fa6537a134d040a70ac51a1894b26ca359f79144118b95e7987e047bb93ba65a027cde001537b3584d3cec086b3e27c659df6e303071e477c3a58db26fb8b63e958016d4407134a1c6ad3bb735af929e46fab50b58e3e72c6f783e01eda411c556fe2951aa513f6942d860b3ae569f9 | ||
43 | g: 0x05c00c36d2e822950087ef09d8252994adc4e48fe3ec70269f035b46063aff0c99b633fd64df4302442e1914c829a41505a275438871f365e91c123d5303ef9e90f4b8cb89bf86cc9b513e74a726349cfd9f953674fab5d511e1c078fc72d72b34086fc82b4b951989eb85325cb203ff98df76bc366bba1d7024c3650f60d0da | ||
44 | |||
45 | q, p=2q+1 are primes with failure prob. < 2^{-32}, g is just a generator | ||
46 | |||
47 | * where's the best place to store the constants when both the service api and | ||
48 | service implementation need to access it? | ||
49 | |||
50 | |||
51 | |||
52 | On the topic of randomness, aren't e.g. identities generated "in process", i.e. with quick random | ||
53 | enabled? | ||
54 | |||
55 | /* we only generate ephemeral keys in-process; for those, | ||
56 | we are fine with "just" using GCRY_STRONG_RANDOM */ | ||
57 | if ((rc = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0))) | ||
58 | 39 | ||
40 | GNS: | ||
41 | * rudimentary implementation in gnunet-java | ||
42 | * why is record type in gns_api int, and not unsigned int? | ||
43 | * gnsrecord: we're lost in java with the plugins | ||
44 | * call some helper bin for e.g. record type printing? | ||
45 | * use JNA (ctypes-style library for Java) | ||
46 | LookupMessage: string termination not documented | ||
47 | * fixed, but can't we agree on one way? | ||
48 | LookupResultMessage: | ||
49 | /* followed by rd_count GNUNET_GNSRECORD_Data structs*/ | ||
50 | can't be true, as the struct contains a pointer ... | ||
diff --git a/src/main/java/org/gnunet/gns/GNS.java b/src/main/java/org/gnunet/gns/GNS.java new file mode 100644 index 0000000..3abc86c --- /dev/null +++ b/src/main/java/org/gnunet/gns/GNS.java | |||
@@ -0,0 +1,145 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012, 2013 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 | package org.gnunet.gns; | ||
22 | |||
23 | import org.gnunet.gns.messages.ClientLookupMessage; | ||
24 | import org.gnunet.gns.messages.ClientLookupResultMessage; | ||
25 | import org.gnunet.mq.Envelope; | ||
26 | import org.gnunet.requests.MatchingRequestContainer; | ||
27 | import org.gnunet.requests.RequestContainer; | ||
28 | import org.gnunet.util.*; | ||
29 | import org.gnunet.util.crypto.EcdsaPrivateKey; | ||
30 | import org.gnunet.util.crypto.EcdsaPublicKey; | ||
31 | import org.slf4j.Logger; | ||
32 | import org.slf4j.LoggerFactory; | ||
33 | |||
34 | /** | ||
35 | * API to the GNUnet name system. | ||
36 | */ | ||
37 | public class GNS { | ||
38 | private static final Logger logger = LoggerFactory | ||
39 | .getLogger(GNS.class); | ||
40 | /** | ||
41 | * All pending and active lookup requests. | ||
42 | */ | ||
43 | private MatchingRequestContainer<Long, LookupRequest> lookupRequests; | ||
44 | |||
45 | private class LookupRequest extends RequestContainer.Request { | ||
46 | long uid; | ||
47 | String name; | ||
48 | EcdsaPublicKey zone; | ||
49 | int type; | ||
50 | boolean onlyCached; | ||
51 | EcdsaPrivateKey shortenZoneKey; | ||
52 | LookupResultProcessor proc; | ||
53 | |||
54 | public LookupRequest(String name, | ||
55 | EcdsaPublicKey zone, | ||
56 | int type, | ||
57 | boolean onlyCached, | ||
58 | EcdsaPrivateKey shortenZoneKey, | ||
59 | LookupResultProcessor proc) { | ||
60 | this.uid = nextUID++; | ||
61 | this.name = name; | ||
62 | this.zone = zone; | ||
63 | this.type = type; | ||
64 | this.onlyCached = onlyCached; | ||
65 | this.shortenZoneKey = shortenZoneKey; | ||
66 | this.proc = proc; | ||
67 | } | ||
68 | |||
69 | @Override | ||
70 | public Envelope assembleRequest() { | ||
71 | ClientLookupMessage m = new ClientLookupMessage(); | ||
72 | if (null != shortenZoneKey) { | ||
73 | m.haveKey = 1; | ||
74 | } else { | ||
75 | m.shortenKey = shortenZoneKey; | ||
76 | } | ||
77 | m.id = uid; | ||
78 | m.name = name; | ||
79 | m.onlyCached = onlyCached ? 1 : 0; | ||
80 | m.type = type; | ||
81 | m.zone = zone; | ||
82 | return new Envelope(m); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | public class GNSMessageReceiver extends RunaboutMessageReceiver { | ||
87 | public void visit(ClientLookupResultMessage m) { | ||
88 | LookupRequest r = lookupRequests.pollRequest(m.id); | ||
89 | if (null == r) { | ||
90 | logger.warn("no matching request for lookup result"); | ||
91 | return; | ||
92 | } | ||
93 | r.proc.process(m.records); | ||
94 | } | ||
95 | |||
96 | @Override | ||
97 | public void handleError() { | ||
98 | } | ||
99 | } | ||
100 | |||
101 | /** | ||
102 | * Request ID for lookup requests. | ||
103 | */ | ||
104 | private long nextUID = 1; | ||
105 | |||
106 | /** | ||
107 | * Client connected to the GNS service. | ||
108 | */ | ||
109 | private Client client; | ||
110 | |||
111 | /** | ||
112 | * Connect to the GNS service | ||
113 | * | ||
114 | * @param cfg configuration to use | ||
115 | */ | ||
116 | public GNS(Configuration cfg) { | ||
117 | client = new Client("gns", cfg); | ||
118 | lookupRequests = new MatchingRequestContainer<Long, LookupRequest>(client); | ||
119 | client.installReceiver(new GNSMessageReceiver()); | ||
120 | } | ||
121 | |||
122 | /** | ||
123 | * Perform an asynchronous lookup operation on the GNS. | ||
124 | * | ||
125 | * @param name the name to look up | ||
126 | * @param zone zone to look in | ||
127 | * @param type the GNS record type to look for | ||
128 | * @param onlyCached true to only check locally (not in the DHT) | ||
129 | * @param shortenZoneKey the private key of the shorten zone (can be NULL); | ||
130 | * specify to enable automatic shortening (given a PSEU | ||
131 | * record, if a given pseudonym is not yet used in the | ||
132 | * shorten zone, we automatically add the respective zone | ||
133 | * under that name) | ||
134 | * @param proc function to call on result | ||
135 | * @return handle to the queued request | ||
136 | */ | ||
137 | public Cancelable lookup(String name, | ||
138 | EcdsaPublicKey zone, | ||
139 | int type, boolean onlyCached, | ||
140 | EcdsaPrivateKey shortenZoneKey, | ||
141 | LookupResultProcessor proc) { | ||
142 | LookupRequest r = new LookupRequest(name, zone, type, onlyCached, shortenZoneKey, proc); | ||
143 | return lookupRequests.addRequest(r.uid, r); | ||
144 | } | ||
145 | } | ||
diff --git a/src/main/java/org/gnunet/gns/GnsRecord.java b/src/main/java/org/gnunet/gns/GnsRecord.java new file mode 100644 index 0000000..431ef07 --- /dev/null +++ b/src/main/java/org/gnunet/gns/GnsRecord.java | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012, 2013 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 | package org.gnunet.gns; | ||
22 | |||
23 | import org.gnunet.construct.Message; | ||
24 | import org.gnunet.construct.UInt32; | ||
25 | import org.gnunet.construct.UInt64; | ||
26 | import org.gnunet.construct.VariableSizeIntegerArray; | ||
27 | |||
28 | /** | ||
29 | * A GNS record. | ||
30 | */ | ||
31 | public class GnsRecord implements Message { | ||
32 | /** | ||
33 | * No special options. | ||
34 | */ | ||
35 | public static final int FLAG_NONE = 0; | ||
36 | /** | ||
37 | * No special options. | ||
38 | */ | ||
39 | public static final int FLAG_PRIVATE = 2; | ||
40 | /** | ||
41 | * This record was added automatically by the system | ||
42 | * and is pending user confimation. | ||
43 | */ | ||
44 | public static final int FLAG_PENDING = 4; | ||
45 | /** | ||
46 | * This expiration time of the record is a relative | ||
47 | * time (not an absolute time). | ||
48 | */ | ||
49 | public static final int FLAG_RELATIVE_EXPIRATION = 8; | ||
50 | /** | ||
51 | * This record should not be used unless all (other) records with an absolute | ||
52 | * expiration time have expired. | ||
53 | */ | ||
54 | public static final int FLAG_SHADOW_RECOD = 8; | ||
55 | /** | ||
56 | * Either absolute or relative expiration time, | ||
57 | * depending on 'flags'. | ||
58 | */ | ||
59 | @UInt64 | ||
60 | public long expirationTime; | ||
61 | |||
62 | /** | ||
63 | * Size of the record data. | ||
64 | */ | ||
65 | @UInt32 | ||
66 | public int dataSize; | ||
67 | |||
68 | /** | ||
69 | * Type of the record. | ||
70 | */ | ||
71 | @UInt32 | ||
72 | public int recordType; | ||
73 | |||
74 | /** | ||
75 | * Flags for the record. | ||
76 | */ | ||
77 | @UInt32 | ||
78 | int flags; | ||
79 | |||
80 | /** | ||
81 | * Binary value stored in the GNS record. | ||
82 | */ | ||
83 | @VariableSizeIntegerArray(lengthField = "dataSize", bitSize = 8, signed = false) | ||
84 | byte[] data; | ||
85 | |||
86 | } | ||
diff --git a/src/main/java/org/gnunet/gns/LookupResultProcessor.java b/src/main/java/org/gnunet/gns/LookupResultProcessor.java new file mode 100644 index 0000000..901b2d3 --- /dev/null +++ b/src/main/java/org/gnunet/gns/LookupResultProcessor.java | |||
@@ -0,0 +1,34 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012, 2013 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 | package org.gnunet.gns; | ||
22 | |||
23 | |||
24 | /** | ||
25 | * Processor for GNS request results. | ||
26 | */ | ||
27 | public interface LookupResultProcessor { | ||
28 | /** | ||
29 | * Process an array of records. | ||
30 | * | ||
31 | * @param records Records to process. | ||
32 | */ | ||
33 | void process(GnsRecord[] records); | ||
34 | } | ||
diff --git a/src/main/java/org/gnunet/gns/messages/ClientLookupMessage.java b/src/main/java/org/gnunet/gns/messages/ClientLookupMessage.java new file mode 100644 index 0000000..13fc37b --- /dev/null +++ b/src/main/java/org/gnunet/gns/messages/ClientLookupMessage.java | |||
@@ -0,0 +1,73 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012, 2013 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 | package org.gnunet.gns.messages; | ||
22 | |||
23 | import org.gnunet.construct.*; | ||
24 | import org.gnunet.util.GnunetMessage; | ||
25 | import org.gnunet.util.crypto.EcdsaPrivateKey; | ||
26 | import org.gnunet.util.crypto.EcdsaPublicKey; | ||
27 | |||
28 | /** | ||
29 | * Message from client to GNS service to lookup records. | ||
30 | */ | ||
31 | @UnionCase(500) | ||
32 | public class ClientLookupMessage implements GnunetMessage.Body { | ||
33 | /** | ||
34 | * Unique identifier for this request (for key collisions). | ||
35 | */ | ||
36 | @UInt32 | ||
37 | public long id; | ||
38 | |||
39 | /** | ||
40 | * Zone that is to be used for lookup | ||
41 | */ | ||
42 | @NestedMessage | ||
43 | public EcdsaPublicKey zone; | ||
44 | /** | ||
45 | * Only check cached results | ||
46 | */ | ||
47 | @Int16 | ||
48 | public int onlyCached; | ||
49 | |||
50 | /** | ||
51 | * Is a shorten key attached? | ||
52 | */ | ||
53 | @Int16 | ||
54 | public int haveKey; | ||
55 | |||
56 | /** | ||
57 | * the type of record to look up | ||
58 | */ | ||
59 | @Int32 | ||
60 | public int type; | ||
61 | |||
62 | /** | ||
63 | * The key for shorten, if haveKey is set | ||
64 | */ | ||
65 | @NestedMessage | ||
66 | public EcdsaPrivateKey shortenKey; | ||
67 | |||
68 | /** | ||
69 | * The name. | ||
70 | */ | ||
71 | @ZeroTerminatedString | ||
72 | public String name; | ||
73 | } | ||
diff --git a/src/main/java/org/gnunet/gns/messages/ClientLookupResultMessage.java b/src/main/java/org/gnunet/gns/messages/ClientLookupResultMessage.java new file mode 100644 index 0000000..c857c9a --- /dev/null +++ b/src/main/java/org/gnunet/gns/messages/ClientLookupResultMessage.java | |||
@@ -0,0 +1,66 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012, 2013 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 | This file is part of GNUnet. | ||
23 | (C) 2012, 2013 Christian Grothoff (and other contributing authors) | ||
24 | |||
25 | GNUnet is free software; you can redistribute it and/or modify | ||
26 | it under the terms of the GNU General Public License as published | ||
27 | by the Free Software Foundation; either version 3, or (at your | ||
28 | option) any later version. | ||
29 | |||
30 | GNUnet is distributed in the hope that it will be useful, but | ||
31 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
33 | General Public License for more details. | ||
34 | |||
35 | You should have received a copy of the GNU General Public License | ||
36 | along with GNUnet; see the file COPYING. If not, write to the | ||
37 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
38 | Boston, MA 02111-1307, USA. | ||
39 | */ | ||
40 | |||
41 | package org.gnunet.gns.messages; | ||
42 | |||
43 | import org.gnunet.construct.*; | ||
44 | import org.gnunet.gns.GnsRecord; | ||
45 | import org.gnunet.util.GnunetMessage; | ||
46 | import org.gnunet.util.crypto.EcdsaPrivateKey; | ||
47 | import org.gnunet.util.crypto.EcdsaPublicKey; | ||
48 | |||
49 | /** | ||
50 | * Message GNS service to client as a response to a lookup request. | ||
51 | */ | ||
52 | @UnionCase(501) | ||
53 | public class ClientLookupResultMessage implements GnunetMessage.Body { | ||
54 | /** | ||
55 | * Unique identifier for this request. | ||
56 | */ | ||
57 | @UInt32 | ||
58 | public long id; | ||
59 | |||
60 | @UInt32 | ||
61 | public long recordCount; | ||
62 | |||
63 | @VariableSizeArray(lengthField = "recordCount") | ||
64 | public | ||
65 | GnsRecord[] records; | ||
66 | } | ||
diff --git a/src/main/java/org/gnunet/requests/MatchingRequestContainer.java b/src/main/java/org/gnunet/requests/MatchingRequestContainer.java index a11807f..b2c671e 100644 --- a/src/main/java/org/gnunet/requests/MatchingRequestContainer.java +++ b/src/main/java/org/gnunet/requests/MatchingRequestContainer.java | |||
@@ -11,7 +11,14 @@ import java.util.Map; | |||
11 | * Container for requests that are responded to with a matching request identification | 11 | * Container for requests that are responded to with a matching request identification |
12 | */ | 12 | */ |
13 | public class MatchingRequestContainer<K, T extends RequestContainer.Request> extends RequestContainer { | 13 | public class MatchingRequestContainer<K, T extends RequestContainer.Request> extends RequestContainer { |
14 | /** | ||
15 | * All queued requests. | ||
16 | */ | ||
14 | private Map<K,T> requests = Maps.newHashMap(); | 17 | private Map<K,T> requests = Maps.newHashMap(); |
18 | |||
19 | /** | ||
20 | * Message queue to send to requests over. | ||
21 | */ | ||
15 | private final MessageQueue mq; | 22 | private final MessageQueue mq; |
16 | 23 | ||
17 | public MatchingRequestContainer(MessageQueue mq) { | 24 | public MatchingRequestContainer(MessageQueue mq) { |
diff --git a/src/main/java/org/gnunet/requests/RequestContainer.java b/src/main/java/org/gnunet/requests/RequestContainer.java index c7627f0..8fc631e 100644 --- a/src/main/java/org/gnunet/requests/RequestContainer.java +++ b/src/main/java/org/gnunet/requests/RequestContainer.java | |||
@@ -4,14 +4,38 @@ package org.gnunet.requests; | |||
4 | import org.gnunet.mq.Envelope; | 4 | import org.gnunet.mq.Envelope; |
5 | import org.gnunet.util.Cancelable; | 5 | import org.gnunet.util.Cancelable; |
6 | 6 | ||
7 | /** | ||
8 | * Container for requests to a service. | ||
9 | */ | ||
7 | public abstract class RequestContainer { | 10 | public abstract class RequestContainer { |
11 | /** | ||
12 | * Do we allow sending pending requests while | ||
13 | * other requests are still active (true), or do we send | ||
14 | * requests one-by-one (false)? | ||
15 | */ | ||
8 | protected boolean overlap = true; | 16 | protected boolean overlap = true; |
9 | 17 | ||
18 | /** | ||
19 | * A request that can be put in a request container. | ||
20 | */ | ||
10 | public abstract static class Request { | 21 | public abstract static class Request { |
11 | private boolean transmitting; | 22 | private boolean transmitting; |
12 | private boolean canceled; | 23 | private boolean canceled; |
13 | private Cancelable cancelRequest; | 24 | private Cancelable cancelRequest; |
25 | |||
26 | /** | ||
27 | * Create an envelope for executing the request. | ||
28 | * | ||
29 | * @return Envelope to be sent to the service with the request message. | ||
30 | */ | ||
14 | public abstract Envelope assembleRequest(); | 31 | public abstract Envelope assembleRequest(); |
32 | |||
33 | /** | ||
34 | * Implement cancellation logic for requests. | ||
35 | * Only called when the request has already been sent to the service. | ||
36 | * | ||
37 | * By default, canceling a request throws an exception. | ||
38 | */ | ||
15 | public void cancel() { | 39 | public void cancel() { |
16 | throw new AssertionError("request of type " + this.getClass() + " can not be canceled (not implemented)"); | 40 | throw new AssertionError("request of type " + this.getClass() + " can not be canceled (not implemented)"); |
17 | } | 41 | } |
@@ -31,6 +55,13 @@ public abstract class RequestContainer { | |||
31 | this.overlap = overlap; | 55 | this.overlap = overlap; |
32 | } | 56 | } |
33 | 57 | ||
58 | /** | ||
59 | * Check if the given request is transmitting, that is, the request | ||
60 | * is waiting to be sent to the service. | ||
61 | * | ||
62 | * @param r request | ||
63 | * @return whether the request is still being transmitted | ||
64 | */ | ||
34 | protected boolean isRequestTransmitting(Request r) { | 65 | protected boolean isRequestTransmitting(Request r) { |
35 | return r.transmitting; | 66 | return r.transmitting; |
36 | } | 67 | } |