diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-05 15:20:49 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-05 15:20:49 +0000 |
commit | dcfa706003e24e7893a8db3d94d5597a4c4829c9 (patch) | |
tree | 004d196b7ae72ccc96515b7a696fc25c34aa8fea | |
parent | f9aec0367413408e654a455ad703f44d352cf476 (diff) | |
download | gnunet-dcfa706003e24e7893a8db3d94d5597a4c4829c9.tar.gz gnunet-dcfa706003e24e7893a8db3d94d5597a4c4829c9.zip |
- changes
-rw-r--r-- | src/namestore/Makefile.am | 7 | ||||
-rw-r--r-- | src/namestore/gnunet-namestore.c | 2 | ||||
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 142 | ||||
-rw-r--r-- | src/namestore/namestore.h | 65 | ||||
-rw-r--r-- | src/namestore/namestore_api.c | 105 | ||||
-rw-r--r-- | src/namestore/test_namestore_api.conf | 2 | ||||
-rw-r--r-- | src/namestore/test_namestore_api_zone_to_name.c | 216 |
7 files changed, 521 insertions, 18 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index 21c8166d0..8bfa0389b 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am | |||
@@ -34,6 +34,7 @@ check_PROGRAMS = \ | |||
34 | test_namestore_api_create_update \ | 34 | test_namestore_api_create_update \ |
35 | test_namestore_api_remove \ | 35 | test_namestore_api_remove \ |
36 | test_namestore_api_remove_not_existing_record \ | 36 | test_namestore_api_remove_not_existing_record \ |
37 | test_namestore_api_zone_to_name \ | ||
37 | test_namestore_api_zone_iteration \ | 38 | test_namestore_api_zone_iteration \ |
38 | test_namestore_record_serialization | 39 | test_namestore_record_serialization |
39 | 40 | ||
@@ -157,6 +158,12 @@ test_namestore_api_remove_not_existing_record_LDADD = \ | |||
157 | $(top_builddir)/src/util/libgnunetutil.la \ | 158 | $(top_builddir)/src/util/libgnunetutil.la \ |
158 | $(top_builddir)/src/namestore/libgnunetnamestore.la | 159 | $(top_builddir)/src/namestore/libgnunetnamestore.la |
159 | 160 | ||
161 | test_namestore_api_zone_to_name_SOURCES = \ | ||
162 | test_namestore_api_zone_to_name.c | ||
163 | test_namestore_api_zone_to_name_LDADD = \ | ||
164 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
165 | $(top_builddir)/src/namestore/libgnunetnamestore.la | ||
166 | |||
160 | test_namestore_api_zone_iteration_SOURCES = \ | 167 | test_namestore_api_zone_iteration_SOURCES = \ |
161 | test_namestore_api_zone_iteration.c | 168 | test_namestore_api_zone_iteration.c |
162 | test_namestore_api_zone_iteration_LDADD = \ | 169 | test_namestore_api_zone_iteration_LDADD = \ |
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 3e1ad4ea0..a80f88052 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -191,7 +191,7 @@ del_continuation (void *cls, | |||
191 | * or the expiration time of the block in the namestore (even if there are zero | 191 | * or the expiration time of the block in the namestore (even if there are zero |
192 | * records matching the desired record type) | 192 | * records matching the desired record type) |
193 | * @param name name that is being mapped (at most 255 characters long) | 193 | * @param name name that is being mapped (at most 255 characters long) |
194 | * @param rd_count number of entries in 'rd' array | 194 | * @param rd_len number of entries in 'rd' array |
195 | * @param rd array of records with data to store | 195 | * @param rd array of records with data to store |
196 | * @param signature signature of the record block, NULL if signature is unavailable (i.e. | 196 | * @param signature signature of the record block, NULL if signature is unavailable (i.e. |
197 | * because the user queried for a particular record type only) | 197 | * because the user queried for a particular record type only) |
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 600965e8a..a3f77dabb 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -1062,6 +1062,146 @@ send: | |||
1062 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1062 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1063 | } | 1063 | } |
1064 | 1064 | ||
1065 | |||
1066 | struct ZoneToNameCtx | ||
1067 | { | ||
1068 | struct GNUNET_NAMESTORE_Client *nc; | ||
1069 | uint32_t rid; | ||
1070 | }; | ||
1071 | |||
1072 | static void | ||
1073 | handle_zone_to_name_it (void *cls, | ||
1074 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | ||
1075 | struct GNUNET_TIME_Absolute expire, | ||
1076 | const char *name, | ||
1077 | unsigned int rd_count, | ||
1078 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
1079 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
1080 | { | ||
1081 | struct ZoneToNameCtx * ztn_ctx = cls; | ||
1082 | struct ZoneToNameResponseMessage *ztnr_msg; | ||
1083 | int16_t res = GNUNET_SYSERR; | ||
1084 | uint16_t name_len = 0; | ||
1085 | uint16_t rd_ser_len = 0 ; | ||
1086 | int32_t contains_sig = 0; | ||
1087 | size_t msg_size = 0; | ||
1088 | |||
1089 | char *rd_ser; | ||
1090 | char *name_tmp; | ||
1091 | char *rd_tmp; | ||
1092 | char *sig_tmp; | ||
1093 | |||
1094 | if ((zone_key != NULL) && (name != NULL)) | ||
1095 | { | ||
1096 | /* found result */ | ||
1097 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found results: name ist \n"); | ||
1098 | res = GNUNET_YES; | ||
1099 | name_len = strlen (name); | ||
1100 | } | ||
1101 | else | ||
1102 | { | ||
1103 | /* no result found */ | ||
1104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found no results\n"); | ||
1105 | res = GNUNET_NO; | ||
1106 | name_len = 0; | ||
1107 | } | ||
1108 | |||
1109 | if (rd_count > 0) | ||
1110 | { | ||
1111 | rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd); | ||
1112 | char rd_ser[rd_ser_len]; | ||
1113 | GNUNET_NAMESTORE_records_serialize(rd_count, rd, rd_ser_len, rd_ser); | ||
1114 | } | ||
1115 | else | ||
1116 | rd_ser_len = 0; | ||
1117 | |||
1118 | if (signature != NULL) | ||
1119 | contains_sig = GNUNET_YES; | ||
1120 | else | ||
1121 | contains_sig = GNUNET_NO; | ||
1122 | |||
1123 | msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len + contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature); | ||
1124 | ztnr_msg = GNUNET_malloc (msg_size); | ||
1125 | |||
1126 | name_tmp = (char *) &ztnr_msg[1]; | ||
1127 | rd_tmp = &name_tmp[name_len]; | ||
1128 | sig_tmp = &rd_tmp[rd_ser_len]; | ||
1129 | |||
1130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "ZONE_TO_NAME_RESPONSE"); | ||
1131 | ztnr_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); | ||
1132 | ztnr_msg->gns_header.header.size = htons (msg_size); | ||
1133 | ztnr_msg->gns_header.r_id = htonl (ztn_ctx->rid); | ||
1134 | ztnr_msg->res = htons (res); | ||
1135 | ztnr_msg->rd_len = htons (rd_ser_len); | ||
1136 | ztnr_msg->rd_count = htons (rd_count); | ||
1137 | ztnr_msg->name_len = htons (name_len); | ||
1138 | ztnr_msg->contains_sig = htons (contains_sig); | ||
1139 | if (zone_key != NULL) | ||
1140 | ztnr_msg->zone_key = *zone_key; | ||
1141 | else | ||
1142 | memset (&ztnr_msg->zone_key, '\0', sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | ||
1143 | |||
1144 | memcpy (&name_tmp, name, name_len); | ||
1145 | memcpy (&rd_tmp, &rd_ser, rd_ser_len); | ||
1146 | memcpy (&sig_tmp, signature, contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature)); | ||
1147 | |||
1148 | GNUNET_SERVER_notification_context_unicast (snc, ztn_ctx->nc->client, (const struct GNUNET_MessageHeader *) ztnr_msg, GNUNET_NO); | ||
1149 | GNUNET_free (ztnr_msg); | ||
1150 | } | ||
1151 | |||
1152 | |||
1153 | static void handle_zone_to_name (void *cls, | ||
1154 | struct GNUNET_SERVER_Client * client, | ||
1155 | const struct GNUNET_MessageHeader * message) | ||
1156 | { | ||
1157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_TO_NAME"); | ||
1158 | struct GNUNET_NAMESTORE_Client *nc; | ||
1159 | struct ZoneToNameCtx ztn_ctx; | ||
1160 | size_t msg_size = 0; | ||
1161 | uint32_t rid = 0; | ||
1162 | int res; | ||
1163 | |||
1164 | |||
1165 | if (ntohs (message->size) != sizeof (struct ZoneToNameMessage)) | ||
1166 | { | ||
1167 | GNUNET_break_op (0); | ||
1168 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1169 | return; | ||
1170 | } | ||
1171 | |||
1172 | nc = client_lookup(client); | ||
1173 | if (nc == NULL) | ||
1174 | { | ||
1175 | GNUNET_break_op (0); | ||
1176 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1177 | return; | ||
1178 | } | ||
1179 | |||
1180 | struct ZoneToNameMessage *ztn_msg = (struct ZoneToNameMessage *) message; | ||
1181 | |||
1182 | if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE) | ||
1183 | { | ||
1184 | GNUNET_break_op (0); | ||
1185 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1186 | return; | ||
1187 | } | ||
1188 | |||
1189 | rid = ntohl (ztn_msg->gns_header.r_id); | ||
1190 | |||
1191 | ztn_ctx.rid = rid; | ||
1192 | ztn_ctx.nc = nc; | ||
1193 | |||
1194 | char * z_tmp = strdup (GNUNET_h2s (&ztn_msg->zone)); | ||
1195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up name for zone `%s' in zone `%s''\n", | ||
1196 | z_tmp, | ||
1197 | GNUNET_h2s (&ztn_msg->value_zone)); | ||
1198 | GNUNET_free (z_tmp); | ||
1199 | |||
1200 | res = GSN_database->zone_to_name (GSN_database->cls, &ztn_msg->zone, &ztn_msg->value_zone, &handle_zone_to_name_it, &ztn_ctx); | ||
1201 | |||
1202 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1203 | } | ||
1204 | |||
1065 | struct ZoneIterationProcResult | 1205 | struct ZoneIterationProcResult |
1066 | { | 1206 | { |
1067 | int have_zone_key; | 1207 | int have_zone_key; |
@@ -1289,6 +1429,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1289 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE, 0}, | 1429 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE, 0}, |
1290 | {&handle_record_remove, NULL, | 1430 | {&handle_record_remove, NULL, |
1291 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE, 0}, | 1431 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE, 0}, |
1432 | {&handle_zone_to_name, NULL, | ||
1433 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, 0}, | ||
1292 | {&handle_iteration_start, NULL, | 1434 | {&handle_iteration_start, NULL, |
1293 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct ZoneIterationStartMessage)}, | 1435 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct ZoneIterationStartMessage)}, |
1294 | {&handle_iteration_stop, NULL, | 1436 | {&handle_iteration_stop, NULL, |
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h index f8aa71f0e..c34422e13 100644 --- a/src/namestore/namestore.h +++ b/src/namestore/namestore.h | |||
@@ -37,13 +37,14 @@ | |||
37 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE 436 | 37 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE 436 |
38 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE 437 | 38 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE 437 |
39 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE 438 | 39 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE 438 |
40 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME 439 | ||
41 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE 440 | ||
40 | 42 | ||
41 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START 439 | 43 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START 445 |
42 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE 440 | 44 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE 446 |
43 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT 441 | 45 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT 447 |
44 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP 442 | 46 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP 448 |
45 | 47 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_DISCONNECT 449 | |
46 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_DISCONNECT 443 | ||
47 | 48 | ||
48 | /** | 49 | /** |
49 | * Sign name and records | 50 | * Sign name and records |
@@ -299,6 +300,7 @@ struct RecordCreateResponseMessage | |||
299 | 300 | ||
300 | }; | 301 | }; |
301 | 302 | ||
303 | |||
302 | /** | 304 | /** |
303 | * Remove a record from the namestore | 305 | * Remove a record from the namestore |
304 | * Memory layout: | 306 | * Memory layout: |
@@ -325,13 +327,11 @@ struct RecordRemoveMessage | |||
325 | /* Length of pubkey */ | 327 | /* Length of pubkey */ |
326 | uint16_t key_len; | 328 | uint16_t key_len; |
327 | }; | 329 | }; |
328 | GNUNET_NETWORK_STRUCT_END | ||
329 | 330 | ||
330 | 331 | ||
331 | /** | 332 | /** |
332 | * Remove a record from the namestore response | 333 | * Remove a record from the namestore response |
333 | */ | 334 | */ |
334 | GNUNET_NETWORK_STRUCT_BEGIN | ||
335 | struct RecordRemoveResponseMessage | 335 | struct RecordRemoveResponseMessage |
336 | { | 336 | { |
337 | /** | 337 | /** |
@@ -351,13 +351,51 @@ struct RecordRemoveResponseMessage | |||
351 | */ | 351 | */ |
352 | uint16_t op_result; | 352 | uint16_t op_result; |
353 | }; | 353 | }; |
354 | GNUNET_NETWORK_STRUCT_END | 354 | |
355 | |||
356 | /** | ||
357 | * Connect to namestore service | ||
358 | */ | ||
359 | struct ZoneToNameMessage | ||
360 | { | ||
361 | struct GNUNET_NAMESTORE_Header gns_header; | ||
362 | |||
363 | /* The hash of public key of the zone to look up in */ | ||
364 | GNUNET_HashCode zone; | ||
365 | |||
366 | /* The hash of the public key of the target zone */ | ||
367 | GNUNET_HashCode value_zone; | ||
368 | }; | ||
369 | |||
370 | /** | ||
371 | * Connect to namestore service | ||
372 | */ | ||
373 | struct ZoneToNameResponseMessage | ||
374 | { | ||
375 | struct GNUNET_NAMESTORE_Header gns_header; | ||
376 | |||
377 | struct GNUNET_TIME_AbsoluteNBO expire; | ||
378 | |||
379 | uint16_t name_len; | ||
380 | |||
381 | uint16_t rd_len; | ||
382 | |||
383 | uint16_t rd_count; | ||
384 | |||
385 | int32_t contains_sig; | ||
386 | |||
387 | /* result in NBO: GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error */ | ||
388 | int16_t res; | ||
389 | |||
390 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key; | ||
391 | |||
392 | }; | ||
393 | |||
355 | 394 | ||
356 | 395 | ||
357 | /** | 396 | /** |
358 | * Start a zone iteration for the given zone | 397 | * Start a zone iteration for the given zone |
359 | */ | 398 | */ |
360 | GNUNET_NETWORK_STRUCT_BEGIN | ||
361 | struct ZoneIterationStartMessage | 399 | struct ZoneIterationStartMessage |
362 | { | 400 | { |
363 | /** | 401 | /** |
@@ -372,12 +410,11 @@ struct ZoneIterationStartMessage | |||
372 | 410 | ||
373 | GNUNET_HashCode zone; | 411 | GNUNET_HashCode zone; |
374 | }; | 412 | }; |
375 | GNUNET_NETWORK_STRUCT_END | 413 | |
376 | 414 | ||
377 | /** | 415 | /** |
378 | * Ask for next result of zone iteration for the given operation | 416 | * Ask for next result of zone iteration for the given operation |
379 | */ | 417 | */ |
380 | GNUNET_NETWORK_STRUCT_BEGIN | ||
381 | struct ZoneIterationNextMessage | 418 | struct ZoneIterationNextMessage |
382 | { | 419 | { |
383 | /** | 420 | /** |
@@ -385,13 +422,11 @@ struct ZoneIterationNextMessage | |||
385 | */ | 422 | */ |
386 | struct GNUNET_NAMESTORE_Header gns_header; | 423 | struct GNUNET_NAMESTORE_Header gns_header; |
387 | }; | 424 | }; |
388 | GNUNET_NETWORK_STRUCT_END | ||
389 | 425 | ||
390 | 426 | ||
391 | /** | 427 | /** |
392 | * Stop zone iteration for the given operation | 428 | * Stop zone iteration for the given operation |
393 | */ | 429 | */ |
394 | GNUNET_NETWORK_STRUCT_BEGIN | ||
395 | struct ZoneIterationStopMessage | 430 | struct ZoneIterationStopMessage |
396 | { | 431 | { |
397 | /** | 432 | /** |
@@ -399,12 +434,10 @@ struct ZoneIterationStopMessage | |||
399 | */ | 434 | */ |
400 | struct GNUNET_NAMESTORE_Header gns_header; | 435 | struct GNUNET_NAMESTORE_Header gns_header; |
401 | }; | 436 | }; |
402 | GNUNET_NETWORK_STRUCT_END | ||
403 | 437 | ||
404 | /** | 438 | /** |
405 | * Ask for next result of zone iteration for the given operation | 439 | * Ask for next result of zone iteration for the given operation |
406 | */ | 440 | */ |
407 | GNUNET_NETWORK_STRUCT_BEGIN | ||
408 | struct ZoneIterationResponseMessage | 441 | struct ZoneIterationResponseMessage |
409 | { | 442 | { |
410 | /** | 443 | /** |
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index 7e9a5f7ac..10c4132f6 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -467,6 +467,37 @@ handle_record_remove_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
467 | GNUNET_free (qe); | 467 | GNUNET_free (qe); |
468 | } | 468 | } |
469 | 469 | ||
470 | static void | ||
471 | handle_zone_to_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | ||
472 | struct ZoneToNameResponseMessage* msg, | ||
473 | size_t size) | ||
474 | { | ||
475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n", | ||
476 | "ZONE_TO_NAME_RESPONSE"); | ||
477 | |||
478 | struct GNUNET_NAMESTORE_Handle *h = qe->nsh; | ||
479 | int res = ntohs (msg->res); | ||
480 | |||
481 | switch (res) { | ||
482 | case GNUNET_SYSERR: | ||
483 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "An error occured during zone to name operation\n"); | ||
484 | if (qe->proc != NULL) | ||
485 | qe->proc (qe->proc_cls, NULL, GNUNET_TIME_absolute_get_zero(), NULL, 0, NULL, NULL); | ||
486 | break; | ||
487 | case GNUNET_NO: | ||
488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore has no result for zone to name mapping \n"); | ||
489 | if (qe->proc != NULL) | ||
490 | qe->proc (qe->proc_cls, NULL, GNUNET_TIME_absolute_get_zero(), NULL, 0, NULL, NULL); | ||
491 | break; | ||
492 | default: | ||
493 | break; | ||
494 | } | ||
495 | |||
496 | /* Operation done, remove */ | ||
497 | GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe); | ||
498 | GNUNET_free (qe); | ||
499 | } | ||
500 | |||
470 | 501 | ||
471 | static void | 502 | static void |
472 | manage_record_operations (struct GNUNET_NAMESTORE_QueueEntry *qe, | 503 | manage_record_operations (struct GNUNET_NAMESTORE_QueueEntry *qe, |
@@ -508,6 +539,14 @@ manage_record_operations (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
508 | } | 539 | } |
509 | handle_record_remove_response (qe, (struct RecordRemoveResponseMessage *) msg, size); | 540 | handle_record_remove_response (qe, (struct RecordRemoveResponseMessage *) msg, size); |
510 | break; | 541 | break; |
542 | case GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE: | ||
543 | if (size < sizeof (struct ZoneToNameResponseMessage)) | ||
544 | { | ||
545 | GNUNET_break_op (0); | ||
546 | break; | ||
547 | } | ||
548 | handle_zone_to_name_response (qe, (struct ZoneToNameResponseMessage *) msg, size); | ||
549 | break; | ||
511 | default: | 550 | default: |
512 | GNUNET_break_op (0); | 551 | GNUNET_break_op (0); |
513 | break; | 552 | break; |
@@ -1321,6 +1360,72 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, | |||
1321 | } | 1360 | } |
1322 | 1361 | ||
1323 | 1362 | ||
1363 | /** | ||
1364 | * Look for an existing PKEY delegation record for a given public key. | ||
1365 | * Returns at most one result to the processor. | ||
1366 | * | ||
1367 | * @param h handle to the namestore | ||
1368 | * @param zone hash of public key of the zone to look up in, never NULL | ||
1369 | * @param value_zone hash of the public key of the target zone (value), never NULL | ||
1370 | * @param proc function to call on the matching records, or with | ||
1371 | * NULL (rd_count == 0) if there are no matching records | ||
1372 | * @param proc_cls closure for proc | ||
1373 | * @return a handle that can be used to | ||
1374 | * cancel | ||
1375 | */ | ||
1376 | struct GNUNET_NAMESTORE_QueueEntry * | ||
1377 | GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, | ||
1378 | const GNUNET_HashCode *zone, | ||
1379 | const GNUNET_HashCode *value_zone, | ||
1380 | GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls) | ||
1381 | { | ||
1382 | struct GNUNET_NAMESTORE_QueueEntry *qe; | ||
1383 | struct PendingMessage *pe; | ||
1384 | size_t msg_size = 0; | ||
1385 | uint32_t rid = 0; | ||
1386 | |||
1387 | GNUNET_assert (NULL != h); | ||
1388 | GNUNET_assert (NULL != zone); | ||
1389 | GNUNET_assert (NULL != value_zone); | ||
1390 | |||
1391 | rid = get_op_id(h); | ||
1392 | qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); | ||
1393 | qe->nsh = h; | ||
1394 | qe->proc = proc; | ||
1395 | qe->proc_cls = proc_cls; | ||
1396 | qe->op_id = rid; | ||
1397 | GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe); | ||
1398 | |||
1399 | /* set msg_size*/ | ||
1400 | msg_size = sizeof (struct ZoneToNameMessage); | ||
1401 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); | ||
1402 | |||
1403 | /* create msg here */ | ||
1404 | struct ZoneToNameMessage * msg; | ||
1405 | pe->size = msg_size; | ||
1406 | pe->is_init = GNUNET_NO; | ||
1407 | msg = (struct ZoneToNameMessage *) &pe[1]; | ||
1408 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME); | ||
1409 | msg->gns_header.header.size = htons (msg_size); | ||
1410 | msg->gns_header.r_id = htonl (rid); | ||
1411 | msg->zone = *zone; | ||
1412 | msg->value_zone = *value_zone; | ||
1413 | |||
1414 | char * z_tmp = strdup (GNUNET_h2s (zone)); | ||
1415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for zone `%s' in zone `%s'\n", | ||
1416 | "NAMESTORE_ZONE_TO_NAME", | ||
1417 | z_tmp, | ||
1418 | GNUNET_h2s (value_zone)); | ||
1419 | GNUNET_free (z_tmp); | ||
1420 | |||
1421 | /* transmit message */ | ||
1422 | GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); | ||
1423 | do_transmit(h); | ||
1424 | |||
1425 | return qe; | ||
1426 | } | ||
1427 | |||
1428 | |||
1324 | 1429 | ||
1325 | /** | 1430 | /** |
1326 | * Starts a new zone iteration (used to periodically PUT all of our | 1431 | * Starts a new zone iteration (used to periodically PUT all of our |
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf index f4cd32dbd..c437b414a 100644 --- a/src/namestore/test_namestore_api.conf +++ b/src/namestore/test_namestore_api.conf | |||
@@ -4,7 +4,7 @@ DEFAULTSERVICES = namestore | |||
4 | UNIXPATH = /tmp/gnunet-p1-service-arm.sock | 4 | UNIXPATH = /tmp/gnunet-p1-service-arm.sock |
5 | 5 | ||
6 | [namestore] | 6 | [namestore] |
7 | #PREFIX = valgrind --leak-check=full | 7 | PREFIX = valgrind --leak-check=full |
8 | AUTOSTART = YES | 8 | AUTOSTART = YES |
9 | UNIXPATH = /tmp/gnunet-service-namestore.sock | 9 | UNIXPATH = /tmp/gnunet-service-namestore.sock |
10 | UNIX_MATCH_UID = YES | 10 | UNIX_MATCH_UID = YES |
diff --git a/src/namestore/test_namestore_api_zone_to_name.c b/src/namestore/test_namestore_api_zone_to_name.c new file mode 100644 index 000000000..387d58272 --- /dev/null +++ b/src/namestore/test_namestore_api_zone_to_name.c | |||
@@ -0,0 +1,216 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file namestore/test_namestore_api_zone_to_name.c | ||
22 | * @brief testcase for zone to name translation | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_common.h" | ||
26 | #include "gnunet_namestore_service.h" | ||
27 | #include "namestore.h" | ||
28 | #include "gnunet_signatures.h" | ||
29 | |||
30 | #define VERBOSE GNUNET_NO | ||
31 | |||
32 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
33 | |||
34 | static struct GNUNET_NAMESTORE_Handle * nsh; | ||
35 | |||
36 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | ||
37 | static struct GNUNET_OS_Process *arm; | ||
38 | |||
39 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; | ||
40 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | ||
41 | |||
42 | static GNUNET_HashCode s_zone; | ||
43 | static GNUNET_HashCode s_zone_value; | ||
44 | |||
45 | static int res; | ||
46 | |||
47 | static void | ||
48 | start_arm (const char *cfgname) | ||
49 | { | ||
50 | arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
51 | "gnunet-service-arm", "-c", cfgname, | ||
52 | #if VERBOSE_PEERS | ||
53 | "-L", "DEBUG", | ||
54 | #else | ||
55 | "-L", "ERROR", | ||
56 | #endif | ||
57 | NULL); | ||
58 | } | ||
59 | |||
60 | static void | ||
61 | stop_arm () | ||
62 | { | ||
63 | if (NULL != arm) | ||
64 | { | ||
65 | if (0 != GNUNET_OS_process_kill (arm, SIGTERM)) | ||
66 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
67 | GNUNET_OS_process_wait (arm); | ||
68 | GNUNET_OS_process_close (arm); | ||
69 | arm = NULL; | ||
70 | } | ||
71 | } | ||
72 | |||
73 | /** | ||
74 | * Re-establish the connection to the service. | ||
75 | * | ||
76 | * @param cls handle to use to re-connect. | ||
77 | * @param tc scheduler context | ||
78 | */ | ||
79 | static void | ||
80 | endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
81 | { | ||
82 | if (nsh != NULL) | ||
83 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); | ||
84 | nsh = NULL; | ||
85 | |||
86 | if (privkey != NULL) | ||
87 | GNUNET_CRYPTO_rsa_key_free (privkey); | ||
88 | privkey = NULL; | ||
89 | |||
90 | if (NULL != arm) | ||
91 | stop_arm(); | ||
92 | |||
93 | res = 1; | ||
94 | } | ||
95 | |||
96 | |||
97 | static void | ||
98 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
99 | { | ||
100 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | ||
101 | { | ||
102 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
103 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | ||
104 | } | ||
105 | |||
106 | if (privkey != NULL) | ||
107 | GNUNET_CRYPTO_rsa_key_free (privkey); | ||
108 | privkey = NULL; | ||
109 | |||
110 | if (nsh != NULL) | ||
111 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); | ||
112 | nsh = NULL; | ||
113 | |||
114 | if (NULL != arm) | ||
115 | stop_arm(); | ||
116 | } | ||
117 | |||
118 | void zone_to_name_proc (void *cls, | ||
119 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | ||
120 | struct GNUNET_TIME_Absolute expire, | ||
121 | const char *n, | ||
122 | unsigned int rd_count, | ||
123 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
124 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
125 | { | ||
126 | if ((zone_key == NULL) && (n == NULL) && (rd_count == 0) && (rd == NULL) && (signature == NULL)) | ||
127 | { | ||
128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No result found\n"); | ||
129 | res = 0; | ||
130 | } | ||
131 | else | ||
132 | { | ||
133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result found\n"); | ||
134 | res = 0; | ||
135 | } | ||
136 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
137 | } | ||
138 | |||
139 | |||
140 | void | ||
141 | delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
142 | { | ||
143 | char *afsdir; | ||
144 | |||
145 | if (GNUNET_OK == | ||
146 | GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite", | ||
147 | "FILENAME", &afsdir)) | ||
148 | { | ||
149 | if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) | ||
150 | if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) | ||
151 | if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir)) | ||
152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir); | ||
153 | GNUNET_free (afsdir); | ||
154 | } | ||
155 | |||
156 | } | ||
157 | |||
158 | static void | ||
159 | run (void *cls, char *const *args, const char *cfgfile, | ||
160 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
161 | { | ||
162 | delete_existing_db(cfg); | ||
163 | |||
164 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); | ||
165 | |||
166 | /* load privat key */ | ||
167 | privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey"); | ||
168 | GNUNET_assert (privkey != NULL); | ||
169 | /* get public key */ | ||
170 | GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); | ||
171 | |||
172 | /* zone hash */ | ||
173 | GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone); | ||
174 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &s_zone_value); | ||
175 | |||
176 | start_arm (cfgfile); | ||
177 | GNUNET_assert (arm != NULL); | ||
178 | |||
179 | nsh = GNUNET_NAMESTORE_connect (cfg); | ||
180 | GNUNET_break (NULL != nsh); | ||
181 | |||
182 | /* create initial record */ | ||
183 | GNUNET_NAMESTORE_zone_to_name (nsh, &s_zone, &s_zone_value, zone_to_name_proc, NULL); | ||
184 | } | ||
185 | |||
186 | static int | ||
187 | check () | ||
188 | { | ||
189 | static char *const argv[] = { "test-namestore-api", | ||
190 | "-c", | ||
191 | "test_namestore_api.conf", | ||
192 | #if VERBOSE | ||
193 | "-L", "DEBUG", | ||
194 | #endif | ||
195 | NULL | ||
196 | }; | ||
197 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
198 | GNUNET_GETOPT_OPTION_END | ||
199 | }; | ||
200 | |||
201 | res = 1; | ||
202 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-namestore-api", | ||
203 | "nohelp", options, &run, &res); | ||
204 | return res; | ||
205 | } | ||
206 | |||
207 | int | ||
208 | main (int argc, char *argv[]) | ||
209 | { | ||
210 | int ret; | ||
211 | |||
212 | ret = check (); | ||
213 | return ret; | ||
214 | } | ||
215 | |||
216 | /* end of test_namestore_api.c */ | ||