diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-10-25 15:36:32 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-10-25 15:36:32 +0000 |
commit | 0b80f1a54fd5efba4bca8dc4269cc0cb8e25d77d (patch) | |
tree | 52a514ecf5d7cb4dda055a0a9c5c9ea0d78a8a77 /src/namestore | |
parent | 1ef878cfd071e9273ca2f8e11e743cfe6886ac1a (diff) | |
download | gnunet-0b80f1a54fd5efba4bca8dc4269cc0cb8e25d77d.tar.gz gnunet-0b80f1a54fd5efba4bca8dc4269cc0cb8e25d77d.zip |
api communication done
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 110 | ||||
-rw-r--r-- | src/namestore/namestore.h | 41 | ||||
-rw-r--r-- | src/namestore/namestore_api.c | 75 | ||||
-rw-r--r-- | src/namestore/test_namestore_api_lookup_private.c | 40 |
4 files changed, 251 insertions, 15 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 79e154cc2..3332ffcc6 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -561,6 +561,48 @@ refresh_block (struct GNUNET_SERVER_Client *client, | |||
561 | GNUNET_free (block); | 561 | GNUNET_free (block); |
562 | } | 562 | } |
563 | 563 | ||
564 | |||
565 | struct RecordLookupContext | ||
566 | { | ||
567 | const char *label; | ||
568 | |||
569 | int found; | ||
570 | |||
571 | unsigned int res_rd_count; | ||
572 | |||
573 | size_t rd_ser_len; | ||
574 | |||
575 | char *res_rd; | ||
576 | }; | ||
577 | |||
578 | static void lookup_it (void *cls, | ||
579 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, | ||
580 | const char *label, | ||
581 | unsigned int rd_count, | ||
582 | const struct GNUNET_GNSRECORD_Data *rd) | ||
583 | { | ||
584 | struct RecordLookupContext *rlc = cls; | ||
585 | |||
586 | if (0 == strcmp (label, rlc->label)) | ||
587 | { | ||
588 | rlc->found = GNUNET_YES; | ||
589 | if (0 != rd_count) | ||
590 | { | ||
591 | rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); | ||
592 | rlc->res_rd_count = rd_count; | ||
593 | rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len); | ||
594 | GNUNET_GNSRECORD_records_serialize (rd_count, rd, rlc->rd_ser_len , rlc->res_rd); | ||
595 | } | ||
596 | else | ||
597 | { | ||
598 | rlc->rd_ser_len = 0; | ||
599 | rlc->res_rd_count = 0; | ||
600 | rlc->res_rd = NULL; | ||
601 | } | ||
602 | } | ||
603 | } | ||
604 | |||
605 | |||
564 | /** | 606 | /** |
565 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message | 607 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message |
566 | * | 608 | * |
@@ -573,11 +615,16 @@ handle_record_lookup (void *cls, | |||
573 | struct GNUNET_SERVER_Client *client, | 615 | struct GNUNET_SERVER_Client *client, |
574 | const struct GNUNET_MessageHeader *message) | 616 | const struct GNUNET_MessageHeader *message) |
575 | { | 617 | { |
576 | const struct LabelLookupMessage * ll_msg; | 618 | const struct LabelLookupMessage *ll_msg; |
619 | struct LabelLookupResponseMessage *llr_msg; | ||
620 | struct RecordLookupContext rlc; | ||
577 | const char *name_tmp; | 621 | const char *name_tmp; |
578 | uint32_t rid; | 622 | char *res_name; |
579 | uint32_t name_len; | 623 | uint32_t name_len; |
580 | size_t msg_size; | 624 | size_t src_size; |
625 | size_t res_size; | ||
626 | int offset; | ||
627 | int res; | ||
581 | 628 | ||
582 | if (ntohs (message->size) < sizeof (struct LabelLookupMessage)) | 629 | if (ntohs (message->size) < sizeof (struct LabelLookupMessage)) |
583 | { | 630 | { |
@@ -587,21 +634,64 @@ handle_record_lookup (void *cls, | |||
587 | } | 634 | } |
588 | 635 | ||
589 | ll_msg = (const struct LabelLookupMessage *) message; | 636 | ll_msg = (const struct LabelLookupMessage *) message; |
590 | rid = ntohl (ll_msg->gns_header.r_id); | 637 | name_len = ntohl (ll_msg->label_len); |
591 | name_len = ntohs (ll_msg->label_len); | 638 | src_size = ntohs (message->size); |
592 | msg_size = ntohs (message->size); | 639 | |
640 | if (name_len != src_size - sizeof (struct LabelLookupMessage)) | ||
641 | { | ||
642 | GNUNET_break (0); | ||
643 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
644 | return; | ||
645 | } | ||
593 | 646 | ||
594 | if (name_len != msg_size - sizeof (struct LabelLookupMessage)) | 647 | name_tmp = (const char *) &ll_msg[1]; |
648 | if ('\0' != name_tmp[name_len -1]) | ||
595 | { | 649 | { |
596 | GNUNET_break (0); | 650 | GNUNET_break (0); |
597 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 651 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
598 | return; | 652 | return; |
599 | } | 653 | } |
600 | name_tmp = &ll_msg[1]; | ||
601 | 654 | ||
655 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
602 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 656 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
603 | "Received `%s' message for name `%s'\n", | 657 | "Received `%s' message for name `%s'\n", |
604 | "NAMESTORE_RECORD_LOOKUP", name_tmp); | 658 | "NAMESTORE_RECORD_LOOKUP", name_tmp); |
659 | |||
660 | |||
661 | rlc.label = name_tmp; | ||
662 | rlc.found = GNUNET_NO; | ||
663 | rlc.res_rd_count = 0; | ||
664 | rlc.rd_ser_len = 0; | ||
665 | rlc.res_rd = NULL; | ||
666 | |||
667 | offset = 0; | ||
668 | do | ||
669 | { | ||
670 | /* changee this call */ | ||
671 | res = GSN_database->iterate_records (GSN_database->cls, | ||
672 | &ll_msg->zone, offset, &lookup_it, &rlc); | ||
673 | offset++; | ||
674 | } | ||
675 | while ((GNUNET_NO == rlc.found) && (GNUNET_OK == res)); | ||
676 | |||
677 | res_size = sizeof (struct LabelLookupResponseMessage) + name_len + rlc.rd_ser_len; | ||
678 | llr_msg = GNUNET_malloc (res_size); | ||
679 | llr_msg->gns_header.header.size = htons (res_size); | ||
680 | llr_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE); | ||
681 | llr_msg->gns_header.r_id = ll_msg->gns_header.r_id; | ||
682 | llr_msg->private_key = ll_msg->zone; | ||
683 | llr_msg->name_len = htons (name_len); | ||
684 | llr_msg->rd_count = htons (rlc.res_rd_count); | ||
685 | llr_msg->rd_len = htons (rlc.rd_ser_len); | ||
686 | res_name = (char *) &llr_msg[1]; | ||
687 | memcpy (&llr_msg[1], name_tmp, name_len); | ||
688 | memcpy (&res_name[name_len], rlc.res_rd, rlc.rd_ser_len); | ||
689 | |||
690 | GNUNET_SERVER_notification_context_unicast (snc, client, &llr_msg->gns_header.header, | ||
691 | GNUNET_NO); | ||
692 | |||
693 | GNUNET_free_non_null (rlc.res_rd); | ||
694 | GNUNET_free (llr_msg); | ||
605 | } | 695 | } |
606 | 696 | ||
607 | 697 | ||
@@ -963,7 +1053,7 @@ struct ZoneIterationProcResult | |||
963 | * @param rd record data | 1053 | * @param rd record data |
964 | */ | 1054 | */ |
965 | static void | 1055 | static void |
966 | zone_iteraterate_proc (void *cls, | 1056 | zone_iterate_proc (void *cls, |
967 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 1057 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
968 | const char *name, | 1058 | const char *name, |
969 | unsigned int rd_count, | 1059 | unsigned int rd_count, |
@@ -1036,7 +1126,7 @@ run_zone_iteration_round (struct ZoneIteration *zi) | |||
1036 | ? NULL | 1126 | ? NULL |
1037 | : &zi->zone, | 1127 | : &zi->zone, |
1038 | zi->offset, | 1128 | zi->offset, |
1039 | &zone_iteraterate_proc, &proc))) | 1129 | &zone_iterate_proc, &proc))) |
1040 | { | 1130 | { |
1041 | GNUNET_break (0); | 1131 | GNUNET_break (0); |
1042 | break; | 1132 | break; |
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h index d633f7393..5e900dbcc 100644 --- a/src/namestore/namestore.h +++ b/src/namestore/namestore.h | |||
@@ -235,6 +235,47 @@ struct LabelLookupMessage | |||
235 | }; | 235 | }; |
236 | 236 | ||
237 | 237 | ||
238 | /** | ||
239 | * Lookup a label | ||
240 | */ | ||
241 | struct LabelLookupResponseMessage | ||
242 | { | ||
243 | /** | ||
244 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE | ||
245 | */ | ||
246 | struct GNUNET_NAMESTORE_Header gns_header; | ||
247 | |||
248 | /** | ||
249 | * Name length | ||
250 | */ | ||
251 | uint16_t name_len GNUNET_PACKED; | ||
252 | |||
253 | /** | ||
254 | * Length of serialized record data | ||
255 | */ | ||
256 | uint16_t rd_len GNUNET_PACKED; | ||
257 | |||
258 | /** | ||
259 | * Number of records contained | ||
260 | */ | ||
261 | uint16_t rd_count GNUNET_PACKED; | ||
262 | |||
263 | /** | ||
264 | * always zero (for alignment) | ||
265 | */ | ||
266 | uint16_t reserved GNUNET_PACKED; | ||
267 | |||
268 | /** | ||
269 | * The private key of the authority. | ||
270 | */ | ||
271 | struct GNUNET_CRYPTO_EcdsaPrivateKey private_key; | ||
272 | |||
273 | /* followed by: | ||
274 | * name with length name_len | ||
275 | * serialized record data with rd_count records | ||
276 | */ | ||
277 | }; | ||
278 | |||
238 | 279 | ||
239 | 280 | ||
240 | /** | 281 | /** |
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index 9d290fca2..303b05c98 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -281,6 +281,72 @@ handle_record_store_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
281 | 281 | ||
282 | /** | 282 | /** |
283 | * Handle an incoming message of type | 283 | * Handle an incoming message of type |
284 | * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE | ||
285 | * | ||
286 | * @param qe the respective entry in the message queue | ||
287 | * @param msg the message we received | ||
288 | * @param size the message size | ||
289 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error and we did NOT notify the client | ||
290 | */ | ||
291 | static int | ||
292 | handle_lookup_result (struct GNUNET_NAMESTORE_QueueEntry *qe, | ||
293 | const struct LabelLookupResponseMessage *msg, | ||
294 | size_t size) | ||
295 | { | ||
296 | const char *name; | ||
297 | const char *rd_tmp; | ||
298 | size_t exp_msg_len; | ||
299 | size_t msg_len; | ||
300 | size_t name_len; | ||
301 | size_t rd_len; | ||
302 | unsigned int rd_count; | ||
303 | |||
304 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
305 | "Received `%s'\n", | ||
306 | "RECORD_LOOKUP_RESULT"); | ||
307 | |||
308 | rd_len = ntohs (msg->rd_len); | ||
309 | rd_count = ntohs (msg->rd_count); | ||
310 | msg_len = ntohs (msg->gns_header.header.size); | ||
311 | name_len = ntohs (msg->name_len); | ||
312 | GNUNET_break (0 == ntohs (msg->reserved)); | ||
313 | exp_msg_len = sizeof (struct LabelLookupResponseMessage) + name_len + rd_len; | ||
314 | if (msg_len != exp_msg_len) | ||
315 | { | ||
316 | GNUNET_break (0); | ||
317 | return GNUNET_SYSERR; | ||
318 | } | ||
319 | name = (const char *) &msg[1]; | ||
320 | if ( (name_len > 0) && | ||
321 | ('\0' != name[name_len -1]) ) | ||
322 | { | ||
323 | GNUNET_break (0); | ||
324 | return GNUNET_SYSERR; | ||
325 | } | ||
326 | rd_tmp = &name[name_len]; | ||
327 | { | ||
328 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | ||
329 | |||
330 | if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize(rd_len, rd_tmp, rd_count, rd)) | ||
331 | { | ||
332 | GNUNET_break (0); | ||
333 | return GNUNET_SYSERR; | ||
334 | } | ||
335 | if (0 == name_len) | ||
336 | name = NULL; | ||
337 | if (NULL != qe->proc) | ||
338 | qe->proc (qe->proc_cls, | ||
339 | &msg->private_key, | ||
340 | name, | ||
341 | rd_count, | ||
342 | (rd_count > 0) ? rd : NULL); | ||
343 | } | ||
344 | return GNUNET_OK; | ||
345 | } | ||
346 | |||
347 | |||
348 | /** | ||
349 | * Handle an incoming message of type | ||
284 | * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT | 350 | * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT |
285 | * | 351 | * |
286 | * @param qe the respective entry in the message queue | 352 | * @param qe the respective entry in the message queue |
@@ -462,6 +528,13 @@ manage_record_operations (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
462 | return GNUNET_SYSERR; | 528 | return GNUNET_SYSERR; |
463 | } | 529 | } |
464 | return handle_record_result (qe, (const struct RecordResultMessage *) msg, size); | 530 | return handle_record_result (qe, (const struct RecordResultMessage *) msg, size); |
531 | case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE: | ||
532 | if (size < sizeof (struct LabelLookupResponseMessage)) | ||
533 | { | ||
534 | GNUNET_break (0); | ||
535 | return GNUNET_SYSERR; | ||
536 | } | ||
537 | return handle_lookup_result (qe, (const struct LabelLookupResponseMessage *) msg, size); | ||
465 | default: | 538 | default: |
466 | GNUNET_break (0); | 539 | GNUNET_break (0); |
467 | return GNUNET_SYSERR; | 540 | return GNUNET_SYSERR; |
@@ -1026,7 +1099,7 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, | |||
1026 | msg->gns_header.header.size = htons (msg_size); | 1099 | msg->gns_header.header.size = htons (msg_size); |
1027 | msg->gns_header.r_id = htonl (qe->op_id); | 1100 | msg->gns_header.r_id = htonl (qe->op_id); |
1028 | msg->zone = *pkey; | 1101 | msg->zone = *pkey; |
1029 | msg->label_len = htons(label_len); | 1102 | msg->label_len = htonl(label_len); |
1030 | memcpy (&msg[1], label, label_len); | 1103 | memcpy (&msg[1], label, label_len); |
1031 | 1104 | ||
1032 | /* transmit message */ | 1105 | /* transmit message */ |
diff --git a/src/namestore/test_namestore_api_lookup_private.c b/src/namestore/test_namestore_api_lookup_private.c index 65b7f87c6..e1aa6b8b8 100644 --- a/src/namestore/test_namestore_api_lookup_private.c +++ b/src/namestore/test_namestore_api_lookup_private.c | |||
@@ -45,7 +45,8 @@ static int res; | |||
45 | 45 | ||
46 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | 46 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; |
47 | 47 | ||
48 | static const char * name = "dummy.dummy.gnunet"; | 48 | //static const char * name = "dummy.dummy.gnunet"; |
49 | static const char * name = "d"; | ||
49 | 50 | ||
50 | static void | 51 | static void |
51 | cleanup () | 52 | cleanup () |
@@ -96,14 +97,45 @@ void lookup_it (void *cls, | |||
96 | unsigned int rd_count, | 97 | unsigned int rd_count, |
97 | const struct GNUNET_GNSRECORD_Data *rd) | 98 | const struct GNUNET_GNSRECORD_Data *rd) |
98 | { | 99 | { |
99 | nsqe = NULL; | 100 | nsqe = NULL; |
100 | /* Check here */ | 101 | |
102 | if (0 != memcmp(privkey, zone, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | ||
103 | { | ||
104 | GNUNET_break(0); | ||
105 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
106 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | ||
107 | return; | ||
108 | } | ||
101 | 109 | ||
102 | 110 | ||
111 | if (NULL == label) | ||
112 | { | ||
113 | GNUNET_break(0); | ||
114 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
115 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | ||
116 | return; | ||
117 | } | ||
118 | |||
119 | if (0 != strcmp (label, name)) | ||
120 | { | ||
121 | GNUNET_break(0); | ||
122 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
123 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | ||
124 | return; | ||
125 | } | ||
126 | |||
127 | if (1 != rd_count) | ||
128 | { | ||
129 | GNUNET_break(0); | ||
130 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
131 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); | ||
132 | return; | ||
133 | } | ||
134 | |||
103 | /* Done */ | 135 | /* Done */ |
104 | GNUNET_SCHEDULER_cancel (endbadly_task); | 136 | GNUNET_SCHEDULER_cancel (endbadly_task); |
105 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | 137 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; |
106 | GNUNET_SCHEDULER_add_now (&end, NULL); | 138 | GNUNET_SCHEDULER_add_now (&end, NULL ); |
107 | } | 139 | } |
108 | 140 | ||
109 | 141 | ||