diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-06-26 11:50:16 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-06-26 11:50:16 +0000 |
commit | 5f38f9933e6f19fcef0ded8aad3d6db4e6cbb666 (patch) | |
tree | 7c17cf8ad811c21520f0e73fd7124d5a33c8935b /src/regex/regex_internal_dht.c | |
parent | ae4ab9e6ce8d7529bec34bef3d7db62c393dd918 (diff) | |
download | gnunet-5f38f9933e6f19fcef0ded8aad3d6db4e6cbb666.tar.gz gnunet-5f38f9933e6f19fcef0ded8aad3d6db4e6cbb666.zip |
-cleaning up block code, moving all of the block logic into the block library
Diffstat (limited to 'src/regex/regex_internal_dht.c')
-rw-r--r-- | src/regex/regex_internal_dht.c | 62 |
1 files changed, 12 insertions, 50 deletions
diff --git a/src/regex/regex_internal_dht.c b/src/regex/regex_internal_dht.c index a11d59752..3ddee06ff 100644 --- a/src/regex/regex_internal_dht.c +++ b/src/regex/regex_internal_dht.c | |||
@@ -91,25 +91,19 @@ regex_iterator (void *cls, | |||
91 | { | 91 | { |
92 | struct REGEX_INTERNAL_Announcement *h = cls; | 92 | struct REGEX_INTERNAL_Announcement *h = cls; |
93 | struct RegexBlock *block; | 93 | struct RegexBlock *block; |
94 | struct RegexEdge *block_edge; | ||
95 | size_t size; | 94 | size_t size; |
96 | size_t len; | ||
97 | unsigned int i; | ||
98 | unsigned int offset; | ||
99 | char *aux; | ||
100 | 95 | ||
101 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 96 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
102 | " regex dht put for state %s\n", | 97 | "DHT PUT for state %s with proof `%s' and %u edges\n", |
103 | GNUNET_h2s (key)); | 98 | GNUNET_h2s (key), |
104 | LOG (GNUNET_ERROR_TYPE_DEBUG, " proof: %s\n", proof); | 99 | proof, |
105 | LOG (GNUNET_ERROR_TYPE_DEBUG, " num edges: %u\n", num_edges); | 100 | num_edges); |
106 | |||
107 | if (GNUNET_YES == accepting) | 101 | if (GNUNET_YES == accepting) |
108 | { | 102 | { |
109 | struct RegexAccept block; | 103 | struct RegexAccept block; |
110 | 104 | ||
111 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 105 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
112 | " state %s is accepting, putting own id\n", | 106 | "State %s is accepting, putting own id\n", |
113 | GNUNET_h2s(key)); | 107 | GNUNET_h2s(key)); |
114 | size = sizeof (block); | 108 | size = sizeof (block); |
115 | block.key = *key; | 109 | block.key = *key; |
@@ -124,53 +118,21 @@ regex_iterator (void *cls, | |||
124 | DHT_OPT | GNUNET_DHT_RO_RECORD_ROUTE, | 118 | DHT_OPT | GNUNET_DHT_RO_RECORD_ROUTE, |
125 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT, | 119 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT, |
126 | size, | 120 | size, |
127 | (char *) &block, | 121 | &block, |
128 | GNUNET_TIME_relative_to_absolute (DHT_TTL), | 122 | GNUNET_TIME_relative_to_absolute (DHT_TTL), |
129 | DHT_TTL, | 123 | DHT_TTL, |
130 | NULL, NULL); | 124 | NULL, NULL); |
131 | } | 125 | } |
132 | len = strlen(proof); | 126 | block = REGEX_INTERNAL_block_create (key, proof, |
133 | size = sizeof (struct RegexBlock) + len; | 127 | num_edges, edges, |
134 | block = GNUNET_malloc (size); | 128 | accepting, |
135 | 129 | &size); | |
136 | block->key = *key; | ||
137 | block->n_proof = htonl (len); | ||
138 | block->n_edges = htonl (num_edges); | ||
139 | block->accepting = htonl (accepting); | ||
140 | |||
141 | /* Store the proof at the end of the block. */ | ||
142 | aux = (char *) &block[1]; | ||
143 | memcpy (aux, proof, len); | ||
144 | aux = &aux[len]; | ||
145 | |||
146 | /* Store each edge in a variable length MeshEdge struct at the | ||
147 | * very end of the MeshRegexBlock structure. | ||
148 | */ | ||
149 | for (i = 0; i < num_edges; i++) | ||
150 | { | ||
151 | LOG (GNUNET_ERROR_TYPE_DEBUG, " edge %s towards %s\n", | ||
152 | edges[i].label, GNUNET_h2s(&edges[i].destination)); | ||
153 | |||
154 | /* aux points at the end of the last block */ | ||
155 | len = strlen (edges[i].label); | ||
156 | size += sizeof (struct RegexEdge) + len; | ||
157 | // Calculate offset FIXME is this ok? use size instead? | ||
158 | offset = aux - (char *) block; | ||
159 | block = GNUNET_realloc (block, size); | ||
160 | aux = &((char *) block)[offset]; | ||
161 | block_edge = (struct RegexEdge *) aux; | ||
162 | block_edge->key = edges[i].destination; | ||
163 | block_edge->n_token = htonl (len); | ||
164 | aux = (char *) &block_edge[1]; | ||
165 | memcpy (aux, edges[i].label, len); | ||
166 | aux = &aux[len]; | ||
167 | } | ||
168 | (void) | 130 | (void) |
169 | GNUNET_DHT_put (h->dht, key, | 131 | GNUNET_DHT_put (h->dht, key, |
170 | DHT_REPLICATION, | 132 | DHT_REPLICATION, |
171 | DHT_OPT, | 133 | DHT_OPT, |
172 | GNUNET_BLOCK_TYPE_REGEX, size, | 134 | GNUNET_BLOCK_TYPE_REGEX, |
173 | (char *) block, | 135 | size, block, |
174 | GNUNET_TIME_relative_to_absolute (DHT_TTL), | 136 | GNUNET_TIME_relative_to_absolute (DHT_TTL), |
175 | DHT_TTL, | 137 | DHT_TTL, |
176 | NULL, NULL); | 138 | NULL, NULL); |