gnunet-service-set_intersection.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2013-2017 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file set/gnunet-service-set_intersection.c
  18. * @brief two-peer set intersection
  19. * @author Christian Fuchs
  20. * @author Christian Grothoff
  21. */
  22. #include "platform.h"
  23. #include "gnunet_util_lib.h"
  24. #include "gnunet_statistics_service.h"
  25. #include "gnunet-service-set.h"
  26. #include "gnunet_block_lib.h"
  27. #include "gnunet-service-set_protocol.h"
  28. #include "gnunet-service-set_intersection.h"
  29. #include <gcrypt.h>
  30. /**
  31. * Current phase we are in for a intersection operation.
  32. */
  33. enum IntersectionOperationPhase
  34. {
  35. /**
  36. * We are just starting.
  37. */
  38. PHASE_INITIAL,
  39. /**
  40. * We have send the number of our elements to the other
  41. * peer, but did not setup our element set yet.
  42. */
  43. PHASE_COUNT_SENT,
  44. /**
  45. * We have initialized our set and are now reducing it by exchanging
  46. * Bloom filters until one party notices the their element hashes
  47. * are equal.
  48. */
  49. PHASE_BF_EXCHANGE,
  50. /**
  51. * We must next send the P2P DONE message (after finishing mostly
  52. * with the local client). Then we will wait for the channel to close.
  53. */
  54. PHASE_MUST_SEND_DONE,
  55. /**
  56. * We have received the P2P DONE message, and must finish with the
  57. * local client before terminating the channel.
  58. */
  59. PHASE_DONE_RECEIVED,
  60. /**
  61. * The protocol is over. Results may still have to be sent to the
  62. * client.
  63. */
  64. PHASE_FINISHED
  65. };
  66. /**
  67. * State of an evaluate operation with another peer.
  68. */
  69. struct OperationState
  70. {
  71. /**
  72. * The bf we currently receive
  73. */
  74. struct GNUNET_CONTAINER_BloomFilter *remote_bf;
  75. /**
  76. * BF of the set's element.
  77. */
  78. struct GNUNET_CONTAINER_BloomFilter *local_bf;
  79. /**
  80. * Remaining elements in the intersection operation.
  81. * Maps element-id-hashes to 'elements in our set'.
  82. */
  83. struct GNUNET_CONTAINER_MultiHashMap *my_elements;
  84. /**
  85. * Iterator for sending the final set of @e my_elements to the client.
  86. */
  87. struct GNUNET_CONTAINER_MultiHashMapIterator *full_result_iter;
  88. /**
  89. * Evaluate operations are held in a linked list.
  90. */
  91. struct OperationState *next;
  92. /**
  93. * Evaluate operations are held in a linked list.
  94. */
  95. struct OperationState *prev;
  96. /**
  97. * For multipart BF transmissions, we have to store the
  98. * bloomfilter-data until we fully received it.
  99. */
  100. char *bf_data;
  101. /**
  102. * XOR of the keys of all of the elements (remaining) in my set.
  103. * Always updated when elements are added or removed to
  104. * @e my_elements.
  105. */
  106. struct GNUNET_HashCode my_xor;
  107. /**
  108. * XOR of the keys of all of the elements (remaining) in
  109. * the other peer's set. Updated when we receive the
  110. * other peer's Bloom filter.
  111. */
  112. struct GNUNET_HashCode other_xor;
  113. /**
  114. * How many bytes of @e bf_data are valid?
  115. */
  116. uint32_t bf_data_offset;
  117. /**
  118. * Current element count contained within @e my_elements.
  119. * (May differ briefly during initialization.)
  120. */
  121. uint32_t my_element_count;
  122. /**
  123. * size of the bloomfilter in @e bf_data.
  124. */
  125. uint32_t bf_data_size;
  126. /**
  127. * size of the bloomfilter
  128. */
  129. uint32_t bf_bits_per_element;
  130. /**
  131. * Salt currently used for BF construction (by us or the other peer,
  132. * depending on where we are in the code).
  133. */
  134. uint32_t salt;
  135. /**
  136. * Current state of the operation.
  137. */
  138. enum IntersectionOperationPhase phase;
  139. /**
  140. * Generation in which the operation handle
  141. * was created.
  142. */
  143. unsigned int generation_created;
  144. /**
  145. * Did we send the client that we are done?
  146. */
  147. int client_done_sent;
  148. /**
  149. * Set whenever we reach the state where the death of the
  150. * channel is perfectly find and should NOT result in the
  151. * operation being cancelled.
  152. */
  153. int channel_death_expected;
  154. };
  155. /**
  156. * Extra state required for efficient set intersection.
  157. * Merely tracks the total number of elements.
  158. */
  159. struct SetState
  160. {
  161. /**
  162. * Number of currently valid elements in the set which have not been
  163. * removed.
  164. */
  165. uint32_t current_set_element_count;
  166. };
  167. /**
  168. * If applicable in the current operation mode, send a result message
  169. * to the client indicating we removed an element.
  170. *
  171. * @param op intersection operation
  172. * @param element element to send
  173. */
  174. static void
  175. send_client_removed_element (struct Operation *op,
  176. struct GNUNET_SET_Element *element)
  177. {
  178. struct GNUNET_MQ_Envelope *ev;
  179. struct GNUNET_SET_ResultMessage *rm;
  180. if (GNUNET_SET_RESULT_REMOVED != op->result_mode)
  181. return; /* Wrong mode for transmitting removed elements */
  182. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  183. "Sending removed element (size %u) to client\n",
  184. element->size);
  185. GNUNET_STATISTICS_update (_GSS_statistics,
  186. "# Element removed messages sent",
  187. 1,
  188. GNUNET_NO);
  189. GNUNET_assert (0 != op->client_request_id);
  190. ev = GNUNET_MQ_msg_extra (rm,
  191. element->size,
  192. GNUNET_MESSAGE_TYPE_SET_RESULT);
  193. if (NULL == ev)
  194. {
  195. GNUNET_break (0);
  196. return;
  197. }
  198. rm->result_status = htons (GNUNET_SET_STATUS_OK);
  199. rm->request_id = htonl (op->client_request_id);
  200. rm->element_type = element->element_type;
  201. GNUNET_memcpy (&rm[1],
  202. element->data,
  203. element->size);
  204. GNUNET_MQ_send (op->set->cs->mq,
  205. ev);
  206. }
  207. /**
  208. * Fills the "my_elements" hashmap with all relevant elements.
  209. *
  210. * @param cls the `struct Operation *` we are performing
  211. * @param key current key code
  212. * @param value the `struct ElementEntry *` from the hash map
  213. * @return #GNUNET_YES (we should continue to iterate)
  214. */
  215. static int
  216. filtered_map_initialization (void *cls,
  217. const struct GNUNET_HashCode *key,
  218. void *value)
  219. {
  220. struct Operation *op = cls;
  221. struct ElementEntry *ee = value;
  222. struct GNUNET_HashCode mutated_hash;
  223. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  224. "FIMA called for %s:%u\n",
  225. GNUNET_h2s (&ee->element_hash),
  226. ee->element.size);
  227. if (GNUNET_NO == _GSS_is_element_of_operation (ee, op))
  228. {
  229. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  230. "Reduced initialization, not starting with %s:%u (wrong generation)\n",
  231. GNUNET_h2s (&ee->element_hash),
  232. ee->element.size);
  233. return GNUNET_YES; /* element not valid in our operation's generation */
  234. }
  235. /* Test if element is in other peer's bloomfilter */
  236. GNUNET_BLOCK_mingle_hash (&ee->element_hash,
  237. op->state->salt,
  238. &mutated_hash);
  239. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  240. "Testing mingled hash %s with salt %u\n",
  241. GNUNET_h2s (&mutated_hash),
  242. op->state->salt);
  243. if (GNUNET_NO ==
  244. GNUNET_CONTAINER_bloomfilter_test (op->state->remote_bf,
  245. &mutated_hash))
  246. {
  247. /* remove this element */
  248. send_client_removed_element (op,
  249. &ee->element);
  250. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  251. "Reduced initialization, not starting with %s:%u\n",
  252. GNUNET_h2s (&ee->element_hash),
  253. ee->element.size);
  254. return GNUNET_YES;
  255. }
  256. op->state->my_element_count++;
  257. GNUNET_CRYPTO_hash_xor (&op->state->my_xor,
  258. &ee->element_hash,
  259. &op->state->my_xor);
  260. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  261. "Filtered initialization of my_elements, adding %s:%u\n",
  262. GNUNET_h2s (&ee->element_hash),
  263. ee->element.size);
  264. GNUNET_break (GNUNET_YES ==
  265. GNUNET_CONTAINER_multihashmap_put (op->state->my_elements,
  266. &ee->element_hash,
  267. ee,
  268. GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
  269. return GNUNET_YES;
  270. }
  271. /**
  272. * Removes elements from our hashmap if they are not contained within the
  273. * provided remote bloomfilter.
  274. *
  275. * @param cls closure with the `struct Operation *`
  276. * @param key current key code
  277. * @param value value in the hash map
  278. * @return #GNUNET_YES (we should continue to iterate)
  279. */
  280. static int
  281. iterator_bf_reduce (void *cls,
  282. const struct GNUNET_HashCode *key,
  283. void *value)
  284. {
  285. struct Operation *op = cls;
  286. struct ElementEntry *ee = value;
  287. struct GNUNET_HashCode mutated_hash;
  288. GNUNET_BLOCK_mingle_hash (&ee->element_hash,
  289. op->state->salt,
  290. &mutated_hash);
  291. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  292. "Testing mingled hash %s with salt %u\n",
  293. GNUNET_h2s (&mutated_hash),
  294. op->state->salt);
  295. if (GNUNET_NO ==
  296. GNUNET_CONTAINER_bloomfilter_test (op->state->remote_bf,
  297. &mutated_hash))
  298. {
  299. GNUNET_break (0 < op->state->my_element_count);
  300. op->state->my_element_count--;
  301. GNUNET_CRYPTO_hash_xor (&op->state->my_xor,
  302. &ee->element_hash,
  303. &op->state->my_xor);
  304. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  305. "Bloom filter reduction of my_elements, removing %s:%u\n",
  306. GNUNET_h2s (&ee->element_hash),
  307. ee->element.size);
  308. GNUNET_assert (GNUNET_YES ==
  309. GNUNET_CONTAINER_multihashmap_remove (op->state->my_elements,
  310. &ee->element_hash,
  311. ee));
  312. send_client_removed_element (op,
  313. &ee->element);
  314. }
  315. else
  316. {
  317. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  318. "Bloom filter reduction of my_elements, keeping %s:%u\n",
  319. GNUNET_h2s (&ee->element_hash),
  320. ee->element.size);
  321. }
  322. return GNUNET_YES;
  323. }
  324. /**
  325. * Create initial bloomfilter based on all the elements given.
  326. *
  327. * @param cls the `struct Operation *`
  328. * @param key current key code
  329. * @param value the `struct ElementEntry` to process
  330. * @return #GNUNET_YES (we should continue to iterate)
  331. */
  332. static int
  333. iterator_bf_create (void *cls,
  334. const struct GNUNET_HashCode *key,
  335. void *value)
  336. {
  337. struct Operation *op = cls;
  338. struct ElementEntry *ee = value;
  339. struct GNUNET_HashCode mutated_hash;
  340. GNUNET_BLOCK_mingle_hash (&ee->element_hash,
  341. op->state->salt,
  342. &mutated_hash);
  343. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  344. "Initializing BF with hash %s with salt %u\n",
  345. GNUNET_h2s (&mutated_hash),
  346. op->state->salt);
  347. GNUNET_CONTAINER_bloomfilter_add (op->state->local_bf,
  348. &mutated_hash);
  349. return GNUNET_YES;
  350. }
  351. /**
  352. * Inform the client that the intersection operation has failed,
  353. * and proceed to destroy the evaluate operation.
  354. *
  355. * @param op the intersection operation to fail
  356. */
  357. static void
  358. fail_intersection_operation (struct Operation *op)
  359. {
  360. struct GNUNET_MQ_Envelope *ev;
  361. struct GNUNET_SET_ResultMessage *msg;
  362. GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
  363. "Intersection operation failed\n");
  364. GNUNET_STATISTICS_update (_GSS_statistics,
  365. "# Intersection operations failed",
  366. 1,
  367. GNUNET_NO);
  368. if (NULL != op->state->my_elements)
  369. {
  370. GNUNET_CONTAINER_multihashmap_destroy (op->state->my_elements);
  371. op->state->my_elements = NULL;
  372. }
  373. ev = GNUNET_MQ_msg (msg,
  374. GNUNET_MESSAGE_TYPE_SET_RESULT);
  375. msg->result_status = htons (GNUNET_SET_STATUS_FAILURE);
  376. msg->request_id = htonl (op->client_request_id);
  377. msg->element_type = htons (0);
  378. GNUNET_MQ_send (op->set->cs->mq,
  379. ev);
  380. _GSS_operation_destroy (op,
  381. GNUNET_YES);
  382. }
  383. /**
  384. * Send a bloomfilter to our peer. After the result done message has
  385. * been sent to the client, destroy the evaluate operation.
  386. *
  387. * @param op intersection operation
  388. */
  389. static void
  390. send_bloomfilter (struct Operation *op)
  391. {
  392. struct GNUNET_MQ_Envelope *ev;
  393. struct BFMessage *msg;
  394. uint32_t bf_size;
  395. uint32_t bf_elementbits;
  396. uint32_t chunk_size;
  397. char *bf_data;
  398. uint32_t offset;
  399. /* We consider the ratio of the set sizes to determine
  400. the number of bits per element, as the smaller set
  401. should use more bits to maximize its set reduction
  402. potential and minimize overall bandwidth consumption. */
  403. bf_elementbits = 2 + ceil (log2 ((double)
  404. (op->remote_element_count
  405. / (double) op->state->my_element_count)));
  406. if (bf_elementbits < 1)
  407. bf_elementbits = 1; /* make sure k is not 0 */
  408. /* optimize BF-size to ~50% of bits set */
  409. bf_size = ceil ((double) (op->state->my_element_count
  410. * bf_elementbits / log (2)));
  411. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  412. "Sending Bloom filter (%u) of size %u bytes\n",
  413. (unsigned int) bf_elementbits,
  414. (unsigned int) bf_size);
  415. op->state->local_bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
  416. bf_size,
  417. bf_elementbits);
  418. op->state->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
  419. UINT32_MAX);
  420. GNUNET_CONTAINER_multihashmap_iterate (op->state->my_elements,
  421. &iterator_bf_create,
  422. op);
  423. /* send our Bloom filter */
  424. GNUNET_STATISTICS_update (_GSS_statistics,
  425. "# Intersection Bloom filters sent",
  426. 1,
  427. GNUNET_NO);
  428. chunk_size = 60 * 1024 - sizeof(struct BFMessage);
  429. if (bf_size <= chunk_size)
  430. {
  431. /* singlepart */
  432. chunk_size = bf_size;
  433. ev = GNUNET_MQ_msg_extra (msg,
  434. chunk_size,
  435. GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF);
  436. GNUNET_assert (GNUNET_SYSERR !=
  437. GNUNET_CONTAINER_bloomfilter_get_raw_data (
  438. op->state->local_bf,
  439. (char *) &msg[1],
  440. bf_size));
  441. msg->sender_element_count = htonl (op->state->my_element_count);
  442. msg->bloomfilter_total_length = htonl (bf_size);
  443. msg->bits_per_element = htonl (bf_elementbits);
  444. msg->sender_mutator = htonl (op->state->salt);
  445. msg->element_xor_hash = op->state->my_xor;
  446. GNUNET_MQ_send (op->mq, ev);
  447. }
  448. else
  449. {
  450. /* multipart */
  451. bf_data = GNUNET_malloc (bf_size);
  452. GNUNET_assert (GNUNET_SYSERR !=
  453. GNUNET_CONTAINER_bloomfilter_get_raw_data (
  454. op->state->local_bf,
  455. bf_data,
  456. bf_size));
  457. offset = 0;
  458. while (offset < bf_size)
  459. {
  460. if (bf_size - chunk_size < offset)
  461. chunk_size = bf_size - offset;
  462. ev = GNUNET_MQ_msg_extra (msg,
  463. chunk_size,
  464. GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF);
  465. GNUNET_memcpy (&msg[1],
  466. &bf_data[offset],
  467. chunk_size);
  468. offset += chunk_size;
  469. msg->sender_element_count = htonl (op->state->my_element_count);
  470. msg->bloomfilter_total_length = htonl (bf_size);
  471. msg->bits_per_element = htonl (bf_elementbits);
  472. msg->sender_mutator = htonl (op->state->salt);
  473. msg->element_xor_hash = op->state->my_xor;
  474. GNUNET_MQ_send (op->mq, ev);
  475. }
  476. GNUNET_free (bf_data);
  477. }
  478. GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf);
  479. op->state->local_bf = NULL;
  480. }
  481. /**
  482. * Signal to the client that the operation has finished and
  483. * destroy the operation.
  484. *
  485. * @param cls operation to destroy
  486. */
  487. static void
  488. send_client_done_and_destroy (void *cls)
  489. {
  490. struct Operation *op = cls;
  491. struct GNUNET_MQ_Envelope *ev;
  492. struct GNUNET_SET_ResultMessage *rm;
  493. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  494. "Intersection succeeded, sending DONE to local client\n");
  495. GNUNET_STATISTICS_update (_GSS_statistics,
  496. "# Intersection operations succeeded",
  497. 1,
  498. GNUNET_NO);
  499. ev = GNUNET_MQ_msg (rm,
  500. GNUNET_MESSAGE_TYPE_SET_RESULT);
  501. rm->request_id = htonl (op->client_request_id);
  502. rm->result_status = htons (GNUNET_SET_STATUS_DONE);
  503. rm->element_type = htons (0);
  504. GNUNET_MQ_send (op->set->cs->mq,
  505. ev);
  506. _GSS_operation_destroy (op,
  507. GNUNET_YES);
  508. }
  509. /**
  510. * Remember that we are done dealing with the local client
  511. * AND have sent the other peer our message that we are done,
  512. * so we are not just waiting for the channel to die before
  513. * telling the local client that we are done as our last act.
  514. *
  515. * @param cls the `struct Operation`.
  516. */
  517. static void
  518. finished_local_operations (void *cls)
  519. {
  520. struct Operation *op = cls;
  521. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  522. "DONE sent to other peer, now waiting for other end to close the channel\n");
  523. op->state->phase = PHASE_FINISHED;
  524. op->state->channel_death_expected = GNUNET_YES;
  525. }
  526. /**
  527. * Notify the other peer that we are done. Once this message
  528. * is out, we still need to notify the local client that we
  529. * are done.
  530. *
  531. * @param op operation to notify for.
  532. */
  533. static void
  534. send_p2p_done (struct Operation *op)
  535. {
  536. struct GNUNET_MQ_Envelope *ev;
  537. struct IntersectionDoneMessage *idm;
  538. GNUNET_assert (PHASE_MUST_SEND_DONE == op->state->phase);
  539. GNUNET_assert (GNUNET_NO == op->state->channel_death_expected);
  540. ev = GNUNET_MQ_msg (idm,
  541. GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE);
  542. idm->final_element_count = htonl (op->state->my_element_count);
  543. idm->element_xor_hash = op->state->my_xor;
  544. GNUNET_MQ_notify_sent (ev,
  545. &finished_local_operations,
  546. op);
  547. GNUNET_MQ_send (op->mq,
  548. ev);
  549. }
  550. /**
  551. * Send all elements in the full result iterator.
  552. *
  553. * @param cls the `struct Operation *`
  554. */
  555. static void
  556. send_remaining_elements (void *cls)
  557. {
  558. struct Operation *op = cls;
  559. const void *nxt;
  560. const struct ElementEntry *ee;
  561. struct GNUNET_MQ_Envelope *ev;
  562. struct GNUNET_SET_ResultMessage *rm;
  563. const struct GNUNET_SET_Element *element;
  564. int res;
  565. res = GNUNET_CONTAINER_multihashmap_iterator_next (
  566. op->state->full_result_iter,
  567. NULL,
  568. &nxt);
  569. if (GNUNET_NO == res)
  570. {
  571. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  572. "Sending done and destroy because iterator ran out\n");
  573. GNUNET_CONTAINER_multihashmap_iterator_destroy (
  574. op->state->full_result_iter);
  575. op->state->full_result_iter = NULL;
  576. if (PHASE_DONE_RECEIVED == op->state->phase)
  577. {
  578. op->state->phase = PHASE_FINISHED;
  579. send_client_done_and_destroy (op);
  580. }
  581. else if (PHASE_MUST_SEND_DONE == op->state->phase)
  582. {
  583. send_p2p_done (op);
  584. }
  585. else
  586. {
  587. GNUNET_assert (0);
  588. }
  589. return;
  590. }
  591. ee = nxt;
  592. element = &ee->element;
  593. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  594. "Sending element %s:%u to client (full set)\n",
  595. GNUNET_h2s (&ee->element_hash),
  596. element->size);
  597. GNUNET_assert (0 != op->client_request_id);
  598. ev = GNUNET_MQ_msg_extra (rm,
  599. element->size,
  600. GNUNET_MESSAGE_TYPE_SET_RESULT);
  601. GNUNET_assert (NULL != ev);
  602. rm->result_status = htons (GNUNET_SET_STATUS_OK);
  603. rm->request_id = htonl (op->client_request_id);
  604. rm->element_type = element->element_type;
  605. GNUNET_memcpy (&rm[1],
  606. element->data,
  607. element->size);
  608. GNUNET_MQ_notify_sent (ev,
  609. &send_remaining_elements,
  610. op);
  611. GNUNET_MQ_send (op->set->cs->mq,
  612. ev);
  613. }
  614. /**
  615. * Fills the "my_elements" hashmap with the initial set of
  616. * (non-deleted) elements from the set of the specification.
  617. *
  618. * @param cls closure with the `struct Operation *`
  619. * @param key current key code for the element
  620. * @param value value in the hash map with the `struct ElementEntry *`
  621. * @return #GNUNET_YES (we should continue to iterate)
  622. */
  623. static int
  624. initialize_map_unfiltered (void *cls,
  625. const struct GNUNET_HashCode *key,
  626. void *value)
  627. {
  628. struct ElementEntry *ee = value;
  629. struct Operation *op = cls;
  630. if (GNUNET_NO == _GSS_is_element_of_operation (ee, op))
  631. return GNUNET_YES; /* element not live in operation's generation */
  632. GNUNET_CRYPTO_hash_xor (&op->state->my_xor,
  633. &ee->element_hash,
  634. &op->state->my_xor);
  635. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  636. "Initial full initialization of my_elements, adding %s:%u\n",
  637. GNUNET_h2s (&ee->element_hash),
  638. ee->element.size);
  639. GNUNET_break (GNUNET_YES ==
  640. GNUNET_CONTAINER_multihashmap_put (op->state->my_elements,
  641. &ee->element_hash,
  642. ee,
  643. GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
  644. return GNUNET_YES;
  645. }
  646. /**
  647. * Send our element count to the peer, in case our element count is
  648. * lower than theirs.
  649. *
  650. * @param op intersection operation
  651. */
  652. static void
  653. send_element_count (struct Operation *op)
  654. {
  655. struct GNUNET_MQ_Envelope *ev;
  656. struct IntersectionElementInfoMessage *msg;
  657. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  658. "Sending our element count (%u)\n",
  659. op->state->my_element_count);
  660. ev = GNUNET_MQ_msg (msg,
  661. GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO);
  662. msg->sender_element_count = htonl (op->state->my_element_count);
  663. GNUNET_MQ_send (op->mq, ev);
  664. }
  665. /**
  666. * We go first, initialize our map with all elements and
  667. * send the first Bloom filter.
  668. *
  669. * @param op operation to start exchange for
  670. */
  671. static void
  672. begin_bf_exchange (struct Operation *op)
  673. {
  674. op->state->phase = PHASE_BF_EXCHANGE;
  675. GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements,
  676. &initialize_map_unfiltered,
  677. op);
  678. send_bloomfilter (op);
  679. }
  680. /**
  681. * Handle the initial `struct IntersectionElementInfoMessage` from a
  682. * remote peer.
  683. *
  684. * @param cls the intersection operation
  685. * @param mh the header of the message
  686. */
  687. void
  688. handle_intersection_p2p_element_info (void *cls,
  689. const struct
  690. IntersectionElementInfoMessage *msg)
  691. {
  692. struct Operation *op = cls;
  693. if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation)
  694. {
  695. GNUNET_break_op (0);
  696. fail_intersection_operation (op);
  697. return;
  698. }
  699. op->remote_element_count = ntohl (msg->sender_element_count);
  700. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  701. "Received remote element count (%u), I have %u\n",
  702. op->remote_element_count,
  703. op->state->my_element_count);
  704. if (((PHASE_INITIAL != op->state->phase) &&
  705. (PHASE_COUNT_SENT != op->state->phase)) ||
  706. (op->state->my_element_count > op->remote_element_count) ||
  707. (0 == op->state->my_element_count) ||
  708. (0 == op->remote_element_count))
  709. {
  710. GNUNET_break_op (0);
  711. fail_intersection_operation (op);
  712. return;
  713. }
  714. GNUNET_break (NULL == op->state->remote_bf);
  715. begin_bf_exchange (op);
  716. GNUNET_CADET_receive_done (op->channel);
  717. }
  718. /**
  719. * Process a Bloomfilter once we got all the chunks.
  720. *
  721. * @param op the intersection operation
  722. */
  723. static void
  724. process_bf (struct Operation *op)
  725. {
  726. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  727. "Received BF in phase %u, foreign count is %u, my element count is %u/%u\n",
  728. op->state->phase,
  729. op->remote_element_count,
  730. op->state->my_element_count,
  731. GNUNET_CONTAINER_multihashmap_size (op->set->content->elements));
  732. switch (op->state->phase)
  733. {
  734. case PHASE_INITIAL:
  735. GNUNET_break_op (0);
  736. fail_intersection_operation (op);
  737. return;
  738. case PHASE_COUNT_SENT:
  739. /* This is the first BF being sent, build our initial map with
  740. filtering in place */
  741. op->state->my_element_count = 0;
  742. GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements,
  743. &filtered_map_initialization,
  744. op);
  745. break;
  746. case PHASE_BF_EXCHANGE:
  747. /* Update our set by reduction */
  748. GNUNET_CONTAINER_multihashmap_iterate (op->state->my_elements,
  749. &iterator_bf_reduce,
  750. op);
  751. break;
  752. case PHASE_MUST_SEND_DONE:
  753. GNUNET_break_op (0);
  754. fail_intersection_operation (op);
  755. return;
  756. case PHASE_DONE_RECEIVED:
  757. GNUNET_break_op (0);
  758. fail_intersection_operation (op);
  759. return;
  760. case PHASE_FINISHED:
  761. GNUNET_break_op (0);
  762. fail_intersection_operation (op);
  763. return;
  764. }
  765. GNUNET_CONTAINER_bloomfilter_free (op->state->remote_bf);
  766. op->state->remote_bf = NULL;
  767. if ((0 == op->state->my_element_count) || /* fully disjoint */
  768. ((op->state->my_element_count == op->remote_element_count) &&
  769. (0 == GNUNET_memcmp (&op->state->my_xor,
  770. &op->state->other_xor))))
  771. {
  772. /* we are done */
  773. op->state->phase = PHASE_MUST_SEND_DONE;
  774. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  775. "Intersection succeeded, sending DONE to other peer\n");
  776. GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf);
  777. op->state->local_bf = NULL;
  778. if (GNUNET_SET_RESULT_FULL == op->result_mode)
  779. {
  780. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  781. "Sending full result set (%u elements)\n",
  782. GNUNET_CONTAINER_multihashmap_size (op->state->my_elements));
  783. op->state->full_result_iter
  784. = GNUNET_CONTAINER_multihashmap_iterator_create (
  785. op->state->my_elements);
  786. send_remaining_elements (op);
  787. return;
  788. }
  789. send_p2p_done (op);
  790. return;
  791. }
  792. op->state->phase = PHASE_BF_EXCHANGE;
  793. send_bloomfilter (op);
  794. }
  795. /**
  796. * Check an BF message from a remote peer.
  797. *
  798. * @param cls the intersection operation
  799. * @param msg the header of the message
  800. * @return #GNUNET_OK if @a msg is well-formed
  801. */
  802. int
  803. check_intersection_p2p_bf (void *cls,
  804. const struct BFMessage *msg)
  805. {
  806. struct Operation *op = cls;
  807. if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation)
  808. {
  809. GNUNET_break_op (0);
  810. return GNUNET_SYSERR;
  811. }
  812. return GNUNET_OK;
  813. }
  814. /**
  815. * Handle an BF message from a remote peer.
  816. *
  817. * @param cls the intersection operation
  818. * @param msg the header of the message
  819. */
  820. void
  821. handle_intersection_p2p_bf (void *cls,
  822. const struct BFMessage *msg)
  823. {
  824. struct Operation *op = cls;
  825. uint32_t bf_size;
  826. uint32_t chunk_size;
  827. uint32_t bf_bits_per_element;
  828. switch (op->state->phase)
  829. {
  830. case PHASE_INITIAL:
  831. GNUNET_break_op (0);
  832. fail_intersection_operation (op);
  833. return;
  834. case PHASE_COUNT_SENT:
  835. case PHASE_BF_EXCHANGE:
  836. bf_size = ntohl (msg->bloomfilter_total_length);
  837. bf_bits_per_element = ntohl (msg->bits_per_element);
  838. chunk_size = htons (msg->header.size) - sizeof(struct BFMessage);
  839. op->state->other_xor = msg->element_xor_hash;
  840. if (bf_size == chunk_size)
  841. {
  842. if (NULL != op->state->bf_data)
  843. {
  844. GNUNET_break_op (0);
  845. fail_intersection_operation (op);
  846. return;
  847. }
  848. /* single part, done here immediately */
  849. op->state->remote_bf
  850. = GNUNET_CONTAINER_bloomfilter_init ((const char *) &msg[1],
  851. bf_size,
  852. bf_bits_per_element);
  853. op->state->salt = ntohl (msg->sender_mutator);
  854. op->remote_element_count = ntohl (msg->sender_element_count);
  855. process_bf (op);
  856. break;
  857. }
  858. /* multipart chunk */
  859. if (NULL == op->state->bf_data)
  860. {
  861. /* first chunk, initialize */
  862. op->state->bf_data = GNUNET_malloc (bf_size);
  863. op->state->bf_data_size = bf_size;
  864. op->state->bf_bits_per_element = bf_bits_per_element;
  865. op->state->bf_data_offset = 0;
  866. op->state->salt = ntohl (msg->sender_mutator);
  867. op->remote_element_count = ntohl (msg->sender_element_count);
  868. }
  869. else
  870. {
  871. /* increment */
  872. if ((op->state->bf_data_size != bf_size) ||
  873. (op->state->bf_bits_per_element != bf_bits_per_element) ||
  874. (op->state->bf_data_offset + chunk_size > bf_size) ||
  875. (op->state->salt != ntohl (msg->sender_mutator)) ||
  876. (op->remote_element_count != ntohl (msg->sender_element_count)))
  877. {
  878. GNUNET_break_op (0);
  879. fail_intersection_operation (op);
  880. return;
  881. }
  882. }
  883. GNUNET_memcpy (&op->state->bf_data[op->state->bf_data_offset],
  884. (const char *) &msg[1],
  885. chunk_size);
  886. op->state->bf_data_offset += chunk_size;
  887. if (op->state->bf_data_offset == bf_size)
  888. {
  889. /* last chunk, run! */
  890. op->state->remote_bf
  891. = GNUNET_CONTAINER_bloomfilter_init (op->state->bf_data,
  892. bf_size,
  893. bf_bits_per_element);
  894. GNUNET_free (op->state->bf_data);
  895. op->state->bf_data = NULL;
  896. op->state->bf_data_size = 0;
  897. process_bf (op);
  898. }
  899. break;
  900. default:
  901. GNUNET_break_op (0);
  902. fail_intersection_operation (op);
  903. return;
  904. }
  905. GNUNET_CADET_receive_done (op->channel);
  906. }
  907. /**
  908. * Remove all elements from our hashmap.
  909. *
  910. * @param cls closure with the `struct Operation *`
  911. * @param key current key code
  912. * @param value value in the hash map
  913. * @return #GNUNET_YES (we should continue to iterate)
  914. */
  915. static int
  916. filter_all (void *cls,
  917. const struct GNUNET_HashCode *key,
  918. void *value)
  919. {
  920. struct Operation *op = cls;
  921. struct ElementEntry *ee = value;
  922. GNUNET_break (0 < op->state->my_element_count);
  923. op->state->my_element_count--;
  924. GNUNET_CRYPTO_hash_xor (&op->state->my_xor,
  925. &ee->element_hash,
  926. &op->state->my_xor);
  927. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  928. "Final reduction of my_elements, removing %s:%u\n",
  929. GNUNET_h2s (&ee->element_hash),
  930. ee->element.size);
  931. GNUNET_assert (GNUNET_YES ==
  932. GNUNET_CONTAINER_multihashmap_remove (op->state->my_elements,
  933. &ee->element_hash,
  934. ee));
  935. send_client_removed_element (op,
  936. &ee->element);
  937. return GNUNET_YES;
  938. }
  939. /**
  940. * Handle a done message from a remote peer
  941. *
  942. * @param cls the intersection operation
  943. * @param mh the message
  944. */
  945. void
  946. handle_intersection_p2p_done (void *cls,
  947. const struct IntersectionDoneMessage *idm)
  948. {
  949. struct Operation *op = cls;
  950. if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation)
  951. {
  952. GNUNET_break_op (0);
  953. fail_intersection_operation (op);
  954. return;
  955. }
  956. if (PHASE_BF_EXCHANGE != op->state->phase)
  957. {
  958. /* wrong phase to conclude? FIXME: Or should we allow this
  959. if the other peer has _initially_ already an empty set? */
  960. GNUNET_break_op (0);
  961. fail_intersection_operation (op);
  962. return;
  963. }
  964. if (0 == ntohl (idm->final_element_count))
  965. {
  966. /* other peer determined empty set is the intersection,
  967. remove all elements */
  968. GNUNET_CONTAINER_multihashmap_iterate (op->state->my_elements,
  969. &filter_all,
  970. op);
  971. }
  972. if ((op->state->my_element_count != ntohl (idm->final_element_count)) ||
  973. (0 != GNUNET_memcmp (&op->state->my_xor,
  974. &idm->element_xor_hash)))
  975. {
  976. /* Other peer thinks we are done, but we disagree on the result! */
  977. GNUNET_break_op (0);
  978. fail_intersection_operation (op);
  979. return;
  980. }
  981. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  982. "Got IntersectionDoneMessage, have %u elements in intersection\n",
  983. op->state->my_element_count);
  984. op->state->phase = PHASE_DONE_RECEIVED;
  985. GNUNET_CADET_receive_done (op->channel);
  986. GNUNET_assert (GNUNET_NO == op->state->client_done_sent);
  987. if (GNUNET_SET_RESULT_FULL == op->result_mode)
  988. {
  989. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  990. "Sending full result set to client (%u elements)\n",
  991. GNUNET_CONTAINER_multihashmap_size (op->state->my_elements));
  992. op->state->full_result_iter
  993. = GNUNET_CONTAINER_multihashmap_iterator_create (op->state->my_elements);
  994. send_remaining_elements (op);
  995. return;
  996. }
  997. op->state->phase = PHASE_FINISHED;
  998. send_client_done_and_destroy (op);
  999. }
  1000. /**
  1001. * Initiate a set intersection operation with a remote peer.
  1002. *
  1003. * @param op operation that is created, should be initialized to
  1004. * begin the evaluation
  1005. * @param opaque_context message to be transmitted to the listener
  1006. * to convince it to accept, may be NULL
  1007. * @return operation-specific state to keep in @a op
  1008. */
  1009. static struct OperationState *
  1010. intersection_evaluate (struct Operation *op,
  1011. const struct GNUNET_MessageHeader *opaque_context)
  1012. {
  1013. struct OperationState *state;
  1014. struct GNUNET_MQ_Envelope *ev;
  1015. struct OperationRequestMessage *msg;
  1016. ev = GNUNET_MQ_msg_nested_mh (msg,
  1017. GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST,
  1018. opaque_context);
  1019. if (NULL == ev)
  1020. {
  1021. /* the context message is too large!? */
  1022. GNUNET_break (0);
  1023. return NULL;
  1024. }
  1025. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  1026. "Initiating intersection operation evaluation\n");
  1027. state = GNUNET_new (struct OperationState);
  1028. /* we started the operation, thus we have to send the operation request */
  1029. state->phase = PHASE_INITIAL;
  1030. state->my_element_count = op->set->state->current_set_element_count;
  1031. state->my_elements
  1032. = GNUNET_CONTAINER_multihashmap_create (state->my_element_count,
  1033. GNUNET_YES);
  1034. msg->operation = htonl (GNUNET_SET_OPERATION_INTERSECTION);
  1035. msg->element_count = htonl (state->my_element_count);
  1036. GNUNET_MQ_send (op->mq,
  1037. ev);
  1038. state->phase = PHASE_COUNT_SENT;
  1039. if (NULL != opaque_context)
  1040. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  1041. "Sent op request with context message\n");
  1042. else
  1043. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  1044. "Sent op request without context message\n");
  1045. return state;
  1046. }
  1047. /**
  1048. * Accept an intersection operation request from a remote peer. Only
  1049. * initializes the private operation state.
  1050. *
  1051. * @param op operation that will be accepted as an intersection operation
  1052. */
  1053. static struct OperationState *
  1054. intersection_accept (struct Operation *op)
  1055. {
  1056. struct OperationState *state;
  1057. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  1058. "Accepting set intersection operation\n");
  1059. state = GNUNET_new (struct OperationState);
  1060. state->phase = PHASE_INITIAL;
  1061. state->my_element_count
  1062. = op->set->state->current_set_element_count;
  1063. state->my_elements
  1064. = GNUNET_CONTAINER_multihashmap_create (GNUNET_MIN (state->my_element_count,
  1065. op->remote_element_count),
  1066. GNUNET_YES);
  1067. op->state = state;
  1068. if (op->remote_element_count < state->my_element_count)
  1069. {
  1070. /* If the other peer (Alice) has fewer elements than us (Bob),
  1071. we just send the count as Alice should send the first BF */
  1072. send_element_count (op);
  1073. state->phase = PHASE_COUNT_SENT;
  1074. return state;
  1075. }
  1076. /* We have fewer elements, so we start with the BF */
  1077. begin_bf_exchange (op);
  1078. return state;
  1079. }
  1080. /**
  1081. * Destroy the intersection operation. Only things specific to the
  1082. * intersection operation are destroyed.
  1083. *
  1084. * @param op intersection operation to destroy
  1085. */
  1086. static void
  1087. intersection_op_cancel (struct Operation *op)
  1088. {
  1089. /* check if the op was canceled twice */
  1090. GNUNET_assert (NULL != op->state);
  1091. if (NULL != op->state->remote_bf)
  1092. {
  1093. GNUNET_CONTAINER_bloomfilter_free (op->state->remote_bf);
  1094. op->state->remote_bf = NULL;
  1095. }
  1096. if (NULL != op->state->local_bf)
  1097. {
  1098. GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf);
  1099. op->state->local_bf = NULL;
  1100. }
  1101. if (NULL != op->state->my_elements)
  1102. {
  1103. GNUNET_CONTAINER_multihashmap_destroy (op->state->my_elements);
  1104. op->state->my_elements = NULL;
  1105. }
  1106. if (NULL != op->state->full_result_iter)
  1107. {
  1108. GNUNET_CONTAINER_multihashmap_iterator_destroy (
  1109. op->state->full_result_iter);
  1110. op->state->full_result_iter = NULL;
  1111. }
  1112. GNUNET_free (op->state);
  1113. op->state = NULL;
  1114. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  1115. "Destroying intersection op state done\n");
  1116. }
  1117. /**
  1118. * Create a new set supporting the intersection operation.
  1119. *
  1120. * @return the newly created set
  1121. */
  1122. static struct SetState *
  1123. intersection_set_create ()
  1124. {
  1125. struct SetState *set_state;
  1126. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  1127. "Intersection set created\n");
  1128. set_state = GNUNET_new (struct SetState);
  1129. set_state->current_set_element_count = 0;
  1130. return set_state;
  1131. }
  1132. /**
  1133. * Add the element from the given element message to the set.
  1134. *
  1135. * @param set_state state of the set want to add to
  1136. * @param ee the element to add to the set
  1137. */
  1138. static void
  1139. intersection_add (struct SetState *set_state,
  1140. struct ElementEntry *ee)
  1141. {
  1142. set_state->current_set_element_count++;
  1143. }
  1144. /**
  1145. * Destroy a set that supports the intersection operation
  1146. *
  1147. * @param set_state the set to destroy
  1148. */
  1149. static void
  1150. intersection_set_destroy (struct SetState *set_state)
  1151. {
  1152. GNUNET_free (set_state);
  1153. }
  1154. /**
  1155. * Remove the element given in the element message from the set.
  1156. *
  1157. * @param set_state state of the set to remove from
  1158. * @param element set element to remove
  1159. */
  1160. static void
  1161. intersection_remove (struct SetState *set_state,
  1162. struct ElementEntry *element)
  1163. {
  1164. GNUNET_assert (0 < set_state->current_set_element_count);
  1165. set_state->current_set_element_count--;
  1166. }
  1167. /**
  1168. * Callback for channel death for the intersection operation.
  1169. *
  1170. * @param op operation that lost the channel
  1171. */
  1172. static void
  1173. intersection_channel_death (struct Operation *op)
  1174. {
  1175. if (GNUNET_YES == op->state->channel_death_expected)
  1176. {
  1177. /* oh goodie, we are done! */
  1178. send_client_done_and_destroy (op);
  1179. }
  1180. else
  1181. {
  1182. /* sorry, channel went down early, too bad. */
  1183. _GSS_operation_destroy (op,
  1184. GNUNET_YES);
  1185. }
  1186. }
  1187. /**
  1188. * Get the table with implementing functions for set intersection.
  1189. *
  1190. * @return the operation specific VTable
  1191. */
  1192. const struct SetVT *
  1193. _GSS_intersection_vt ()
  1194. {
  1195. static const struct SetVT intersection_vt = {
  1196. .create = &intersection_set_create,
  1197. .add = &intersection_add,
  1198. .remove = &intersection_remove,
  1199. .destroy_set = &intersection_set_destroy,
  1200. .evaluate = &intersection_evaluate,
  1201. .accept = &intersection_accept,
  1202. .cancel = &intersection_op_cancel,
  1203. .channel_death = &intersection_channel_death,
  1204. };
  1205. return &intersection_vt;
  1206. }