diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-10-08 19:00:19 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-10-08 19:00:19 +0000 |
commit | fe947a9704bed14c2fc74b2f2069596fe884cbad (patch) | |
tree | 644efdaa37d692b09f8e279bfe5e8b2ebe81448b /src/util | |
parent | a8b0ab037820f6a9f405be3855ce8d3ebbd4399b (diff) | |
download | gnunet-fe947a9704bed14c2fc74b2f2069596fe884cbad.tar.gz gnunet-fe947a9704bed14c2fc74b2f2069596fe884cbad.zip |
better comments
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/common_logging.c | 6 | ||||
-rw-r--r-- | src/util/container_bloomfilter.c | 6 | ||||
-rw-r--r-- | src/util/container_meta_data.c | 27 | ||||
-rw-r--r-- | src/util/crypto_hash.c | 2 | ||||
-rw-r--r-- | src/util/crypto_random.c | 21 | ||||
-rw-r--r-- | src/util/crypto_rsa.c | 24 | ||||
-rw-r--r-- | src/util/getopt.c | 2 | ||||
-rw-r--r-- | src/util/gnunet-service-resolver.c | 60 | ||||
-rw-r--r-- | src/util/os_network.c | 12 | ||||
-rw-r--r-- | src/util/os_priority.c | 14 | ||||
-rw-r--r-- | src/util/pseudonym.c | 2 | ||||
-rw-r--r-- | src/util/resolver.h | 2 | ||||
-rw-r--r-- | src/util/resolver_api.c | 2 | ||||
-rw-r--r-- | src/util/strings.c | 24 |
14 files changed, 135 insertions, 69 deletions
diff --git a/src/util/common_logging.c b/src/util/common_logging.c index 0ee4edbe2..96cfcd85c 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c | |||
@@ -438,14 +438,14 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind) | |||
438 | * This is one of the very few calls in the entire API that is | 438 | * This is one of the very few calls in the entire API that is |
439 | * NOT reentrant! | 439 | * NOT reentrant! |
440 | * | 440 | * |
441 | * @param pid the peer identity | 441 | * @param hc the hash code |
442 | * @return string form; will be overwritten by next call to GNUNET_h2s. | 442 | * @return string form; will be overwritten by next call to GNUNET_h2s. |
443 | */ | 443 | */ |
444 | const char * | 444 | const char * |
445 | GNUNET_h2s (const GNUNET_HashCode *pid) | 445 | GNUNET_h2s (const GNUNET_HashCode *hc) |
446 | { | 446 | { |
447 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; | 447 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; |
448 | GNUNET_CRYPTO_hash_to_enc (pid, &ret); | 448 | GNUNET_CRYPTO_hash_to_enc (hc, &ret); |
449 | ret.encoding[8] = '\0'; | 449 | ret.encoding[8] = '\0'; |
450 | return (const char *) ret.encoding; | 450 | return (const char *) ret.encoding; |
451 | } | 451 | } |
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c index 5e69fe8ab..612bad92f 100644 --- a/src/util/container_bloomfilter.c +++ b/src/util/container_bloomfilter.c | |||
@@ -666,14 +666,14 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
666 | * | 666 | * |
667 | * @param bf the filter | 667 | * @param bf the filter |
668 | * @param iterator an iterator over all elements stored in the BF | 668 | * @param iterator an iterator over all elements stored in the BF |
669 | * @param iterator_arg argument to the iterator function | 669 | * @param iterator_cls argument to the iterator function |
670 | * @param size the new size for the filter | 670 | * @param size the new size for the filter |
671 | * @param k the new number of GNUNET_CRYPTO_hash-function to apply per element | 671 | * @param k the new number of GNUNET_CRYPTO_hash-function to apply per element |
672 | */ | 672 | */ |
673 | void | 673 | void |
674 | GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, | 674 | GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, |
675 | GNUNET_HashCodeIterator iterator, | 675 | GNUNET_HashCodeIterator iterator, |
676 | void *iterator_arg, | 676 | void *iterator_cls, |
677 | size_t size, | 677 | size_t size, |
678 | unsigned int k) | 678 | unsigned int k) |
679 | { | 679 | { |
@@ -691,7 +691,7 @@ GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
691 | memset (bf->bitArray, 0, bf->bitArraySize); | 691 | memset (bf->bitArray, 0, bf->bitArraySize); |
692 | if (bf->filename != NULL) | 692 | if (bf->filename != NULL) |
693 | makeEmptyFile (bf->fh, bf->bitArraySize * 4); | 693 | makeEmptyFile (bf->fh, bf->bitArraySize * 4); |
694 | while (GNUNET_YES == iterator (iterator_arg, &hc)) | 694 | while (GNUNET_YES == iterator (iterator_cls, &hc)) |
695 | GNUNET_CONTAINER_bloomfilter_add (bf, &hc); | 695 | GNUNET_CONTAINER_bloomfilter_add (bf, &hc); |
696 | } | 696 | } |
697 | 697 | ||
diff --git a/src/util/container_meta_data.c b/src/util/container_meta_data.c index bbe6dad3b..5ae3b15cf 100644 --- a/src/util/container_meta_data.c +++ b/src/util/container_meta_data.c | |||
@@ -139,6 +139,11 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, | |||
139 | 139 | ||
140 | /** | 140 | /** |
141 | * Remove an item. | 141 | * Remove an item. |
142 | * | ||
143 | * @param md metadata to manipulate | ||
144 | * @param type type of the item to remove | ||
145 | * @param data specific value to remove, NULL to remove all | ||
146 | * entries of the given type | ||
142 | * @return GNUNET_OK on success, GNUNET_SYSERR if the item does not exist in md | 147 | * @return GNUNET_OK on success, GNUNET_SYSERR if the item does not exist in md |
143 | */ | 148 | */ |
144 | int | 149 | int |
@@ -170,13 +175,16 @@ GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md, | |||
170 | /** | 175 | /** |
171 | * Iterate over MD entries, excluding thumbnails. | 176 | * Iterate over MD entries, excluding thumbnails. |
172 | * | 177 | * |
178 | * @param md metadata to inspect | ||
179 | * @param iter function to call on each entry | ||
180 | * @param iter_cls closure for iterator | ||
173 | * @return number of entries | 181 | * @return number of entries |
174 | */ | 182 | */ |
175 | int | 183 | int |
176 | GNUNET_CONTAINER_meta_data_get_contents (const struct | 184 | GNUNET_CONTAINER_meta_data_get_contents (const struct |
177 | GNUNET_CONTAINER_MetaData *md, | 185 | GNUNET_CONTAINER_MetaData *md, |
178 | GNUNET_CONTAINER_MetaDataProcessor | 186 | GNUNET_CONTAINER_MetaDataProcessor |
179 | iterator, void *closure) | 187 | iter, void *iter_cls) |
180 | { | 188 | { |
181 | uint32_t i; | 189 | uint32_t i; |
182 | uint32_t sub; | 190 | uint32_t sub; |
@@ -187,9 +195,9 @@ GNUNET_CONTAINER_meta_data_get_contents (const struct | |||
187 | if (!EXTRACTOR_isBinaryType (md->items[i].type)) | 195 | if (!EXTRACTOR_isBinaryType (md->items[i].type)) |
188 | { | 196 | { |
189 | if ((iterator != NULL) && | 197 | if ((iterator != NULL) && |
190 | (GNUNET_OK != iterator (closure, | 198 | (GNUNET_OK != iter (iter_cls, |
191 | md->items[i].type, | 199 | md->items[i].type, |
192 | md->items[i].data))) | 200 | md->items[i].data))) |
193 | return GNUNET_SYSERR; | 201 | return GNUNET_SYSERR; |
194 | } | 202 | } |
195 | else | 203 | else |
@@ -280,6 +288,9 @@ GNUNET_CONTAINER_meta_data_get_thumbnail (const struct | |||
280 | 288 | ||
281 | /** | 289 | /** |
282 | * Duplicate struct GNUNET_CONTAINER_MetaData. | 290 | * Duplicate struct GNUNET_CONTAINER_MetaData. |
291 | * | ||
292 | * @param md what to duplicate | ||
293 | * @return duplicate meta-data container | ||
283 | */ | 294 | */ |
284 | struct GNUNET_CONTAINER_MetaData * | 295 | struct GNUNET_CONTAINER_MetaData * |
285 | GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData | 296 | GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData |
@@ -439,7 +450,7 @@ struct MetaDataHeader | |||
439 | * @param md metadata to serialize | 450 | * @param md metadata to serialize |
440 | * @param target where to write the serialized metadata | 451 | * @param target where to write the serialized metadata |
441 | * @param max maximum number of bytes available in target | 452 | * @param max maximum number of bytes available in target |
442 | * @param part is it ok to just write SOME of the | 453 | * @param opt is it ok to just write SOME of the |
443 | * meta-data to match the size constraint, | 454 | * meta-data to match the size constraint, |
444 | * possibly discarding some data? | 455 | * possibly discarding some data? |
445 | * @return number of bytes written on success, | 456 | * @return number of bytes written on success, |
@@ -451,7 +462,7 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData | |||
451 | *md, char *target, size_t max, | 462 | *md, char *target, size_t max, |
452 | enum | 463 | enum |
453 | GNUNET_CONTAINER_MetaDataSerializationOptions | 464 | GNUNET_CONTAINER_MetaDataSerializationOptions |
454 | part) | 465 | opt) |
455 | { | 466 | { |
456 | struct MetaDataHeader *hdr; | 467 | struct MetaDataHeader *hdr; |
457 | size_t size; | 468 | size_t size; |
@@ -488,7 +499,7 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData | |||
488 | } | 499 | } |
489 | 500 | ||
490 | hdr->size = htonl (size); | 501 | hdr->size = htonl (size); |
491 | if ((part & GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS) == 0) | 502 | if ((opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS) == 0) |
492 | { | 503 | { |
493 | pos = tryCompression ((char *) &hdr[1], | 504 | pos = tryCompression ((char *) &hdr[1], |
494 | size - sizeof (struct MetaDataHeader)); | 505 | size - sizeof (struct MetaDataHeader)); |
@@ -507,7 +518,7 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData | |||
507 | GNUNET_free (hdr); | 518 | GNUNET_free (hdr); |
508 | hdr = NULL; | 519 | hdr = NULL; |
509 | 520 | ||
510 | if ((part & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART) == 0) | 521 | if ((opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART) == 0) |
511 | { | 522 | { |
512 | return GNUNET_SYSERR; /* does not fit! */ | 523 | return GNUNET_SYSERR; /* does not fit! */ |
513 | } | 524 | } |
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index c3fb9a84c..60e0ec5a2 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c | |||
@@ -562,7 +562,7 @@ getValue__ (unsigned char a) | |||
562 | * small number of characters. The GNUnet encoding uses 102 | 562 | * small number of characters. The GNUnet encoding uses 102 |
563 | * characters plus a null terminator. | 563 | * characters plus a null terminator. |
564 | * | 564 | * |
565 | * @param block the GNUNET_CRYPTO_hash code | 565 | * @param block the hash code |
566 | * @param result where to store the encoding (struct GNUNET_CRYPTO_HashAsciiEncoded can be | 566 | * @param result where to store the encoding (struct GNUNET_CRYPTO_HashAsciiEncoded can be |
567 | * safely cast to char*, a '\\0' termination is set). | 567 | * safely cast to char*, a '\\0' termination is set). |
568 | */ | 568 | */ |
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c index b56523a46..50af9f251 100644 --- a/src/util/crypto_random.c +++ b/src/util/crypto_random.c | |||
@@ -30,6 +30,10 @@ | |||
30 | #include <gcrypt.h> | 30 | #include <gcrypt.h> |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Produce a random value. | ||
34 | * | ||
35 | * @param mode desired quality of the random number | ||
36 | * @param i the upper limit (exclusive) for the random number | ||
33 | * @return a random value in the interval [0,i[. | 37 | * @return a random value in the interval [0,i[. |
34 | */ | 38 | */ |
35 | uint32_t | 39 | uint32_t |
@@ -97,26 +101,31 @@ GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n) | |||
97 | 101 | ||
98 | /** | 102 | /** |
99 | * Random on unsigned 64-bit values. | 103 | * Random on unsigned 64-bit values. |
104 | * | ||
105 | * | ||
106 | * @param mode desired quality of the random number | ||
107 | * @param max value returned will be in range [0,max) (exclusive) | ||
108 | * @return random 64-bit number | ||
100 | */ | 109 | */ |
101 | uint64_t | 110 | uint64_t |
102 | GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, | 111 | GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, |
103 | uint64_t u) | 112 | uint64_t max) |
104 | { | 113 | { |
105 | uint64_t ret; | 114 | uint64_t ret; |
106 | 115 | ||
107 | GNUNET_assert (u > 0); | 116 | GNUNET_assert (max > 0); |
108 | if (mode == GNUNET_CRYPTO_QUALITY_STRONG) | 117 | if (mode == GNUNET_CRYPTO_QUALITY_STRONG) |
109 | { | 118 | { |
110 | gcry_randomize ((unsigned char *) &ret, | 119 | gcry_randomize ((unsigned char *) &ret, |
111 | sizeof (uint64_t), | 120 | sizeof (uint64_t), |
112 | GCRY_STRONG_RANDOM); | 121 | GCRY_STRONG_RANDOM); |
113 | return ret % u; | 122 | return ret % max; |
114 | } | 123 | } |
115 | else | 124 | else |
116 | { | 125 | { |
117 | ret = u * ((double) RANDOM () / RAND_MAX); | 126 | ret = max * ((double) RANDOM () / RAND_MAX); |
118 | if (ret >= u) | 127 | if (ret >= max) |
119 | ret = u - 1; | 128 | ret = max - 1; |
120 | return ret; | 129 | return ret; |
121 | } | 130 | } |
122 | } | 131 | } |
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index 7bffa71ee..9da95a56e 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c | |||
@@ -186,15 +186,15 @@ key_from_sexp (gcry_mpi_t * array, | |||
186 | 186 | ||
187 | /** | 187 | /** |
188 | * Extract the public key of the host. | 188 | * Extract the public key of the host. |
189 | * @param hostkey the hostkey to extract into the result. | 189 | * @param priv the private key |
190 | * @param result where to write the result. | 190 | * @param pub where to write the public key |
191 | */ | 191 | */ |
192 | void | 192 | void |
193 | GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey | 193 | GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey |
194 | *hostkey, | 194 | *priv, |
195 | struct | 195 | struct |
196 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded | 196 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded |
197 | *result) | 197 | *pub) |
198 | { | 198 | { |
199 | gcry_mpi_t skey[2]; | 199 | gcry_mpi_t skey[2]; |
200 | size_t size; | 200 | size_t size; |
@@ -750,15 +750,15 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block, | |||
750 | /** | 750 | /** |
751 | * Decrypt a given block with the hostkey. | 751 | * Decrypt a given block with the hostkey. |
752 | * | 752 | * |
753 | * @param hostkey the hostkey with which to decrypt this block | 753 | * @param key the key with which to decrypt this block |
754 | * @param block the data to decrypt, encoded as returned by encrypt | 754 | * @param block the data to decrypt, encoded as returned by encrypt |
755 | * @param result pointer to a location where the result can be stored | 755 | * @param result pointer to a location where the result can be stored |
756 | * @param max the maximum number of bits to store for the result, if | 756 | * @param max the maximum number of bits to store for the result, if |
757 | * the decrypted block is bigger, an error is returned | 757 | * the decrypted block is bigger, an error is returned |
758 | * @returns the size of the decrypted block, -1 on error | 758 | * @return the size of the decrypted block, -1 on error |
759 | */ | 759 | */ |
760 | ssize_t | 760 | ssize_t |
761 | GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey, | 761 | GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *key, |
762 | const struct GNUNET_CRYPTO_RsaEncryptedData *block, | 762 | const struct GNUNET_CRYPTO_RsaEncryptedData *block, |
763 | void *result, | 763 | void *result, |
764 | size_t max) | 764 | size_t max) |
@@ -772,7 +772,7 @@ GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey, | |||
772 | unsigned char *tmp; | 772 | unsigned char *tmp; |
773 | 773 | ||
774 | #if EXTRA_CHECKS | 774 | #if EXTRA_CHECKS |
775 | GNUNET_assert (0 == gcry_pk_testkey (hostkey->sexp)); | 775 | GNUNET_assert (0 == gcry_pk_testkey (key->sexp)); |
776 | #endif | 776 | #endif |
777 | size = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData); | 777 | size = sizeof (struct GNUNET_CRYPTO_RsaEncryptedData); |
778 | GNUNET_assert (0 == gcry_mpi_scan (&val, | 778 | GNUNET_assert (0 == gcry_mpi_scan (&val, |
@@ -782,7 +782,7 @@ GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey, | |||
782 | gcry_sexp_build (&data, &erroff, | 782 | gcry_sexp_build (&data, &erroff, |
783 | "(enc-val(flags)(rsa(a %m)))", val)); | 783 | "(enc-val(flags)(rsa(a %m)))", val)); |
784 | gcry_mpi_release (val); | 784 | gcry_mpi_release (val); |
785 | GNUNET_assert (0 == gcry_pk_decrypt (&resultsexp, data, hostkey->sexp)); | 785 | GNUNET_assert (0 == gcry_pk_decrypt (&resultsexp, data, key->sexp)); |
786 | gcry_sexp_release (data); | 786 | gcry_sexp_release (data); |
787 | /* resultsexp has format "(value %m)" */ | 787 | /* resultsexp has format "(value %m)" */ |
788 | GNUNET_assert (NULL != | 788 | GNUNET_assert (NULL != |
@@ -805,13 +805,13 @@ GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey, | |||
805 | /** | 805 | /** |
806 | * Sign a given block. | 806 | * Sign a given block. |
807 | * | 807 | * |
808 | * @param hostkey private key to use for the signing | 808 | * @param key private key to use for the signing |
809 | * @param purpose what to sign (size, purpose) | 809 | * @param purpose what to sign (size, purpose) |
810 | * @param sig where to write the signature | 810 | * @param sig where to write the signature |
811 | * @return GNUNET_SYSERR on error, GNUNET_OK on success | 811 | * @return GNUNET_SYSERR on error, GNUNET_OK on success |
812 | */ | 812 | */ |
813 | int | 813 | int |
814 | GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey, | 814 | GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key, |
815 | const struct GNUNET_CRYPTO_RsaSignaturePurpose | 815 | const struct GNUNET_CRYPTO_RsaSignaturePurpose |
816 | *purpose, struct GNUNET_CRYPTO_RsaSignature *sig) | 816 | *purpose, struct GNUNET_CRYPTO_RsaSignature *sig) |
817 | { | 817 | { |
@@ -835,7 +835,7 @@ GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey, | |||
835 | - 1], &hc, sizeof (GNUNET_HashCode)); | 835 | - 1], &hc, sizeof (GNUNET_HashCode)); |
836 | GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0)); | 836 | GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0)); |
837 | GNUNET_free (buff); | 837 | GNUNET_free (buff); |
838 | GNUNET_assert (0 == gcry_pk_sign (&result, data, hostkey->sexp)); | 838 | GNUNET_assert (0 == gcry_pk_sign (&result, data, key->sexp)); |
839 | gcry_sexp_release (data); | 839 | gcry_sexp_release (data); |
840 | GNUNET_assert (0 == key_from_sexp (&rval, result, "rsa", "s")); | 840 | GNUNET_assert (0 == key_from_sexp (&rval, result, "rsa", "s")); |
841 | gcry_sexp_release (result); | 841 | gcry_sexp_release (result); |
diff --git a/src/util/getopt.c b/src/util/getopt.c index e37390a3a..82d0baebd 100644 --- a/src/util/getopt.c +++ b/src/util/getopt.c | |||
@@ -987,7 +987,7 @@ GNgetopt_long (int argc, | |||
987 | /** | 987 | /** |
988 | * Parse the command line. | 988 | * Parse the command line. |
989 | * | 989 | * |
990 | * @param binaryOptions name of this binary / application | 990 | * @param binaryOptions Name of application with option summary |
991 | * @param allOptions defined options and handlers | 991 | * @param allOptions defined options and handlers |
992 | * @param argc number of arguments | 992 | * @param argc number of arguments |
993 | * @param argv actual arguments | 993 | * @param argv actual arguments |
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c index 304f11b7b..1dce5cedc 100644 --- a/src/util/gnunet-service-resolver.c +++ b/src/util/gnunet-service-resolver.c | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file resolver/gnunet-service-resolver.c | 22 | * @file util/gnunet-service-resolver.c |
23 | * @brief code to do DNS resolution | 23 | * @brief code to do DNS resolution |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
@@ -35,24 +35,55 @@ | |||
35 | #include "gnunet_time_lib.h" | 35 | #include "gnunet_time_lib.h" |
36 | #include "resolver.h" | 36 | #include "resolver.h" |
37 | 37 | ||
38 | 38 | /** | |
39 | * A cached DNS lookup result. | ||
40 | */ | ||
39 | struct IPCache | 41 | struct IPCache |
40 | { | 42 | { |
43 | /** | ||
44 | * This is a linked list. | ||
45 | */ | ||
41 | struct IPCache *next; | 46 | struct IPCache *next; |
47 | |||
48 | /** | ||
49 | * Hostname in human-readable form. | ||
50 | */ | ||
42 | char *addr; | 51 | char *addr; |
52 | |||
53 | /** | ||
54 | * Hostname in binary format. | ||
55 | */ | ||
43 | struct sockaddr *sa; | 56 | struct sockaddr *sa; |
57 | |||
58 | /** | ||
59 | * Last time this entry was updated. | ||
60 | */ | ||
44 | struct GNUNET_TIME_Absolute last_refresh; | 61 | struct GNUNET_TIME_Absolute last_refresh; |
62 | |||
63 | /** | ||
64 | * Last time this entry was requested. | ||
65 | */ | ||
45 | struct GNUNET_TIME_Absolute last_request; | 66 | struct GNUNET_TIME_Absolute last_request; |
46 | unsigned int salen; | 67 | |
68 | /** | ||
69 | * Number of bytes in sa. | ||
70 | */ | ||
71 | socklen_t salen; | ||
47 | }; | 72 | }; |
48 | 73 | ||
49 | 74 | ||
75 | /** | ||
76 | * Start of the linked list of cached DNS lookup results. | ||
77 | */ | ||
50 | static struct IPCache *head; | 78 | static struct IPCache *head; |
51 | 79 | ||
52 | 80 | ||
53 | |||
54 | |||
55 | #if HAVE_GETNAMEINFO | 81 | #if HAVE_GETNAMEINFO |
82 | /** | ||
83 | * Resolve the given request using getnameinfo | ||
84 | * | ||
85 | * @param cache the request to resolve (and where to store the result) | ||
86 | */ | ||
56 | static void | 87 | static void |
57 | getnameinfo_resolve (struct IPCache *cache) | 88 | getnameinfo_resolve (struct IPCache *cache) |
58 | { | 89 | { |
@@ -69,6 +100,11 @@ getnameinfo_resolve (struct IPCache *cache) | |||
69 | 100 | ||
70 | 101 | ||
71 | #if HAVE_GETHOSTBYADDR | 102 | #if HAVE_GETHOSTBYADDR |
103 | /** | ||
104 | * Resolve the given request using gethostbyaddr | ||
105 | * | ||
106 | * @param cache the request to resolve (and where to store the result) | ||
107 | */ | ||
72 | static void | 108 | static void |
73 | gethostbyaddr_resolve (struct IPCache *cache) | 109 | gethostbyaddr_resolve (struct IPCache *cache) |
74 | { | 110 | { |
@@ -92,7 +128,11 @@ gethostbyaddr_resolve (struct IPCache *cache) | |||
92 | } | 128 | } |
93 | #endif | 129 | #endif |
94 | 130 | ||
95 | 131 | /** | |
132 | * Resolve the given request using the available methods. | ||
133 | * | ||
134 | * @param cache the request to resolve (and where to store the result) | ||
135 | */ | ||
96 | static void | 136 | static void |
97 | cache_resolve (struct IPCache *cache) | 137 | cache_resolve (struct IPCache *cache) |
98 | { | 138 | { |
@@ -114,11 +154,13 @@ cache_resolve (struct IPCache *cache) | |||
114 | * may not immediately result in the FQN (but instead in a | 154 | * may not immediately result in the FQN (but instead in a |
115 | * human-readable IP address). | 155 | * human-readable IP address). |
116 | * | 156 | * |
157 | * @param client handle to the client making the request (for sending the reply) | ||
117 | * @param sa should be of type "struct sockaddr*" | 158 | * @param sa should be of type "struct sockaddr*" |
159 | * @param salen number of bytes in sa | ||
118 | */ | 160 | */ |
119 | static void | 161 | static void |
120 | get_ip_as_string (struct GNUNET_SERVER_Client *client, | 162 | get_ip_as_string (struct GNUNET_SERVER_Client *client, |
121 | const struct sockaddr *sav, socklen_t salen) | 163 | const struct sockaddr *sa, socklen_t salen) |
122 | { | 164 | { |
123 | struct IPCache *cache; | 165 | struct IPCache *cache; |
124 | struct IPCache *prev; | 166 | struct IPCache *prev; |
@@ -134,7 +176,7 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client, | |||
134 | cache = head; | 176 | cache = head; |
135 | prev = NULL; | 177 | prev = NULL; |
136 | while ((cache != NULL) && | 178 | while ((cache != NULL) && |
137 | ((cache->salen != salen) || (0 != memcmp (cache->sa, sav, salen)))) | 179 | ((cache->salen != salen) || (0 != memcmp (cache->sa, sa, salen)))) |
138 | { | 180 | { |
139 | if (GNUNET_TIME_absolute_get_duration (cache->last_request).value < | 181 | if (GNUNET_TIME_absolute_get_duration (cache->last_request).value < |
140 | 60 * 60 * 1000) | 182 | 60 * 60 * 1000) |
@@ -178,7 +220,7 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client, | |||
178 | cache->next = head; | 220 | cache->next = head; |
179 | cache->salen = salen; | 221 | cache->salen = salen; |
180 | cache->sa = GNUNET_malloc (salen); | 222 | cache->sa = GNUNET_malloc (salen); |
181 | memcpy (cache->sa, sav, salen); | 223 | memcpy (cache->sa, sa, salen); |
182 | cache->last_request = GNUNET_TIME_absolute_get (); | 224 | cache->last_request = GNUNET_TIME_absolute_get (); |
183 | cache->last_refresh = GNUNET_TIME_absolute_get (); | 225 | cache->last_refresh = GNUNET_TIME_absolute_get (); |
184 | cache->addr = NULL; | 226 | cache->addr = NULL; |
diff --git a/src/util/os_network.c b/src/util/os_network.c index c78dc71c5..d18e5eb76 100644 --- a/src/util/os_network.c +++ b/src/util/os_network.c | |||
@@ -35,11 +35,11 @@ | |||
35 | * @brief Enumerate all network interfaces | 35 | * @brief Enumerate all network interfaces |
36 | * | 36 | * |
37 | * @param proc the callback function | 37 | * @param proc the callback function |
38 | * @param cls closure for proc | 38 | * @param proc_cls closure for proc |
39 | */ | 39 | */ |
40 | void | 40 | void |
41 | GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, | 41 | GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, |
42 | void *cls) | 42 | void *proc_cls) |
43 | { | 43 | { |
44 | #ifdef MINGW | 44 | #ifdef MINGW |
45 | PMIB_IFTABLE pTable; | 45 | PMIB_IFTABLE pTable; |
@@ -148,7 +148,7 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, | |||
148 | free (pszIfName); | 148 | free (pszIfName); |
149 | 149 | ||
150 | if (GNUNET_OK != | 150 | if (GNUNET_OK != |
151 | proc (cls, | 151 | proc (proc_cls, |
152 | szEntry, | 152 | szEntry, |
153 | pAddrTable->table[dwIfIdx].dwIndex == dwExternalNIC, | 153 | pAddrTable->table[dwIfIdx].dwIndex == dwExternalNIC, |
154 | NULL /* FIXME: pass actual IP address! */ , | 154 | NULL /* FIXME: pass actual IP address! */ , |
@@ -182,7 +182,7 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, | |||
182 | alen = sizeof (struct sockaddr_in); | 182 | alen = sizeof (struct sockaddr_in); |
183 | else | 183 | else |
184 | alen = sizeof (struct sockaddr_in6); | 184 | alen = sizeof (struct sockaddr_in6); |
185 | if (GNUNET_OK != proc (cls, | 185 | if (GNUNET_OK != proc (proc_cls, |
186 | ifa_ptr->ifa_name, | 186 | ifa_ptr->ifa_name, |
187 | 0 == strcmp (ifa_ptr->ifa_name, | 187 | 0 == strcmp (ifa_ptr->ifa_name, |
188 | GNUNET_DEFAULT_INTERFACE), | 188 | GNUNET_DEFAULT_INTERFACE), |
@@ -255,7 +255,7 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, | |||
255 | a4.sin_family = AF_INET; | 255 | a4.sin_family = AF_INET; |
256 | a4.sin_addr = v4; | 256 | a4.sin_addr = v4; |
257 | if (GNUNET_OK != | 257 | if (GNUNET_OK != |
258 | proc (cls, | 258 | proc (proc_cls, |
259 | ifc, | 259 | ifc, |
260 | 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), | 260 | 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), |
261 | (const struct sockaddr *) &a4, sizeof (a4))) | 261 | (const struct sockaddr *) &a4, sizeof (a4))) |
@@ -270,7 +270,7 @@ GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, | |||
270 | a6.sin6_addr = v6; | 270 | a6.sin6_addr = v6; |
271 | fprintf (stderr, "procing %s\n", addrstr); | 271 | fprintf (stderr, "procing %s\n", addrstr); |
272 | if (GNUNET_OK != | 272 | if (GNUNET_OK != |
273 | proc (cls, | 273 | proc (proc_cls, |
274 | ifc, | 274 | ifc, |
275 | 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), | 275 | 0 == strcmp (ifc, GNUNET_DEFAULT_INTERFACE), |
276 | (const struct sockaddr *) &a6, sizeof (a6))) | 276 | (const struct sockaddr *) &a6, sizeof (a6))) |
diff --git a/src/util/os_priority.c b/src/util/os_priority.c index 46e2deb5c..6e18d9278 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c | |||
@@ -29,19 +29,23 @@ | |||
29 | #include "gnunet_os_lib.h" | 29 | #include "gnunet_os_lib.h" |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * Set our process priority | 32 | * Set process priority |
33 | * | ||
34 | * @param proc id of the process | ||
35 | * @param prio priority value | ||
36 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
33 | */ | 37 | */ |
34 | int | 38 | int |
35 | GNUNET_OS_set_process_priority (pid_t proc, | 39 | GNUNET_OS_set_process_priority (pid_t proc, |
36 | enum GNUNET_SCHEDULER_Priority eprio) | 40 | enum GNUNET_SCHEDULER_Priority prio) |
37 | { | 41 | { |
38 | int prio = 0; | 42 | int prio = 0; |
39 | 43 | ||
40 | GNUNET_assert (eprio < GNUNET_SCHEDULER_PRIORITY_COUNT); | 44 | GNUNET_assert (prio < GNUNET_SCHEDULER_PRIORITY_COUNT); |
41 | if (eprio == GNUNET_SCHEDULER_PRIORITY_KEEP) | 45 | if (prio == GNUNET_SCHEDULER_PRIORITY_KEEP) |
42 | return GNUNET_OK; | 46 | return GNUNET_OK; |
43 | /* convert to MINGW/Unix values */ | 47 | /* convert to MINGW/Unix values */ |
44 | switch (eprio) | 48 | switch (prio) |
45 | { | 49 | { |
46 | case GNUNET_SCHEDULER_PRIORITY_DEFAULT: | 50 | case GNUNET_SCHEDULER_PRIORITY_DEFAULT: |
47 | #ifdef MINGW | 51 | #ifdef MINGW |
diff --git a/src/util/pseudonym.c b/src/util/pseudonym.c index 8687b5c4d..04a6a1f78 100644 --- a/src/util/pseudonym.c +++ b/src/util/pseudonym.c | |||
@@ -588,7 +588,7 @@ merge_meta_helper (void *cls, | |||
588 | /** | 588 | /** |
589 | * Add a pseudonym to the set of known pseudonyms. | 589 | * Add a pseudonym to the set of known pseudonyms. |
590 | * For all pseudonym advertisements that we discover | 590 | * For all pseudonym advertisements that we discover |
591 | * FSUI should automatically call this function. | 591 | * FS should automatically call this function. |
592 | * | 592 | * |
593 | * @param cfg overall configuration | 593 | * @param cfg overall configuration |
594 | * @param id the pseudonym identifier | 594 | * @param id the pseudonym identifier |
diff --git a/src/util/resolver.h b/src/util/resolver.h index 31637f01d..5adf43633 100644 --- a/src/util/resolver.h +++ b/src/util/resolver.h | |||
@@ -20,7 +20,7 @@ | |||
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @author Christian Grothoff | 22 | * @author Christian Grothoff |
23 | * @file resolver/resolver.h | 23 | * @file util/resolver.h |
24 | */ | 24 | */ |
25 | #ifndef RESOLVER_H | 25 | #ifndef RESOLVER_H |
26 | #define RESOLVER_H | 26 | #define RESOLVER_H |
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index cc81aa6b8..b2c8fda66 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file resolver/resolver_api.c | 22 | * @file util/resolver_api.c |
23 | * @brief resolver for writing a tool | 23 | * @brief resolver for writing a tool |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
diff --git a/src/util/strings.c b/src/util/strings.c index 23e6cd85b..133fda857 100644 --- a/src/util/strings.c +++ b/src/util/strings.c | |||
@@ -353,37 +353,37 @@ GNUNET_STRINGS_filename_expand (const char *fil) | |||
353 | /** | 353 | /** |
354 | * Give relative time in human-readable fancy format. | 354 | * Give relative time in human-readable fancy format. |
355 | * | 355 | * |
356 | * @param del time in milli seconds | 356 | * @param delta time in milli seconds |
357 | * @return time as human-readable string | 357 | * @return time as human-readable string |
358 | */ | 358 | */ |
359 | char * | 359 | char * |
360 | GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative del) | 360 | GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta) |
361 | { | 361 | { |
362 | const char *unit = _( /* time unit */ "ms"); | 362 | const char *unit = _( /* time unit */ "ms"); |
363 | char *ret; | 363 | char *ret; |
364 | uint64_t delta = del.value; | 364 | uint64_t dval = delta.value; |
365 | 365 | ||
366 | if (delta > 5 * 1000) | 366 | if (dval > 5 * 1000) |
367 | { | 367 | { |
368 | delta = delta / 1000; | 368 | dval = dval / 1000; |
369 | unit = _( /* time unit */ "s"); | 369 | unit = _( /* time unit */ "s"); |
370 | if (delta > 5 * 60) | 370 | if (dval > 5 * 60) |
371 | { | 371 | { |
372 | delta = delta / 60; | 372 | dval = dval / 60; |
373 | unit = _( /* time unit */ "m"); | 373 | unit = _( /* time unit */ "m"); |
374 | if (delta > 5 * 60) | 374 | if (dval > 5 * 60) |
375 | { | 375 | { |
376 | delta = delta / 60; | 376 | dval = dval / 60; |
377 | unit = _( /* time unit */ "h"); | 377 | unit = _( /* time unit */ "h"); |
378 | if (delta > 5 * 24) | 378 | if (dval > 5 * 24) |
379 | { | 379 | { |
380 | delta = delta / 24; | 380 | dval = dval / 24; |
381 | unit = _( /* time unit */ " days"); | 381 | unit = _( /* time unit */ " days"); |
382 | } | 382 | } |
383 | } | 383 | } |
384 | } | 384 | } |
385 | } | 385 | } |
386 | GNUNET_asprintf (&ret, "%llu%s", delta, unit); | 386 | GNUNET_asprintf (&ret, "%llu%s", dval, unit); |
387 | return ret; | 387 | return ret; |
388 | } | 388 | } |
389 | 389 | ||