aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/namestore_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/namestore_api.c')
-rw-r--r--src/namestore/namestore_api.c105
1 files changed, 105 insertions, 0 deletions
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
470static void
471handle_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
471static void 502static void
472manage_record_operations (struct GNUNET_NAMESTORE_QueueEntry *qe, 503manage_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 */
1376struct GNUNET_NAMESTORE_QueueEntry *
1377GNUNET_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