From d1b1c834fbb65d70fca837e1ab742e71e16adf50 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 27 Jun 2013 11:31:48 +0000 Subject: [PATCH] -move struct RegexBlock into regex_block_lib --- src/include/block_regex.h | 45 ------------------------ src/regex/regex_block_lib.c | 62 ++++++++++++++++++++++++++++++++++ src/regex/regex_block_lib.h | 15 ++++++++ src/regex/regex_internal_dht.c | 33 +++++++++--------- 4 files changed, 94 insertions(+), 61 deletions(-) diff --git a/src/include/block_regex.h b/src/include/block_regex.h index be9d305ad..bfaf411eb 100644 --- a/src/include/block_regex.h +++ b/src/include/block_regex.h @@ -42,51 +42,6 @@ extern "C" GNUNET_NETWORK_STRUCT_BEGIN -/** - * @brief A RegexBlock contains one or more of this struct in the payload. - */ -struct RegexEdge -{ - /** - * Destination of this edge. - */ - struct GNUNET_HashCode key; - - /** - * Length of the token towards the new state. - */ - uint32_t n_token GNUNET_PACKED; - - /* char token[n_token] */ -}; - - -/** - * @brief Block to announce a regex state. - */ -struct RegexBlock -{ - - /** - * Length of the proof regex string. - */ - uint16_t proof_len GNUNET_PACKED; - - /** - * Is this state an accepting state? - */ - int16_t is_accepting GNUNET_PACKED; - - /** - * Numer of edges parting from this state. - */ - uint32_t n_edges GNUNET_PACKED; - - /* char proof[n_proof] */ - /* struct RegexEdge edges[n_edges] */ -}; - - /** * @brief Block to announce a peer accepting a state. */ diff --git a/src/regex/regex_block_lib.c b/src/regex/regex_block_lib.c index 01c591caa..842c9f366 100644 --- a/src/regex/regex_block_lib.c +++ b/src/regex/regex_block_lib.c @@ -28,6 +28,68 @@ #define LOG(kind,...) GNUNET_log_from (kind,"regex-bck",__VA_ARGS__) +GNUNET_NETWORK_STRUCT_BEGIN + +/** + * @brief Block to announce a regex state. + */ +struct RegexBlock +{ + + /** + * Length of the proof regex string. + */ + uint16_t proof_len GNUNET_PACKED; + + /** + * Is this state an accepting state? + */ + int16_t is_accepting GNUNET_PACKED; + + /** + * Numer of edges parting from this state. + */ + uint32_t n_edges GNUNET_PACKED; + + /* char proof[n_proof] */ + /* struct RegexEdge edges[n_edges] */ +}; + + +/** + * @brief A RegexBlock contains one or more of this struct in the payload. + */ +struct RegexEdge +{ + /** + * Destination of this edge. + */ + struct GNUNET_HashCode key; + + /** + * Length of the token towards the new state. + */ + uint32_t n_token GNUNET_PACKED; + + /* char token[n_token] */ +}; + + +GNUNET_NETWORK_STRUCT_END + + +/** + * Test if this block is marked as being an accept state. + * + * @param block block to test + * @return GNUNET_YES if the block is accepting, GNUNET_NO if not + */ +int +GNUNET_BLOCK_is_accepting (const struct RegexBlock *block) +{ + return ntohs (block->is_accepting); +} + /** * Check if the given 'proof' matches the given 'key'. diff --git a/src/regex/regex_block_lib.h b/src/regex/regex_block_lib.h index dec025205..7c48bbefd 100644 --- a/src/regex/regex_block_lib.h +++ b/src/regex/regex_block_lib.h @@ -40,6 +40,12 @@ extern "C" #include "block_regex.h" +/** + * Representation of a Regex node (and edges) in the DHT. + */ +struct RegexBlock; + + /** * Edge representation. */ @@ -146,6 +152,15 @@ REGEX_BLOCK_get_key (const struct RegexBlock *block, struct GNUNET_HashCode *key); +/** + * Test if this block is marked as being an accept state. + * + * @param block block to test + * @return GNUNET_YES if the block is accepting, GNUNET_NO if not + */ +int +GNUNET_BLOCK_is_accepting (const struct RegexBlock *block); + /** * Construct a regex block to be stored in the DHT. diff --git a/src/regex/regex_internal_dht.c b/src/regex/regex_internal_dht.c index 3d6cf7360..15f53e953 100644 --- a/src/regex/regex_internal_dht.c +++ b/src/regex/regex_internal_dht.c @@ -107,36 +107,36 @@ regex_iterator (void *cls, num_edges); if (GNUNET_YES == accepting) { - struct RegexAcceptBlock block; + struct RegexAcceptBlock ab; LOG (GNUNET_ERROR_TYPE_DEBUG, "State %s is accepting, putting own id\n", GNUNET_h2s(key)); - size = sizeof (block); - block.purpose.size = sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + + size = sizeof (struct RegexAcceptBlock); + ab.purpose.size = sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + sizeof (struct GNUNET_TIME_AbsoluteNBO) + sizeof (struct GNUNET_HashCode); - block.purpose.purpose = ntohl (GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT); - block.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_DHT_MAX_EXPIRATION)); - block.key = *key; + ab.purpose.purpose = ntohl (GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT); + ab.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_DHT_MAX_EXPIRATION)); + ab.key = *key; GNUNET_CRYPTO_ecc_key_get_public (h->priv, - &block.public_key); + &ab.public_key); GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecc_sign (h->priv, - &block.purpose, - &block.signature)); + &ab.purpose, + &ab.signature)); GNUNET_STATISTICS_update (h->stats, "# regex accepting blocks stored", 1, GNUNET_NO); GNUNET_STATISTICS_update (h->stats, "# regex accepting block bytes stored", - sizeof (block), GNUNET_NO); + sizeof (struct RegexAcceptBlock), GNUNET_NO); (void) GNUNET_DHT_put (h->dht, key, DHT_REPLICATION, DHT_OPT | GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_BLOCK_TYPE_REGEX_ACCEPT, size, - &block, + &ab, GNUNET_TIME_relative_to_absolute (DHT_TTL), DHT_TTL, NULL, NULL); @@ -463,7 +463,7 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp, GNUNET_free (datastore); copy = GNUNET_malloc (size); - memcpy (copy, data, size); + memcpy (copy, block, size); GNUNET_break ( GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (info->dht_get_results, @@ -473,7 +473,7 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp, len = strlen (info->description); if (len == ctx->position) // String processed { - if (GNUNET_YES == ntohs (block->is_accepting)) + if (GNUNET_YES == GNUNET_BLOCK_is_accepting (block)) { regex_find_path (key, ctx); } @@ -504,8 +504,9 @@ regex_result_iterator (void *cls, struct RegexBlock *block = value; struct RegexSearchContext *ctx = cls; - if (GNUNET_YES == ntohs (block->is_accepting) && - ctx->position == strlen (ctx->info->description)) + if ( (GNUNET_YES == + GNUNET_BLOCK_is_accepting (block)) && + (ctx->position == strlen (ctx->info->description)) ) { LOG (GNUNET_ERROR_TYPE_INFO, " * Found accepting known block\n"); regex_find_path (key, ctx); @@ -513,7 +514,7 @@ regex_result_iterator (void *cls, } LOG (GNUNET_ERROR_TYPE_DEBUG, "* %u, %u, [%u]\n", ctx->position, strlen(ctx->info->description), - ntohs (block->is_accepting)); + GNUNET_BLOCK_is_accepting (block)); regex_next_edge (block, SIZE_MAX, ctx); -- 2.25.1