aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-06 11:16:26 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-06 11:16:26 +0000
commit2ebfdbbe8af9eef26ad1a2776a20227715560558 (patch)
tree9ce4e1f88ab32a156653dc6d74a9c02a82c77ee1 /src
parentb0f956058355ea7e96a7d3022b08dd951acd99a5 (diff)
downloadgnunet-2ebfdbbe8af9eef26ad1a2776a20227715560558.tar.gz
gnunet-2ebfdbbe8af9eef26ad1a2776a20227715560558.zip
-load revocations from disk, misc doxygen/style fixes
Diffstat (limited to 'src')
-rw-r--r--src/fs/fs_file_information.c2
-rw-r--r--src/include/gnunet_configuration_lib.h11
-rw-r--r--src/include/gnunet_crypto_lib.h54
-rw-r--r--src/include/gnunet_disk_lib.h49
-rw-r--r--src/revocation/gnunet-service-revocation.c77
-rw-r--r--src/util/disk.c158
6 files changed, 225 insertions, 126 deletions
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index 1e997cfab..87d618b07 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -116,7 +116,7 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
116 char fn_conv[MAX_PATH]; 116 char fn_conv[MAX_PATH];
117#endif 117#endif
118 118
119 /* FIXME: should includeSymLinks be GNUNET_NO or GNUNET_YES here? */ 119 /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */
120 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)) 120 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES))
121 { 121 {
122 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); 122 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h
index 10cfc4138..05ba8a2db 100644
--- a/src/include/gnunet_configuration_lib.h
+++ b/src/include/gnunet_configuration_lib.h
@@ -324,9 +324,10 @@ GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
324 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 324 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
325 */ 325 */
326int 326int
327GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle 327GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
328 *cfg, const char *section, 328 const char *section,
329 const char *option, char **value); 329 const char *option,
330 char **value);
330 331
331 332
332/** 333/**
@@ -341,11 +342,11 @@ GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
341 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 342 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
342 */ 343 */
343int 344int
344GNUNET_CONFIGURATION_get_value_filename (const struct 345GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
345 GNUNET_CONFIGURATION_Handle *cfg,
346 const char *section, 346 const char *section,
347 const char *option, char **value); 347 const char *option, char **value);
348 348
349
349/** 350/**
350 * Iterate over the set of filenames stored in a configuration value. 351 * Iterate over the set of filenames stored in a configuration value.
351 * 352 *
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index c72c135c1..eda23077b 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -189,7 +189,6 @@ struct GNUNET_CRYPTO_EccPublicSignKey
189}; 189};
190 190
191 191
192
193/** 192/**
194 * The identity of the host (wraps the signing key of the peer). 193 * The identity of the host (wraps the signing key of the peer).
195 */ 194 */
@@ -296,7 +295,7 @@ GNUNET_CRYPTO_seed_weak_random (int32_t seed);
296 * @param sum current sum, initially 0 295 * @param sum current sum, initially 0
297 * @param buf buffer to calculate CRC over (must be 16-bit aligned) 296 * @param buf buffer to calculate CRC over (must be 16-bit aligned)
298 * @param len number of bytes in @a buf, must be multiple of 2 297 * @param len number of bytes in @a buf, must be multiple of 2
299 * @return updated crc sum (must be subjected to GNUNET_CRYPTO_crc16_finish to get actual crc16) 298 * @return updated crc sum (must be subjected to #GNUNET_CRYPTO_crc16_finish to get actual crc16)
300 */ 299 */
301uint32_t 300uint32_t
302GNUNET_CRYPTO_crc16_step (uint32_t sum, const void *buf, size_t len); 301GNUNET_CRYPTO_crc16_step (uint32_t sum, const void *buf, size_t len);
@@ -426,7 +425,7 @@ GNUNET_CRYPTO_symmetric_decrypt (const void *block, size_t size,
426 * @param iv initialization vector 425 * @param iv initialization vector
427 * @param skey session key 426 * @param skey session key
428 * @param salt salt for the derivation 427 * @param salt salt for the derivation
429 * @param salt_len size of the salt 428 * @param salt_len size of the @a salt
430 * @param ... pairs of void * & size_t for context chunks, terminated by NULL 429 * @param ... pairs of void * & size_t for context chunks, terminated by NULL
431 */ 430 */
432void 431void
@@ -441,7 +440,7 @@ GNUNET_CRYPTO_symmetric_derive_iv (struct GNUNET_CRYPTO_SymmetricInitializationV
441 * @param iv initialization vector 440 * @param iv initialization vector
442 * @param skey session key 441 * @param skey session key
443 * @param salt salt for the derivation 442 * @param salt salt for the derivation
444 * @param salt_len size of the salt 443 * @param salt_len size of the @a salt
445 * @param argp pairs of void * & size_t for context chunks, terminated by NULL 444 * @param argp pairs of void * & size_t for context chunks, terminated by NULL
446 */ 445 */
447void 446void
@@ -494,7 +493,7 @@ GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen,
494 * @ingroup hash 493 * @ingroup hash
495 * 494 *
496 * Compute the distance between 2 hashcodes. The 495 * Compute the distance between 2 hashcodes. The
497 * computation must be fast, not involve a[0] or a[4] (they're used 496 * computation must be fast, not involve @a a[0] or @a a[4] (they're used
498 * elsewhere), and be somewhat consistent. And of course, the result 497 * elsewhere), and be somewhat consistent. And of course, the result
499 * should be a positive number. 498 * should be a positive number.
500 * 499 *
@@ -503,8 +502,8 @@ GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen,
503 * @return number between 0 and UINT32_MAX 502 * @return number between 0 and UINT32_MAX
504 */ 503 */
505uint32_t 504uint32_t
506GNUNET_CRYPTO_hash_distance_u32 (const struct GNUNET_HashCode * a, 505GNUNET_CRYPTO_hash_distance_u32 (const struct GNUNET_HashCode *a,
507 const struct GNUNET_HashCode * b); 506 const struct GNUNET_HashCode *b);
508 507
509 508
510/** 509/**
@@ -542,8 +541,7 @@ GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
542 * @param res resulting hash, NULL on error 541 * @param res resulting hash, NULL on error
543 */ 542 */
544typedef void (*GNUNET_CRYPTO_HashCompletedCallback) (void *cls, 543typedef void (*GNUNET_CRYPTO_HashCompletedCallback) (void *cls,
545 const struct GNUNET_HashCode * 544 const struct GNUNET_HashCode *res);
546 res);
547 545
548 546
549/** 547/**
@@ -593,30 +591,30 @@ GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
593 591
594/** 592/**
595 * @ingroup hash 593 * @ingroup hash
596 * compute result(delta) = b - a 594 * compute @a result = @a b - @a a
597 * 595 *
598 * @param a some hash code 596 * @param a some hash code
599 * @param b some hash code 597 * @param b some hash code
600 * @param result set to @a b - @a a 598 * @param result set to @a b - @a a
601 */ 599 */
602void 600void
603GNUNET_CRYPTO_hash_difference (const struct GNUNET_HashCode * a, 601GNUNET_CRYPTO_hash_difference (const struct GNUNET_HashCode *a,
604 const struct GNUNET_HashCode * b, 602 const struct GNUNET_HashCode *b,
605 struct GNUNET_HashCode * result); 603 struct GNUNET_HashCode *result);
606 604
607 605
608/** 606/**
609 * @ingroup hash 607 * @ingroup hash
610 * compute result(b) = a + delta 608 * compute @a result = @a a + @a delta
611 * 609 *
612 * @param a some hash code 610 * @param a some hash code
613 * @param delta some hash code 611 * @param delta some hash code
614 * @param result set to @a a + @a delta 612 * @param result set to @a a + @a delta
615 */ 613 */
616void 614void
617GNUNET_CRYPTO_hash_sum (const struct GNUNET_HashCode * a, 615GNUNET_CRYPTO_hash_sum (const struct GNUNET_HashCode *a,
618 const struct GNUNET_HashCode * delta, 616 const struct GNUNET_HashCode *delta,
619 struct GNUNET_HashCode * result); 617 struct GNUNET_HashCode *result);
620 618
621 619
622/** 620/**
@@ -643,8 +641,7 @@ GNUNET_CRYPTO_hash_xor (const struct GNUNET_HashCode * a, const struct GNUNET_Ha
643void 641void
644GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode * hc, 642GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode * hc,
645 struct GNUNET_CRYPTO_SymmetricSessionKey *skey, 643 struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
646 struct GNUNET_CRYPTO_SymmetricInitializationVector 644 struct GNUNET_CRYPTO_SymmetricInitializationVector *iv);
647 *iv);
648 645
649 646
650/** 647/**
@@ -663,7 +660,7 @@ GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code,
663/** 660/**
664 * @ingroup hash 661 * @ingroup hash
665 * Determine how many low order bits match in two 662 * Determine how many low order bits match in two
666 * struct GNUNET_HashCodes. i.e. - 010011 and 011111 share 663 * `struct GNUNET_HashCodes`. i.e. - 010011 and 011111 share
667 * the first two lowest order bits, and therefore the 664 * the first two lowest order bits, and therefore the
668 * return value is two (NOT XOR distance, nor how many 665 * return value is two (NOT XOR distance, nor how many
669 * bits match absolutely!). 666 * bits match absolutely!).
@@ -673,8 +670,8 @@ GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code,
673 * @return the number of bits that match 670 * @return the number of bits that match
674 */ 671 */
675unsigned int 672unsigned int
676GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode * first, 673GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode *first,
677 const struct GNUNET_HashCode * second); 674 const struct GNUNET_HashCode *second);
678 675
679 676
680/** 677/**
@@ -684,10 +681,11 @@ GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode * first,
684 * 681 *
685 * @param h1 some hash code 682 * @param h1 some hash code
686 * @param h2 some hash code 683 * @param h2 some hash code
687 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. 684 * @return 1 if @a h1 > @a h2, -1 if @a h1 < @a h2 and 0 if @a h1 == @a h2.
688 */ 685 */
689int 686int
690GNUNET_CRYPTO_hash_cmp (const struct GNUNET_HashCode * h1, const struct GNUNET_HashCode * h2); 687GNUNET_CRYPTO_hash_cmp (const struct GNUNET_HashCode *h1,
688 const struct GNUNET_HashCode *h2);
691 689
692 690
693/** 691/**
@@ -698,12 +696,12 @@ GNUNET_CRYPTO_hash_cmp (const struct GNUNET_HashCode * h1, const struct GNUNET_H
698 * @param h1 some hash code 696 * @param h1 some hash code
699 * @param h2 some hash code 697 * @param h2 some hash code
700 * @param target some hash code 698 * @param target some hash code
701 * @return -1 if h1 is closer, 1 if h2 is closer and 0 if h1==h2. 699 * @return -1 if @a h1 is closer, 1 if @a h2 is closer and 0 if @a h1== @a h2.
702 */ 700 */
703int 701int
704GNUNET_CRYPTO_hash_xorcmp (const struct GNUNET_HashCode * h1, 702GNUNET_CRYPTO_hash_xorcmp (const struct GNUNET_HashCode *h1,
705 const struct GNUNET_HashCode * h2, 703 const struct GNUNET_HashCode *h2,
706 const struct GNUNET_HashCode * target); 704 const struct GNUNET_HashCode *target);
707 705
708 706
709/** 707/**
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h
index a800010f8..b5f0ccdda 100644
--- a/src/include/gnunet_disk_lib.h
+++ b/src/include/gnunet_disk_lib.h
@@ -282,7 +282,7 @@ GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h);
282 * (of a file that exists and that is not a directory). 282 * (of a file that exists and that is not a directory).
283 * 283 *
284 * @param fil filename to check 284 * @param fil filename to check
285 * @return GNUNET_YES if yes, GNUNET_NO if not a file, GNUNET_SYSERR if something 285 * @return #GNUNET_YES if yes, #GNUNET_NO if not a file, #GNUNET_SYSERR if something
286 * else (will print an error message in that case, too). 286 * else (will print an error message in that case, too).
287 */ 287 */
288int 288int
@@ -320,15 +320,16 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, OFF_T offset,
320 * @param size set to the size of the file (or, 320 * @param size set to the size of the file (or,
321 * in the case of directories, the sum 321 * in the case of directories, the sum
322 * of all sizes of files in the directory) 322 * of all sizes of files in the directory)
323 * @param includeSymLinks should symbolic links be 323 * @param include_symbolic_links should symbolic links be
324 * included? 324 * included?
325 * @param singleFileMode GNUNET_YES to only get size of one file 325 * @param single_file_mode #GNUNET_YES to only get size of one file
326 * and return GNUNET_SYSERR for directories. 326 * and return #GNUNET_SYSERR for directories.
327 * @return GNUNET_SYSERR on error, GNUNET_OK on success 327 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
328 */ 328 */
329int 329int
330GNUNET_DISK_file_size (const char *filename, uint64_t * size, 330GNUNET_DISK_file_size (const char *filename, uint64_t *size,
331 int includeSymLinks, int singleFileMode); 331 int include_symbolic_links,
332 int single_file_mode);
332 333
333 334
334/** 335/**
@@ -347,8 +348,9 @@ GNUNET_DISK_file_size (const char *filename, uint64_t * size,
347 * @return GNUNET_OK on success 348 * @return GNUNET_OK on success
348 */ 349 */
349int 350int
350GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev, 351GNUNET_DISK_file_get_identifiers (const char *filename,
351 uint64_t * ino); 352 uint64_t *dev,
353 uint64_t *ino);
352 354
353 355
354/** 356/**
@@ -392,7 +394,8 @@ GNUNET_DISK_mkdtemp (const char *t);
392 * @return IO handle on success, NULL on error 394 * @return IO handle on success, NULL on error
393 */ 395 */
394struct GNUNET_DISK_FileHandle * 396struct GNUNET_DISK_FileHandle *
395GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, 397GNUNET_DISK_file_open (const char *fn,
398 enum GNUNET_DISK_OpenFlags flags,
396 enum GNUNET_DISK_AccessPermissions perm); 399 enum GNUNET_DISK_AccessPermissions perm);
397 400
398 401
@@ -418,7 +421,10 @@ GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
418 * @return handle to the new pipe, NULL on error 421 * @return handle to the new pipe, NULL on error
419 */ 422 */
420struct GNUNET_DISK_PipeHandle * 423struct GNUNET_DISK_PipeHandle *
421GNUNET_DISK_pipe (int blocking_read, int blocking_write, int inherit_read, int inherit_write); 424GNUNET_DISK_pipe (int blocking_read,
425 int blocking_write,
426 int inherit_read,
427 int inherit_write);
422 428
423 429
424/** 430/**
@@ -432,7 +438,9 @@ GNUNET_DISK_pipe (int blocking_read, int blocking_write, int inherit_read, int i
432 * @return handle to the new pipe, NULL on error 438 * @return handle to the new pipe, NULL on error
433 */ 439 */
434struct GNUNET_DISK_PipeHandle * 440struct GNUNET_DISK_PipeHandle *
435GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2]); 441GNUNET_DISK_pipe_from_fd (int blocking_read,
442 int blocking_write,
443 int fd[2]);
436 444
437 445
438/** 446/**
@@ -529,13 +537,15 @@ GNUNET_DISK_get_handle_from_native (FILE *fd);
529 537
530/** 538/**
531 * Read the contents of a binary file into a buffer. 539 * Read the contents of a binary file into a buffer.
540 *
532 * @param h handle to an open file 541 * @param h handle to an open file
533 * @param result the buffer to write the result to 542 * @param result the buffer to write the result to
534 * @param len the maximum number of bytes to read 543 * @param len the maximum number of bytes to read
535 * @return the number of bytes read on success, #GNUNET_SYSERR on failure 544 * @return the number of bytes read on success, #GNUNET_SYSERR on failure
536 */ 545 */
537ssize_t 546ssize_t
538GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, void *result, 547GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
548 void *result,
539 size_t len); 549 size_t len);
540 550
541 551
@@ -579,18 +589,20 @@ GNUNET_DISK_fn_read (const char *fn,
579 */ 589 */
580ssize_t 590ssize_t
581GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, 591GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h,
582 const void *buffer, size_t n); 592 const void *buffer,
593 size_t n);
583 594
584 595
585/** 596/**
586 * Write a buffer to a file, blocking, if necessary. 597 * Write a buffer to a file, blocking, if necessary.
598 *
587 * @param h handle to open file 599 * @param h handle to open file
588 * @param buffer the data to write 600 * @param buffer the data to write
589 * @param n number of bytes to write 601 * @param n number of bytes to write
590 * @return number of bytes written on success, #GNUNET_SYSERR on error 602 * @return number of bytes written on success, #GNUNET_SYSERR on error
591 */ 603 */
592ssize_t 604ssize_t
593GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h, 605GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h,
594 const void *buffer, 606 const void *buffer,
595 size_t n); 607 size_t n);
596 608
@@ -606,7 +618,9 @@ GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h,
606 * @return number of bytes written on success, #GNUNET_SYSERR on error 618 * @return number of bytes written on success, #GNUNET_SYSERR on error
607 */ 619 */
608ssize_t 620ssize_t
609GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n, 621GNUNET_DISK_fn_write (const char *fn,
622 const void *buffer,
623 size_t n,
610 enum GNUNET_DISK_AccessPermissions mode); 624 enum GNUNET_DISK_AccessPermissions mode);
611 625
612 626
@@ -766,7 +780,8 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh,
766 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 780 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
767 */ 781 */
768int 782int
769GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, OFF_T unlock_start, 783GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh,
784 OFF_T unlock_start,
770 OFF_T unlock_end); 785 OFF_T unlock_end);
771 786
772 787
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c
index dbf8817f8..a410f7b4e 100644
--- a/src/revocation/gnunet-service-revocation.c
+++ b/src/revocation/gnunet-service-revocation.c
@@ -31,7 +31,6 @@
31 * peers that connect. 31 * peers that connect.
32 * 32 *
33 * TODO: 33 * TODO:
34 * - load revocations from disk
35 * - store revocations to disk 34 * - store revocations to disk
36 * - handle p2p revocations 35 * - handle p2p revocations
37 * - handle p2p connect (trigger SET union) 36 * - handle p2p connect (trigger SET union)
@@ -122,6 +121,11 @@ static struct GNUNET_SERVER_Handle *srv;
122static struct GNUNET_SERVER_NotificationContext *nc; 121static struct GNUNET_SERVER_NotificationContext *nc;
123 122
124/** 123/**
124 * File handle for the revocation database.
125 */
126static struct GNUNET_DISK_FileHandle *revocation_db;
127
128/**
125 * Amount of work required (W-bit collisions) for REVOCATION proofs, in collision-bits. 129 * Amount of work required (W-bit collisions) for REVOCATION proofs, in collision-bits.
126 */ 130 */
127static unsigned long long revocation_work_required; 131static unsigned long long revocation_work_required;
@@ -401,6 +405,11 @@ shutdown_task (void *cls,
401 GNUNET_SERVER_notification_context_destroy (nc); 405 GNUNET_SERVER_notification_context_destroy (nc);
402 nc = NULL; 406 nc = NULL;
403 } 407 }
408 if (NULL != revocation_db)
409 {
410 GNUNET_DISK_file_close (revocation_db);
411 revocation_db = NULL;
412 }
404 GNUNET_CONTAINER_multihashmap_iterate (revocation_map, 413 GNUNET_CONTAINER_multihashmap_iterate (revocation_map,
405 &free_entry, 414 &free_entry,
406 NULL); 415 NULL);
@@ -453,7 +462,23 @@ run (void *cls,
453 sizeof (struct RevokeMessage)}, 462 sizeof (struct RevokeMessage)},
454 {NULL, 0, 0} 463 {NULL, 0, 0}
455 }; 464 };
465 char *fn;
466 uint64_t left;
467 struct RevokeMessage *rm;
468 struct GNUNET_HashCode hc;
456 469
470 if (GNUNET_OK !=
471 GNUNET_CONFIGURATION_get_value_filename (c,
472 "REVOCATION",
473 "DATABASE",
474 &fn))
475 {
476 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
477 "REVOCATION",
478 "DATABASE");
479 GNUNET_SCHEDULER_shutdown ();
480 return;
481 }
457 cfg = c; 482 cfg = c;
458 srv = server; 483 srv = server;
459 revocation_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); 484 revocation_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO);
@@ -466,6 +491,7 @@ run (void *cls,
466 "REVOCATION", 491 "REVOCATION",
467 "WORKBITS"); 492 "WORKBITS");
468 GNUNET_SCHEDULER_shutdown (); 493 GNUNET_SCHEDULER_shutdown ();
494 GNUNET_free (fn);
469 return; 495 return;
470 } 496 }
471 if (revocation_work_required >= sizeof (struct GNUNET_HashCode) * 8) 497 if (revocation_work_required >= sizeof (struct GNUNET_HashCode) * 8)
@@ -475,10 +501,59 @@ run (void *cls,
475 "WORKBITS", 501 "WORKBITS",
476 _("Value is too large.\n")); 502 _("Value is too large.\n"));
477 GNUNET_SCHEDULER_shutdown (); 503 GNUNET_SCHEDULER_shutdown ();
504 GNUNET_free (fn);
478 return; 505 return;
479 } 506 }
480 revocation_set = GNUNET_SET_create (cfg, 507 revocation_set = GNUNET_SET_create (cfg,
481 GNUNET_SET_OPERATION_UNION); 508 GNUNET_SET_OPERATION_UNION);
509
510 revocation_db = GNUNET_DISK_file_open (fn,
511 GNUNET_DISK_OPEN_READWRITE |
512 GNUNET_DISK_OPEN_CREATE,
513 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE |
514 GNUNET_DISK_PERM_GROUP_READ |
515 GNUNET_DISK_PERM_OTHER_READ);
516 if (NULL == revocation_db)
517 {
518 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
519 "REVOCATION",
520 "DATABASE",
521 _("Could not open revocation database file!"));
522 GNUNET_SCHEDULER_shutdown ();
523 GNUNET_free (fn);
524 return;
525 }
526 if (GNUNET_OK !=
527 GNUNET_DISK_file_size (fn, &left, GNUNET_YES, GNUNET_YES))
528 left = 0;
529 while (left > sizeof (struct RevokeMessage))
530 {
531 rm = GNUNET_new (struct RevokeMessage);
532 if (sizeof (struct RevokeMessage) !=
533 GNUNET_DISK_file_read (revocation_db,
534 rm,
535 sizeof (struct RevokeMessage)))
536 {
537 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
538 "read",
539 fn);
540 GNUNET_free (rm);
541 GNUNET_SCHEDULER_shutdown ();
542 GNUNET_free (fn);
543 return;
544 }
545 GNUNET_break (0 == ntohl (rm->reserved));
546 GNUNET_CRYPTO_hash (&rm->public_key,
547 sizeof (struct GNUNET_CRYPTO_EccPublicSignKey),
548 &hc);
549 GNUNET_break (GNUNET_OK ==
550 GNUNET_CONTAINER_multihashmap_put (revocation_map,
551 &hc,
552 rm,
553 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
554 }
555 GNUNET_free (fn);
556
482 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, 557 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
483 NULL); 558 NULL);
484 peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); 559 peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
diff --git a/src/util/disk.c b/src/util/disk.c
index 9390743fd..d349aeb8e 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -282,23 +282,23 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, OFF_T offset,
282 * @param size set to the size of the file (or, 282 * @param size set to the size of the file (or,
283 * in the case of directories, the sum 283 * in the case of directories, the sum
284 * of all sizes of files in the directory) 284 * of all sizes of files in the directory)
285 * @param includeSymLinks should symbolic links be 285 * @param include_symbolic_links should symbolic links be
286 * included? 286 * included?
287 * @param singleFileMode GNUNET_YES to only get size of one file 287 * @param single_file_mode GNUNET_YES to only get size of one file
288 * and return GNUNET_SYSERR for directories. 288 * and return GNUNET_SYSERR for directories.
289 * @return GNUNET_SYSERR on error, GNUNET_OK on success 289 * @return GNUNET_SYSERR on error, GNUNET_OK on success
290 */ 290 */
291int 291int
292GNUNET_DISK_file_size (const char *filename, uint64_t * size, 292GNUNET_DISK_file_size (const char *filename, uint64_t * size,
293 int includeSymLinks, int singleFileMode) 293 int include_symbolic_links, int single_file_mode)
294{ 294{
295 struct GetFileSizeData gfsd; 295 struct GetFileSizeData gfsd;
296 int ret; 296 int ret;
297 297
298 GNUNET_assert (size != NULL); 298 GNUNET_assert (size != NULL);
299 gfsd.total = 0; 299 gfsd.total = 0;
300 gfsd.include_sym_links = includeSymLinks; 300 gfsd.include_sym_links = include_symbolic_links;
301 gfsd.single_file_mode = singleFileMode; 301 gfsd.single_file_mode = single_file_mode;
302 ret = getSizeRec (&gfsd, filename); 302 ret = getSizeRec (&gfsd, filename);
303 *size = gfsd.total; 303 *size = gfsd.total;
304 return ret; 304 return ret;
@@ -318,7 +318,7 @@ GNUNET_DISK_file_size (const char *filename, uint64_t * size,
318 * @param filename name of the file 318 * @param filename name of the file
319 * @param dev set to the device ID 319 * @param dev set to the device ID
320 * @param ino set to the inode ID 320 * @param ino set to the inode ID
321 * @return GNUNET_OK on success 321 * @return #GNUNET_OK on success
322 */ 322 */
323int 323int
324GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev, 324GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev,
@@ -557,15 +557,15 @@ GNUNET_DISK_mktemp (const char *t)
557 557
558 558
559/** 559/**
560 * Test if "fil" is a directory and listable. Optionally, also check if the 560 * Test if @a fil is a directory and listable. Optionally, also check if the
561 * directory is readable. Will not print an error message if the directory does 561 * directory is readable. Will not print an error message if the directory does
562 * not exist. Will log errors if GNUNET_SYSERR is returned (i.e., a file exists 562 * not exist. Will log errors if #GNUNET_SYSERR is returned (i.e., a file exists
563 * with the same name). 563 * with the same name).
564 * 564 *
565 * @param fil filename to test 565 * @param fil filename to test
566 * @param is_readable GNUNET_YES to additionally check if "fil" is readable; 566 * @param is_readable GNUNET_YES to additionally check if @a fil is readable;
567 * GNUNET_NO to disable this check 567 * #GNUNET_NO to disable this check
568 * @return GNUNET_YES if yes, GNUNET_NO if not; GNUNET_SYSERR if it 568 * @return #GNUNET_YES if yes, #GNUNET_NO if not; #GNUNET_SYSERR if it
569 * does not exist or stat'ed 569 * does not exist or stat'ed
570 */ 570 */
571int 571int
@@ -605,7 +605,7 @@ GNUNET_DISK_directory_test (const char *fil, int is_readable)
605 * (of a file that exists and that is not a directory). 605 * (of a file that exists and that is not a directory).
606 * 606 *
607 * @param fil filename to check 607 * @param fil filename to check
608 * @return GNUNET_YES if yes, GNUNET_NO if not a file, GNUNET_SYSERR if something 608 * @return #GNUNET_YES if yes, GNUNET_NO if not a file, #GNUNET_SYSERR if something
609 * else (will print an error message in that case, too). 609 * else (will print an error message in that case, too).
610 */ 610 */
611int 611int
@@ -651,7 +651,7 @@ GNUNET_DISK_file_test (const char *fil)
651 * Implementation of "mkdir -p" 651 * Implementation of "mkdir -p"
652 * 652 *
653 * @param dir the directory to create 653 * @param dir the directory to create
654 * @returns GNUNET_OK on success, GNUNET_SYSERR on failure 654 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
655 */ 655 */
656int 656int
657GNUNET_DISK_directory_create (const char *dir) 657GNUNET_DISK_directory_create (const char *dir)
@@ -759,9 +759,9 @@ GNUNET_DISK_directory_create (const char *dir)
759 * a file. 759 * a file.
760 * 760 *
761 * @param filename name of a file in the directory 761 * @param filename name of a file in the directory
762 * @returns GNUNET_OK on success, 762 * @returns #GNUNET_OK on success,
763 * GNUNET_SYSERR on failure, 763 * #GNUNET_SYSERR on failure,
764 * GNUNET_NO if the directory 764 * #GNUNET_NO if the directory
765 * exists but is not writeable for us 765 * exists but is not writeable for us
766 */ 766 */
767int 767int
@@ -788,27 +788,29 @@ GNUNET_DISK_directory_create_for_file (const char *filename)
788 788
789/** 789/**
790 * Read the contents of a binary file into a buffer. 790 * Read the contents of a binary file into a buffer.
791 *
791 * @param h handle to an open file 792 * @param h handle to an open file
792 * @param result the buffer to write the result to 793 * @param result the buffer to write the result to
793 * @param len the maximum number of bytes to read 794 * @param len the maximum number of bytes to read
794 * @return the number of bytes read on success, GNUNET_SYSERR on failure 795 * @return the number of bytes read on success, #GNUNET_SYSERR on failure
795 */ 796 */
796ssize_t 797ssize_t
797GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle * h, void *result, 798GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
799 void *result,
798 size_t len) 800 size_t len)
799{ 801{
800 if (h == NULL) 802 if (NULL == h)
801 { 803 {
802 errno = EINVAL; 804 errno = EINVAL;
803 return GNUNET_SYSERR; 805 return GNUNET_SYSERR;
804 } 806 }
805 807
806#ifdef MINGW 808#ifdef MINGW
807 DWORD bytesRead; 809 DWORD bytes_read;
808 810
809 if (h->type != GNUNET_DISK_HANLDE_TYPE_PIPE) 811 if (h->type != GNUNET_DISK_HANLDE_TYPE_PIPE)
810 { 812 {
811 if (!ReadFile (h->h, result, len, &bytesRead, NULL)) 813 if (!ReadFile (h->h, result, len, &bytes_read, NULL))
812 { 814 {
813 SetErrnoFromWinError (GetLastError ()); 815 SetErrnoFromWinError (GetLastError ());
814 return GNUNET_SYSERR; 816 return GNUNET_SYSERR;
@@ -816,7 +818,7 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle * h, void *result,
816 } 818 }
817 else 819 else
818 { 820 {
819 if (!ReadFile (h->h, result, len, &bytesRead, h->oOverlapRead)) 821 if (!ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead))
820 { 822 {
821 if (GetLastError () != ERROR_IO_PENDING) 823 if (GetLastError () != ERROR_IO_PENDING)
822 { 824 {
@@ -825,11 +827,11 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle * h, void *result,
825 return GNUNET_SYSERR; 827 return GNUNET_SYSERR;
826 } 828 }
827 LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); 829 LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n");
828 GetOverlappedResult (h->h, h->oOverlapRead, &bytesRead, TRUE); 830 GetOverlappedResult (h->h, h->oOverlapRead, &bytes_read, TRUE);
829 } 831 }
830 LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes from pipe\n", bytesRead); 832 LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes from pipe\n", bytes_read);
831 } 833 }
832 return bytesRead; 834 return bytes_read;
833#else 835#else
834 return read (h->fd, result, len); 836 return read (h->fd, result, len);
835#endif 837#endif
@@ -844,25 +846,25 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle * h, void *result,
844 * @param h handle to an open file 846 * @param h handle to an open file
845 * @param result the buffer to write the result to 847 * @param result the buffer to write the result to
846 * @param len the maximum number of bytes to read 848 * @param len the maximum number of bytes to read
847 * @return the number of bytes read on success, GNUNET_SYSERR on failure 849 * @return the number of bytes read on success, #GNUNET_SYSERR on failure
848 */ 850 */
849ssize_t 851ssize_t
850GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle * h, 852GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
851 void *result, 853 void *result,
852 size_t len) 854 size_t len)
853{ 855{
854 if (h == NULL) 856 if (NULL == h)
855 { 857 {
856 errno = EINVAL; 858 errno = EINVAL;
857 return GNUNET_SYSERR; 859 return GNUNET_SYSERR;
858 } 860 }
859 861
860#ifdef MINGW 862#ifdef MINGW
861 DWORD bytesRead; 863 DWORD bytes_read;
862 864
863 if (h->type != GNUNET_DISK_HANLDE_TYPE_PIPE) 865 if (h->type != GNUNET_DISK_HANLDE_TYPE_PIPE)
864 { 866 {
865 if (!ReadFile (h->h, result, len, &bytesRead, NULL)) 867 if (!ReadFile (h->h, result, len, &bytes_read, NULL))
866 { 868 {
867 SetErrnoFromWinError (GetLastError ()); 869 SetErrnoFromWinError (GetLastError ());
868 return GNUNET_SYSERR; 870 return GNUNET_SYSERR;
@@ -870,7 +872,7 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle * h,
870 } 872 }
871 else 873 else
872 { 874 {
873 if (!ReadFile (h->h, result, len, &bytesRead, h->oOverlapRead)) 875 if (!ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead))
874 { 876 {
875 if (GetLastError () != ERROR_IO_PENDING) 877 if (GetLastError () != ERROR_IO_PENDING)
876 { 878 {
@@ -887,9 +889,9 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle * h,
887 return GNUNET_SYSERR; 889 return GNUNET_SYSERR;
888 } 890 }
889 } 891 }
890 LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes\n", bytesRead); 892 LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes\n", bytes_read);
891 } 893 }
892 return bytesRead; 894 return bytes_read;
893#else 895#else
894 int flags; 896 int flags;
895 ssize_t ret; 897 ssize_t ret;
@@ -916,10 +918,12 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle * h,
916 * @param fn file name 918 * @param fn file name
917 * @param result the buffer to write the result to 919 * @param result the buffer to write the result to
918 * @param len the maximum number of bytes to read 920 * @param len the maximum number of bytes to read
919 * @return number of bytes read, GNUNET_SYSERR on failure 921 * @return number of bytes read, #GNUNET_SYSERR on failure
920 */ 922 */
921ssize_t 923ssize_t
922GNUNET_DISK_fn_read (const char *fn, void *result, size_t len) 924GNUNET_DISK_fn_read (const char *fn,
925 void *result,
926 size_t len)
923{ 927{
924 struct GNUNET_DISK_FileHandle *fh; 928 struct GNUNET_DISK_FileHandle *fh;
925 ssize_t ret; 929 ssize_t ret;
@@ -936,27 +940,28 @@ GNUNET_DISK_fn_read (const char *fn, void *result, size_t len)
936 940
937/** 941/**
938 * Write a buffer to a file. 942 * Write a buffer to a file.
943 *
939 * @param h handle to open file 944 * @param h handle to open file
940 * @param buffer the data to write 945 * @param buffer the data to write
941 * @param n number of bytes to write 946 * @param n number of bytes to write
942 * @return number of bytes written on success, GNUNET_SYSERR on error 947 * @return number of bytes written on success, #GNUNET_SYSERR on error
943 */ 948 */
944ssize_t 949ssize_t
945GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h, 950GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
946 const void *buffer, size_t n) 951 const void *buffer, size_t n)
947{ 952{
948 if (h == NULL) 953 if (NULL == h)
949 { 954 {
950 errno = EINVAL; 955 errno = EINVAL;
951 return GNUNET_SYSERR; 956 return GNUNET_SYSERR;
952 } 957 }
953 958
954#ifdef MINGW 959#ifdef MINGW
955 DWORD bytesWritten; 960 DWORD bytes_written;
956 961
957 if (h->type != GNUNET_DISK_HANLDE_TYPE_PIPE) 962 if (h->type != GNUNET_DISK_HANLDE_TYPE_PIPE)
958 { 963 {
959 if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL)) 964 if (!WriteFile (h->h, buffer, n, &bytes_written, NULL))
960 { 965 {
961 SetErrnoFromWinError (GetLastError ()); 966 SetErrnoFromWinError (GetLastError ());
962 return GNUNET_SYSERR; 967 return GNUNET_SYSERR;
@@ -965,7 +970,7 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
965 else 970 else
966 { 971 {
967 LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write %u bytes\n", n); 972 LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write %u bytes\n", n);
968 if (!WriteFile (h->h, buffer, n, &bytesWritten, h->oOverlapWrite)) 973 if (!WriteFile (h->h, buffer, n, &bytes_written, h->oOverlapWrite))
969 { 974 {
970 if (GetLastError () != ERROR_IO_PENDING) 975 if (GetLastError () != ERROR_IO_PENDING)
971 { 976 {
@@ -975,7 +980,7 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
975 return GNUNET_SYSERR; 980 return GNUNET_SYSERR;
976 } 981 }
977 LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n"); 982 LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n");
978 if (!GetOverlappedResult (h->h, h->oOverlapWrite, &bytesWritten, TRUE)) 983 if (!GetOverlappedResult (h->h, h->oOverlapWrite, &bytes_written, TRUE))
979 { 984 {
980 SetErrnoFromWinError (GetLastError ()); 985 SetErrnoFromWinError (GetLastError ());
981 LOG (GNUNET_ERROR_TYPE_DEBUG, 986 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -997,21 +1002,21 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
997 { 1002 {
998 LOG (GNUNET_ERROR_TYPE_DEBUG, 1003 LOG (GNUNET_ERROR_TYPE_DEBUG,
999 "Wrote %u bytes (ovr says %u), picking the greatest\n", 1004 "Wrote %u bytes (ovr says %u), picking the greatest\n",
1000 bytesWritten, ovr); 1005 bytes_written, ovr);
1001 } 1006 }
1002 } 1007 }
1003 if (bytesWritten == 0) 1008 if (bytes_written == 0)
1004 { 1009 {
1005 if (n > 0) 1010 if (n > 0)
1006 { 1011 {
1007 LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes, returning -1 with EAGAIN\n", bytesWritten); 1012 LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes, returning -1 with EAGAIN\n", bytes_written);
1008 errno = EAGAIN; 1013 errno = EAGAIN;
1009 return GNUNET_SYSERR; 1014 return GNUNET_SYSERR;
1010 } 1015 }
1011 } 1016 }
1012 LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytesWritten); 1017 LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytes_written);
1013 } 1018 }
1014 return bytesWritten; 1019 return bytes_written;
1015#else 1020#else
1016 return write (h->fd, buffer, n); 1021 return write (h->fd, buffer, n);
1017#endif 1022#endif
@@ -1020,37 +1025,39 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
1020 1025
1021/** 1026/**
1022 * Write a buffer to a file, blocking, if necessary. 1027 * Write a buffer to a file, blocking, if necessary.
1028 *
1023 * @param h handle to open file 1029 * @param h handle to open file
1024 * @param buffer the data to write 1030 * @param buffer the data to write
1025 * @param n number of bytes to write 1031 * @param n number of bytes to write
1026 * @return number of bytes written on success, GNUNET_SYSERR on error 1032 * @return number of bytes written on success, #GNUNET_SYSERR on error
1027 */ 1033 */
1028ssize_t 1034ssize_t
1029GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h, 1035GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h,
1030 const void *buffer, size_t n) 1036 const void *buffer,
1037 size_t n)
1031{ 1038{
1032 if (h == NULL) 1039 if (NULL == h)
1033 { 1040 {
1034 errno = EINVAL; 1041 errno = EINVAL;
1035 return GNUNET_SYSERR; 1042 return GNUNET_SYSERR;
1036 } 1043 }
1037 1044
1038#ifdef MINGW 1045#ifdef MINGW
1039 DWORD bytesWritten; 1046 DWORD bytes_written;
1040 /* We do a non-overlapped write, which is as blocking as it gets */ 1047 /* We do a non-overlapped write, which is as blocking as it gets */
1041 LOG (GNUNET_ERROR_TYPE_DEBUG, "Writing %u bytes\n", n); 1048 LOG (GNUNET_ERROR_TYPE_DEBUG, "Writing %u bytes\n", n);
1042 if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL)) 1049 if (!WriteFile (h->h, buffer, n, &bytes_written, NULL))
1043 { 1050 {
1044 SetErrnoFromWinError (GetLastError ()); 1051 SetErrnoFromWinError (GetLastError ());
1045 LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n", 1052 LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n",
1046 GetLastError ()); 1053 GetLastError ());
1047 return GNUNET_SYSERR; 1054 return GNUNET_SYSERR;
1048 } 1055 }
1049 if (bytesWritten == 0 && n > 0) 1056 if (bytes_written == 0 && n > 0)
1050 { 1057 {
1051 LOG (GNUNET_ERROR_TYPE_DEBUG, "Waiting for pipe to clean\n"); 1058 LOG (GNUNET_ERROR_TYPE_DEBUG, "Waiting for pipe to clean\n");
1052 WaitForSingleObject (h->h, INFINITE); 1059 WaitForSingleObject (h->h, INFINITE);
1053 if (!WriteFile (h->h, buffer, n, &bytesWritten, NULL)) 1060 if (!WriteFile (h->h, buffer, n, &bytes_written, NULL))
1054 { 1061 {
1055 SetErrnoFromWinError (GetLastError ()); 1062 SetErrnoFromWinError (GetLastError ());
1056 LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n", 1063 LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n",
@@ -1058,8 +1065,10 @@ GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h,
1058 return GNUNET_SYSERR; 1065 return GNUNET_SYSERR;
1059 } 1066 }
1060 } 1067 }
1061 LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytesWritten); 1068 LOG (GNUNET_ERROR_TYPE_DEBUG,
1062 return bytesWritten; 1069 "Wrote %u bytes\n",
1070 bytes_written);
1071 return bytes_written;
1063#else 1072#else
1064 int flags; 1073 int flags;
1065 ssize_t ret; 1074 ssize_t ret;
@@ -1084,7 +1093,7 @@ GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h,
1084 * @param buffer the data to write 1093 * @param buffer the data to write
1085 * @param n number of bytes to write 1094 * @param n number of bytes to write
1086 * @param mode file permissions 1095 * @param mode file permissions
1087 * @return number of bytes written on success, GNUNET_SYSERR on error 1096 * @return number of bytes written on success, #GNUNET_SYSERR on error
1088 */ 1097 */
1089ssize_t 1098ssize_t
1090GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n, 1099GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n,
@@ -1110,9 +1119,9 @@ GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n,
1110 * @param dir_name the name of the directory 1119 * @param dir_name the name of the directory
1111 * @param callback the method to call for each file, 1120 * @param callback the method to call for each file,
1112 * can be NULL, in that case, we only count 1121 * can be NULL, in that case, we only count
1113 * @param callback_cls closure for callback 1122 * @param callback_cls closure for @a callback
1114 * @return the number of files found, GNUNET_SYSERR on error or 1123 * @return the number of files found, #GNUNET_SYSERR on error or
1115 * ieration aborted by callback returning GNUNET_SYSERR 1124 * ieration aborted by callback returning #GNUNET_SYSERR
1116 */ 1125 */
1117int 1126int
1118GNUNET_DISK_directory_scan (const char *dir_name, 1127GNUNET_DISK_directory_scan (const char *dir_name,
@@ -1143,7 +1152,8 @@ GNUNET_DISK_directory_scan (const char *dir_name,
1143 } 1152 }
1144 if (!S_ISDIR (istat.st_mode)) 1153 if (!S_ISDIR (istat.st_mode))
1145 { 1154 {
1146 LOG (GNUNET_ERROR_TYPE_WARNING, _("Expected `%s' to be a directory!\n"), 1155 LOG (GNUNET_ERROR_TYPE_WARNING,
1156 _("Expected `%s' to be a directory!\n"),
1147 dir_name); 1157 dir_name);
1148 GNUNET_free (dname); 1158 GNUNET_free (dname);
1149 return GNUNET_SYSERR; 1159 return GNUNET_SYSERR;
@@ -1324,7 +1334,7 @@ GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio,
1324{ 1334{
1325 struct GNUNET_DISK_DirectoryIterator *di; 1335 struct GNUNET_DISK_DirectoryIterator *di;
1326 1336
1327 di = GNUNET_malloc (sizeof (struct GNUNET_DISK_DirectoryIterator)); 1337 di = GNUNET_new (struct GNUNET_DISK_DirectoryIterator);
1328 di->callback = callback; 1338 di->callback = callback;
1329 di->callback_cls = callback_cls; 1339 di->callback_cls = callback_cls;
1330 di->directory = OPENDIR (dir_name); 1340 di->directory = OPENDIR (dir_name);
@@ -1748,7 +1758,7 @@ GNUNET_DISK_file_open (const char *fn,
1748 } 1758 }
1749#endif 1759#endif
1750 1760
1751 ret = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle)); 1761 ret = GNUNET_new (struct GNUNET_DISK_FileHandle);
1752#ifdef MINGW 1762#ifdef MINGW
1753 ret->h = h; 1763 ret->h = h;
1754 ret->type = GNUNET_DISK_HANLDE_TYPE_FILE; 1764 ret->type = GNUNET_DISK_HANLDE_TYPE_FILE;
@@ -1843,7 +1853,7 @@ GNUNET_DISK_get_handle_from_w32_handle (HANDLE osfh)
1843 return NULL; 1853 return NULL;
1844 } 1854 }
1845 1855
1846 fh = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle)); 1856 fh = GNUNET_new (struct GNUNET_DISK_FileHandle);
1847 1857
1848 fh->h = osfh; 1858 fh->h = osfh;
1849 fh->type = ftype; 1859 fh->type = ftype;
@@ -1883,7 +1893,7 @@ GNUNET_DISK_get_handle_from_int_fd (int fno)
1883 return NULL; /* invalid FD */ 1893 return NULL; /* invalid FD */
1884 1894
1885#ifndef WINDOWS 1895#ifndef WINDOWS
1886 fh = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle)); 1896 fh = GNUNET_new (struct GNUNET_DISK_FileHandle);
1887 1897
1888 fh->fd = fno; 1898 fh->fd = fno;
1889#else 1899#else
@@ -2064,7 +2074,7 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
2064 return NULL; 2074 return NULL;
2065 } 2075 }
2066 2076
2067 *m = GNUNET_malloc (sizeof (struct GNUNET_DISK_MapHandle)); 2077 *m = GNUNET_new (struct GNUNET_DISK_MapHandle);
2068 (*m)->h = CreateFileMapping (h->h, NULL, protect, 0, 0, NULL); 2078 (*m)->h = CreateFileMapping (h->h, NULL, protect, 0, 0, NULL);
2069 if ((*m)->h == INVALID_HANDLE_VALUE) 2079 if ((*m)->h == INVALID_HANDLE_VALUE)
2070 { 2080 {
@@ -2090,7 +2100,7 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
2090 prot = PROT_READ; 2100 prot = PROT_READ;
2091 if (access & GNUNET_DISK_MAP_TYPE_WRITE) 2101 if (access & GNUNET_DISK_MAP_TYPE_WRITE)
2092 prot |= PROT_WRITE; 2102 prot |= PROT_WRITE;
2093 *m = GNUNET_malloc (sizeof (struct GNUNET_DISK_MapHandle)); 2103 *m = GNUNET_new (struct GNUNET_DISK_MapHandle);
2094 (*m)->addr = mmap (NULL, len, prot, MAP_SHARED, h->fd, 0); 2104 (*m)->addr = mmap (NULL, len, prot, MAP_SHARED, h->fd, 0);
2095 GNUNET_assert (NULL != (*m)->addr); 2105 GNUNET_assert (NULL != (*m)->addr);
2096 if (MAP_FAILED == (*m)->addr) 2106 if (MAP_FAILED == (*m)->addr)
@@ -2322,9 +2332,9 @@ GNUNET_DISK_pipe (int blocking_read, int blocking_write, int inherit_read, int i
2322 HANDLE tmp_handle; 2332 HANDLE tmp_handle;
2323 int save_errno; 2333 int save_errno;
2324 2334
2325 p = GNUNET_malloc (sizeof (struct GNUNET_DISK_PipeHandle)); 2335 p = GNUNET_new (struct GNUNET_DISK_PipeHandle);
2326 p->fd[0] = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle)); 2336 p->fd[0] = GNUNET_new (struct GNUNET_DISK_FileHandle);
2327 p->fd[1] = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle)); 2337 p->fd[1] = GNUNET_new (struct GNUNET_DISK_FileHandle);
2328 2338
2329 /* All pipes are overlapped. If you want them to block - just 2339 /* All pipes are overlapped. If you want them to block - just
2330 * call WriteFile() and ReadFile() with NULL overlapped pointer. 2340 * call WriteFile() and ReadFile() with NULL overlapped pointer.
@@ -2417,7 +2427,7 @@ GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2])
2417{ 2427{
2418 struct GNUNET_DISK_PipeHandle *p; 2428 struct GNUNET_DISK_PipeHandle *p;
2419 2429
2420 p = GNUNET_malloc (sizeof (struct GNUNET_DISK_PipeHandle)); 2430 p = GNUNET_new (struct GNUNET_DISK_PipeHandle);
2421 2431
2422#ifndef MINGW 2432#ifndef MINGW
2423 int ret; 2433 int ret;
@@ -2427,7 +2437,7 @@ GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2])
2427 ret = 0; 2437 ret = 0;
2428 if (fd[0] >= 0) 2438 if (fd[0] >= 0)
2429 { 2439 {
2430 p->fd[0] = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle)); 2440 p->fd[0] = GNUNET_new (struct GNUNET_DISK_FileHandle);
2431 p->fd[0]->fd = fd[0]; 2441 p->fd[0]->fd = fd[0];
2432 if (!blocking_read) 2442 if (!blocking_read)
2433 { 2443 {
@@ -2450,7 +2460,7 @@ GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2])
2450 2460
2451 if (fd[1] >= 0) 2461 if (fd[1] >= 0)
2452 { 2462 {
2453 p->fd[1] = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle)); 2463 p->fd[1] = GNUNET_new (struct GNUNET_DISK_FileHandle);
2454 p->fd[1]->fd = fd[1]; 2464 p->fd[1]->fd = fd[1];
2455 if (!blocking_write) 2465 if (!blocking_write)
2456 { 2466 {
@@ -2487,7 +2497,7 @@ GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2])
2487#else 2497#else
2488 if (fd[0] >= 0) 2498 if (fd[0] >= 0)
2489 { 2499 {
2490 p->fd[0] = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle)); 2500 p->fd[0] = GNUNET_new (struct GNUNET_DISK_FileHandle);
2491 p->fd[0]->h = (HANDLE) _get_osfhandle (fd[0]); 2501 p->fd[0]->h = (HANDLE) _get_osfhandle (fd[0]);
2492 if (p->fd[0]->h != INVALID_HANDLE_VALUE) 2502 if (p->fd[0]->h != INVALID_HANDLE_VALUE)
2493 { 2503 {
@@ -2505,7 +2515,7 @@ GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2])
2505 } 2515 }
2506 if (fd[1] >= 0) 2516 if (fd[1] >= 0)
2507 { 2517 {
2508 p->fd[1] = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle)); 2518 p->fd[1] = GNUNET_new (struct GNUNET_DISK_FileHandle);
2509 p->fd[1]->h = (HANDLE) _get_osfhandle (fd[1]); 2519 p->fd[1]->h = (HANDLE) _get_osfhandle (fd[1]);
2510 if (p->fd[1]->h != INVALID_HANDLE_VALUE) 2520 if (p->fd[1]->h != INVALID_HANDLE_VALUE)
2511 { 2521 {