-comments: the world ain't all male
[oweals/gnunet.git] / src / set / gnunet-service-set_protocol.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2013, 2014 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 /**
19  * @author Florian Dold
20  * @author Christian Grothoff
21  * @file set/gnunet-service-set_protocol.h
22  * @brief Peer-to-Peer messages for gnunet set
23  */
24 #ifndef SET_PROTOCOL_H
25 #define SET_PROTOCOL_H
26
27 #include "platform.h"
28 #include "gnunet_common.h"
29
30
31 GNUNET_NETWORK_STRUCT_BEGIN
32
33 struct OperationRequestMessage
34 {
35   /**
36    * Type: #GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST
37    */
38   struct GNUNET_MessageHeader header;
39
40   /**
41    * Operation to request, values from `enum GNUNET_SET_OperationType`
42    */
43   uint32_t operation GNUNET_PACKED;
44
45   /**
46    * For Intersection: my element count
47    */
48   uint32_t element_count GNUNET_PACKED;
49
50   /**
51    * Application-specific identifier of the request.
52    */
53   struct GNUNET_HashCode app_idX;
54
55   /* rest: optional message */
56 };
57
58
59 /**
60  * Message containing buckets of an invertible bloom filter.
61  *
62  * If an IBF has too many buckets for an IBF message,
63  * it is split into multiple messages.
64  */
65 struct IBFMessage
66 {
67   /**
68    * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF
69    */
70   struct GNUNET_MessageHeader header;
71
72   /**
73    * Order of the whole ibf, where
74    * num_buckets = 2^order
75    */
76   uint8_t order;
77
78   /**
79    * Padding, must be 0.
80    */
81   uint8_t reserved1;
82
83   /**
84    * Padding, must be 0.
85    */
86   uint16_t reserved2 GNUNET_PACKED;
87
88   /**
89    * Offset of the strata in the rest of the message
90    */
91   uint32_t offset GNUNET_PACKED;
92
93   /**
94    * Salt used when hashing elements for this IBF.
95    */
96   uint32_t salt GNUNET_PACKED;
97
98   /* rest: buckets */
99 };
100
101
102 struct InquiryMessage
103 {
104   /**
105    * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF
106    */
107   struct GNUNET_MessageHeader header;
108
109   /**
110    * Salt used when hashing elements for this inquiry.
111    */
112   uint32_t salt GNUNET_PACKED;
113
114   /**
115    * Reserved, set to 0.
116    */
117   uint32_t reserved GNUNET_PACKED;
118
119   /* rest: inquiry IBF keys */
120 };
121
122
123 /**
124  * During intersection, the first (and possibly second) message
125  * send it the number of elements in the set, to allow the peers
126  * to decide who should start with the Bloom filter.
127  */
128 struct IntersectionElementInfoMessage
129 {
130   /**
131    * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO
132    */
133   struct GNUNET_MessageHeader header;
134
135   /**
136    * mutator used with this bloomfilter.
137    */
138   uint32_t sender_element_count GNUNET_PACKED;
139
140 };
141
142
143 /**
144  * Bloom filter messages exchanged for set intersection calculation.
145  */
146 struct BFMessage
147 {
148   /**
149    * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF
150    */
151   struct GNUNET_MessageHeader header;
152
153   /**
154    * Number of elements the sender still has in the set.
155    */
156   uint32_t sender_element_count GNUNET_PACKED;
157
158   /**
159    * XOR of all hashes over all elements remaining in the set.
160    * Used to determine termination.
161    */
162   struct GNUNET_HashCode element_xor_hash;
163
164   /**
165    * Mutator used with this bloomfilter.
166    */
167   uint32_t sender_mutator GNUNET_PACKED;
168
169   /**
170    * Total length of the bloomfilter data.
171    */
172   uint32_t bloomfilter_total_length GNUNET_PACKED;
173
174   /**
175    * Number of bits (k-value) used in encoding the bloomfilter.
176    */
177   uint32_t bits_per_element GNUNET_PACKED;
178
179   /**
180    * rest: the sender's bloomfilter
181    */
182 };
183
184
185 /**
186  * Last message, send to confirm the final set.  Contains the element
187  * count as it is possible that the peer determined that we were done
188  * by getting the empty set, which in that case also needs to be
189  * communicated.
190  */
191 struct IntersectionDoneMessage
192 {
193   /**
194    * Type: #GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE
195    */
196   struct GNUNET_MessageHeader header;
197
198   /**
199    * Final number of elements in intersection.
200    */
201   uint32_t final_element_count GNUNET_PACKED;
202
203   /**
204    * XOR of all hashes over all elements remaining in the set.
205    */
206   struct GNUNET_HashCode element_xor_hash;
207 };
208
209
210 /**
211  * Strata estimator together with the peer's overall set size.
212  */
213 struct StrataEstimatorMessage
214 {
215   /**
216    * Type: #GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE(C)
217    */
218   struct GNUNET_MessageHeader header;
219
220   uint64_t set_size;
221 };
222
223 GNUNET_NETWORK_STRUCT_END
224
225 #endif