From 1ca1140d4602dcc5c66da0d1ab1b082db9258ead Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 19 Aug 2020 17:54:21 +0200 Subject: -implement the symmetric option in setu --- src/setu/gnunet-service-setu.c | 34 +++++++++++++++++++++++++--------- src/setu/setu.h | 15 +++++++++++++-- src/setu/setu_api.c | 31 ++++++++++++++++++++++++++++--- 3 files changed, 66 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/setu/gnunet-service-setu.c b/src/setu/gnunet-service-setu.c index e61e1ab0c..326589186 100644 --- a/src/setu/gnunet-service-setu.c +++ b/src/setu/gnunet-service-setu.c @@ -370,6 +370,12 @@ struct Operation */ int byzantine; + /** + * #GNUNET_YES to also send back set elements we are sending to + * the remote peer. + */ + int symmetric; + /** * Lower bound for the set size, used only when * byzantine mode is enabled. @@ -1576,7 +1582,9 @@ decode_and_send (struct Operation *op) last_key = key; - res = ibf_decode (diff_ibf, &side, &key); + res = ibf_decode (diff_ibf, + &side, + &key); if (res == GNUNET_OK) { LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -1839,7 +1847,7 @@ handle_union_p2p_ibf (void *cls, static void send_client_element (struct Operation *op, const struct GNUNET_SETU_Element *element, - int status) + enum GNUNET_SETU_Status status) { struct GNUNET_MQ_Envelope *ev; struct GNUNET_SETU_ResultMessage *rm; @@ -2071,8 +2079,8 @@ handle_union_p2p_full_element (void *cls, ee->element.data = &ee[1]; ee->element.element_type = ntohs (emsg->element_type); ee->remote = GNUNET_YES; - GNUNET_SETU_element_hash (&ee->element, &ee->element_hash); - + GNUNET_SETU_element_hash (&ee->element, + &ee->element_hash); LOG (GNUNET_ERROR_TYPE_DEBUG, "Got element (full diff, size %u, hash %s) from peer\n", (unsigned int) element_size, @@ -2285,7 +2293,6 @@ handle_union_p2p_full_done (void *cls, GNUNET_CONTAINER_multihashmap32_iterate (op->key_to_element, &send_missing_full_elements_iter, op); - ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SETU_P2P_FULL_DONE); GNUNET_MQ_send (op->mq, ev); @@ -2387,9 +2394,12 @@ handle_union_p2p_demand (void *cls, fail_union_operation (op); return; } - ev = GNUNET_MQ_msg_extra (emsg, ee->element.size, + ev = GNUNET_MQ_msg_extra (emsg, + ee->element.size, GNUNET_MESSAGE_TYPE_SETU_P2P_ELEMENTS); - GNUNET_memcpy (&emsg[1], ee->element.data, ee->element.size); + GNUNET_memcpy (&emsg[1], + ee->element.data, + ee->element.size); emsg->reserved = htons (0); emsg->element_type = htons (ee->element.element_type); LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -2402,6 +2412,10 @@ handle_union_p2p_demand (void *cls, "# exchanged elements", 1, GNUNET_NO); + if (op->symmetric) + send_client_element (op, + &ee->element, + GNUNET_SET_STATUS_ADD_REMOTE); } GNUNET_CADET_receive_done (op->channel); } @@ -3316,9 +3330,10 @@ handle_client_evaluate (void *cls, op->peer = msg->target_peer; op->client_request_id = ntohl (msg->request_id); op->byzantine = msg->byzantine; - op->byzantine_lower_bound = msg->byzantine_lower_bound; + op->byzantine_lower_bound = ntohl (msg->byzantine_lower_bound); op->force_full = msg->force_full; op->force_delta = msg->force_delta; + op->symmetric = msg->symmetric; context = GNUNET_MQ_extract_nested_mh (msg); /* Advance generation values, so that @@ -3500,9 +3515,10 @@ handle_client_accept (void *cls, op); op->client_request_id = ntohl (msg->request_id); op->byzantine = msg->byzantine; - op->byzantine_lower_bound = msg->byzantine_lower_bound; + op->byzantine_lower_bound = ntohl (msg->byzantine_lower_bound); op->force_full = msg->force_full; op->force_delta = msg->force_delta; + op->symmetric = msg->symmetric; /* Advance generation values, so that future mutations do not interfer with the running operation. */ diff --git a/src/setu/setu.h b/src/setu/setu.h index f1c5df92b..e9a0def95 100644 --- a/src/setu/setu.h +++ b/src/setu/setu.h @@ -110,11 +110,17 @@ struct GNUNET_SETU_AcceptMessage */ uint8_t byzantine; + /** + * #GNUNET_YES to also send back set elements we are sending to + * the remote peer. + */ + uint8_t symmetric; + /** * Lower bound for the set size, used only when * byzantine mode is enabled. */ - uint8_t byzantine_lower_bound; + uint32_t byzantine_lower_bound; }; @@ -208,11 +214,16 @@ struct GNUNET_SETU_EvaluateMessage */ uint8_t byzantine; + /** + * Also return set elements we are sending to the remote peer. + */ + uint8_t symmetric; + /** * Lower bound for the set size, used only when * byzantine mode is enabled. */ - uint8_t byzantine_lower_bound; + uint32_t byzantine_lower_bound; /* rest: context message, that is, application-specific message to convince listener to pick up */ diff --git a/src/setu/setu_api.c b/src/setu/setu_api.c index 48260de55..dd3a4a769 100644 --- a/src/setu/setu_api.c +++ b/src/setu/setu_api.c @@ -235,8 +235,7 @@ handle_result (void *cls, switch (result_status) { case GNUNET_SETU_STATUS_ADD_LOCAL: - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Treating result as element\n"); + case GNUNET_SETU_STATUS_ADD_REMOTE: e.data = &msg[1]; e.size = ntohs (msg->header.size) - sizeof(struct GNUNET_SETU_ResultMessage); @@ -533,7 +532,7 @@ GNUNET_SETU_prepare (const struct GNUNET_PeerIdentity *other_peer, { case GNUNET_SETU_OPTION_BYZANTINE: msg->byzantine = GNUNET_YES; - msg->byzantine_lower_bound = opt->v.num; + msg->byzantine_lower_bound = htonl (opt->v.num); break; case GNUNET_SETU_OPTION_FORCE_FULL: msg->force_full = GNUNET_YES; @@ -541,6 +540,9 @@ GNUNET_SETU_prepare (const struct GNUNET_PeerIdentity *other_peer, case GNUNET_SETU_OPTION_FORCE_DELTA: msg->force_delta = GNUNET_YES; break; + case GNUNET_SETU_OPTION_SYMMETRIC: + msg->symmetric = GNUNET_YES; + break; default: LOG (GNUNET_ERROR_TYPE_ERROR, "Option with type %d not recognized\n", @@ -786,6 +788,29 @@ GNUNET_SETU_accept (struct GNUNET_SETU_Request *request, mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SETU_ACCEPT); msg->accept_reject_id = htonl (request->accept_id); + for (const struct GNUNET_SETU_Option *opt = options; opt->type != 0; opt++) + { + switch (opt->type) + { + case GNUNET_SETU_OPTION_BYZANTINE: + msg->byzantine = GNUNET_YES; + msg->byzantine_lower_bound = htonl (opt->v.num); + break; + case GNUNET_SETU_OPTION_FORCE_FULL: + msg->force_full = GNUNET_YES; + break; + case GNUNET_SETU_OPTION_FORCE_DELTA: + msg->force_delta = GNUNET_YES; + break; + case GNUNET_SETU_OPTION_SYMMETRIC: + msg->symmetric = GNUNET_YES; + break; + default: + LOG (GNUNET_ERROR_TYPE_ERROR, + "Option with type %d not recognized\n", + (int) opt->type); + } + } oh = GNUNET_new (struct GNUNET_SETU_OperationHandle); oh->result_cb = result_cb; oh->result_cls = result_cls; -- cgit v1.2.3