aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-08-19 17:54:21 +0200
committerChristian Grothoff <christian@grothoff.org>2020-08-19 17:54:21 +0200
commit1ca1140d4602dcc5c66da0d1ab1b082db9258ead (patch)
tree4a57b97b7f5f4f2b93f67bd8d39e890f3fa67dc3
parentaa2b84ff8caed28aec31e9a39375a02fceeb4e8c (diff)
downloadgnunet-1ca1140d4602dcc5c66da0d1ab1b082db9258ead.tar.gz
gnunet-1ca1140d4602dcc5c66da0d1ab1b082db9258ead.zip
-implement the symmetric option in setu
-rw-r--r--src/setu/gnunet-service-setu.c34
-rw-r--r--src/setu/setu.h15
-rw-r--r--src/setu/setu_api.c31
3 files changed, 66 insertions, 14 deletions
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
@@ -371,6 +371,12 @@ struct Operation
371 int byzantine; 371 int byzantine;
372 372
373 /** 373 /**
374 * #GNUNET_YES to also send back set elements we are sending to
375 * the remote peer.
376 */
377 int symmetric;
378
379 /**
374 * Lower bound for the set size, used only when 380 * Lower bound for the set size, used only when
375 * byzantine mode is enabled. 381 * byzantine mode is enabled.
376 */ 382 */
@@ -1576,7 +1582,9 @@ decode_and_send (struct Operation *op)
1576 1582
1577 last_key = key; 1583 last_key = key;
1578 1584
1579 res = ibf_decode (diff_ibf, &side, &key); 1585 res = ibf_decode (diff_ibf,
1586 &side,
1587 &key);
1580 if (res == GNUNET_OK) 1588 if (res == GNUNET_OK)
1581 { 1589 {
1582 LOG (GNUNET_ERROR_TYPE_DEBUG, 1590 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1839,7 +1847,7 @@ handle_union_p2p_ibf (void *cls,
1839static void 1847static void
1840send_client_element (struct Operation *op, 1848send_client_element (struct Operation *op,
1841 const struct GNUNET_SETU_Element *element, 1849 const struct GNUNET_SETU_Element *element,
1842 int status) 1850 enum GNUNET_SETU_Status status)
1843{ 1851{
1844 struct GNUNET_MQ_Envelope *ev; 1852 struct GNUNET_MQ_Envelope *ev;
1845 struct GNUNET_SETU_ResultMessage *rm; 1853 struct GNUNET_SETU_ResultMessage *rm;
@@ -2071,8 +2079,8 @@ handle_union_p2p_full_element (void *cls,
2071 ee->element.data = &ee[1]; 2079 ee->element.data = &ee[1];
2072 ee->element.element_type = ntohs (emsg->element_type); 2080 ee->element.element_type = ntohs (emsg->element_type);
2073 ee->remote = GNUNET_YES; 2081 ee->remote = GNUNET_YES;
2074 GNUNET_SETU_element_hash (&ee->element, &ee->element_hash); 2082 GNUNET_SETU_element_hash (&ee->element,
2075 2083 &ee->element_hash);
2076 LOG (GNUNET_ERROR_TYPE_DEBUG, 2084 LOG (GNUNET_ERROR_TYPE_DEBUG,
2077 "Got element (full diff, size %u, hash %s) from peer\n", 2085 "Got element (full diff, size %u, hash %s) from peer\n",
2078 (unsigned int) element_size, 2086 (unsigned int) element_size,
@@ -2285,7 +2293,6 @@ handle_union_p2p_full_done (void *cls,
2285 GNUNET_CONTAINER_multihashmap32_iterate (op->key_to_element, 2293 GNUNET_CONTAINER_multihashmap32_iterate (op->key_to_element,
2286 &send_missing_full_elements_iter, 2294 &send_missing_full_elements_iter,
2287 op); 2295 op);
2288
2289 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SETU_P2P_FULL_DONE); 2296 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SETU_P2P_FULL_DONE);
2290 GNUNET_MQ_send (op->mq, 2297 GNUNET_MQ_send (op->mq,
2291 ev); 2298 ev);
@@ -2387,9 +2394,12 @@ handle_union_p2p_demand (void *cls,
2387 fail_union_operation (op); 2394 fail_union_operation (op);
2388 return; 2395 return;
2389 } 2396 }
2390 ev = GNUNET_MQ_msg_extra (emsg, ee->element.size, 2397 ev = GNUNET_MQ_msg_extra (emsg,
2398 ee->element.size,
2391 GNUNET_MESSAGE_TYPE_SETU_P2P_ELEMENTS); 2399 GNUNET_MESSAGE_TYPE_SETU_P2P_ELEMENTS);
2392 GNUNET_memcpy (&emsg[1], ee->element.data, ee->element.size); 2400 GNUNET_memcpy (&emsg[1],
2401 ee->element.data,
2402 ee->element.size);
2393 emsg->reserved = htons (0); 2403 emsg->reserved = htons (0);
2394 emsg->element_type = htons (ee->element.element_type); 2404 emsg->element_type = htons (ee->element.element_type);
2395 LOG (GNUNET_ERROR_TYPE_DEBUG, 2405 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -2402,6 +2412,10 @@ handle_union_p2p_demand (void *cls,
2402 "# exchanged elements", 2412 "# exchanged elements",
2403 1, 2413 1,
2404 GNUNET_NO); 2414 GNUNET_NO);
2415 if (op->symmetric)
2416 send_client_element (op,
2417 &ee->element,
2418 GNUNET_SET_STATUS_ADD_REMOTE);
2405 } 2419 }
2406 GNUNET_CADET_receive_done (op->channel); 2420 GNUNET_CADET_receive_done (op->channel);
2407} 2421}
@@ -3316,9 +3330,10 @@ handle_client_evaluate (void *cls,
3316 op->peer = msg->target_peer; 3330 op->peer = msg->target_peer;
3317 op->client_request_id = ntohl (msg->request_id); 3331 op->client_request_id = ntohl (msg->request_id);
3318 op->byzantine = msg->byzantine; 3332 op->byzantine = msg->byzantine;
3319 op->byzantine_lower_bound = msg->byzantine_lower_bound; 3333 op->byzantine_lower_bound = ntohl (msg->byzantine_lower_bound);
3320 op->force_full = msg->force_full; 3334 op->force_full = msg->force_full;
3321 op->force_delta = msg->force_delta; 3335 op->force_delta = msg->force_delta;
3336 op->symmetric = msg->symmetric;
3322 context = GNUNET_MQ_extract_nested_mh (msg); 3337 context = GNUNET_MQ_extract_nested_mh (msg);
3323 3338
3324 /* Advance generation values, so that 3339 /* Advance generation values, so that
@@ -3500,9 +3515,10 @@ handle_client_accept (void *cls,
3500 op); 3515 op);
3501 op->client_request_id = ntohl (msg->request_id); 3516 op->client_request_id = ntohl (msg->request_id);
3502 op->byzantine = msg->byzantine; 3517 op->byzantine = msg->byzantine;
3503 op->byzantine_lower_bound = msg->byzantine_lower_bound; 3518 op->byzantine_lower_bound = ntohl (msg->byzantine_lower_bound);
3504 op->force_full = msg->force_full; 3519 op->force_full = msg->force_full;
3505 op->force_delta = msg->force_delta; 3520 op->force_delta = msg->force_delta;
3521 op->symmetric = msg->symmetric;
3506 3522
3507 /* Advance generation values, so that future mutations do not 3523 /* Advance generation values, so that future mutations do not
3508 interfer with the running operation. */ 3524 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
@@ -111,10 +111,16 @@ struct GNUNET_SETU_AcceptMessage
111 uint8_t byzantine; 111 uint8_t byzantine;
112 112
113 /** 113 /**
114 * #GNUNET_YES to also send back set elements we are sending to
115 * the remote peer.
116 */
117 uint8_t symmetric;
118
119 /**
114 * Lower bound for the set size, used only when 120 * Lower bound for the set size, used only when
115 * byzantine mode is enabled. 121 * byzantine mode is enabled.
116 */ 122 */
117 uint8_t byzantine_lower_bound; 123 uint32_t byzantine_lower_bound;
118}; 124};
119 125
120 126
@@ -209,10 +215,15 @@ struct GNUNET_SETU_EvaluateMessage
209 uint8_t byzantine; 215 uint8_t byzantine;
210 216
211 /** 217 /**
218 * Also return set elements we are sending to the remote peer.
219 */
220 uint8_t symmetric;
221
222 /**
212 * Lower bound for the set size, used only when 223 * Lower bound for the set size, used only when
213 * byzantine mode is enabled. 224 * byzantine mode is enabled.
214 */ 225 */
215 uint8_t byzantine_lower_bound; 226 uint32_t byzantine_lower_bound;
216 227
217 /* rest: context message, that is, application-specific 228 /* rest: context message, that is, application-specific
218 message to convince listener to pick up */ 229 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,
235 switch (result_status) 235 switch (result_status)
236 { 236 {
237 case GNUNET_SETU_STATUS_ADD_LOCAL: 237 case GNUNET_SETU_STATUS_ADD_LOCAL:
238 LOG (GNUNET_ERROR_TYPE_DEBUG, 238 case GNUNET_SETU_STATUS_ADD_REMOTE:
239 "Treating result as element\n");
240 e.data = &msg[1]; 239 e.data = &msg[1];
241 e.size = ntohs (msg->header.size) 240 e.size = ntohs (msg->header.size)
242 - sizeof(struct GNUNET_SETU_ResultMessage); 241 - sizeof(struct GNUNET_SETU_ResultMessage);
@@ -533,7 +532,7 @@ GNUNET_SETU_prepare (const struct GNUNET_PeerIdentity *other_peer,
533 { 532 {
534 case GNUNET_SETU_OPTION_BYZANTINE: 533 case GNUNET_SETU_OPTION_BYZANTINE:
535 msg->byzantine = GNUNET_YES; 534 msg->byzantine = GNUNET_YES;
536 msg->byzantine_lower_bound = opt->v.num; 535 msg->byzantine_lower_bound = htonl (opt->v.num);
537 break; 536 break;
538 case GNUNET_SETU_OPTION_FORCE_FULL: 537 case GNUNET_SETU_OPTION_FORCE_FULL:
539 msg->force_full = GNUNET_YES; 538 msg->force_full = GNUNET_YES;
@@ -541,6 +540,9 @@ GNUNET_SETU_prepare (const struct GNUNET_PeerIdentity *other_peer,
541 case GNUNET_SETU_OPTION_FORCE_DELTA: 540 case GNUNET_SETU_OPTION_FORCE_DELTA:
542 msg->force_delta = GNUNET_YES; 541 msg->force_delta = GNUNET_YES;
543 break; 542 break;
543 case GNUNET_SETU_OPTION_SYMMETRIC:
544 msg->symmetric = GNUNET_YES;
545 break;
544 default: 546 default:
545 LOG (GNUNET_ERROR_TYPE_ERROR, 547 LOG (GNUNET_ERROR_TYPE_ERROR,
546 "Option with type %d not recognized\n", 548 "Option with type %d not recognized\n",
@@ -786,6 +788,29 @@ GNUNET_SETU_accept (struct GNUNET_SETU_Request *request,
786 mqm = GNUNET_MQ_msg (msg, 788 mqm = GNUNET_MQ_msg (msg,
787 GNUNET_MESSAGE_TYPE_SETU_ACCEPT); 789 GNUNET_MESSAGE_TYPE_SETU_ACCEPT);
788 msg->accept_reject_id = htonl (request->accept_id); 790 msg->accept_reject_id = htonl (request->accept_id);
791 for (const struct GNUNET_SETU_Option *opt = options; opt->type != 0; opt++)
792 {
793 switch (opt->type)
794 {
795 case GNUNET_SETU_OPTION_BYZANTINE:
796 msg->byzantine = GNUNET_YES;
797 msg->byzantine_lower_bound = htonl (opt->v.num);
798 break;
799 case GNUNET_SETU_OPTION_FORCE_FULL:
800 msg->force_full = GNUNET_YES;
801 break;
802 case GNUNET_SETU_OPTION_FORCE_DELTA:
803 msg->force_delta = GNUNET_YES;
804 break;
805 case GNUNET_SETU_OPTION_SYMMETRIC:
806 msg->symmetric = GNUNET_YES;
807 break;
808 default:
809 LOG (GNUNET_ERROR_TYPE_ERROR,
810 "Option with type %d not recognized\n",
811 (int) opt->type);
812 }
813 }
789 oh = GNUNET_new (struct GNUNET_SETU_OperationHandle); 814 oh = GNUNET_new (struct GNUNET_SETU_OperationHandle);
790 oh->result_cb = result_cb; 815 oh->result_cb = result_cb;
791 oh->result_cls = result_cls; 816 oh->result_cls = result_cls;