aboutsummaryrefslogtreecommitdiff
path: root/src/regex
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
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')
-rw-r--r--src/regex/gnunet-daemon-regexprofiler.c20
-rw-r--r--src/regex/gnunet-service-regex.c24
-rw-r--r--src/regex/plugin_block_regex.c125
-rw-r--r--src/regex/regex_api.c2
-rw-r--r--src/regex/regex_internal_dht.c101
-rw-r--r--src/regex/regex_internal_lib.h12
-rw-r--r--src/regex/regex_ipc.h5
7 files changed, 181 insertions, 108 deletions
diff --git a/src/regex/gnunet-daemon-regexprofiler.c b/src/regex/gnunet-daemon-regexprofiler.c
index 3f4dd087f..d4c9cb7cb 100644
--- a/src/regex/gnunet-daemon-regexprofiler.c
+++ b/src/regex/gnunet-daemon-regexprofiler.c
@@ -95,6 +95,12 @@ static char *rx_with_pfx;
95 */ 95 */
96static unsigned int rounds = 5; 96static unsigned int rounds = 5;
97 97
98/**
99 * Private key for this peer.
100 */
101static struct GNUNET_CRYPTO_EccPrivateKey *my_private_key;
102
103
98 104
99/** 105/**
100 * Task run during shutdown. 106 * Task run during shutdown.
@@ -118,6 +124,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
118 GNUNET_DHT_disconnect (dht_handle); 124 GNUNET_DHT_disconnect (dht_handle);
119 dht_handle = NULL; 125 dht_handle = NULL;
120 } 126 }
127 GNUNET_CRYPTO_ecc_key_free (my_private_key);
128 my_private_key = NULL;
121 129
122 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 130 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
123 "Daemon for %s shutting down\n", 131 "Daemon for %s shutting down\n",
@@ -134,7 +142,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
134static void 142static void
135reannounce_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 143reannounce_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
136{ 144{
137 struct GNUNET_PeerIdentity id;
138 struct GNUNET_TIME_Relative random_delay; 145 struct GNUNET_TIME_Relative random_delay;
139 char *regex = cls; 146 char *regex = cls;
140 147
@@ -159,12 +166,11 @@ reannounce_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
160 "First time, creating regex: %s\n", 167 "First time, creating regex: %s\n",
161 regex); 168 regex);
162 memset (&id, 0, sizeof (struct GNUNET_PeerIdentity));
163 announce_handle = REGEX_INTERNAL_announce (dht_handle, 169 announce_handle = REGEX_INTERNAL_announce (dht_handle,
164 &id, 170 my_private_key,
165 regex, 171 regex,
166 (unsigned int) max_path_compression, 172 (unsigned int) max_path_compression,
167 stats_handle); 173 stats_handle);
168 } 174 }
169 else 175 else
170 { 176 {
@@ -252,6 +258,8 @@ run (void *cls, char *const *args GNUNET_UNUSED,
252 258
253 cfg = cfg_; 259 cfg = cfg_;
254 260
261 my_private_key = GNUNET_CRYPTO_ecc_key_create_from_configuration (cfg);
262 GNUNET_assert (NULL != my_private_key);
255 if (GNUNET_OK != 263 if (GNUNET_OK !=
256 GNUNET_CONFIGURATION_get_value_number (cfg, "REGEXPROFILER", 264 GNUNET_CONFIGURATION_get_value_number (cfg, "REGEXPROFILER",
257 "MAX_PATH_COMPRESSION", 265 "MAX_PATH_COMPRESSION",
diff --git a/src/regex/gnunet-service-regex.c b/src/regex/gnunet-service-regex.c
index 697b04a36..96a6b82b1 100644
--- a/src/regex/gnunet-service-regex.c
+++ b/src/regex/gnunet-service-regex.c
@@ -99,6 +99,11 @@ static struct ClientEntry *client_tail;
99 */ 99 */
100static struct GNUNET_SERVER_NotificationContext *nc; 100static struct GNUNET_SERVER_NotificationContext *nc;
101 101
102/**
103 * Private key for this peer.
104 */
105static struct GNUNET_CRYPTO_EccPrivateKey *my_private_key;
106
102 107
103/** 108/**
104 * Task run during shutdown. 109 * Task run during shutdown.
@@ -115,6 +120,8 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
115 stats = NULL; 120 stats = NULL;
116 GNUNET_SERVER_notification_context_destroy (nc); 121 GNUNET_SERVER_notification_context_destroy (nc);
117 nc = NULL; 122 nc = NULL;
123 GNUNET_CRYPTO_ecc_key_free (my_private_key);
124 my_private_key = NULL;
118} 125}
119 126
120 127
@@ -208,10 +215,10 @@ handle_announce (void *cls,
208 ce = GNUNET_new (struct ClientEntry); 215 ce = GNUNET_new (struct ClientEntry);
209 ce->client = client; 216 ce->client = client;
210 ce->ah = REGEX_INTERNAL_announce (dht, 217 ce->ah = REGEX_INTERNAL_announce (dht,
211 &am->pid, 218 my_private_key,
212 regex, 219 regex,
213 ntohs (am->compression), 220 ntohs (am->compression),
214 stats); 221 stats);
215 if (NULL == ce->ah) 222 if (NULL == ce->ah)
216 { 223 {
217 GNUNET_break (0); 224 GNUNET_break (0);
@@ -347,9 +354,18 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
347 {&handle_search, NULL, GNUNET_MESSAGE_TYPE_REGEX_SEARCH, 0}, 354 {&handle_search, NULL, GNUNET_MESSAGE_TYPE_REGEX_SEARCH, 0},
348 {NULL, NULL, 0, 0} 355 {NULL, NULL, 0, 0}
349 }; 356 };
357
358 my_private_key = GNUNET_CRYPTO_ecc_key_create_from_configuration (cfg);
359 if (NULL == my_private_key)
360 {
361 GNUNET_SCHEDULER_shutdown ();
362 return;
363 }
350 dht = GNUNET_DHT_connect (cfg, 1024); 364 dht = GNUNET_DHT_connect (cfg, 1024);
351 if (NULL == dht) 365 if (NULL == dht)
352 { 366 {
367 GNUNET_CRYPTO_ecc_key_free (my_private_key);
368 my_private_key = NULL;
353 GNUNET_SCHEDULER_shutdown (); 369 GNUNET_SCHEDULER_shutdown ();
354 return; 370 return;
355 } 371 }
diff --git a/src/regex/plugin_block_regex.c b/src/regex/plugin_block_regex.c
index 9eeb13190..d8312a1a0 100644
--- a/src/regex/plugin_block_regex.c
+++ b/src/regex/plugin_block_regex.c
@@ -28,35 +28,8 @@
28#include "gnunet_block_plugin.h" 28#include "gnunet_block_plugin.h"
29#include "block_regex.h" 29#include "block_regex.h"
30#include "regex_block_lib.h" 30#include "regex_block_lib.h"
31 31#include "gnunet_constants.h"
32/** 32#include "gnunet_signatures.h"
33 * Number of bits we set per entry in the bloomfilter.
34 * Do not change!
35 */
36#define BLOOMFILTER_K 16
37
38
39/**
40 * Show debug info about outgoing edges from a block.
41 *
42 * @param cls Closure (uunsed).
43 * @param token Edge label.
44 * @param len Length of @c token.
45 * @param key Block the edge point to.
46 *
47 * @return GNUNET_YES to keep iterating.
48 */
49static int
50rdebug (void *cls,
51 const char *token,
52 size_t len,
53 const struct GNUNET_HashCode *key)
54{
55 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
56 "%s: %.*s\n",
57 GNUNET_h2s (key), len, token);
58 return GNUNET_YES;
59}
60 33
61 34
62/** 35/**
@@ -86,8 +59,21 @@ evaluate_block_regex (void *cls, enum GNUNET_BLOCK_Type type,
86 size_t xquery_size, const void *reply_block, 59 size_t xquery_size, const void *reply_block,
87 size_t reply_block_size) 60 size_t reply_block_size)
88{ 61{
89 if (NULL == reply_block) /* queries (GET) are always valid */ 62 if (NULL == reply_block)
90 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 63 {
64 if (0 != xquery_size)
65 {
66 const char *s;
67
68 s = (const char *) xquery;
69 if ('\0' != s[xquery_size - 1]) /* must be valid 0-terminated string */
70 {
71 GNUNET_break_op (0);
72 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
73 }
74 }
75 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
76 }
91 if (0 != xquery_size) 77 if (0 != xquery_size)
92 { 78 {
93 const char *query; 79 const char *query;
@@ -95,22 +81,15 @@ evaluate_block_regex (void *cls, enum GNUNET_BLOCK_Type type,
95 query = (const char *) xquery; 81 query = (const char *) xquery;
96 if ('\0' != query[xquery_size - 1]) /* must be valid 0-terminated string */ 82 if ('\0' != query[xquery_size - 1]) /* must be valid 0-terminated string */
97 { 83 {
98 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 84 GNUNET_break_op (0);
99 "Block xquery not a valid string\n"); 85 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
100 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
101 } 86 }
102 } 87 }
103 else if (NULL != query) /* PUTs don't need xquery */ 88 else
104 { 89 {
105 const struct RegexBlock *rblock = reply_block; 90 /* xquery is required for regex, at least an empty string */
106
107 GNUNET_break_op (0); 91 GNUNET_break_op (0);
108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 92 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
109 "Block with no xquery, query: %s, %u edges\n",
110 GNUNET_h2s (query),
111 ntohl (rblock->n_edges));
112 REGEX_BLOCK_iterate (rblock, reply_block_size, &rdebug, NULL);
113 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
114 } 93 }
115 switch (REGEX_BLOCK_check (reply_block, 94 switch (REGEX_BLOCK_check (reply_block,
116 reply_block_size, 95 reply_block_size,
@@ -121,12 +100,9 @@ evaluate_block_regex (void *cls, enum GNUNET_BLOCK_Type type,
121 GNUNET_break_op(0); 100 GNUNET_break_op(0);
122 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 101 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
123 case GNUNET_NO: 102 case GNUNET_NO:
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 103 /* xquery missmatch, can happen */
125 "BLOCK XQUERY %s not accepted\n", xquery);
126 return GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT; 104 return GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT;
127 default: 105 default:
128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
129 "BLOCK XQUERY %s accepted\n", xquery);
130 break; 106 break;
131 } 107 }
132 if (NULL != bf) 108 if (NULL != bf)
@@ -143,7 +119,7 @@ evaluate_block_regex (void *cls, enum GNUNET_BLOCK_Type type,
143 } 119 }
144 else 120 else
145 { 121 {
146 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K); 122 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, GNUNET_CONSTANTS_BLOOMFILTER_K);
147 } 123 }
148 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); 124 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
149 } 125 }
@@ -178,6 +154,8 @@ evaluate_block_regex_accept (void *cls, enum GNUNET_BLOCK_Type type,
178 size_t xquery_size, const void *reply_block, 154 size_t xquery_size, const void *reply_block,
179 size_t reply_block_size) 155 size_t reply_block_size)
180{ 156{
157 const struct RegexAcceptBlock *rba;
158
181 if (0 != xquery_size) 159 if (0 != xquery_size)
182 { 160 {
183 GNUNET_break_op (0); 161 GNUNET_break_op (0);
@@ -185,7 +163,31 @@ evaluate_block_regex_accept (void *cls, enum GNUNET_BLOCK_Type type,
185 } 163 }
186 if (NULL == reply_block) 164 if (NULL == reply_block)
187 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 165 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
188 if (sizeof (struct RegexAccept) != reply_block_size) 166 if (sizeof (struct RegexAcceptBlock) != reply_block_size)
167 {
168 GNUNET_break_op(0);
169 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
170 }
171 rba = reply_block;
172 if (ntohl (rba->purpose.size) !=
173 sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
174 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
175 sizeof (struct GNUNET_HashCode))
176 {
177 GNUNET_break_op(0);
178 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
179 }
180 if (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (rba->expiration_time)).rel_value)
181 {
182 /* technically invalid, but can happen without an error, so
183 we're nice by reporting it as a 'duplicate' */
184 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
185 }
186 if (GNUNET_OK !=
187 GNUNET_CRYPTO_ecc_verify (GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT,
188 &rba->purpose,
189 &rba->signature,
190 &rba->public_key))
189 { 191 {
190 GNUNET_break_op(0); 192 GNUNET_break_op(0);
191 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 193 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
@@ -204,7 +206,7 @@ evaluate_block_regex_accept (void *cls, enum GNUNET_BLOCK_Type type,
204 } 206 }
205 else 207 else
206 { 208 {
207 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K); 209 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, GNUNET_CONSTANTS_BLOOMFILTER_K);
208 } 210 }
209 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash); 211 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
210 } 212 }
@@ -247,7 +249,6 @@ block_plugin_regex_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
247 xquery, xquery_size, 249 xquery, xquery_size,
248 reply_block, reply_block_size); 250 reply_block, reply_block_size);
249 break; 251 break;
250
251 case GNUNET_BLOCK_TYPE_REGEX_ACCEPT: 252 case GNUNET_BLOCK_TYPE_REGEX_ACCEPT:
252 result = evaluate_block_regex_accept (cls, type, query, bf, bf_mutator, 253 result = evaluate_block_regex_accept (cls, type, query, bf, bf_mutator,
253 xquery, xquery_size, 254 xquery, xquery_size,
@@ -277,18 +278,24 @@ block_plugin_regex_get_key (void *cls, enum GNUNET_BLOCK_Type type,
277 const void *block, size_t block_size, 278 const void *block, size_t block_size,
278 struct GNUNET_HashCode * key) 279 struct GNUNET_HashCode * key)
279{ 280{
280 int ret;
281
282 switch (type) 281 switch (type)
283 { 282 {
284 case GNUNET_BLOCK_TYPE_REGEX: 283 case GNUNET_BLOCK_TYPE_REGEX:
285 ret = REGEX_BLOCK_get_key (block, block_size, 284 if (GNUNET_OK !=
286 key); 285 REGEX_BLOCK_get_key (block, block_size,
287 GNUNET_break_op (GNUNET_OK == ret); 286 key))
288 return ret; 287 {
288 GNUNET_break_op (0);
289 return GNUNET_NO;
290 }
291 return GNUNET_OK;
289 case GNUNET_BLOCK_TYPE_REGEX_ACCEPT: 292 case GNUNET_BLOCK_TYPE_REGEX_ACCEPT:
290 GNUNET_assert (sizeof (struct RegexAccept) <= block_size); 293 if (sizeof (struct RegexAcceptBlock) != block_size);
291 *key = ((struct RegexAccept *) block)->key; 294 {
295 GNUNET_break_op (0);
296 return GNUNET_NO;
297 }
298 *key = ((struct RegexAcceptBlock *) block)->key;
292 return GNUNET_OK; 299 return GNUNET_OK;
293 default: 300 default:
294 GNUNET_break (0); 301 GNUNET_break (0);
diff --git a/src/regex/regex_api.c b/src/regex/regex_api.c
index ec9ee0de8..fdfd05058 100644
--- a/src/regex/regex_api.c
+++ b/src/regex/regex_api.c
@@ -118,7 +118,6 @@ handle_a_reconnect (void *cls,
118 */ 118 */
119struct GNUNET_REGEX_Announcement * 119struct GNUNET_REGEX_Announcement *
120GNUNET_REGEX_announce (const struct GNUNET_CONFIGURATION_Handle *cfg, 120GNUNET_REGEX_announce (const struct GNUNET_CONFIGURATION_Handle *cfg,
121 const struct GNUNET_PeerIdentity *id,
122 const char *regex, 121 const char *regex,
123 struct GNUNET_TIME_Relative refresh_delay, 122 struct GNUNET_TIME_Relative refresh_delay,
124 uint16_t compression) 123 uint16_t compression)
@@ -142,7 +141,6 @@ GNUNET_REGEX_announce (const struct GNUNET_CONFIGURATION_Handle *cfg,
142 a->msg.compression = htons (compression); 141 a->msg.compression = htons (compression);
143 a->msg.reserved = htons (0); 142 a->msg.reserved = htons (0);
144 a->msg.refresh_delay = GNUNET_TIME_relative_hton (refresh_delay); 143 a->msg.refresh_delay = GNUNET_TIME_relative_hton (refresh_delay);
145 a->msg.pid = *id;
146 memcpy (&a[1], regex, slen); 144 memcpy (&a[1], regex, slen);
147 retry_announcement (a); 145 retry_announcement (a);
148 return a; 146 return a;
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}
diff --git a/src/regex/regex_internal_lib.h b/src/regex/regex_internal_lib.h
index 3d4a1b65c..391a33fd2 100644
--- a/src/regex/regex_internal_lib.h
+++ b/src/regex/regex_internal_lib.h
@@ -150,12 +150,13 @@ struct REGEX_INTERNAL_Announcement;
150 */ 150 */
151struct REGEX_INTERNAL_Search; 151struct REGEX_INTERNAL_Search;
152 152
153
153/** 154/**
154 * Announce a regular expression: put all states of the automaton in the DHT. 155 * Announce a regular expression: put all states of the automaton in the DHT.
155 * Does not free resources, must call REGEX_INTERNAL_announce_cancel for that. 156 * Does not free resources, must call REGEX_INTERNAL_announce_cancel for that.
156 * 157 *
157 * @param dht An existing and valid DHT service handle. CANNOT be NULL. 158 * @param dht An existing and valid DHT service handle. CANNOT be NULL.
158 * @param id ID to announce as provider of regex. Own ID in most cases. 159 * @param priv our private key, must remain valid until the announcement is cancelled
159 * @param regex Regular expression to announce. 160 * @param regex Regular expression to announce.
160 * @param compression How many characters per edge can we squeeze? 161 * @param compression How many characters per edge can we squeeze?
161 * @param stats Optional statistics handle to report usage. Can be NULL. 162 * @param stats Optional statistics handle to report usage. Can be NULL.
@@ -165,10 +166,11 @@ struct REGEX_INTERNAL_Search;
165 */ 166 */
166struct REGEX_INTERNAL_Announcement * 167struct REGEX_INTERNAL_Announcement *
167REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht, 168REGEX_INTERNAL_announce (struct GNUNET_DHT_Handle *dht,
168 const struct GNUNET_PeerIdentity *id, 169 const struct GNUNET_CRYPTO_EccPrivateKey *priv,
169 const char *regex, 170 const char *regex,
170 uint16_t compression, 171 uint16_t compression,
171 struct GNUNET_STATISTICS_Handle *stats); 172 struct GNUNET_STATISTICS_Handle *stats);
173
172 174
173/** 175/**
174 * Announce again a regular expression previously announced. 176 * Announce again a regular expression previously announced.
diff --git a/src/regex/regex_ipc.h b/src/regex/regex_ipc.h
index b94fceb86..fd6440bb8 100644
--- a/src/regex/regex_ipc.h
+++ b/src/regex/regex_ipc.h
@@ -54,11 +54,6 @@ struct AnnounceMessage
54 */ 54 */
55 struct GNUNET_TIME_RelativeNBO refresh_delay; 55 struct GNUNET_TIME_RelativeNBO refresh_delay;
56 56
57 /**
58 * Which PID to announce as the provider?
59 */
60 struct GNUNET_PeerIdentity pid;
61
62 /* followed by 0-terminated regex as string */ 57 /* followed by 0-terminated regex as string */
63}; 58};
64 59