diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-07-19 12:22:39 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-07-19 12:22:39 +0000 |
commit | be8b1a087b70b2ee0dc905f7589199ebfa19c064 (patch) | |
tree | 03021e8ec5326e406f908b5279025dcb2c71923b /src/datastore | |
parent | fa17e0a271f2e8a51017dc35756dab1254cf4b0a (diff) | |
download | gnunet-be8b1a087b70b2ee0dc905f7589199ebfa19c064.tar.gz gnunet-be8b1a087b70b2ee0dc905f7589199ebfa19c064.zip |
bugfixes
Diffstat (limited to 'src/datastore')
-rw-r--r-- | src/datastore/gnunet-service-datastore.c | 10 | ||||
-rw-r--r-- | src/datastore/perf_datastore_api.c | 49 | ||||
-rw-r--r-- | src/datastore/test_datastore_api.c | 125 |
3 files changed, 101 insertions, 83 deletions
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index 74196dd1e..f491d2453 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c | |||
@@ -516,11 +516,6 @@ check_data (const struct GNUNET_MessageHeader *message) | |||
516 | GNUNET_break (0); | 516 | GNUNET_break (0); |
517 | return NULL; | 517 | return NULL; |
518 | } | 518 | } |
519 | if (ntohl(dm->type) == 0) | ||
520 | { | ||
521 | GNUNET_break (0); | ||
522 | return NULL; | ||
523 | } | ||
524 | return dm; | 519 | return dm; |
525 | } | 520 | } |
526 | 521 | ||
@@ -547,6 +542,11 @@ handle_put (void *cls, | |||
547 | "Processing `%s' request\n", | 542 | "Processing `%s' request\n", |
548 | "PUT"); | 543 | "PUT"); |
549 | #endif | 544 | #endif |
545 | if (ntohl(dm->type) == 0) | ||
546 | { | ||
547 | GNUNET_break (0); | ||
548 | dm = NULL; | ||
549 | } | ||
550 | if (dm == NULL) | 550 | if (dm == NULL) |
551 | { | 551 | { |
552 | GNUNET_break (0); | 552 | GNUNET_break (0); |
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c index 552feac24..a3cb7cb0f 100644 --- a/src/datastore/perf_datastore_api.c +++ b/src/datastore/perf_datastore_api.c | |||
@@ -37,13 +37,16 @@ | |||
37 | #include "gnunet_protocols.h" | 37 | #include "gnunet_protocols.h" |
38 | #include "gnunet_datastore_service.h" | 38 | #include "gnunet_datastore_service.h" |
39 | 39 | ||
40 | static struct GNUNET_DATASTORE_Handle *datastore; | 40 | #define VERBOSE GNUNET_YES |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * How long until we give up on transmitting the message? | 43 | * How long until we give up on transmitting the message? |
44 | */ | 44 | */ |
45 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 45 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) |
46 | 46 | ||
47 | |||
48 | static struct GNUNET_DATASTORE_Handle *datastore; | ||
49 | |||
47 | /** | 50 | /** |
48 | * Target datastore size (in bytes). | 51 | * Target datastore size (in bytes). |
49 | * <p> | 52 | * <p> |
@@ -193,6 +196,8 @@ remove_next(void *cls, | |||
193 | int success, | 196 | int success, |
194 | const char *msg) | 197 | const char *msg) |
195 | { | 198 | { |
199 | struct CpsRunContext *crc = cls; | ||
200 | |||
196 | static int dc; | 201 | static int dc; |
197 | dc++; | 202 | dc++; |
198 | #if REPORT_ID | 203 | #if REPORT_ID |
@@ -200,6 +205,11 @@ remove_next(void *cls, | |||
200 | fprintf (stderr, "D"); | 205 | fprintf (stderr, "D"); |
201 | #endif | 206 | #endif |
202 | GNUNET_assert (GNUNET_OK == success); | 207 | GNUNET_assert (GNUNET_OK == success); |
208 | GNUNET_SCHEDULER_add_continuation (crc->sched, | ||
209 | GNUNET_NO, | ||
210 | &run_continuation, | ||
211 | crc, | ||
212 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
203 | } | 213 | } |
204 | 214 | ||
205 | 215 | ||
@@ -210,6 +220,8 @@ do_delete (void *cls, | |||
210 | { | 220 | { |
211 | struct CpsRunContext *crc = cls; | 221 | struct CpsRunContext *crc = cls; |
212 | 222 | ||
223 | stored_bytes -= crc->esize; | ||
224 | stored_entries--; | ||
213 | GNUNET_DATASTORE_remove (datastore, | 225 | GNUNET_DATASTORE_remove (datastore, |
214 | &crc->key, | 226 | &crc->key, |
215 | crc->esize, | 227 | crc->esize, |
@@ -234,29 +246,31 @@ delete_value (void *cls, | |||
234 | { | 246 | { |
235 | struct CpsRunContext *crc = cls; | 247 | struct CpsRunContext *crc = cls; |
236 | 248 | ||
237 | if (stored_bytes < MAX_SIZE) | ||
238 | return; | ||
239 | if (key == NULL) | 249 | if (key == NULL) |
240 | { | 250 | { |
241 | crc->phase = RP_REPORT; | 251 | crc->phase = RP_REPORT; |
242 | GNUNET_SCHEDULER_add_continuation (crc->sched, | 252 | if (stored_bytes < MAX_SIZE) |
243 | GNUNET_NO, | 253 | { |
244 | &run_continuation, | 254 | GNUNET_SCHEDULER_add_continuation (crc->sched, |
245 | crc, | 255 | GNUNET_NO, |
246 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 256 | &run_continuation, |
257 | crc, | ||
258 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
259 | return; | ||
260 | } | ||
261 | GNUNET_SCHEDULER_add_after (crc->sched, | ||
262 | GNUNET_NO, | ||
263 | GNUNET_SCHEDULER_PRIORITY_HIGH, | ||
264 | GNUNET_SCHEDULER_NO_PREREQUISITE_TASK, | ||
265 | &do_delete, | ||
266 | crc); | ||
247 | return; | 267 | return; |
248 | } | 268 | } |
249 | stored_bytes -= size; | 269 | if (stored_bytes < MAX_SIZE) |
250 | stored_entries--; | 270 | return; |
251 | crc->key = *key; | 271 | crc->key = *key; |
252 | crc->esize = size; | 272 | crc->esize = size; |
253 | memcpy (crc->data, data, size); | 273 | memcpy (crc->data, data, size); |
254 | GNUNET_SCHEDULER_add_after (crc->sched, | ||
255 | GNUNET_NO, | ||
256 | GNUNET_SCHEDULER_PRIORITY_HIGH, | ||
257 | GNUNET_SCHEDULER_NO_PREREQUISITE_TASK, | ||
258 | &do_delete, | ||
259 | crc); | ||
260 | } | 274 | } |
261 | 275 | ||
262 | 276 | ||
@@ -293,7 +307,7 @@ run_continuation (void *cls, | |||
293 | &key, | 307 | &key, |
294 | size, | 308 | size, |
295 | data, | 309 | data, |
296 | i, | 310 | i+1, |
297 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100), | 311 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100), |
298 | i, | 312 | i, |
299 | GNUNET_TIME_relative_to_absolute | 313 | GNUNET_TIME_relative_to_absolute |
@@ -398,6 +412,7 @@ main (int argc, char *argv[]) | |||
398 | { | 412 | { |
399 | int ret; | 413 | int ret; |
400 | 414 | ||
415 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-datastore"); | ||
401 | GNUNET_log_setup ("perf-datastore-api", | 416 | GNUNET_log_setup ("perf-datastore-api", |
402 | #if VERBOSE | 417 | #if VERBOSE |
403 | "DEBUG", | 418 | "DEBUG", |
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index 56cf0e588..7eaa09262 100644 --- a/src/datastore/test_datastore_api.c +++ b/src/datastore/test_datastore_api.c | |||
@@ -33,7 +33,7 @@ | |||
33 | #include "gnunet_protocols.h" | 33 | #include "gnunet_protocols.h" |
34 | #include "gnunet_datastore_service.h" | 34 | #include "gnunet_datastore_service.h" |
35 | 35 | ||
36 | #define VERBOSE GNUNET_YES | 36 | #define VERBOSE GNUNET_NO |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * How long until we give up on transmitting the message? | 39 | * How long until we give up on transmitting the message? |
@@ -101,6 +101,7 @@ enum RunPhase | |||
101 | RP_PUT, | 101 | RP_PUT, |
102 | RP_GET, | 102 | RP_GET, |
103 | RP_DEL, | 103 | RP_DEL, |
104 | RP_DO_DEL, | ||
104 | RP_DELVALIDATE | 105 | RP_DELVALIDATE |
105 | }; | 106 | }; |
106 | 107 | ||
@@ -112,6 +113,8 @@ struct CpsRunContext | |||
112 | int *iptr; | 113 | int *iptr; |
113 | struct GNUNET_SCHEDULER_Handle *sched; | 114 | struct GNUNET_SCHEDULER_Handle *sched; |
114 | struct GNUNET_CONFIGURATION_Handle *cfg; | 115 | struct GNUNET_CONFIGURATION_Handle *cfg; |
116 | void *data; | ||
117 | size_t size; | ||
115 | enum RunPhase phase; | 118 | enum RunPhase phase; |
116 | }; | 119 | }; |
117 | 120 | ||
@@ -131,22 +134,8 @@ check_success (void *cls, | |||
131 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 134 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
132 | "%s\n", msg); | 135 | "%s\n", msg); |
133 | GNUNET_assert (GNUNET_OK == success); | 136 | GNUNET_assert (GNUNET_OK == success); |
134 | GNUNET_SCHEDULER_add_continuation (crc->sched, | 137 | GNUNET_free_non_null (crc->data); |
135 | GNUNET_NO, | 138 | crc->data = NULL; |
136 | &run_continuation, | ||
137 | crc, | ||
138 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
139 | } | ||
140 | |||
141 | |||
142 | static void | ||
143 | check_failure (void *cls, | ||
144 | int success, | ||
145 | const char *msg) | ||
146 | { | ||
147 | struct CpsRunContext *crc = cls; | ||
148 | GNUNET_assert (GNUNET_OK != success); | ||
149 | GNUNET_assert (NULL != msg); | ||
150 | GNUNET_SCHEDULER_add_continuation (crc->sched, | 139 | GNUNET_SCHEDULER_add_continuation (crc->sched, |
151 | GNUNET_NO, | 140 | GNUNET_NO, |
152 | &run_continuation, | 141 | &run_continuation, |
@@ -170,7 +159,19 @@ check_value (void *cls, | |||
170 | int i; | 159 | int i; |
171 | 160 | ||
172 | if (key == NULL) | 161 | if (key == NULL) |
173 | return; | 162 | { |
163 | if (crc->i == 0) | ||
164 | { | ||
165 | crc->phase = RP_DEL; | ||
166 | crc->i = ITERATIONS; | ||
167 | } | ||
168 | GNUNET_SCHEDULER_add_continuation (crc->sched, | ||
169 | GNUNET_NO, | ||
170 | &run_continuation, | ||
171 | crc, | ||
172 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
173 | return; | ||
174 | } | ||
174 | i = crc->i; | 175 | i = crc->i; |
175 | GNUNET_assert (size == get_size (i)); | 176 | GNUNET_assert (size == get_size (i)); |
176 | GNUNET_assert (0 == memcmp (data, get_data(i), size)); | 177 | GNUNET_assert (0 == memcmp (data, get_data(i), size)); |
@@ -178,11 +179,6 @@ check_value (void *cls, | |||
178 | GNUNET_assert (priority == get_priority (i)); | 179 | GNUNET_assert (priority == get_priority (i)); |
179 | GNUNET_assert (anonymity == get_anonymity(i)); | 180 | GNUNET_assert (anonymity == get_anonymity(i)); |
180 | GNUNET_assert (expiration.value == get_expiration(i).value); | 181 | GNUNET_assert (expiration.value == get_expiration(i).value); |
181 | GNUNET_SCHEDULER_add_continuation (crc->sched, | ||
182 | GNUNET_NO, | ||
183 | &run_continuation, | ||
184 | crc, | ||
185 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
186 | } | 182 | } |
187 | 183 | ||
188 | 184 | ||
@@ -199,31 +195,23 @@ delete_value (void *cls, | |||
199 | { | 195 | { |
200 | struct CpsRunContext *crc = cls; | 196 | struct CpsRunContext *crc = cls; |
201 | if (key == NULL) | 197 | if (key == NULL) |
202 | return; | 198 | { |
203 | GNUNET_DATASTORE_remove (datastore, | 199 | crc->phase = RP_DO_DEL; |
204 | key, | 200 | GNUNET_SCHEDULER_add_continuation (crc->sched, |
205 | size, | 201 | GNUNET_NO, |
206 | data, | 202 | &run_continuation, |
207 | &check_success, | 203 | crc, |
208 | NULL, | 204 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
209 | TIMEOUT); | 205 | return; |
210 | ((int*)key)[0]++; | 206 | } |
211 | GNUNET_DATASTORE_remove (datastore, | 207 | GNUNET_assert (crc->data == NULL); |
212 | key, | 208 | crc->size = size; |
213 | size, | 209 | crc->key = *key; |
214 | data, | 210 | crc->data = GNUNET_malloc (size); |
215 | &check_failure, | 211 | memcpy (crc->data, data, size); |
216 | NULL, | ||
217 | TIMEOUT); | ||
218 | GNUNET_SCHEDULER_add_continuation (crc->sched, | ||
219 | GNUNET_NO, | ||
220 | &run_continuation, | ||
221 | crc, | ||
222 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
223 | } | 212 | } |
224 | 213 | ||
225 | 214 | ||
226 | |||
227 | static void | 215 | static void |
228 | check_nothing (void *cls, | 216 | check_nothing (void *cls, |
229 | const GNUNET_HashCode * key, | 217 | const GNUNET_HashCode * key, |
@@ -237,6 +225,10 @@ check_nothing (void *cls, | |||
237 | { | 225 | { |
238 | struct CpsRunContext *crc = cls; | 226 | struct CpsRunContext *crc = cls; |
239 | GNUNET_assert (key == NULL); | 227 | GNUNET_assert (key == NULL); |
228 | if (crc->i == 0) | ||
229 | { | ||
230 | crc->phase = RP_DONE; | ||
231 | } | ||
240 | GNUNET_SCHEDULER_add_continuation (crc->sched, | 232 | GNUNET_SCHEDULER_add_continuation (crc->sched, |
241 | GNUNET_NO, | 233 | GNUNET_NO, |
242 | &run_continuation, | 234 | &run_continuation, |
@@ -260,7 +252,7 @@ run_continuation (void *cls, | |||
260 | "PUT", | 252 | "PUT", |
261 | crc->i); | 253 | crc->i); |
262 | #endif | 254 | #endif |
263 | memset (&crc->key, ITERATIONS - crc->i, sizeof (GNUNET_HashCode)); | 255 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); |
264 | GNUNET_DATASTORE_put (datastore, | 256 | GNUNET_DATASTORE_put (datastore, |
265 | 0, | 257 | 0, |
266 | &crc->key, | 258 | &crc->key, |
@@ -285,18 +277,13 @@ run_continuation (void *cls, | |||
285 | "GET", | 277 | "GET", |
286 | crc->i); | 278 | crc->i); |
287 | #endif | 279 | #endif |
288 | memset (&crc->key, ITERATIONS - crc->i, sizeof (GNUNET_HashCode)); | 280 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); |
289 | GNUNET_DATASTORE_get (datastore, | 281 | GNUNET_DATASTORE_get (datastore, |
290 | &crc->key, | 282 | &crc->key, |
291 | get_type (crc->i), | 283 | get_type (crc->i), |
292 | &check_value, | 284 | &check_value, |
293 | crc, | 285 | crc, |
294 | TIMEOUT); | 286 | TIMEOUT); |
295 | if (crc->i == 0) | ||
296 | { | ||
297 | crc->phase = RP_DEL; | ||
298 | crc->i = ITERATIONS; | ||
299 | } | ||
300 | break; | 287 | break; |
301 | case RP_DEL: | 288 | case RP_DEL: |
302 | crc->i--; | 289 | crc->i--; |
@@ -306,19 +293,38 @@ run_continuation (void *cls, | |||
306 | "DEL", | 293 | "DEL", |
307 | crc->i); | 294 | crc->i); |
308 | #endif | 295 | #endif |
309 | memset (&crc->key, ITERATIONS - crc->i, sizeof (GNUNET_HashCode)); | 296 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); |
310 | GNUNET_DATASTORE_get (datastore, | 297 | GNUNET_DATASTORE_get (datastore, |
311 | &crc->key, | 298 | &crc->key, |
312 | get_type (crc->i), | 299 | get_type (crc->i), |
313 | &delete_value, | 300 | &delete_value, |
314 | crc, | 301 | crc, |
315 | TIMEOUT); | 302 | TIMEOUT); |
303 | break; | ||
304 | case RP_DO_DEL: | ||
305 | #if VERBOSE | ||
306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
307 | "Executing `%s' number %u\n", | ||
308 | "DO_DEL", | ||
309 | crc->i); | ||
310 | #endif | ||
316 | if (crc->i == 0) | 311 | if (crc->i == 0) |
317 | { | 312 | { |
318 | crc->phase = RP_DELVALIDATE; | ||
319 | crc->i = ITERATIONS; | 313 | crc->i = ITERATIONS; |
314 | crc->phase = RP_DELVALIDATE; | ||
315 | } | ||
316 | else | ||
317 | { | ||
318 | crc->phase = RP_DEL; | ||
320 | } | 319 | } |
321 | break; | 320 | GNUNET_DATASTORE_remove (datastore, |
321 | &crc->key, | ||
322 | crc->size, | ||
323 | crc->data, | ||
324 | &check_success, | ||
325 | crc, | ||
326 | TIMEOUT); | ||
327 | break; | ||
322 | case RP_DELVALIDATE: | 328 | case RP_DELVALIDATE: |
323 | crc->i--; | 329 | crc->i--; |
324 | #if VERBOSE | 330 | #if VERBOSE |
@@ -327,17 +333,13 @@ run_continuation (void *cls, | |||
327 | "DEL-VALIDATE", | 333 | "DEL-VALIDATE", |
328 | crc->i); | 334 | crc->i); |
329 | #endif | 335 | #endif |
330 | memset (&crc->key, ITERATIONS - crc->i, sizeof (GNUNET_HashCode)); | 336 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); |
331 | GNUNET_DATASTORE_get (datastore, | 337 | GNUNET_DATASTORE_get (datastore, |
332 | &crc->key, | 338 | &crc->key, |
333 | get_type (crc->i), | 339 | get_type (crc->i), |
334 | &check_nothing, | 340 | &check_nothing, |
335 | crc, | 341 | crc, |
336 | TIMEOUT); | 342 | TIMEOUT); |
337 | if (crc->i == 0) | ||
338 | { | ||
339 | crc->phase = RP_DONE; | ||
340 | } | ||
341 | break; | 343 | break; |
342 | /* check reservations */ | 344 | /* check reservations */ |
343 | /* check update */ | 345 | /* check update */ |
@@ -417,7 +419,8 @@ int | |||
417 | main (int argc, char *argv[]) | 419 | main (int argc, char *argv[]) |
418 | { | 420 | { |
419 | int ret; | 421 | int ret; |
420 | 422 | ||
423 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-datastore"); | ||
421 | GNUNET_log_setup ("test-datastore-api", | 424 | GNUNET_log_setup ("test-datastore-api", |
422 | #if VERBOSE | 425 | #if VERBOSE |
423 | "DEBUG", | 426 | "DEBUG", |