diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-06-27 11:31:48 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-06-27 11:31:48 +0000 |
commit | d1b1c834fbb65d70fca837e1ab742e71e16adf50 (patch) | |
tree | ff3c5f148bee8c53a8a36447a8bd5535ed5573c2 /src/regex | |
parent | 1350dd76782b3cea091cd3c41dc53a6fc244414b (diff) | |
download | gnunet-d1b1c834fbb65d70fca837e1ab742e71e16adf50.tar.gz gnunet-d1b1c834fbb65d70fca837e1ab742e71e16adf50.zip |
-move struct RegexBlock into regex_block_lib
Diffstat (limited to 'src/regex')
-rw-r--r-- | src/regex/regex_block_lib.c | 62 | ||||
-rw-r--r-- | src/regex/regex_block_lib.h | 15 | ||||
-rw-r--r-- | src/regex/regex_internal_dht.c | 33 |
3 files changed, 94 insertions, 16 deletions
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 @@ | |||
28 | 28 | ||
29 | #define LOG(kind,...) GNUNET_log_from (kind,"regex-bck",__VA_ARGS__) | 29 | #define LOG(kind,...) GNUNET_log_from (kind,"regex-bck",__VA_ARGS__) |
30 | 30 | ||
31 | GNUNET_NETWORK_STRUCT_BEGIN | ||
32 | |||
33 | /** | ||
34 | * @brief Block to announce a regex state. | ||
35 | */ | ||
36 | struct RegexBlock | ||
37 | { | ||
38 | |||
39 | /** | ||
40 | * Length of the proof regex string. | ||
41 | */ | ||
42 | uint16_t proof_len GNUNET_PACKED; | ||
43 | |||
44 | /** | ||
45 | * Is this state an accepting state? | ||
46 | */ | ||
47 | int16_t is_accepting GNUNET_PACKED; | ||
48 | |||
49 | /** | ||
50 | * Numer of edges parting from this state. | ||
51 | */ | ||
52 | uint32_t n_edges GNUNET_PACKED; | ||
53 | |||
54 | /* char proof[n_proof] */ | ||
55 | /* struct RegexEdge edges[n_edges] */ | ||
56 | }; | ||
57 | |||
58 | |||
59 | /** | ||
60 | * @brief A RegexBlock contains one or more of this struct in the payload. | ||
61 | */ | ||
62 | struct RegexEdge | ||
63 | { | ||
64 | /** | ||
65 | * Destination of this edge. | ||
66 | */ | ||
67 | struct GNUNET_HashCode key; | ||
68 | |||
69 | /** | ||
70 | * Length of the token towards the new state. | ||
71 | */ | ||
72 | uint32_t n_token GNUNET_PACKED; | ||
73 | |||
74 | /* char token[n_token] */ | ||
75 | }; | ||
76 | |||
77 | |||
78 | GNUNET_NETWORK_STRUCT_END | ||
79 | |||
80 | |||
81 | /** | ||
82 | * Test if this block is marked as being an accept state. | ||
83 | * | ||
84 | * @param block block to test | ||
85 | * @return GNUNET_YES if the block is accepting, GNUNET_NO if not | ||
86 | */ | ||
87 | int | ||
88 | GNUNET_BLOCK_is_accepting (const struct RegexBlock *block) | ||
89 | { | ||
90 | return ntohs (block->is_accepting); | ||
91 | } | ||
92 | |||
31 | 93 | ||
32 | /** | 94 | /** |
33 | * Check if the given 'proof' matches the given 'key'. | 95 | * 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 | |||
@@ -41,6 +41,12 @@ extern "C" | |||
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Representation of a Regex node (and edges) in the DHT. | ||
45 | */ | ||
46 | struct RegexBlock; | ||
47 | |||
48 | |||
49 | /** | ||
44 | * Edge representation. | 50 | * Edge representation. |
45 | */ | 51 | */ |
46 | struct REGEX_BLOCK_Edge | 52 | struct REGEX_BLOCK_Edge |
@@ -146,6 +152,15 @@ REGEX_BLOCK_get_key (const struct RegexBlock *block, | |||
146 | struct GNUNET_HashCode *key); | 152 | struct GNUNET_HashCode *key); |
147 | 153 | ||
148 | 154 | ||
155 | /** | ||
156 | * Test if this block is marked as being an accept state. | ||
157 | * | ||
158 | * @param block block to test | ||
159 | * @return GNUNET_YES if the block is accepting, GNUNET_NO if not | ||
160 | */ | ||
161 | int | ||
162 | GNUNET_BLOCK_is_accepting (const struct RegexBlock *block); | ||
163 | |||
149 | 164 | ||
150 | /** | 165 | /** |
151 | * Construct a regex block to be stored in the DHT. | 166 | * 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, | |||
107 | num_edges); | 107 | num_edges); |
108 | if (GNUNET_YES == accepting) | 108 | if (GNUNET_YES == accepting) |
109 | { | 109 | { |
110 | struct RegexAcceptBlock block; | 110 | struct RegexAcceptBlock ab; |
111 | 111 | ||
112 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 112 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
113 | "State %s is accepting, putting own id\n", | 113 | "State %s is accepting, putting own id\n", |
114 | GNUNET_h2s(key)); | 114 | GNUNET_h2s(key)); |
115 | size = sizeof (block); | 115 | size = sizeof (struct RegexAcceptBlock); |
116 | block.purpose.size = sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + | 116 | ab.purpose.size = sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + |
117 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + | 117 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + |
118 | sizeof (struct GNUNET_HashCode); | 118 | sizeof (struct GNUNET_HashCode); |
119 | block.purpose.purpose = ntohl (GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT); | 119 | ab.purpose.purpose = ntohl (GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT); |
120 | block.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_DHT_MAX_EXPIRATION)); | 120 | ab.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_DHT_MAX_EXPIRATION)); |
121 | block.key = *key; | 121 | ab.key = *key; |
122 | GNUNET_CRYPTO_ecc_key_get_public (h->priv, | 122 | GNUNET_CRYPTO_ecc_key_get_public (h->priv, |
123 | &block.public_key); | 123 | &ab.public_key); |
124 | GNUNET_assert (GNUNET_OK == | 124 | GNUNET_assert (GNUNET_OK == |
125 | GNUNET_CRYPTO_ecc_sign (h->priv, | 125 | GNUNET_CRYPTO_ecc_sign (h->priv, |
126 | &block.purpose, | 126 | &ab.purpose, |
127 | &block.signature)); | 127 | &ab.signature)); |
128 | 128 | ||
129 | GNUNET_STATISTICS_update (h->stats, "# regex accepting blocks stored", | 129 | GNUNET_STATISTICS_update (h->stats, "# regex accepting blocks stored", |
130 | 1, GNUNET_NO); | 130 | 1, GNUNET_NO); |
131 | GNUNET_STATISTICS_update (h->stats, "# regex accepting block bytes stored", | 131 | GNUNET_STATISTICS_update (h->stats, "# regex accepting block bytes stored", |
132 | sizeof (block), GNUNET_NO); | 132 | sizeof (struct RegexAcceptBlock), GNUNET_NO); |
133 | (void) | 133 | (void) |
134 | GNUNET_DHT_put (h->dht, key, | 134 | GNUNET_DHT_put (h->dht, key, |
135 | DHT_REPLICATION, | 135 | DHT_REPLICATION, |
136 | DHT_OPT | GNUNET_DHT_RO_RECORD_ROUTE, | 136 | DHT_OPT | GNUNET_DHT_RO_RECORD_ROUTE, |
137 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT, | 137 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT, |
138 | size, | 138 | size, |
139 | &block, | 139 | &ab, |
140 | GNUNET_TIME_relative_to_absolute (DHT_TTL), | 140 | GNUNET_TIME_relative_to_absolute (DHT_TTL), |
141 | DHT_TTL, | 141 | DHT_TTL, |
142 | NULL, NULL); | 142 | NULL, NULL); |
@@ -463,7 +463,7 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
463 | GNUNET_free (datastore); | 463 | GNUNET_free (datastore); |
464 | 464 | ||
465 | copy = GNUNET_malloc (size); | 465 | copy = GNUNET_malloc (size); |
466 | memcpy (copy, data, size); | 466 | memcpy (copy, block, size); |
467 | GNUNET_break ( | 467 | GNUNET_break ( |
468 | GNUNET_OK == | 468 | GNUNET_OK == |
469 | GNUNET_CONTAINER_multihashmap_put (info->dht_get_results, | 469 | GNUNET_CONTAINER_multihashmap_put (info->dht_get_results, |
@@ -473,7 +473,7 @@ dht_get_string_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
473 | len = strlen (info->description); | 473 | len = strlen (info->description); |
474 | if (len == ctx->position) // String processed | 474 | if (len == ctx->position) // String processed |
475 | { | 475 | { |
476 | if (GNUNET_YES == ntohs (block->is_accepting)) | 476 | if (GNUNET_YES == GNUNET_BLOCK_is_accepting (block)) |
477 | { | 477 | { |
478 | regex_find_path (key, ctx); | 478 | regex_find_path (key, ctx); |
479 | } | 479 | } |
@@ -504,8 +504,9 @@ regex_result_iterator (void *cls, | |||
504 | struct RegexBlock *block = value; | 504 | struct RegexBlock *block = value; |
505 | struct RegexSearchContext *ctx = cls; | 505 | struct RegexSearchContext *ctx = cls; |
506 | 506 | ||
507 | if (GNUNET_YES == ntohs (block->is_accepting) && | 507 | if ( (GNUNET_YES == |
508 | ctx->position == strlen (ctx->info->description)) | 508 | GNUNET_BLOCK_is_accepting (block)) && |
509 | (ctx->position == strlen (ctx->info->description)) ) | ||
509 | { | 510 | { |
510 | LOG (GNUNET_ERROR_TYPE_INFO, " * Found accepting known block\n"); | 511 | LOG (GNUNET_ERROR_TYPE_INFO, " * Found accepting known block\n"); |
511 | regex_find_path (key, ctx); | 512 | regex_find_path (key, ctx); |
@@ -513,7 +514,7 @@ regex_result_iterator (void *cls, | |||
513 | } | 514 | } |
514 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* %u, %u, [%u]\n", | 515 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* %u, %u, [%u]\n", |
515 | ctx->position, strlen(ctx->info->description), | 516 | ctx->position, strlen(ctx->info->description), |
516 | ntohs (block->is_accepting)); | 517 | GNUNET_BLOCK_is_accepting (block)); |
517 | 518 | ||
518 | regex_next_edge (block, SIZE_MAX, ctx); | 519 | regex_next_edge (block, SIZE_MAX, ctx); |
519 | 520 | ||