diff options
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/Makefile.am | 3 | ||||
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 91 | ||||
-rw-r--r-- | src/namestore/namestore.h | 69 | ||||
-rw-r--r-- | src/namestore/namestore_api.c | 96 | ||||
-rw-r--r-- | src/namestore/plugin_namestore_sqlite.c | 2 | ||||
-rw-r--r-- | src/namestore/test_namestore_api.c | 37 | ||||
-rw-r--r-- | src/namestore/test_namestore_api.conf | 2 |
7 files changed, 273 insertions, 27 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index 6f19d96d3..f3211d6a0 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am | |||
@@ -76,7 +76,8 @@ test_namestore_api_LDADD = \ | |||
76 | 76 | ||
77 | EXTRADIST = \ | 77 | EXTRADIST = \ |
78 | test_namestore_api.conf \ | 78 | test_namestore_api.conf \ |
79 | test_plugin_namestore_sqlite.conf | 79 | test_plugin_namestore_sqlite.conf \ |
80 | hostkey | ||
80 | 81 | ||
81 | 82 | ||
82 | test_plugin_namestore_sqlite_SOURCES = \ | 83 | test_plugin_namestore_sqlite_SOURCES = \ |
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index e7c03bf21..1700925de 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -287,7 +287,6 @@ handle_lookup_name_it (void *cls, | |||
287 | 287 | ||
288 | if (GNUNET_YES == contains_signature) | 288 | if (GNUNET_YES == contains_signature) |
289 | memcpy (signature_tmp, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature)); | 289 | memcpy (signature_tmp, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature)); |
290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DONE `%s' message\n", "NAMESTORE_LOOKUP_NAME_RESPONSE"); | ||
291 | GNUNET_SERVER_notification_context_unicast (snc, lnc->nc->client, (const struct GNUNET_MessageHeader *) lnr_msg, GNUNET_NO); | 290 | GNUNET_SERVER_notification_context_unicast (snc, lnc->nc->client, (const struct GNUNET_MessageHeader *) lnr_msg, GNUNET_NO); |
292 | 291 | ||
293 | GNUNET_free (lnr_msg); | 292 | GNUNET_free (lnr_msg); |
@@ -349,6 +348,94 @@ static void handle_lookup_name (void *cls, | |||
349 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 348 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
350 | } | 349 | } |
351 | 350 | ||
351 | static void handle_record_put (void *cls, | ||
352 | struct GNUNET_SERVER_Client * client, | ||
353 | const struct GNUNET_MessageHeader * message) | ||
354 | { | ||
355 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_PUT"); | ||
356 | struct GNUNET_NAMESTORE_Client *nc; | ||
357 | struct GNUNET_TIME_Absolute expire; | ||
358 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key; | ||
359 | struct GNUNET_NAMESTORE_RecordData *rd; | ||
360 | struct GNUNET_CRYPTO_RsaSignature *signature; | ||
361 | struct RecordPutResponseMessage rpr_msg; | ||
362 | size_t name_len; | ||
363 | size_t msg_size; | ||
364 | size_t msg_size_exp; | ||
365 | char * name; | ||
366 | uint32_t id = 0; | ||
367 | uint32_t rd_count; | ||
368 | int res = GNUNET_SYSERR; | ||
369 | |||
370 | if (ntohs (message->size) < sizeof (struct RecordPutMessage)) | ||
371 | { | ||
372 | GNUNET_break_op (0); | ||
373 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
374 | return; | ||
375 | } | ||
376 | |||
377 | nc = client_lookup(client); | ||
378 | if (nc == NULL) | ||
379 | { | ||
380 | GNUNET_break_op (0); | ||
381 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
382 | return; | ||
383 | } | ||
384 | |||
385 | struct RecordPutMessage * rp_msg = (struct RecordPutMessage *) message; | ||
386 | id = ntohl (rp_msg->op_id); | ||
387 | name_len = ntohs (rp_msg->name_len); | ||
388 | rd_count = ntohl(rp_msg->rd_count); | ||
389 | msg_size = ntohs (message->size); | ||
390 | msg_size_exp = sizeof (struct RecordPutMessage) + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + name_len + rd_count * (sizeof (struct GNUNET_NAMESTORE_RecordData)); | ||
391 | |||
392 | if (msg_size != msg_size_exp) | ||
393 | { | ||
394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size); | ||
395 | GNUNET_break_op (0); | ||
396 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
397 | return; | ||
398 | } | ||
399 | |||
400 | |||
401 | if ((name_len == 0) || (name_len > 256)) | ||
402 | { | ||
403 | GNUNET_break_op (0); | ||
404 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
405 | return; | ||
406 | } | ||
407 | |||
408 | zone_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &rp_msg[1]; | ||
409 | name = (char *) &zone_key[1]; | ||
410 | expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire); | ||
411 | signature = (struct GNUNET_CRYPTO_RsaSignature *) &rp_msg->signature; | ||
412 | rd = (struct GNUNET_NAMESTORE_RecordData *) &name[name_len]; | ||
413 | |||
414 | /* Database operation */ | ||
415 | res = GSN_database->put_records(GSN_database->cls, | ||
416 | zone_key, | ||
417 | expire, | ||
418 | name, | ||
419 | rd_count, rd, | ||
420 | signature); | ||
421 | |||
422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting record for name `%s': %s\n", | ||
423 | name, (res == GNUNET_OK) ? "OK" : "FAIL"); | ||
424 | |||
425 | /* Send response */ | ||
426 | |||
427 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_PUT_RESPONSE"); | ||
428 | rpr_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE); | ||
429 | rpr_msg.op_id = rp_msg->op_id; | ||
430 | rpr_msg.header.size = htons (sizeof (struct RecordPutResponseMessage)); | ||
431 | if (GNUNET_OK == res) | ||
432 | rpr_msg.op_result = htons (GNUNET_OK); | ||
433 | else | ||
434 | rpr_msg.op_result = htons (GNUNET_NO); | ||
435 | GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rpr_msg, GNUNET_NO); | ||
436 | |||
437 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
438 | } | ||
352 | 439 | ||
353 | /** | 440 | /** |
354 | * Process template requests. | 441 | * Process template requests. |
@@ -370,6 +457,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
370 | GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)}, | 457 | GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)}, |
371 | {&handle_lookup_name, NULL, | 458 | {&handle_lookup_name, NULL, |
372 | GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, 0}, | 459 | GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, 0}, |
460 | {&handle_record_put, NULL, | ||
461 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT, 0}, | ||
373 | {NULL, NULL, 0, 0} | 462 | {NULL, NULL, 0, 0} |
374 | }; | 463 | }; |
375 | 464 | ||
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h index 143f233d4..03b4bb45a 100644 --- a/src/namestore/namestore.h +++ b/src/namestore/namestore.h | |||
@@ -31,6 +31,8 @@ | |||
31 | */ | 31 | */ |
32 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME 431 | 32 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME 431 |
33 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE 432 | 33 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE 432 |
34 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT 433 | ||
35 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE 434 | ||
34 | 36 | ||
35 | GNUNET_NETWORK_STRUCT_BEGIN | 37 | GNUNET_NETWORK_STRUCT_BEGIN |
36 | /** | 38 | /** |
@@ -67,11 +69,10 @@ struct GenericMessage | |||
67 | GNUNET_NETWORK_STRUCT_END | 69 | GNUNET_NETWORK_STRUCT_END |
68 | 70 | ||
69 | 71 | ||
70 | |||
71 | GNUNET_NETWORK_STRUCT_BEGIN | ||
72 | /** | 72 | /** |
73 | * Connect to namestore service | 73 | * Connect to namestore service |
74 | */ | 74 | */ |
75 | GNUNET_NETWORK_STRUCT_BEGIN | ||
75 | struct LookupNameMessage | 76 | struct LookupNameMessage |
76 | { | 77 | { |
77 | /** | 78 | /** |
@@ -96,15 +97,12 @@ struct LookupNameMessage | |||
96 | GNUNET_NETWORK_STRUCT_END | 97 | GNUNET_NETWORK_STRUCT_END |
97 | 98 | ||
98 | 99 | ||
99 | |||
100 | GNUNET_NETWORK_STRUCT_BEGIN | ||
101 | |||
102 | /** | 100 | /** |
103 | * Lookup response | 101 | * Lookup response |
104 | * Memory layout: | 102 | * Memory layout: |
105 | * [struct LookupNameResponseMessage][struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded][char *name][rc_count * struct GNUNET_NAMESTORE_RecordData][struct GNUNET_CRYPTO_RsaSignature] | 103 | * [struct LookupNameResponseMessage][struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded][char *name][rc_count * struct GNUNET_NAMESTORE_RecordData][struct GNUNET_CRYPTO_RsaSignature] |
106 | */ | 104 | */ |
107 | 105 | GNUNET_NETWORK_STRUCT_BEGIN | |
108 | struct LookupNameResponseMessage | 106 | struct LookupNameResponseMessage |
109 | { | 107 | { |
110 | /** | 108 | /** |
@@ -126,10 +124,69 @@ struct LookupNameResponseMessage | |||
126 | /* Requested record type */ | 124 | /* Requested record type */ |
127 | uint32_t rc_count; | 125 | uint32_t rc_count; |
128 | }; | 126 | }; |
127 | GNUNET_NETWORK_STRUCT_END | ||
128 | |||
129 | |||
130 | /** | ||
131 | * Put a record to the namestore | ||
132 | * Memory layout: | ||
133 | * [struct RecordPutMessage][struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded][char *name][rc_count * struct GNUNET_NAMESTORE_RecordData] | ||
134 | */ | ||
135 | GNUNET_NETWORK_STRUCT_BEGIN | ||
136 | struct RecordPutMessage | ||
137 | { | ||
138 | /** | ||
139 | * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_RECORD_PUT | ||
140 | */ | ||
141 | struct GNUNET_MessageHeader header; | ||
142 | |||
143 | /** | ||
144 | * Operation ID in NBO | ||
145 | */ | ||
146 | uint32_t op_id; | ||
147 | |||
148 | /* Contenct starts here */ | ||
149 | |||
150 | /* name length */ | ||
151 | uint16_t name_len; | ||
152 | |||
153 | /* Requested record type */ | ||
154 | uint32_t rd_count; | ||
155 | |||
156 | struct GNUNET_TIME_AbsoluteNBO expire; | ||
157 | |||
158 | struct GNUNET_CRYPTO_RsaSignature signature; | ||
159 | }; | ||
160 | GNUNET_NETWORK_STRUCT_END | ||
161 | |||
162 | /** | ||
163 | * Put a record to the namestore | ||
164 | * Memory layout: | ||
165 | * [struct RecordPutMessage][struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded][char *name][rc_count * struct GNUNET_NAMESTORE_RecordData] | ||
166 | */ | ||
167 | GNUNET_NETWORK_STRUCT_BEGIN | ||
168 | struct RecordPutResponseMessage | ||
169 | { | ||
170 | /** | ||
171 | * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE | ||
172 | */ | ||
173 | struct GNUNET_MessageHeader header; | ||
129 | 174 | ||
175 | /** | ||
176 | * Operation ID in NBO | ||
177 | */ | ||
178 | uint32_t op_id; | ||
179 | |||
180 | /* Contenct starts here */ | ||
130 | 181 | ||
182 | /** | ||
183 | * name length: GNUNET_NO (0) on error, GNUNET_OK (1) on success | ||
184 | */ | ||
185 | uint16_t op_result; | ||
186 | }; | ||
131 | GNUNET_NETWORK_STRUCT_END | 187 | GNUNET_NETWORK_STRUCT_END |
132 | 188 | ||
133 | 189 | ||
190 | |||
134 | /* end of namestore.h */ | 191 | /* end of namestore.h */ |
135 | #endif | 192 | #endif |
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index 21b24567a..882e5a5de 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -245,12 +245,51 @@ handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
245 | { | 245 | { |
246 | qe->proc (qe->proc_cls, zone_key, expire, name, rd_count, rd, signature); | 246 | qe->proc (qe->proc_cls, zone_key, expire, name, rd_count, rd, signature); |
247 | } | 247 | } |
248 | /* Operation done, remove */ | ||
249 | GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe); | ||
250 | GNUNET_free (qe); | ||
251 | } | ||
252 | |||
253 | |||
254 | static void | ||
255 | handle_record_put_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | ||
256 | struct RecordPutResponseMessage* msg, | ||
257 | size_t size) | ||
258 | { | ||
259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n", | ||
260 | "RECORD_PUT_RESPONSE"); | ||
261 | |||
262 | struct GNUNET_NAMESTORE_Handle *h = qe->nsh; | ||
263 | int res = GNUNET_OK; | ||
264 | |||
265 | if (ntohs (msg->op_result) == GNUNET_OK) | ||
266 | { | ||
267 | res = GNUNET_OK; | ||
268 | if (qe->cont != NULL) | ||
269 | { | ||
270 | qe->cont (qe->cont_cls, res, _("Namestore added record successfully")); | ||
271 | } | ||
272 | |||
273 | } | ||
274 | else if (ntohs (msg->op_result) == GNUNET_NO) | ||
275 | { | ||
276 | res = GNUNET_SYSERR; | ||
277 | if (qe->cont != NULL) | ||
278 | { | ||
279 | qe->cont (qe->cont_cls, res, _("Namestore failed to add record")); | ||
280 | } | ||
281 | } | ||
282 | else | ||
283 | { | ||
284 | GNUNET_break_op (0); | ||
285 | return; | ||
286 | } | ||
248 | 287 | ||
249 | 288 | ||
250 | /* Operation done, remove */ | 289 | /* Operation done, remove */ |
251 | GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe); | 290 | GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe); |
252 | GNUNET_free (qe); | ||
253 | 291 | ||
292 | GNUNET_free (qe); | ||
254 | } | 293 | } |
255 | 294 | ||
256 | 295 | ||
@@ -326,6 +365,14 @@ process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
326 | } | 365 | } |
327 | handle_lookup_name_response (qe, (struct LookupNameResponseMessage *) msg, size); | 366 | handle_lookup_name_response (qe, (struct LookupNameResponseMessage *) msg, size); |
328 | break; | 367 | break; |
368 | case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE: | ||
369 | if (size != sizeof (struct RecordPutResponseMessage)) | ||
370 | { | ||
371 | GNUNET_break_op (0); | ||
372 | break; | ||
373 | } | ||
374 | handle_record_put_response (qe, (struct RecordPutResponseMessage *) msg, size); | ||
375 | break; | ||
329 | default: | 376 | default: |
330 | GNUNET_break_op (0); | 377 | GNUNET_break_op (0); |
331 | break; | 378 | break; |
@@ -575,7 +622,14 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, | |||
575 | { | 622 | { |
576 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 623 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
577 | struct PendingMessage *pe; | 624 | struct PendingMessage *pe; |
625 | |||
626 | /* pointer to elements */ | ||
627 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key_tmp; | ||
628 | struct GNUNET_NAMESTORE_RecordData *rd_tmp; | ||
629 | char * name_tmp; | ||
630 | |||
578 | size_t msg_size = 0; | 631 | size_t msg_size = 0; |
632 | size_t name_len = strlen(name) + 1; | ||
579 | uint32_t id = 0; | 633 | uint32_t id = 0; |
580 | 634 | ||
581 | GNUNET_assert (NULL != h); | 635 | GNUNET_assert (NULL != h); |
@@ -588,24 +642,40 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, | |||
588 | GNUNET_CONTAINER_DLL_insert(h->op_head, h->op_tail, qe); | 642 | GNUNET_CONTAINER_DLL_insert(h->op_head, h->op_tail, qe); |
589 | 643 | ||
590 | /* set msg_size*/ | 644 | /* set msg_size*/ |
591 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); | 645 | struct RecordPutMessage * msg; |
646 | msg_size = sizeof (struct RecordPutMessage) + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + name_len + rd_count * (sizeof (struct GNUNET_NAMESTORE_RecordData)); | ||
592 | 647 | ||
593 | /* create msg here */ | 648 | /* create msg here */ |
649 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); | ||
650 | pe->size = msg_size; | ||
651 | pe->is_init = GNUNET_NO; | ||
652 | msg = (struct RecordPutMessage *) &pe[1]; | ||
653 | zone_key_tmp = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &msg[1]; | ||
654 | name_tmp = (char *) &zone_key_tmp[1]; | ||
655 | rd_tmp = (struct GNUNET_NAMESTORE_RecordData *) &name_tmp[name_len]; | ||
656 | |||
657 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT); | ||
658 | msg->header.size = htons (msg_size); | ||
659 | msg->op_id = htonl (id); | ||
660 | memcpy (zone_key_tmp, zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | ||
661 | msg->signature = *signature; | ||
662 | msg->name_len = htons (name_len); | ||
663 | memcpy (name_tmp, name, name_len); | ||
664 | msg->expire = GNUNET_TIME_absolute_hton (expire); | ||
665 | msg->rd_count = htonl(rd_count); | ||
666 | memcpy (rd_tmp, rd, rd_count * (sizeof (struct GNUNET_NAMESTORE_RecordData))); | ||
667 | |||
668 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for name `%s' with size %u\n", "NAMESTORE_RECORD_PUT", name, msg_size); | ||
669 | |||
670 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CALC: %u %u %u %u\n", | ||
671 | sizeof (struct RecordPutMessage), | ||
672 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
673 | name_len, | ||
674 | rd_count * (sizeof (struct GNUNET_NAMESTORE_RecordData))); | ||
594 | 675 | ||
595 | GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe); | 676 | GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe); |
596 | do_transmit(h); | 677 | do_transmit(h); |
597 | 678 | ||
598 | #if 0 | ||
599 | struct GNUNET_NAMESTORE_SimpleRecord *sr; | ||
600 | sr = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_SimpleRecord)); | ||
601 | sr->name = name; | ||
602 | sr->record_type = record_type; | ||
603 | sr->expiration = expiration; | ||
604 | sr->flags = flags; | ||
605 | sr->data_size = data_size; | ||
606 | sr->data = data; | ||
607 | GNUNET_CONTAINER_DLL_insert(h->records_head, h->records_tail, sr); | ||
608 | #endif | ||
609 | return qe; | 679 | return qe; |
610 | } | 680 | } |
611 | 681 | ||
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index ba8f8bca6..c29721643 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c | |||
@@ -465,7 +465,7 @@ namestore_sqlite_remove_records (void *cls, | |||
465 | * @param rd array of records with data to store | 465 | * @param rd array of records with data to store |
466 | * @param signature signature of the record block, NULL if signature is unavailable (i.e. | 466 | * @param signature signature of the record block, NULL if signature is unavailable (i.e. |
467 | * because the user queried for a particular record type only) | 467 | * because the user queried for a particular record type only) |
468 | * @return GNUNET_OK on success | 468 | * @return GNUNET_OK on success, else GNUNET_SYSERR |
469 | */ | 469 | */ |
470 | static int | 470 | static int |
471 | namestore_sqlite_put_records (void *cls, | 471 | namestore_sqlite_put_records (void *cls, |
diff --git a/src/namestore/test_namestore_api.c b/src/namestore/test_namestore_api.c index 62cfa808a..b907c7139 100644 --- a/src/namestore/test_namestore_api.c +++ b/src/namestore/test_namestore_api.c | |||
@@ -34,6 +34,10 @@ static struct GNUNET_NAMESTORE_Handle * nsh; | |||
34 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | 34 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; |
35 | static struct GNUNET_OS_Process *arm; | 35 | static struct GNUNET_OS_Process *arm; |
36 | 36 | ||
37 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; | ||
38 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | ||
39 | static GNUNET_HashCode zone; | ||
40 | |||
37 | static int res; | 41 | static int res; |
38 | 42 | ||
39 | 43 | ||
@@ -76,6 +80,10 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
76 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); | 80 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); |
77 | nsh = NULL; | 81 | nsh = NULL; |
78 | 82 | ||
83 | if (privkey != NULL) | ||
84 | GNUNET_CRYPTO_rsa_key_free (privkey); | ||
85 | privkey = NULL; | ||
86 | |||
79 | if (NULL != arm) | 87 | if (NULL != arm) |
80 | stop_arm(); | 88 | stop_arm(); |
81 | 89 | ||
@@ -92,6 +100,10 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
92 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | 100 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; |
93 | } | 101 | } |
94 | 102 | ||
103 | if (privkey != NULL) | ||
104 | GNUNET_CRYPTO_rsa_key_free (privkey); | ||
105 | privkey = NULL; | ||
106 | |||
95 | if (nsh != NULL) | 107 | if (nsh != NULL) |
96 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); | 108 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); |
97 | nsh = NULL; | 109 | nsh = NULL; |
@@ -112,19 +124,34 @@ void name_lookup_proc (void *cls, | |||
112 | const struct GNUNET_NAMESTORE_RecordData *rd, | 124 | const struct GNUNET_NAMESTORE_RecordData *rd, |
113 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 125 | const struct GNUNET_CRYPTO_RsaSignature *signature) |
114 | { | 126 | { |
115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "name_lookup_proc %p `%s' %i %p %p\n", zone_key, name, rd_count, rd, signature); | 127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore lookup result %p `%s' %i %p %p\n", zone_key, name, rd_count, rd, signature); |
116 | res = 0; | 128 | res = 0; |
117 | GNUNET_SCHEDULER_add_now(&end, NULL); | 129 | GNUNET_SCHEDULER_add_now(&end, NULL); |
118 | } | 130 | } |
119 | 131 | ||
132 | void put_cont (void *cls, int32_t success, const char *emsg) | ||
133 | { | ||
134 | char * name = cls; | ||
135 | |||
136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | ||
137 | |||
138 | GNUNET_NAMESTORE_lookup_record (nsh, &zone, name, 0, &name_lookup_proc, NULL); | ||
139 | } | ||
140 | |||
120 | static void | 141 | static void |
121 | run (void *cls, char *const *args, const char *cfgfile, | 142 | run (void *cls, char *const *args, const char *cfgfile, |
122 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 143 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
123 | { | 144 | { |
124 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); | 145 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); |
125 | 146 | ||
126 | GNUNET_HashCode zone; | 147 | privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey"); |
127 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &zone); | 148 | GNUNET_assert (privkey != NULL); |
149 | GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); | ||
150 | |||
151 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &zone); | ||
152 | |||
153 | |||
154 | struct GNUNET_CRYPTO_RsaSignature signature; | ||
128 | char * name = "dummy.dummy.gnunet"; | 155 | char * name = "dummy.dummy.gnunet"; |
129 | 156 | ||
130 | start_arm (cfgfile); | 157 | start_arm (cfgfile); |
@@ -133,7 +160,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
133 | nsh = GNUNET_NAMESTORE_connect (cfg); | 160 | nsh = GNUNET_NAMESTORE_connect (cfg); |
134 | GNUNET_break (NULL != nsh); | 161 | GNUNET_break (NULL != nsh); |
135 | 162 | ||
136 | GNUNET_NAMESTORE_lookup_record (nsh, &zone, name, 0, &name_lookup_proc, NULL); | 163 | GNUNET_NAMESTORE_record_put (nsh, &pubkey, name, |
164 | GNUNET_TIME_absolute_get_forever(), | ||
165 | 0, NULL, &signature, put_cont, name); | ||
137 | } | 166 | } |
138 | 167 | ||
139 | static int | 168 | static int |
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf index 1683d13cf..1b83e8f13 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 |