From d5af1252b2a83d75fe4a8f6e48e1d01ab027b553 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 23 Feb 2017 15:15:33 +0100 Subject: [PATCH] add set operation options --- src/consensus/gnunet-service-consensus.c | 2 + src/dv/gnunet-service-dv.c | 2 + src/include/gnunet_protocols.h | 7 +++ src/include/gnunet_set_service.h | 51 +++++++++++++++++++ src/revocation/gnunet-service-revocation.c | 2 + .../gnunet-service-scalarproduct-ecc_alice.c | 1 + .../gnunet-service-scalarproduct-ecc_bob.c | 1 + .../gnunet-service-scalarproduct_alice.c | 1 + .../gnunet-service-scalarproduct_bob.c | 1 + src/set/gnunet-set-profiler.c | 4 +- src/set/set_api.c | 2 + src/set/test_set_api.c | 3 ++ src/set/test_set_intersection_result_full.c | 2 + src/set/test_set_union_result_symmetric.c | 2 + 14 files changed, 80 insertions(+), 1 deletion(-) diff --git a/src/consensus/gnunet-service-consensus.c b/src/consensus/gnunet-service-consensus.c index 16ca6a57f..4036d2b11 100644 --- a/src/consensus/gnunet-service-consensus.c +++ b/src/consensus/gnunet-service-consensus.c @@ -2013,6 +2013,7 @@ task_start_reconcile (struct TaskEntry *task) &session->global_id, &rcm.header, GNUNET_SET_RESULT_SYMMETRIC, + (struct GNUNET_SET_Option[]) { 0 }, set_result_cb, task); @@ -2439,6 +2440,7 @@ set_listen_cb (void *cls, task->cls.setop.op = GNUNET_SET_accept (request, GNUNET_SET_RESULT_SYMMETRIC, + (struct GNUNET_SET_Option[]) { 0 }, set_result_cb, task); diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index 6adaa04d9..e4b664f4b 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c @@ -1528,6 +1528,7 @@ listen_set_union (void *cls, GNUNET_SET_OPERATION_UNION); neighbor->set_op = GNUNET_SET_accept (request, GNUNET_SET_RESULT_ADDED, + (struct GNUNET_SET_Option[]) { 0 }, &handle_set_union_result, neighbor); neighbor->consensus_insertion_offset = 0; @@ -1558,6 +1559,7 @@ initiate_set_union (void *cls) &neighbor->real_session_id, NULL, GNUNET_SET_RESULT_ADDED, + (struct GNUNET_SET_Option[]) { 0 }, &handle_set_union_result, neighbor); neighbor->consensus_insertion_offset = 0; diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index eeb9a8a92..a10c0ca5d 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -1795,6 +1795,13 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT 596 +/** + * Request all missing elements from the other peer, + * based on their sets and the elements we previously sent + * with #GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS. + */ +#define GNUNET_MESSAGE_TYPE_SET_UNION_P2P_GET_MISSING 597 + /******************************************************************************* * TESTBED LOGGER message types diff --git a/src/include/gnunet_set_service.h b/src/include/gnunet_set_service.h index 52613ad59..f9b477f47 100644 --- a/src/include/gnunet_set_service.h +++ b/src/include/gnunet_set_service.h @@ -153,6 +153,7 @@ enum GNUNET_SET_Status }; + /** * The way results are given to the client. */ @@ -211,6 +212,54 @@ struct GNUNET_SET_Element }; +/** + * Possible options to pass to a set operation. + * + * Used as tag for struct #GNUNET_SET_Option. + */ +enum GNUNET_SET_OptionType +{ + /** + * Fail set operations when the other peer shows weird behavior + * that might by a Byzantine fault. + * + * For set union, 'v.num' is a lower bound on elements + * that the other peer must have in common with us. + */ + GNUNET_SET_OPTION_BYZANTINE=1, + /** + * Do not use the optimized set operation, but send full sets. + * Might trigger Byzantine fault detection. + */ + GNUNET_SET_OPTION_FORCE_FULL=2, + /** + * Only use optimized set operations, even though for this + * particular set operation they might be much slower. + * Might trigger Byzantine fault detection. + */ + GNUNET_SET_OPTION_FORCE_DELTA=4, +}; + + +/** + * Option for set operations. + */ +struct GNUNET_SET_Option +{ + /** + * Type of the option. + */ + enum GNUNET_SET_OptionType type; + + /** + * Value for the option, only used with some options. + */ + union { + uint64_t num; + } v; +}; + + /** * Continuation used for some of the set operations * @@ -367,6 +416,7 @@ GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer, const struct GNUNET_HashCode *app_id, const struct GNUNET_MessageHeader *context_msg, enum GNUNET_SET_ResultMode result_mode, + struct GNUNET_SET_Option options[], GNUNET_SET_ResultIterator result_cb, void *result_cls); @@ -420,6 +470,7 @@ GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh); struct GNUNET_SET_OperationHandle * GNUNET_SET_accept (struct GNUNET_SET_Request *request, enum GNUNET_SET_ResultMode result_mode, + struct GNUNET_SET_Option options[], GNUNET_SET_ResultIterator result_cb, void *result_cls); diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c index 2965808fa..b5669d9ea 100644 --- a/src/revocation/gnunet-service-revocation.c +++ b/src/revocation/gnunet-service-revocation.c @@ -509,6 +509,7 @@ transmit_task_cb (void *cls) &revocation_set_union_app_id, NULL, GNUNET_SET_RESULT_ADDED, + (struct GNUNET_SET_Option[]) { 0 }, &add_revocation, peer_entry); if (GNUNET_OK != @@ -755,6 +756,7 @@ handle_revocation_union_request (void *cls, } peer_entry->so = GNUNET_SET_accept (request, GNUNET_SET_RESULT_ADDED, + (struct GNUNET_SET_Option[]) { 0 }, &add_revocation, peer_entry); if (GNUNET_OK != diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c index 9f8d98657..34149435c 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c +++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c @@ -788,6 +788,7 @@ cb_intersection_request_alice (void *cls, s->intersection_op = GNUNET_SET_accept (request, GNUNET_SET_RESULT_REMOVED, + (struct GNUNET_SET_Option[]) { 0 }, &cb_intersection_element_removed, s); if (NULL == s->intersection_op) diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c index 7fd69a4ea..db8241bb7 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c +++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c @@ -670,6 +670,7 @@ start_intersection (struct BobServiceSession *s) &set_sid, NULL, GNUNET_SET_RESULT_REMOVED, + (struct GNUNET_SET_Option[]) { 0 }, &cb_intersection_element_removed, s); if (GNUNET_OK != diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c index 779d84b60..f99ff6168 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c +++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.c @@ -1022,6 +1022,7 @@ cb_intersection_request_alice (void *cls, s->intersection_op = GNUNET_SET_accept (request, GNUNET_SET_RESULT_REMOVED, + (struct GNUNET_SET_Option[]) { 0 }, &cb_intersection_element_removed, s); if (NULL == s->intersection_op) diff --git a/src/scalarproduct/gnunet-service-scalarproduct_bob.c b/src/scalarproduct/gnunet-service-scalarproduct_bob.c index a2bceba43..4da2ba50e 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct_bob.c +++ b/src/scalarproduct/gnunet-service-scalarproduct_bob.c @@ -964,6 +964,7 @@ start_intersection (struct BobServiceSession *s) &s->session_id, NULL, GNUNET_SET_RESULT_REMOVED, + (struct GNUNET_SET_Option[]) { 0 }, &cb_intersection_element_removed, s); if (GNUNET_OK != diff --git a/src/set/gnunet-set-profiler.c b/src/set/gnunet-set-profiler.c index f89817ff5..22a9d85cf 100644 --- a/src/set/gnunet-set-profiler.c +++ b/src/set/gnunet-set-profiler.c @@ -225,7 +225,8 @@ set_listen_cb (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set listen cb called\n"); info2.oh = GNUNET_SET_accept (request, GNUNET_SET_RESULT_SYMMETRIC, - set_result_cb, &info2); + (struct GNUNET_SET_Option[]) { 0 }, + set_result_cb, &info2); GNUNET_SET_commit (info2.oh, info2.set); } @@ -352,6 +353,7 @@ run (void *cls, info1.oh = GNUNET_SET_prepare (&local_peer, &app_id, NULL, GNUNET_SET_RESULT_SYMMETRIC, + (struct GNUNET_SET_Option[]) { 0 }, set_result_cb, &info1); GNUNET_SET_commit (info1.oh, info1.set); GNUNET_SET_destroy (info1.set); diff --git a/src/set/set_api.c b/src/set/set_api.c index baeee6da0..c2e2cd1e9 100644 --- a/src/set/set_api.c +++ b/src/set/set_api.c @@ -766,6 +766,7 @@ GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer, const struct GNUNET_HashCode *app_id, const struct GNUNET_MessageHeader *context_msg, enum GNUNET_SET_ResultMode result_mode, + struct GNUNET_SET_Option options[], GNUNET_SET_ResultIterator result_cb, void *result_cls) { @@ -1006,6 +1007,7 @@ GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh) struct GNUNET_SET_OperationHandle * GNUNET_SET_accept (struct GNUNET_SET_Request *request, enum GNUNET_SET_ResultMode result_mode, + struct GNUNET_SET_Option options[], GNUNET_SET_ResultIterator result_cb, void *result_cls) { diff --git a/src/set/test_set_api.c b/src/set/test_set_api.c index 21af45f8a..4bc6bd1c3 100644 --- a/src/set/test_set_api.c +++ b/src/set/test_set_api.c @@ -149,6 +149,7 @@ listen_cb (void *cls, listen_handle = NULL; oh2 = GNUNET_SET_accept (request, GNUNET_SET_RESULT_ADDED, + (struct GNUNET_SET_Option[]) { 0 }, &result_cb_set2, NULL); GNUNET_SET_commit (oh2, @@ -179,6 +180,7 @@ start (void *cls) &app_id, &context_msg, GNUNET_SET_RESULT_ADDED, + (struct GNUNET_SET_Option[]) { 0 }, &result_cb_set1, NULL); GNUNET_SET_commit (oh1, @@ -378,6 +380,7 @@ run (void *cls, &app_id, NULL, GNUNET_SET_RESULT_ADDED, + (struct GNUNET_SET_Option[]) { 0 }, NULL, NULL); diff --git a/src/set/test_set_intersection_result_full.c b/src/set/test_set_intersection_result_full.c index b2d6ce8a9..cbe1ce149 100644 --- a/src/set/test_set_intersection_result_full.c +++ b/src/set/test_set_intersection_result_full.c @@ -133,6 +133,7 @@ listen_cb (void *cls, listen_handle = NULL; oh2 = GNUNET_SET_accept (request, GNUNET_SET_RESULT_FULL, + (struct GNUNET_SET_Option[]) { 0 }, &result_cb_set2, NULL); GNUNET_SET_commit (oh2, @@ -163,6 +164,7 @@ start (void *cls) &app_id, &context_msg, GNUNET_SET_RESULT_FULL, + (struct GNUNET_SET_Option[]) { 0 }, &result_cb_set1, NULL); GNUNET_SET_commit (oh1, diff --git a/src/set/test_set_union_result_symmetric.c b/src/set/test_set_union_result_symmetric.c index ab191a34a..8dff40ec0 100644 --- a/src/set/test_set_union_result_symmetric.c +++ b/src/set/test_set_union_result_symmetric.c @@ -184,6 +184,7 @@ listen_cb (void *cls, listen_handle = NULL; oh2 = GNUNET_SET_accept (request, GNUNET_SET_RESULT_SYMMETRIC, + (struct GNUNET_SET_Option[]) { 0 }, &result_cb_set2, NULL); GNUNET_SET_commit (oh2, @@ -212,6 +213,7 @@ start (void *cls) &app_id, &context_msg, GNUNET_SET_RESULT_SYMMETRIC, + (struct GNUNET_SET_Option[]) { 0 }, &result_cb_set1, NULL); GNUNET_SET_commit (oh1, set1); } -- 2.25.1