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.c128
1 files changed, 104 insertions, 24 deletions
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 67541b45a..26e1477f4 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -674,6 +674,60 @@ handle_record_result_end (void *cls, const struct GNUNET_NAMESTORE_Header *msg)
674 free_ze (ze); 674 free_ze (ze);
675} 675}
676 676
677/**
678 * Handle an incoming message of type
679 * #GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL_RESULT.
680 *
681 * @param qe the respective entry in the message queue
682 * @param msg the message we received
683 * @return #GNUNET_OK on success, #GNUNET_SYSERR if message malformed
684 */
685static int
686check_tx_control_result (void *cls,
687 const struct TxControlResultMessage *msg)
688{
689 const char *err_tmp;
690 size_t err_len;
691
692 (void) cls;
693 err_len = ntohs (msg->gns_header.header.size)
694 - sizeof (struct TxControlResultMessage);
695 if ((GNUNET_YES == ntohs (msg->success)) && (err_len > 0))
696 {
697 GNUNET_break (0);
698 return GNUNET_SYSERR;
699 }
700 err_tmp = (const char *) &msg[1];
701 if ((err_len > 0) && ('\0' != err_tmp[err_len - 1]))
702 {
703 GNUNET_break (0);
704 return GNUNET_SYSERR;
705 }
706 return GNUNET_OK;
707}
708
709static void
710handle_tx_control_result (void *cls,
711 const struct TxControlResultMessage *msg)
712{
713 struct GNUNET_NAMESTORE_Handle *h = cls;
714 struct GNUNET_NAMESTORE_QueueEntry *qe;
715 int res;
716 const char *emsg;
717
718 qe = find_qe (h, ntohl (msg->gns_header.r_id));
719 emsg = (const char *) &msg[1];
720 res = ntohs (msg->success);
721 LOG (GNUNET_ERROR_TYPE_DEBUG,
722 "Received TX_CONTROL_RESULT with result %d\n",
723 res);
724 if (NULL == qe)
725 return;
726 if (NULL != qe->cont)
727 qe->cont (qe->cont_cls, res,
728 (GNUNET_YES == res) ? NULL : emsg);
729 free_qe (qe);
730}
677 731
678/** 732/**
679 * Handle an incoming message of type 733 * Handle an incoming message of type
@@ -839,6 +893,10 @@ reconnect (struct GNUNET_NAMESTORE_Handle *h)
839 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE, 893 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE,
840 struct LabelLookupResponseMessage, 894 struct LabelLookupResponseMessage,
841 h), 895 h),
896 GNUNET_MQ_hd_var_size (tx_control_result,
897 GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL_RESULT,
898 struct TxControlResultMessage,
899 h),
842 GNUNET_MQ_handler_end () }; 900 GNUNET_MQ_handler_end () };
843 struct GNUNET_NAMESTORE_ZoneIterator *it; 901 struct GNUNET_NAMESTORE_ZoneIterator *it;
844 struct GNUNET_NAMESTORE_QueueEntry *qe; 902 struct GNUNET_NAMESTORE_QueueEntry *qe;
@@ -1344,43 +1402,65 @@ GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe)
1344 * New API draft. Experimental 1402 * New API draft. Experimental
1345 */ 1403 */
1346 1404
1347struct GNUNET_NAMESTORE_QueueEntry * 1405static struct GNUNET_NAMESTORE_QueueEntry *
1348GNUNET_NAMESTORE_transaction_begin (struct GNUNET_NAMESTORE_Handle *h, 1406send_transaction_control_msg (struct GNUNET_NAMESTORE_Handle *h,
1349 GNUNET_SCHEDULER_TaskCallback error_cb, 1407 GNUNET_NAMESTORE_ContinuationWithStatus cont,
1350 void *error_cb_cls) 1408 void *cont_cls,
1409 enum GNUNET_NAMESTORE_TxControl ctrl)
1351{ 1410{
1411 struct GNUNET_NAMESTORE_QueueEntry *qe;
1412 struct GNUNET_MQ_Envelope *env;
1413 struct TxControlMessage *msg;
1414 uint32_t rid;
1415
1416 rid = get_op_id (h);
1417 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
1418 qe->h = h;
1419 qe->cont = cont;
1420 qe->cont_cls = cont_cls;
1421 qe->op_id = rid;
1422 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1423
1424 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL);
1425 msg->gns_header.r_id = htonl (rid);
1426 msg->control = htons (ctrl);
1427 if (NULL == h->mq)
1428 qe->env = env;
1429 else
1430 GNUNET_MQ_send (h->mq, env);
1431 return qe;
1352 GNUNET_break (0); 1432 GNUNET_break (0);
1353 return NULL; 1433 return NULL;
1354} 1434}
1355 1435
1436struct GNUNET_NAMESTORE_QueueEntry *
1437GNUNET_NAMESTORE_transaction_begin (struct GNUNET_NAMESTORE_Handle *h,
1438 GNUNET_NAMESTORE_ContinuationWithStatus cont,
1439 void *cont_cls)
1440{
1441 return send_transaction_control_msg (h, cont, cont_cls,
1442 GNUNET_NAMESTORE_TX_BEGIN);
1443}
1356 1444
1357struct GNUNET_NAMESTORE_QueueEntry * 1445struct GNUNET_NAMESTORE_QueueEntry *
1358GNUNET_NAMESTORE_transaction_rollback (struct GNUNET_NAMESTORE_Handle *h, 1446GNUNET_NAMESTORE_transaction_commit (struct GNUNET_NAMESTORE_Handle *h,
1359 GNUNET_SCHEDULER_TaskCallback error_cb, 1447 GNUNET_NAMESTORE_ContinuationWithStatus
1360 void *error_cb_cls) 1448 cont,
1449 void *cont_cls)
1361{ 1450{
1362 GNUNET_break (0); 1451 return send_transaction_control_msg (h, cont, cont_cls,
1363 return NULL; 1452 GNUNET_NAMESTORE_TX_COMMIT);
1364} 1453}
1365 1454
1366 1455
1367/**
1368 * Commit a namestore transaction.
1369 * Saves all actions performed since #GNUNET_NAMESTORE_transaction_begin
1370 *
1371 * @param h handle to the namestore
1372 * @param error_cb function to call on error (i.e. disconnect or unable to get lock)
1373 * the handle is afterwards invalid
1374 * @param error_cb_cls closure for @a error_cb
1375 * @return handle to abort the request
1376 */
1377struct GNUNET_NAMESTORE_QueueEntry * 1456struct GNUNET_NAMESTORE_QueueEntry *
1378GNUNET_NAMESTORE_transaction_commit (struct GNUNET_NAMESTORE_Handle *h, 1457GNUNET_NAMESTORE_transaction_rollback (struct GNUNET_NAMESTORE_Handle *h,
1379 GNUNET_SCHEDULER_TaskCallback error_cb, 1458 GNUNET_NAMESTORE_ContinuationWithStatus
1380 void *error_cb_cls) 1459 cont,
1460 void *cont_cls)
1381{ 1461{
1382 GNUNET_break (0); 1462 return send_transaction_control_msg (h, cont, cont_cls,
1383 return NULL; 1463 GNUNET_NAMESTORE_TX_ROLLBACK);
1384} 1464}
1385 1465
1386 1466