aboutsummaryrefslogtreecommitdiff
path: root/src/regex/regex_internal_dht.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-06-26 17:21:22 +0000
committerChristian Grothoff <christian@grothoff.org>2013-06-26 17:21:22 +0000
commit3999807382f98843cdde19211fc94484d0793087 (patch)
treeeab97299e72edbfdd5d6f409db0729d9780d3e5e /src/regex/regex_internal_dht.c
parentabc1a0ea19b7dc199b83749d31e32622c7469ded (diff)
downloadgnunet-3999807382f98843cdde19211fc94484d0793087.tar.gz
gnunet-3999807382f98843cdde19211fc94484d0793087.zip
-introducing signing of regex accept states, removing PID from regex API
Diffstat (limited to 'src/regex/regex_internal_dht.c')
-rw-r--r--src/regex/regex_internal_dht.c101
1 files changed, 74 insertions, 27 deletions
diff --git a/src/regex/regex_internal_dht.c b/src/regex/regex_internal_dht.c
index e7259edcc..3d6cf7360 100644
--- a/src/regex/regex_internal_dht.c
+++ b/src/regex/regex_internal_dht.c
@@ -28,6 +28,9 @@
28#include "regex_block_lib.h" 28#include "regex_block_lib.h"
29#include "gnunet_dht_service.h" 29#include "gnunet_dht_service.h"
30#include "gnunet_statistics_service.h" 30#include "gnunet_statistics_service.h"
31#include "gnunet_constants.h"
32#include "gnunet_signatures.h"
33
31 34
32#define LOG(kind,...) GNUNET_log_from (kind,"regex-dht",__VA_ARGS__) 35#define LOG(kind,...) GNUNET_log_from (kind,"regex-dht",__VA_ARGS__)
33 36
@@ -42,6 +45,10 @@
42#define DHT_OPT GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE 45#define DHT_OPT GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
43#endif 46#endif
44 47
48
49/**
50 * Handle to store cached data about a regex announce.
51 */
45struct REGEX_INTERNAL_Announcement 52struct REGEX_INTERNAL_Announcement
46{ 53{
47 /** 54 /**
@@ -60,9 +67,9 @@ struct REGEX_INTERNAL_Announcement
60 struct REGEX_INTERNAL_Automaton* dfa; 67 struct REGEX_INTERNAL_Automaton* dfa;
61 68
62 /** 69 /**
63 * Identity under which to announce the regex. 70 * Our private key.
64 */ 71 */
65 struct GNUNET_PeerIdentity id; 72 const struct GNUNET_CRYPTO_EccPrivateKey *priv;
66 73
67 /** 74 /**
68 * Optional statistics handle to report usage. Can be NULL. 75 * Optional statistics handle to report usage. Can be NULL.
@@ -100,14 +107,25 @@ regex_iterator (void *cls,
100 num_edges); 107 num_edges);
101 if (GNUNET_YES == accepting) 108 if (GNUNET_YES == accepting)
102 { 109 {
103 struct RegexAccept block; 110 struct RegexAcceptBlock block;
104 111
105 LOG (GNUNET_ERROR_TYPE_DEBUG, 112 LOG (GNUNET_ERROR_TYPE_DEBUG,
106 "State %s is accepting, putting own id\n", 113 "State %s is accepting, putting own id\n",
107 GNUNET_h2s(key)); 114 GNUNET_h2s(key));
108 size = sizeof (block); 115 size = sizeof (block);
116 block.purpose.size = sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
117 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
118 sizeof (struct GNUNET_HashCode);
119 block.purpose.purpose = ntohl (GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT);
120 block.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_DHT_MAX_EXPIRATION));
109 block.key = *key; 121 block.key = *key;
110 block.id = h->id; 122 GNUNET_CRYPTO_ecc_key_get_public (h->priv,
123 &block.public_key);
124 GNUNET_assert (GNUNET_OK ==
125 GNUNET_CRYPTO_ecc_sign (h->priv,
126 &block.purpose,
127 &block.signature));
128
111 GNUNET_STATISTICS_update (h->stats, "# regex accepting blocks stored", 129 GNUNET_STATISTICS_update (h->stats, "# regex accepting blocks stored",
112 1, GNUNET_NO); 130 1, GNUNET_NO);
113 GNUNET_STATISTICS_update (h->stats, "# regex accepting block bytes stored", 131 GNUNET_STATISTICS_update (h->stats, "# regex accepting block bytes stored",
@@ -144,12 +162,25 @@ regex_iterator (void *cls,
144} 162}
145 163
146 164
165/**
166 * Announce a regular expression: put all states of the automaton in the DHT.
167 * Does not free resources, must call REGEX_INTERNAL_announce_cancel for that.
168 *
169 * @param dht An existing and valid DHT service handle. CANNOT be NULL.
170 * @param priv our private key, must remain valid until the announcement is cancelled
171 * @param regex Regular expression to announce.
172 * @param compression How many characters per edge can we squeeze?
173 * @param stats Optional statistics handle to report usage. Can be NULL.
174 *
175 * @return Handle to reuse o free cached resources.
176 * Must be freed by calling REGEX_INTERNAL_announce_cancel.
177 */
147struct REGEX_INTERNAL_Announcement * 178struct REGEX_INTERNAL_Announcement *
148REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht, 179REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht,
149 const struct GNUNET_PeerIdentity *id, 180 const struct GNUNET_CRYPTO_EccPrivateKey *priv,
150 const char *regex, 181 const char *regex,
151 uint16_t compression, 182 uint16_t compression,
152 struct GNUNET_STATISTICS_Handle *stats) 183 struct GNUNET_STATISTICS_Handle *stats)
153{ 184{
154 struct REGEX_INTERNAL_Announcement *h; 185 struct REGEX_INTERNAL_Announcement *h;
155 186
@@ -158,7 +189,7 @@ REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht,
158 h->regex = regex; 189 h->regex = regex;
159 h->dht = dht; 190 h->dht = dht;
160 h->stats = stats; 191 h->stats = stats;
161 h->id = *id; 192 h->priv = priv;
162 h->dfa = REGEX_INTERNAL_construct_dfa (regex, 193 h->dfa = REGEX_INTERNAL_construct_dfa (regex,
163 strlen (regex), 194 strlen (regex),
164 compression); 195 compression);
@@ -167,6 +198,12 @@ REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht,
167} 198}
168 199
169 200
201/**
202 * Announce again a regular expression previously announced.
203 * Does use caching to speed up process.
204 *
205 * @param h Handle returned by a previous REGEX_INTERNAL_announce call.
206 */
170void 207void
171REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h) 208REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h)
172{ 209{
@@ -177,6 +214,13 @@ REGEX_INTERNAL_reannounce (struct REGEX_INTERNAL_Announcement *h)
177} 214}
178 215
179 216
217
218/**
219 * Clear all cached data used by a regex announce.
220 * Does not close DHT connection.
221 *
222 * @param h Handle returned by a previous REGEX_INTERNAL_announce call.
223 */
180void 224void
181REGEX_INTERNAL_announce_cancel (struct REGEX_INTERNAL_Announcement *h) 225REGEX_INTERNAL_announce_cancel (struct REGEX_INTERNAL_Announcement *h)
182{ 226{
@@ -194,26 +238,26 @@ REGEX_INTERNAL_announce_cancel (struct REGEX_INTERNAL_Announcement *h)
194 */ 238 */
195struct RegexSearchContext 239struct RegexSearchContext
196{ 240{
197 /** 241 /**
198 * Part of the description already consumed by 242 * Part of the description already consumed by
199 * this particular search branch. 243 * this particular search branch.
200 */ 244 */
201 size_t position; 245 size_t position;
202 246
203 /** 247 /**
204 * Information about the search. 248 * Information about the search.
205 */ 249 */
206 struct REGEX_INTERNAL_Search *info; 250 struct REGEX_INTERNAL_Search *info;
207 251
208 /** 252 /**
209 * We just want to look for one edge, the longer the better. 253 * We just want to look for one edge, the longer the better.
210 * Keep its length. 254 * Keep its length.
211 */ 255 */
212 unsigned int longest_match; 256 unsigned int longest_match;
213 257
214 /** 258 /**
215 * Destination hash of the longest match. 259 * Destination hash of the longest match.
216 */ 260 */
217 struct GNUNET_HashCode hash; 261 struct GNUNET_HashCode hash;
218}; 262};
219 263
@@ -304,7 +348,7 @@ regex_next_edge (const struct RegexBlock *block,
304 */ 348 */
305static void 349static void
306dht_get_string_accept_handler (void *cls, struct GNUNET_TIME_Absolute exp, 350dht_get_string_accept_handler (void *cls, struct GNUNET_TIME_Absolute exp,
307 const struct GNUNET_HashCode * key, 351 const struct GNUNET_HashCode *key,
308 const struct GNUNET_PeerIdentity *get_path, 352 const struct GNUNET_PeerIdentity *get_path,
309 unsigned int get_path_length, 353 unsigned int get_path_length,
310 const struct GNUNET_PeerIdentity *put_path, 354 const struct GNUNET_PeerIdentity *put_path,
@@ -312,9 +356,10 @@ dht_get_string_accept_handler (void *cls, struct GNUNET_TIME_Absolute exp,
312 enum GNUNET_BLOCK_Type type, 356 enum GNUNET_BLOCK_Type type,
313 size_t size, const void *data) 357 size_t size, const void *data)
314{ 358{
315 const struct RegexAccept *block = data; 359 const struct RegexAcceptBlock *block = data;
316 struct RegexSearchContext *ctx = cls; 360 struct RegexSearchContext *ctx = cls;
317 struct REGEX_INTERNAL_Search *info = ctx->info; 361 struct REGEX_INTERNAL_Search *info = ctx->info;
362 struct GNUNET_PeerIdentity pid;
318 363
319 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got regex results from DHT!\n"); 364 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got regex results from DHT!\n");
320 LOG (GNUNET_ERROR_TYPE_INFO, " accept for %s (key %s)\n", 365 LOG (GNUNET_ERROR_TYPE_INFO, " accept for %s (key %s)\n",
@@ -324,9 +369,11 @@ dht_get_string_accept_handler (void *cls, struct GNUNET_TIME_Absolute exp,
324 1, GNUNET_NO); 369 1, GNUNET_NO);
325 GNUNET_STATISTICS_update (info->stats, "# regex accepting block bytes found", 370 GNUNET_STATISTICS_update (info->stats, "# regex accepting block bytes found",
326 size, GNUNET_NO); 371 size, GNUNET_NO);
327 372 GNUNET_CRYPTO_hash (&block->public_key,
373 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
374 &pid.hashPubKey);
328 info->callback (info->callback_cls, 375 info->callback (info->callback_cls,
329 &block->id, 376 &pid,
330 get_path, get_path_length, 377 get_path, get_path_length,
331 put_path, put_path_length); 378 put_path, put_path_length);
332} 379}