diff options
-rw-r--r-- | src/gns/gnunet-service-gns.c | 2 | ||||
-rw-r--r-- | src/include/gnunet_common.h | 35 | ||||
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 11 | ||||
-rw-r--r-- | src/util/common_logging.c | 37 |
4 files changed, 73 insertions, 12 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index d3f7ffabf4..18bb26fe83 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -412,7 +412,7 @@ put_gns_record(void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Records for name `%s' in zone %s too large to fit into DHT"), name, - GNUNET_h2s (&zhash) /* FIXME: write converter for short hash... */); + GNUNET_short_h2s (&zhash)); GNUNET_free(nrb); zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next, NULL); diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index dae3d4945a..60bf191c64 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -247,6 +247,16 @@ struct GNUNET_HashCode /** + * FIXME + * @brief 256-bit hashcode + **/ +struct GNUNET_CRYPTO_ShortHashCode +{ + uint32_t bits[256 / 8 / sizeof (uint32_t)]; /* = 8 */ +}; + + +/** * The identity of the host (basically the SHA-512 hashcode of * it's public key). */ @@ -438,6 +448,31 @@ GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls); /** + * Convert a short hash value to a string (for printing debug messages). + * This is one of the very few calls in the entire API that is + * NOT reentrant! + * + * @param hc the short hash code + * @return string + */ +const char * +GNUNET_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc); + + +/** + * Convert a short hash value to a string (for printing debug messages). + * This prints all 104 characters of a hashcode! + * This is one of the very few calls in the entire API that is + * NOT reentrant! + * + * @param hc the short hash code + * @return string + */ +const char * +GNUNET_short_h2s_full (const struct GNUNET_CRYPTO_ShortHashCode * hc); + + +/** * Convert a hash value to a string (for printing debug messages). * This is one of the very few calls in the entire API that is * NOT reentrant! diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 710ef31790..57fcf8bc01 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -137,17 +137,6 @@ struct GNUNET_CRYPTO_HashAsciiEncoded }; - - -/** - * @brief 256-bit hashcode - */ -struct GNUNET_CRYPTO_ShortHashCode -{ - uint32_t bits[256 / 8 / sizeof (uint32_t)]; /* = 8 */ -}; - - /** * @brief 0-terminated ASCII encoding of a 'struct GNUNET_ShortHashCode'. */ diff --git a/src/util/common_logging.c b/src/util/common_logging.c index fbc0de50c9..6161d0c6d0 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c @@ -1012,6 +1012,43 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind) /** + * Convert a short hash to a string (for printing debug messages). + * This is one of the very few calls in the entire API that is + * NOT reentrant! + * + * @param hc the short hash code + * @return string form; will be overwritten by next call to GNUNET_h2s. + */ +const char * +GNUNET_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc) +{ + static struct GNUNET_CRYPTO_ShortHashAsciiEncoded ret; + + GNUNET_CRYPTO_short_hash_to_enc (hc, &ret); + ret.short_encoding[8] = '\0'; + return (const char *) ret.short_encoding; +} + + +/** + * Convert a short hash to a string (for printing debug messages). + * This is one of the very few calls in the entire API that is + * NOT reentrant! + * + * @param hc the short hash code + * @return string form; will be overwritten by next call to GNUNET_h2s_full. + */ +const char * +GNUNET_short_h2s_full (const struct GNUNET_CRYPTO_ShortHashCode * hc) +{ + static struct GNUNET_CRYPTO_ShortHashAsciiEncoded ret; + + GNUNET_CRYPTO_short_hash_to_enc (hc, &ret); + ret.short_encoding[sizeof (ret) - 1] = '\0'; + return (const char *) ret.short_encoding; +} + +/** * Convert a hash to a string (for printing debug messages). * This is one of the very few calls in the entire API that is * NOT reentrant! |