aboutsummaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-02-24 18:07:42 +0100
committerFlorian Dold <florian.dold@gmail.com>2017-02-24 18:10:11 +0100
commitebabb581efd0516a80b4d649e0dea852f46329f5 (patch)
tree0855e6436e2a1ffb3548fc798b602cafea55044e /src/set
parent592b43fdf3f3572892f4095808daf22010469d0b (diff)
downloadgnunet-ebabb581efd0516a80b4d649e0dea852f46329f5.tar.gz
gnunet-ebabb581efd0516a80b4d649e0dea852f46329f5.zip
always send bigger set on full send
Diffstat (limited to 'src/set')
-rw-r--r--src/set/gnunet-service-set.c8
-rw-r--r--src/set/gnunet-service-set_protocol.h14
-rw-r--r--src/set/gnunet-service-set_union.c81
3 files changed, 92 insertions, 11 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c
index 126bf02d2..c48518f08 100644
--- a/src/set/gnunet-service-set.c
+++ b/src/set/gnunet-service-set.c
@@ -1375,6 +1375,10 @@ handle_client_listen (void *cls,
1375 struct GNUNET_MessageHeader, 1375 struct GNUNET_MessageHeader,
1376 NULL), 1376 NULL),
1377 GNUNET_MQ_hd_var_size (p2p_message, 1377 GNUNET_MQ_hd_var_size (p2p_message,
1378 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL,
1379 struct GNUNET_MessageHeader,
1380 NULL),
1381 GNUNET_MQ_hd_var_size (p2p_message,
1378 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, 1382 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE,
1379 struct GNUNET_MessageHeader, 1383 struct GNUNET_MessageHeader,
1380 NULL), 1384 NULL),
@@ -1645,6 +1649,10 @@ handle_client_evaluate (void *cls,
1645 struct GNUNET_MessageHeader, 1649 struct GNUNET_MessageHeader,
1646 op), 1650 op),
1647 GNUNET_MQ_hd_var_size (p2p_message, 1651 GNUNET_MQ_hd_var_size (p2p_message,
1652 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL,
1653 struct GNUNET_MessageHeader,
1654 op),
1655 GNUNET_MQ_hd_var_size (p2p_message,
1648 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, 1656 GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT,
1649 struct GNUNET_MessageHeader, 1657 struct GNUNET_MessageHeader,
1650 op), 1658 op),
diff --git a/src/set/gnunet-service-set_protocol.h b/src/set/gnunet-service-set_protocol.h
index 748da15fc..0138b21c7 100644
--- a/src/set/gnunet-service-set_protocol.h
+++ b/src/set/gnunet-service-set_protocol.h
@@ -208,6 +208,20 @@ struct IntersectionDoneMessage
208 struct GNUNET_HashCode element_xor_hash; 208 struct GNUNET_HashCode element_xor_hash;
209}; 209};
210 210
211
212/**
213 * Strata estimator together with the peer's overall set size.
214 */
215struct StrataEstimatorMessage
216{
217 /**
218 * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE(C)
219 */
220 struct GNUNET_MessageHeader header;
221
222 uint64_t set_size;
223};
224
211GNUNET_NETWORK_STRUCT_END 225GNUNET_NETWORK_STRUCT_END
212 226
213#endif 227#endif
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c
index d2dfe049b..ab39a2e8a 100644
--- a/src/set/gnunet-service-set_union.c
+++ b/src/set/gnunet-service-set_union.c
@@ -85,6 +85,7 @@ enum UnionOperationPhase
85 * upon initialization and later via #PHASE_EXPECT_ELEMENTS_AND_REQUESTS. 85 * upon initialization and later via #PHASE_EXPECT_ELEMENTS_AND_REQUESTS.
86 * 86 *
87 * XXX: could use better wording. 87 * XXX: could use better wording.
88 * XXX: repurposed to also expect a "request full set" message, should be renamed
88 * 89 *
89 * After receiving the complete IBF, we enter #PHASE_EXPECT_ELEMENTS 90 * After receiving the complete IBF, we enter #PHASE_EXPECT_ELEMENTS
90 */ 91 */
@@ -202,6 +203,12 @@ struct OperationState
202 * Total number of elements received from the other peer. 203 * Total number of elements received from the other peer.
203 */ 204 */
204 uint32_t received_total; 205 uint32_t received_total;
206
207 /**
208 * Initial size of our set, just before
209 * the operation started.
210 */
211 uint64_t initial_size;
205}; 212};
206 213
207 214
@@ -708,7 +715,7 @@ send_strata_estimator (struct Operation *op)
708{ 715{
709 const struct StrataEstimator *se = op->state->se; 716 const struct StrataEstimator *se = op->state->se;
710 struct GNUNET_MQ_Envelope *ev; 717 struct GNUNET_MQ_Envelope *ev;
711 struct GNUNET_MessageHeader *strata_msg; 718 struct StrataEstimatorMessage *strata_msg;
712 char *buf; 719 char *buf;
713 size_t len; 720 size_t len;
714 uint16_t type; 721 uint16_t type;
@@ -720,13 +727,14 @@ send_strata_estimator (struct Operation *op)
720 type = GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC; 727 type = GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC;
721 else 728 else
722 type = GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE; 729 type = GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE;
723 ev = GNUNET_MQ_msg_header_extra (strata_msg, 730 ev = GNUNET_MQ_msg_extra (strata_msg,
724 len, 731 len,
725 type); 732 type);
726 GNUNET_memcpy (&strata_msg[1], 733 GNUNET_memcpy (&strata_msg[1],
727 buf, 734 buf,
728 len); 735 len);
729 GNUNET_free (buf); 736 GNUNET_free (buf);
737 strata_msg->set_size = GNUNET_htonll (GNUNET_CONTAINER_multihashmap_size (op->spec->set->content->elements));
730 GNUNET_MQ_send (op->mq, 738 GNUNET_MQ_send (op->mq,
731 ev); 739 ev);
732 op->state->phase = PHASE_EXPECT_IBF; 740 op->state->phase = PHASE_EXPECT_IBF;
@@ -814,7 +822,9 @@ handle_p2p_strata_estimator (void *cls,
814{ 822{
815 struct Operation *op = cls; 823 struct Operation *op = cls;
816 struct StrataEstimator *remote_se; 824 struct StrataEstimator *remote_se;
817 int diff; 825 struct StrataEstimatorMessage *msg = (void *) mh;
826 unsigned int diff;
827 uint64_t other_size;
818 size_t len; 828 size_t len;
819 829
820 GNUNET_STATISTICS_update (_GSS_statistics, 830 GNUNET_STATISTICS_update (_GSS_statistics,
@@ -824,11 +834,11 @@ handle_p2p_strata_estimator (void *cls,
824 834
825 if (op->state->phase != PHASE_EXPECT_SE) 835 if (op->state->phase != PHASE_EXPECT_SE)
826 { 836 {
827 fail_union_operation (op);
828 GNUNET_break (0); 837 GNUNET_break (0);
838 fail_union_operation (op);
829 return GNUNET_SYSERR; 839 return GNUNET_SYSERR;
830 } 840 }
831 len = ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader); 841 len = ntohs (mh->size) - sizeof (struct StrataEstimatorMessage);
832 if ( (GNUNET_NO == is_compressed) && 842 if ( (GNUNET_NO == is_compressed) &&
833 (len != SE_STRATA_COUNT * SE_IBF_SIZE * IBF_BUCKET_SIZE) ) 843 (len != SE_STRATA_COUNT * SE_IBF_SIZE * IBF_BUCKET_SIZE) )
834 { 844 {
@@ -836,6 +846,7 @@ handle_p2p_strata_estimator (void *cls,
836 GNUNET_break (0); 846 GNUNET_break (0);
837 return GNUNET_SYSERR; 847 return GNUNET_SYSERR;
838 } 848 }
849 other_size = GNUNET_ntohll (msg->set_size);
839 remote_se = strata_estimator_create (SE_STRATA_COUNT, 850 remote_se = strata_estimator_create (SE_STRATA_COUNT,
840 SE_IBF_SIZE, 851 SE_IBF_SIZE,
841 SE_IBF_HASH_NUM); 852 SE_IBF_HASH_NUM);
@@ -846,7 +857,7 @@ handle_p2p_strata_estimator (void *cls,
846 return GNUNET_SYSERR; 857 return GNUNET_SYSERR;
847 } 858 }
848 if (GNUNET_OK != 859 if (GNUNET_OK !=
849 strata_estimator_read (&mh[1], 860 strata_estimator_read (&msg[1],
850 len, 861 len,
851 is_compressed, 862 is_compressed,
852 remote_se)) 863 remote_se))
@@ -867,13 +878,30 @@ handle_p2p_strata_estimator (void *cls,
867 diff, 878 diff,
868 1<<get_order_from_difference (diff)); 879 1<<get_order_from_difference (diff));
869 880
870 if (diff > GNUNET_CONTAINER_multihashmap_size (op->spec->set->content->elements) / 2) 881 if ((GNUNET_YES == op->spec->byzantine) && (other_size < op->spec->byzantine_lower_bound))
882 {
883 GNUNET_break (0);
884 fail_union_operation (op);
885 return GNUNET_SYSERR;
886 }
887
888
889 if ( (GNUNET_YES == op->spec->force_full) || (diff > op->state->initial_size / 2))
871 { 890 {
872 LOG (GNUNET_ERROR_TYPE_INFO, 891 LOG (GNUNET_ERROR_TYPE_INFO,
873 "Sending full set (diff=%d, own set=%u)\n", 892 "Sending full set (diff=%d, own set=%u)\n",
874 diff, 893 diff,
875 GNUNET_CONTAINER_multihashmap_size (op->spec->set->content->elements)); 894 op->state->initial_size);
876 send_full_set (op); 895 if (op->state->initial_size <= other_size)
896 {
897 send_full_set (op);
898 }
899 else
900 {
901 struct GNUNET_MQ_Envelope *ev;
902 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL);
903 GNUNET_MQ_send (op->mq, ev);
904 }
877 } 905 }
878 else 906 else
879 { 907 {
@@ -1610,6 +1638,32 @@ send_missing_elements_iter (void *cls,
1610 return GNUNET_YES; 1638 return GNUNET_YES;
1611} 1639}
1612 1640
1641
1642/**
1643 * Handle a
1644 *
1645 * @parem cls closure, a set union operation
1646 * @param mh the demand message
1647 */
1648static void
1649handle_p2p_request_full (void *cls,
1650 const struct GNUNET_MessageHeader *mh)
1651{
1652 struct Operation *op = cls;
1653
1654 if (PHASE_EXPECT_IBF != op->state->phase)
1655 {
1656 fail_union_operation (op);
1657 GNUNET_break_op (0);
1658 return;
1659 }
1660
1661 // FIXME: we need to check that our set is larger than the
1662 // byzantine_lower_bound by some threshold
1663 send_full_set (op);
1664}
1665
1666
1613/** 1667/**
1614 * Handle a "full done" message. 1668 * Handle a "full done" message.
1615 * 1669 *
@@ -1914,6 +1968,7 @@ union_evaluate (struct Operation *op,
1914 LOG (GNUNET_ERROR_TYPE_DEBUG, 1968 LOG (GNUNET_ERROR_TYPE_DEBUG,
1915 "sent op request without context message\n"); 1969 "sent op request without context message\n");
1916 1970
1971 op->state->initial_size = GNUNET_CONTAINER_multihashmap_size (op->spec->set->content->elements);
1917 initialize_key_to_element (op); 1972 initialize_key_to_element (op);
1918} 1973}
1919 1974
@@ -1944,6 +1999,7 @@ union_accept (struct Operation *op)
1944 op->state->se = strata_estimator_dup (op->spec->set->state->se); 1999 op->state->se = strata_estimator_dup (op->spec->set->state->se);
1945 op->state->demanded_hashes = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); 2000 op->state->demanded_hashes = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
1946 op->state->salt_receive = op->state->salt_send = 42; 2001 op->state->salt_receive = op->state->salt_send = 42;
2002 op->state->initial_size = GNUNET_CONTAINER_multihashmap_size (op->spec->set->content->elements);
1947 initialize_key_to_element (op); 2003 initialize_key_to_element (op);
1948 /* kick off the operation */ 2004 /* kick off the operation */
1949 send_strata_estimator (op); 2005 send_strata_estimator (op);
@@ -2070,6 +2126,9 @@ union_handle_p2p_message (struct Operation *op,
2070 case GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE: 2126 case GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE:
2071 handle_p2p_full_done (op, mh); 2127 handle_p2p_full_done (op, mh);
2072 break; 2128 break;
2129 case GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL:
2130 handle_p2p_request_full (op, mh);
2131 break;
2073 default: 2132 default:
2074 /* Something wrong with cadet's message handlers? */ 2133 /* Something wrong with cadet's message handlers? */
2075 GNUNET_assert (0); 2134 GNUNET_assert (0);