diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-27 14:26:17 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-27 14:26:17 +0000 |
commit | 11e0d70c68bdec7df62a1118ce346fc8ec629c4a (patch) | |
tree | 34bf19338a645af52ec466c7054621f455ccb216 /src/namestore/namestore_api.c | |
parent | 506334f0bb9d2b6e9414eb060642b5da6cb5bfcf (diff) | |
download | gnunet-11e0d70c68bdec7df62a1118ce346fc8ec629c4a.tar.gz gnunet-11e0d70c68bdec7df62a1118ce346fc8ec629c4a.zip |
- put record
Diffstat (limited to 'src/namestore/namestore_api.c')
-rw-r--r-- | src/namestore/namestore_api.c | 96 |
1 files changed, 83 insertions, 13 deletions
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 | ||