diff options
Diffstat (limited to 'src/namestore/test_namestore_api_create.c')
-rw-r--r-- | src/namestore/test_namestore_api_create.c | 164 |
1 files changed, 133 insertions, 31 deletions
diff --git a/src/namestore/test_namestore_api_create.c b/src/namestore/test_namestore_api_create.c index 93c3dba2d..a2e1366c8 100644 --- a/src/namestore/test_namestore_api_create.c +++ b/src/namestore/test_namestore_api_create.c | |||
@@ -50,8 +50,8 @@ static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | |||
50 | struct GNUNET_CRYPTO_RsaSignature *s_signature; | 50 | struct GNUNET_CRYPTO_RsaSignature *s_signature; |
51 | struct GNUNET_CRYPTO_RsaSignature *s_signature_updated; | 51 | struct GNUNET_CRYPTO_RsaSignature *s_signature_updated; |
52 | static GNUNET_HashCode s_zone; | 52 | static GNUNET_HashCode s_zone; |
53 | struct GNUNET_NAMESTORE_RecordData *s_rd; | 53 | struct GNUNET_NAMESTORE_RecordData *s_first_record; |
54 | struct GNUNET_NAMESTORE_RecordData *s_create_rd; | 54 | struct GNUNET_NAMESTORE_RecordData *s_second_record; |
55 | static char *s_name; | 55 | static char *s_name; |
56 | 56 | ||
57 | 57 | ||
@@ -117,11 +117,9 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
117 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | 117 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; |
118 | } | 118 | } |
119 | 119 | ||
120 | int c; | 120 | GNUNET_free ((void *) s_first_record->data); |
121 | for (c = 0; c < RECORDS; c++) | 121 | GNUNET_free (s_first_record); |
122 | GNUNET_free_non_null((void *) s_rd[c].data); | 122 | GNUNET_free_non_null (s_second_record); |
123 | GNUNET_free (s_rd); | ||
124 | //GNUNET_free (s_create_rd); | ||
125 | 123 | ||
126 | if (privkey != NULL) | 124 | if (privkey != NULL) |
127 | GNUNET_CRYPTO_rsa_key_free (privkey); | 125 | GNUNET_CRYPTO_rsa_key_free (privkey); |
@@ -135,7 +133,105 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
135 | stop_arm(); | 133 | stop_arm(); |
136 | } | 134 | } |
137 | 135 | ||
138 | void name_lookup_proc (void *cls, | 136 | void name_lookup_second_proc (void *cls, |
137 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | ||
138 | struct GNUNET_TIME_Absolute expire, | ||
139 | const char *n, | ||
140 | unsigned int rd_count, | ||
141 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
142 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
143 | { | ||
144 | static int found = GNUNET_NO; | ||
145 | int failed = GNUNET_NO; | ||
146 | int c; | ||
147 | |||
148 | if (n != NULL) | ||
149 | { | ||
150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking returned results\n"); | ||
151 | if (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))) | ||
152 | { | ||
153 | GNUNET_break (0); | ||
154 | failed = GNUNET_YES; | ||
155 | } | ||
156 | |||
157 | if (0 != strcmp(n, s_name)) | ||
158 | { | ||
159 | GNUNET_break (0); | ||
160 | failed = GNUNET_YES; | ||
161 | } | ||
162 | |||
163 | if (2 != rd_count) | ||
164 | { | ||
165 | GNUNET_break (0); | ||
166 | failed = GNUNET_YES; | ||
167 | } | ||
168 | |||
169 | for (c = 0; c < rd_count; c++) | ||
170 | { | ||
171 | if ((GNUNET_NO == GNUNET_NAMESTORE_records_cmp(&rd[c], s_first_record)) && | ||
172 | (GNUNET_NO == GNUNET_NAMESTORE_records_cmp(&rd[c], s_second_record))) | ||
173 | { | ||
174 | GNUNET_break (0); | ||
175 | failed = GNUNET_YES; | ||
176 | } | ||
177 | } | ||
178 | |||
179 | if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature(&pubkey, n, rd_count, rd, signature)) | ||
180 | { | ||
181 | GNUNET_break (0); | ||
182 | failed = GNUNET_YES; | ||
183 | } | ||
184 | |||
185 | struct GNUNET_NAMESTORE_RecordData rd_new[2]; | ||
186 | rd_new[0] = *s_first_record; | ||
187 | rd_new[1] = *s_second_record; | ||
188 | s_signature_updated = GNUNET_NAMESTORE_create_signature(privkey, s_name, rd_new, 2); | ||
189 | |||
190 | if (0 != memcmp (s_signature_updated, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature))) | ||
191 | { | ||
192 | GNUNET_break (0); | ||
193 | failed = GNUNET_YES; | ||
194 | } | ||
195 | |||
196 | found = GNUNET_YES; | ||
197 | if (failed == GNUNET_NO) | ||
198 | res = 0; | ||
199 | else | ||
200 | res = 1; | ||
201 | } | ||
202 | else | ||
203 | { | ||
204 | if (found != GNUNET_YES) | ||
205 | { | ||
206 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to lookup records for name `%s'\n", s_name); | ||
207 | res = 1; | ||
208 | } | ||
209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Lookup done for name %s'\n", s_name); | ||
210 | } | ||
211 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
212 | } | ||
213 | |||
214 | |||
215 | void | ||
216 | create_second_cont (void *cls, int32_t success, const char *emsg) | ||
217 | { | ||
218 | char *name = cls; | ||
219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create second record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | ||
220 | if (success == GNUNET_OK) | ||
221 | { | ||
222 | res = 0; | ||
223 | GNUNET_NAMESTORE_lookup_record (nsh, &s_zone, name, 0, &name_lookup_second_proc, name); | ||
224 | } | ||
225 | else | ||
226 | { | ||
227 | res = 1; | ||
228 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to put records for name `%s'\n", name); | ||
229 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
230 | } | ||
231 | |||
232 | } | ||
233 | |||
234 | void name_lookup_initial_proc (void *cls, | ||
139 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | 235 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, |
140 | struct GNUNET_TIME_Absolute expire, | 236 | struct GNUNET_TIME_Absolute expire, |
141 | const char *n, | 237 | const char *n, |
@@ -143,6 +239,7 @@ void name_lookup_proc (void *cls, | |||
143 | const struct GNUNET_NAMESTORE_RecordData *rd, | 239 | const struct GNUNET_NAMESTORE_RecordData *rd, |
144 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 240 | const struct GNUNET_CRYPTO_RsaSignature *signature) |
145 | { | 241 | { |
242 | char * name = cls; | ||
146 | static int found = GNUNET_NO; | 243 | static int found = GNUNET_NO; |
147 | int failed = GNUNET_NO; | 244 | int failed = GNUNET_NO; |
148 | int c; | 245 | int c; |
@@ -170,10 +267,11 @@ void name_lookup_proc (void *cls, | |||
170 | 267 | ||
171 | for (c = 0; c < RECORDS; c++) | 268 | for (c = 0; c < RECORDS; c++) |
172 | { | 269 | { |
173 | GNUNET_break (rd[c].expiration.abs_value == s_rd[c].expiration.abs_value); | 270 | if (GNUNET_NO == GNUNET_NAMESTORE_records_cmp(&rd[c], &s_first_record[c])) |
174 | GNUNET_break (rd[c].record_type == TEST_RECORD_TYPE); | 271 | { |
175 | GNUNET_break (rd[c].data_size == TEST_RECORD_DATALEN); | 272 | GNUNET_break (0); |
176 | GNUNET_break (0 == memcmp (rd[c].data, s_rd[c].data, TEST_RECORD_DATALEN)); | 273 | failed = GNUNET_YES; |
274 | } | ||
177 | } | 275 | } |
178 | 276 | ||
179 | if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature(&pubkey, n, rd_count, rd, signature)) | 277 | if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature(&pubkey, n, rd_count, rd, signature)) |
@@ -193,6 +291,18 @@ void name_lookup_proc (void *cls, | |||
193 | res = 0; | 291 | res = 0; |
194 | else | 292 | else |
195 | res = 1; | 293 | res = 1; |
294 | |||
295 | /* create a second record */ | ||
296 | s_second_record = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_RecordData) + TEST_CREATE_RECORD_DATALEN); | ||
297 | s_second_record->expiration = GNUNET_TIME_absolute_get_forever(); | ||
298 | s_second_record->record_type = TEST_CREATE_RECORD_TYPE; | ||
299 | s_second_record->flags = GNUNET_NAMESTORE_RF_AUTHORITY; | ||
300 | s_second_record->data = &s_second_record[1]; | ||
301 | s_second_record->data_size = TEST_CREATE_RECORD_DATALEN; | ||
302 | memset ((char *) s_second_record->data, TEST_CREATE_RECORD_DATA, TEST_CREATE_RECORD_DATALEN); | ||
303 | |||
304 | GNUNET_NAMESTORE_record_create (nsh, privkey, name, s_second_record, &create_second_cont, name); | ||
305 | |||
196 | } | 306 | } |
197 | else | 307 | else |
198 | { | 308 | { |
@@ -202,19 +312,20 @@ void name_lookup_proc (void *cls, | |||
202 | res = 1; | 312 | res = 1; |
203 | } | 313 | } |
204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Lookup done for name %s'\n", s_name); | 314 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Lookup done for name %s'\n", s_name); |
315 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
205 | } | 316 | } |
206 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
207 | } | 317 | } |
208 | 318 | ||
209 | void | 319 | void |
210 | create_cont (void *cls, int32_t success, const char *emsg) | 320 | create_first_cont (void *cls, int32_t success, const char *emsg) |
211 | { | 321 | { |
212 | char *name = cls; | 322 | char *name = cls; |
213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
214 | if (success == GNUNET_OK) | 324 | if (success == GNUNET_OK) |
215 | { | 325 | { |
216 | res = 0; | 326 | res = 0; |
217 | GNUNET_NAMESTORE_lookup_record (nsh, &s_zone, name, 0, &name_lookup_proc, name); | 327 | /* check if record was created correct */ |
328 | GNUNET_NAMESTORE_lookup_record (nsh, &s_zone, name, 0, &name_lookup_initial_proc, name); | ||
218 | } | 329 | } |
219 | else | 330 | else |
220 | { | 331 | { |
@@ -232,16 +343,7 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
233 | if (success == GNUNET_OK) | 344 | if (success == GNUNET_OK) |
234 | { | 345 | { |
235 | res = 0; | 346 | |
236 | s_create_rd = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_RecordData) + TEST_CREATE_RECORD_DATALEN); | ||
237 | s_create_rd->expiration = GNUNET_TIME_absolute_get_forever(); | ||
238 | s_create_rd->record_type = TEST_CREATE_RECORD_TYPE; | ||
239 | s_create_rd->flags = GNUNET_NAMESTORE_RF_AUTHORITY; | ||
240 | s_create_rd->data = &s_create_rd[1]; | ||
241 | s_create_rd->data_size = TEST_CREATE_RECORD_DATALEN; | ||
242 | memset ((char *) s_create_rd->data, TEST_CREATE_RECORD_DATA, TEST_CREATE_RECORD_DATALEN); | ||
243 | |||
244 | GNUNET_NAMESTORE_record_create (nsh, privkey, name, s_create_rd, &create_cont, name); | ||
245 | } | 347 | } |
246 | else | 348 | else |
247 | { | 349 | { |
@@ -305,13 +407,13 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
305 | 407 | ||
306 | /* create record */ | 408 | /* create record */ |
307 | s_name = "dummy.dummy.gnunet"; | 409 | s_name = "dummy.dummy.gnunet"; |
308 | s_rd = create_record (1); | 410 | s_first_record = create_record (1); |
309 | 411 | ||
310 | rd_ser_len = GNUNET_NAMESTORE_records_get_size(1, s_rd); | 412 | rd_ser_len = GNUNET_NAMESTORE_records_get_size(1, s_first_record); |
311 | char rd_ser[rd_ser_len]; | 413 | char rd_ser[rd_ser_len]; |
312 | GNUNET_NAMESTORE_records_serialize(1, s_rd, rd_ser_len, rd_ser); | 414 | GNUNET_NAMESTORE_records_serialize(1, s_first_record, rd_ser_len, rd_ser); |
313 | 415 | ||
314 | s_signature = GNUNET_NAMESTORE_create_signature(privkey, s_name, s_rd, 1); | 416 | s_signature = GNUNET_NAMESTORE_create_signature(privkey, s_name, s_first_record, 1); |
315 | 417 | ||
316 | /* create random zone hash */ | 418 | /* create random zone hash */ |
317 | GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone); | 419 | GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone); |
@@ -324,11 +426,11 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
324 | nsh = GNUNET_NAMESTORE_connect (cfg); | 426 | nsh = GNUNET_NAMESTORE_connect (cfg); |
325 | GNUNET_break (NULL != nsh); | 427 | GNUNET_break (NULL != nsh); |
326 | 428 | ||
327 | GNUNET_break (s_rd != NULL); | 429 | GNUNET_break (s_first_record != NULL); |
328 | GNUNET_break (s_name != NULL); | 430 | GNUNET_break (s_name != NULL); |
329 | 431 | ||
330 | /* create initial record */ | 432 | /* create initial record */ |
331 | GNUNET_NAMESTORE_record_create (nsh, privkey, s_name, s_rd, &create_cont, s_name); | 433 | GNUNET_NAMESTORE_record_create (nsh, privkey, s_name, s_first_record, &create_first_cont, s_name); |
332 | } | 434 | } |
333 | 435 | ||
334 | static int | 436 | static int |