gnunet-service-set_intersection.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  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 (op->state->local_bf,
  438. (char*) &msg[1],
  439. bf_size));
  440. msg->sender_element_count = htonl (op->state->my_element_count);
  441. msg->bloomfilter_total_length = htonl (bf_size);
  442. msg->bits_per_element = htonl (bf_elementbits);
  443. msg->sender_mutator = htonl (op->state->salt);
  444. msg->element_xor_hash = op->state->my_xor;
  445. GNUNET_MQ_send (op->mq, ev);
  446. }
  447. else
  448. {
  449. /* multipart */
  450. bf_data = GNUNET_malloc (bf_size);
  451. GNUNET_assert (GNUNET_SYSERR !=
  452. GNUNET_CONTAINER_bloomfilter_get_raw_data (op->state->local_bf,
  453. bf_data,
  454. bf_size));
  455. offset = 0;
  456. while (offset < bf_size)
  457. {
  458. if (bf_size - chunk_size < offset)
  459. chunk_size = bf_size - offset;
  460. ev = GNUNET_MQ_msg_extra (msg,
  461. chunk_size,
  462. GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF);
  463. GNUNET_memcpy (&msg[1],
  464. &bf_data[offset],
  465. chunk_size);
  466. offset += chunk_size;
  467. msg->sender_element_count = htonl (op->state->my_element_count);
  468. msg->bloomfilter_total_length = htonl (bf_size);
  469. msg->bits_per_element = htonl (bf_elementbits);
  470. msg->sender_mutator = htonl (op->state->salt);
  471. msg->element_xor_hash = op->state->my_xor;
  472. GNUNET_MQ_send (op->mq, ev);
  473. }
  474. GNUNET_free (bf_data);
  475. }
  476. GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf);
  477. op->state->local_bf = NULL;
  478. }
  479. /**
  480. * Signal to the client that the operation has finished and
  481. * destroy the operation.
  482. *
  483. * @param cls operation to destroy
  484. */
  485. static void
  486. send_client_done_and_destroy (void *cls)
  487. {
  488. struct Operation *op = cls;
  489. struct GNUNET_MQ_Envelope *ev;
  490. struct GNUNET_SET_ResultMessage *rm;
  491. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  492. "Intersection succeeded, sending DONE to local client\n");
  493. GNUNET_STATISTICS_update (_GSS_statistics,
  494. "# Intersection operations succeeded",
  495. 1,
  496. GNUNET_NO);
  497. ev = GNUNET_MQ_msg (rm,
  498. GNUNET_MESSAGE_TYPE_SET_RESULT);
  499. rm->request_id = htonl (op->client_request_id);
  500. rm->result_status = htons (GNUNET_SET_STATUS_DONE);
  501. rm->element_type = htons (0);
  502. GNUNET_MQ_send (op->set->cs->mq,
  503. ev);
  504. _GSS_operation_destroy (op,
  505. GNUNET_YES);
  506. }
  507. /**
  508. * Remember that we are done dealing with the local client
  509. * AND have sent the other peer our message that we are done,
  510. * so we are not just waiting for the channel to die before
  511. * telling the local client that we are done as our last act.
  512. *
  513. * @param cls the `struct Operation`.
  514. */
  515. static void
  516. finished_local_operations (void *cls)
  517. {
  518. struct Operation *op = cls;
  519. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  520. "DONE sent to other peer, now waiting for other end to close the channel\n");
  521. op->state->phase = PHASE_FINISHED;
  522. op->state->channel_death_expected = GNUNET_YES;
  523. }
  524. /**
  525. * Notify the other peer that we are done. Once this message
  526. * is out, we still need to notify the local client that we
  527. * are done.
  528. *
  529. * @param op operation to notify for.
  530. */
  531. static void
  532. send_p2p_done (struct Operation *op)
  533. {
  534. struct GNUNET_MQ_Envelope *ev;
  535. struct IntersectionDoneMessage *idm;
  536. GNUNET_assert (PHASE_MUST_SEND_DONE == op->state->phase);
  537. GNUNET_assert (GNUNET_NO == op->state->channel_death_expected);
  538. ev = GNUNET_MQ_msg (idm,
  539. GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE);
  540. idm->final_element_count = htonl (op->state->my_element_count);
  541. idm->element_xor_hash = op->state->my_xor;
  542. GNUNET_MQ_notify_sent (ev,
  543. &finished_local_operations,
  544. op);
  545. GNUNET_MQ_send (op->mq,
  546. ev);
  547. }
  548. /**
  549. * Send all elements in the full result iterator.
  550. *
  551. * @param cls the `struct Operation *`
  552. */
  553. static void
  554. send_remaining_elements (void *cls)
  555. {
  556. struct Operation *op = cls;
  557. const void *nxt;
  558. const struct ElementEntry *ee;
  559. struct GNUNET_MQ_Envelope *ev;
  560. struct GNUNET_SET_ResultMessage *rm;
  561. const struct GNUNET_SET_Element *element;
  562. int res;
  563. res = GNUNET_CONTAINER_multihashmap_iterator_next (op->state->full_result_iter,
  564. NULL,
  565. &nxt);
  566. if (GNUNET_NO == res)
  567. {
  568. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  569. "Sending done and destroy because iterator ran out\n");
  570. GNUNET_CONTAINER_multihashmap_iterator_destroy (op->state->full_result_iter);
  571. op->state->full_result_iter = NULL;
  572. if (PHASE_DONE_RECEIVED == op->state->phase)
  573. {
  574. op->state->phase = PHASE_FINISHED;
  575. send_client_done_and_destroy (op);
  576. }
  577. else if (PHASE_MUST_SEND_DONE == op->state->phase)
  578. {
  579. send_p2p_done (op);
  580. }
  581. else
  582. {
  583. GNUNET_assert (0);
  584. }
  585. return;
  586. }
  587. ee = nxt;
  588. element = &ee->element;
  589. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  590. "Sending element %s:%u to client (full set)\n",
  591. GNUNET_h2s (&ee->element_hash),
  592. element->size);
  593. GNUNET_assert (0 != op->client_request_id);
  594. ev = GNUNET_MQ_msg_extra (rm,
  595. element->size,
  596. GNUNET_MESSAGE_TYPE_SET_RESULT);
  597. GNUNET_assert (NULL != ev);
  598. rm->result_status = htons (GNUNET_SET_STATUS_OK);
  599. rm->request_id = htonl (op->client_request_id);
  600. rm->element_type = element->element_type;
  601. GNUNET_memcpy (&rm[1],
  602. element->data,
  603. element->size);
  604. GNUNET_MQ_notify_sent (ev,
  605. &send_remaining_elements,
  606. op);
  607. GNUNET_MQ_send (op->set->cs->mq,
  608. ev);
  609. }
  610. /**
  611. * Fills the "my_elements" hashmap with the initial set of
  612. * (non-deleted) elements from the set of the specification.
  613. *
  614. * @param cls closure with the `struct Operation *`
  615. * @param key current key code for the element
  616. * @param value value in the hash map with the `struct ElementEntry *`
  617. * @return #GNUNET_YES (we should continue to iterate)
  618. */
  619. static int
  620. initialize_map_unfiltered (void *cls,
  621. const struct GNUNET_HashCode *key,
  622. void *value)
  623. {
  624. struct ElementEntry *ee = value;
  625. struct Operation *op = cls;
  626. if (GNUNET_NO == _GSS_is_element_of_operation (ee, op))
  627. return GNUNET_YES; /* element not live in operation's generation */
  628. GNUNET_CRYPTO_hash_xor (&op->state->my_xor,
  629. &ee->element_hash,
  630. &op->state->my_xor);
  631. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  632. "Initial full initialization of my_elements, adding %s:%u\n",
  633. GNUNET_h2s (&ee->element_hash),
  634. ee->element.size);
  635. GNUNET_break (GNUNET_YES ==
  636. GNUNET_CONTAINER_multihashmap_put (op->state->my_elements,
  637. &ee->element_hash,
  638. ee,
  639. GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
  640. return GNUNET_YES;
  641. }
  642. /**
  643. * Send our element count to the peer, in case our element count is
  644. * lower than theirs.
  645. *
  646. * @param op intersection operation
  647. */
  648. static void
  649. send_element_count (struct Operation *op)
  650. {
  651. struct GNUNET_MQ_Envelope *ev;
  652. struct IntersectionElementInfoMessage *msg;
  653. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  654. "Sending our element count (%u)\n",
  655. op->state->my_element_count);
  656. ev = GNUNET_MQ_msg (msg,
  657. GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO);
  658. msg->sender_element_count = htonl (op->state->my_element_count);
  659. GNUNET_MQ_send (op->mq, ev);
  660. }
  661. /**
  662. * We go first, initialize our map with all elements and
  663. * send the first Bloom filter.
  664. *
  665. * @param op operation to start exchange for
  666. */
  667. static void
  668. begin_bf_exchange (struct Operation *op)
  669. {
  670. op->state->phase = PHASE_BF_EXCHANGE;
  671. GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements,
  672. &initialize_map_unfiltered,
  673. op);
  674. send_bloomfilter (op);
  675. }
  676. /**
  677. * Handle the initial `struct IntersectionElementInfoMessage` from a
  678. * remote peer.
  679. *
  680. * @param cls the intersection operation
  681. * @param mh the header of the message
  682. */
  683. void
  684. handle_intersection_p2p_element_info (void *cls,
  685. const struct IntersectionElementInfoMessage *msg)
  686. {
  687. struct Operation *op = cls;
  688. if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation)
  689. {
  690. GNUNET_break_op (0);
  691. fail_intersection_operation(op);
  692. return;
  693. }
  694. op->remote_element_count = ntohl (msg->sender_element_count);
  695. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  696. "Received remote element count (%u), I have %u\n",
  697. op->remote_element_count,
  698. op->state->my_element_count);
  699. if ( ( (PHASE_INITIAL != op->state->phase) &&
  700. (PHASE_COUNT_SENT != op->state->phase) ) ||
  701. (op->state->my_element_count > op->remote_element_count) ||
  702. (0 == op->state->my_element_count) ||
  703. (0 == op->remote_element_count) )
  704. {
  705. GNUNET_break_op (0);
  706. fail_intersection_operation(op);
  707. return;
  708. }
  709. GNUNET_break (NULL == op->state->remote_bf);
  710. begin_bf_exchange (op);
  711. GNUNET_CADET_receive_done (op->channel);
  712. }
  713. /**
  714. * Process a Bloomfilter once we got all the chunks.
  715. *
  716. * @param op the intersection operation
  717. */
  718. static void
  719. process_bf (struct Operation *op)
  720. {
  721. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  722. "Received BF in phase %u, foreign count is %u, my element count is %u/%u\n",
  723. op->state->phase,
  724. op->remote_element_count,
  725. op->state->my_element_count,
  726. GNUNET_CONTAINER_multihashmap_size (op->set->content->elements));
  727. switch (op->state->phase)
  728. {
  729. case PHASE_INITIAL:
  730. GNUNET_break_op (0);
  731. fail_intersection_operation(op);
  732. return;
  733. case PHASE_COUNT_SENT:
  734. /* This is the first BF being sent, build our initial map with
  735. filtering in place */
  736. op->state->my_element_count = 0;
  737. GNUNET_CONTAINER_multihashmap_iterate (op->set->content->elements,
  738. &filtered_map_initialization,
  739. op);
  740. break;
  741. case PHASE_BF_EXCHANGE:
  742. /* Update our set by reduction */
  743. GNUNET_CONTAINER_multihashmap_iterate (op->state->my_elements,
  744. &iterator_bf_reduce,
  745. op);
  746. break;
  747. case PHASE_MUST_SEND_DONE:
  748. GNUNET_break_op (0);
  749. fail_intersection_operation(op);
  750. return;
  751. case PHASE_DONE_RECEIVED:
  752. GNUNET_break_op (0);
  753. fail_intersection_operation(op);
  754. return;
  755. case PHASE_FINISHED:
  756. GNUNET_break_op (0);
  757. fail_intersection_operation(op);
  758. return;
  759. }
  760. GNUNET_CONTAINER_bloomfilter_free (op->state->remote_bf);
  761. op->state->remote_bf = NULL;
  762. if ( (0 == op->state->my_element_count) || /* fully disjoint */
  763. ( (op->state->my_element_count == op->remote_element_count) &&
  764. (0 == memcmp (&op->state->my_xor,
  765. &op->state->other_xor,
  766. sizeof (struct GNUNET_HashCode))) ) )
  767. {
  768. /* we are done */
  769. op->state->phase = PHASE_MUST_SEND_DONE;
  770. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  771. "Intersection succeeded, sending DONE to other peer\n");
  772. GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf);
  773. op->state->local_bf = NULL;
  774. if (GNUNET_SET_RESULT_FULL == op->result_mode)
  775. {
  776. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  777. "Sending full result set (%u elements)\n",
  778. GNUNET_CONTAINER_multihashmap_size (op->state->my_elements));
  779. op->state->full_result_iter
  780. = GNUNET_CONTAINER_multihashmap_iterator_create (op->state->my_elements);
  781. send_remaining_elements (op);
  782. return;
  783. }
  784. send_p2p_done (op);
  785. return;
  786. }
  787. op->state->phase = PHASE_BF_EXCHANGE;
  788. send_bloomfilter (op);
  789. }
  790. /**
  791. * Check an BF message from a remote peer.
  792. *
  793. * @param cls the intersection operation
  794. * @param msg the header of the message
  795. * @return #GNUNET_OK if @a msg is well-formed
  796. */
  797. int
  798. check_intersection_p2p_bf (void *cls,
  799. const struct BFMessage *msg)
  800. {
  801. struct Operation *op = cls;
  802. if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation)
  803. {
  804. GNUNET_break_op (0);
  805. return GNUNET_SYSERR;
  806. }
  807. return GNUNET_OK;
  808. }
  809. /**
  810. * Handle an BF message from a remote peer.
  811. *
  812. * @param cls the intersection operation
  813. * @param msg the header of the message
  814. */
  815. void
  816. handle_intersection_p2p_bf (void *cls,
  817. const struct BFMessage *msg)
  818. {
  819. struct Operation *op = cls;
  820. uint32_t bf_size;
  821. uint32_t chunk_size;
  822. uint32_t bf_bits_per_element;
  823. switch (op->state->phase)
  824. {
  825. case PHASE_INITIAL:
  826. GNUNET_break_op (0);
  827. fail_intersection_operation (op);
  828. return;
  829. case PHASE_COUNT_SENT:
  830. case PHASE_BF_EXCHANGE:
  831. bf_size = ntohl (msg->bloomfilter_total_length);
  832. bf_bits_per_element = ntohl (msg->bits_per_element);
  833. chunk_size = htons (msg->header.size) - sizeof (struct BFMessage);
  834. op->state->other_xor = msg->element_xor_hash;
  835. if (bf_size == chunk_size)
  836. {
  837. if (NULL != op->state->bf_data)
  838. {
  839. GNUNET_break_op (0);
  840. fail_intersection_operation (op);
  841. return;
  842. }
  843. /* single part, done here immediately */
  844. op->state->remote_bf
  845. = GNUNET_CONTAINER_bloomfilter_init ((const char*) &msg[1],
  846. bf_size,
  847. bf_bits_per_element);
  848. op->state->salt = ntohl (msg->sender_mutator);
  849. op->remote_element_count = ntohl (msg->sender_element_count);
  850. process_bf (op);
  851. break;
  852. }
  853. /* multipart chunk */
  854. if (NULL == op->state->bf_data)
  855. {
  856. /* first chunk, initialize */
  857. op->state->bf_data = GNUNET_malloc (bf_size);
  858. op->state->bf_data_size = bf_size;
  859. op->state->bf_bits_per_element = bf_bits_per_element;
  860. op->state->bf_data_offset = 0;
  861. op->state->salt = ntohl (msg->sender_mutator);
  862. op->remote_element_count = ntohl (msg->sender_element_count);
  863. }
  864. else
  865. {
  866. /* increment */
  867. if ( (op->state->bf_data_size != bf_size) ||
  868. (op->state->bf_bits_per_element != bf_bits_per_element) ||
  869. (op->state->bf_data_offset + chunk_size > bf_size) ||
  870. (op->state->salt != ntohl (msg->sender_mutator)) ||
  871. (op->remote_element_count != ntohl (msg->sender_element_count)) )
  872. {
  873. GNUNET_break_op (0);
  874. fail_intersection_operation (op);
  875. return;
  876. }
  877. }
  878. GNUNET_memcpy (&op->state->bf_data[op->state->bf_data_offset],
  879. (const char*) &msg[1],
  880. chunk_size);
  881. op->state->bf_data_offset += chunk_size;
  882. if (op->state->bf_data_offset == bf_size)
  883. {
  884. /* last chunk, run! */
  885. op->state->remote_bf
  886. = GNUNET_CONTAINER_bloomfilter_init (op->state->bf_data,
  887. bf_size,
  888. bf_bits_per_element);
  889. GNUNET_free (op->state->bf_data);
  890. op->state->bf_data = NULL;
  891. op->state->bf_data_size = 0;
  892. process_bf (op);
  893. }
  894. break;
  895. default:
  896. GNUNET_break_op (0);
  897. fail_intersection_operation (op);
  898. return;
  899. }
  900. GNUNET_CADET_receive_done (op->channel);
  901. }
  902. /**
  903. * Remove all elements from our hashmap.
  904. *
  905. * @param cls closure with the `struct Operation *`
  906. * @param key current key code
  907. * @param value value in the hash map
  908. * @return #GNUNET_YES (we should continue to iterate)
  909. */
  910. static int
  911. filter_all (void *cls,
  912. const struct GNUNET_HashCode *key,
  913. void *value)
  914. {
  915. struct Operation *op = cls;
  916. struct ElementEntry *ee = value;
  917. GNUNET_break (0 < op->state->my_element_count);
  918. op->state->my_element_count--;
  919. GNUNET_CRYPTO_hash_xor (&op->state->my_xor,
  920. &ee->element_hash,
  921. &op->state->my_xor);
  922. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  923. "Final reduction of my_elements, removing %s:%u\n",
  924. GNUNET_h2s (&ee->element_hash),
  925. ee->element.size);
  926. GNUNET_assert (GNUNET_YES ==
  927. GNUNET_CONTAINER_multihashmap_remove (op->state->my_elements,
  928. &ee->element_hash,
  929. ee));
  930. send_client_removed_element (op,
  931. &ee->element);
  932. return GNUNET_YES;
  933. }
  934. /**
  935. * Handle a done message from a remote peer
  936. *
  937. * @param cls the intersection operation
  938. * @param mh the message
  939. */
  940. void
  941. handle_intersection_p2p_done (void *cls,
  942. const struct IntersectionDoneMessage *idm)
  943. {
  944. struct Operation *op = cls;
  945. if (GNUNET_SET_OPERATION_INTERSECTION != op->set->operation)
  946. {
  947. GNUNET_break_op (0);
  948. fail_intersection_operation (op);
  949. return;
  950. }
  951. if (PHASE_BF_EXCHANGE != op->state->phase)
  952. {
  953. /* wrong phase to conclude? FIXME: Or should we allow this
  954. if the other peer has _initially_ already an empty set? */
  955. GNUNET_break_op (0);
  956. fail_intersection_operation (op);
  957. return;
  958. }
  959. if (0 == ntohl (idm->final_element_count))
  960. {
  961. /* other peer determined empty set is the intersection,
  962. remove all elements */
  963. GNUNET_CONTAINER_multihashmap_iterate (op->state->my_elements,
  964. &filter_all,
  965. op);
  966. }
  967. if ( (op->state->my_element_count != ntohl (idm->final_element_count)) ||
  968. (0 != memcmp (&op->state->my_xor,
  969. &idm->element_xor_hash,
  970. sizeof (struct GNUNET_HashCode))) )
  971. {
  972. /* Other peer thinks we are done, but we disagree on the result! */
  973. GNUNET_break_op (0);
  974. fail_intersection_operation (op);
  975. return;
  976. }
  977. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  978. "Got IntersectionDoneMessage, have %u elements in intersection\n",
  979. op->state->my_element_count);
  980. op->state->phase = PHASE_DONE_RECEIVED;
  981. GNUNET_CADET_receive_done (op->channel);
  982. GNUNET_assert (GNUNET_NO == op->state->client_done_sent);
  983. if (GNUNET_SET_RESULT_FULL == op->result_mode)
  984. {
  985. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  986. "Sending full result set to client (%u elements)\n",
  987. GNUNET_CONTAINER_multihashmap_size (op->state->my_elements));
  988. op->state->full_result_iter
  989. = GNUNET_CONTAINER_multihashmap_iterator_create (op->state->my_elements);
  990. send_remaining_elements (op);
  991. return;
  992. }
  993. op->state->phase = PHASE_FINISHED;
  994. send_client_done_and_destroy (op);
  995. }
  996. /**
  997. * Initiate a set intersection operation with a remote peer.
  998. *
  999. * @param op operation that is created, should be initialized to
  1000. * begin the evaluation
  1001. * @param opaque_context message to be transmitted to the listener
  1002. * to convince it to accept, may be NULL
  1003. * @return operation-specific state to keep in @a op
  1004. */
  1005. static struct OperationState *
  1006. intersection_evaluate (struct Operation *op,
  1007. const struct GNUNET_MessageHeader *opaque_context)
  1008. {
  1009. struct OperationState *state;
  1010. struct GNUNET_MQ_Envelope *ev;
  1011. struct OperationRequestMessage *msg;
  1012. ev = GNUNET_MQ_msg_nested_mh (msg,
  1013. GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST,
  1014. opaque_context);
  1015. if (NULL == ev)
  1016. {
  1017. /* the context message is too large!? */
  1018. GNUNET_break (0);
  1019. return NULL;
  1020. }
  1021. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  1022. "Initiating intersection operation evaluation\n");
  1023. state = GNUNET_new (struct OperationState);
  1024. /* we started the operation, thus we have to send the operation request */
  1025. state->phase = PHASE_INITIAL;
  1026. state->my_element_count = op->set->state->current_set_element_count;
  1027. state->my_elements
  1028. = GNUNET_CONTAINER_multihashmap_create (state->my_element_count,
  1029. GNUNET_YES);
  1030. msg->operation = htonl (GNUNET_SET_OPERATION_INTERSECTION);
  1031. msg->element_count = htonl (state->my_element_count);
  1032. GNUNET_MQ_send (op->mq,
  1033. ev);
  1034. state->phase = PHASE_COUNT_SENT;
  1035. if (NULL != opaque_context)
  1036. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  1037. "Sent op request with context message\n");
  1038. else
  1039. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  1040. "Sent op request without context message\n");
  1041. return state;
  1042. }
  1043. /**
  1044. * Accept an intersection operation request from a remote peer. Only
  1045. * initializes the private operation state.
  1046. *
  1047. * @param op operation that will be accepted as an intersection operation
  1048. */
  1049. static struct OperationState *
  1050. intersection_accept (struct Operation *op)
  1051. {
  1052. struct OperationState *state;
  1053. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  1054. "Accepting set intersection operation\n");
  1055. state = GNUNET_new (struct OperationState);
  1056. state->phase = PHASE_INITIAL;
  1057. state->my_element_count
  1058. = op->set->state->current_set_element_count;
  1059. state->my_elements
  1060. = GNUNET_CONTAINER_multihashmap_create (GNUNET_MIN (state->my_element_count,
  1061. op->remote_element_count),
  1062. GNUNET_YES);
  1063. op->state = state;
  1064. if (op->remote_element_count < state->my_element_count)
  1065. {
  1066. /* If the other peer (Alice) has fewer elements than us (Bob),
  1067. we just send the count as Alice should send the first BF */
  1068. send_element_count (op);
  1069. state->phase = PHASE_COUNT_SENT;
  1070. return state;
  1071. }
  1072. /* We have fewer elements, so we start with the BF */
  1073. begin_bf_exchange (op);
  1074. return state;
  1075. }
  1076. /**
  1077. * Destroy the intersection operation. Only things specific to the
  1078. * intersection operation are destroyed.
  1079. *
  1080. * @param op intersection operation to destroy
  1081. */
  1082. static void
  1083. intersection_op_cancel (struct Operation *op)
  1084. {
  1085. /* check if the op was canceled twice */
  1086. GNUNET_assert (NULL != op->state);
  1087. if (NULL != op->state->remote_bf)
  1088. {
  1089. GNUNET_CONTAINER_bloomfilter_free (op->state->remote_bf);
  1090. op->state->remote_bf = NULL;
  1091. }
  1092. if (NULL != op->state->local_bf)
  1093. {
  1094. GNUNET_CONTAINER_bloomfilter_free (op->state->local_bf);
  1095. op->state->local_bf = NULL;
  1096. }
  1097. if (NULL != op->state->my_elements)
  1098. {
  1099. GNUNET_CONTAINER_multihashmap_destroy (op->state->my_elements);
  1100. op->state->my_elements = NULL;
  1101. }
  1102. if (NULL != op->state->full_result_iter)
  1103. {
  1104. GNUNET_CONTAINER_multihashmap_iterator_destroy (op->state->full_result_iter);
  1105. op->state->full_result_iter = NULL;
  1106. }
  1107. GNUNET_free (op->state);
  1108. op->state = NULL;
  1109. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  1110. "Destroying intersection op state done\n");
  1111. }
  1112. /**
  1113. * Create a new set supporting the intersection operation.
  1114. *
  1115. * @return the newly created set
  1116. */
  1117. static struct SetState *
  1118. intersection_set_create ()
  1119. {
  1120. struct SetState *set_state;
  1121. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  1122. "Intersection set created\n");
  1123. set_state = GNUNET_new (struct SetState);
  1124. set_state->current_set_element_count = 0;
  1125. return set_state;
  1126. }
  1127. /**
  1128. * Add the element from the given element message to the set.
  1129. *
  1130. * @param set_state state of the set want to add to
  1131. * @param ee the element to add to the set
  1132. */
  1133. static void
  1134. intersection_add (struct SetState *set_state,
  1135. struct ElementEntry *ee)
  1136. {
  1137. set_state->current_set_element_count++;
  1138. }
  1139. /**
  1140. * Destroy a set that supports the intersection operation
  1141. *
  1142. * @param set_state the set to destroy
  1143. */
  1144. static void
  1145. intersection_set_destroy (struct SetState *set_state)
  1146. {
  1147. GNUNET_free (set_state);
  1148. }
  1149. /**
  1150. * Remove the element given in the element message from the set.
  1151. *
  1152. * @param set_state state of the set to remove from
  1153. * @param element set element to remove
  1154. */
  1155. static void
  1156. intersection_remove (struct SetState *set_state,
  1157. struct ElementEntry *element)
  1158. {
  1159. GNUNET_assert (0 < set_state->current_set_element_count);
  1160. set_state->current_set_element_count--;
  1161. }
  1162. /**
  1163. * Callback for channel death for the intersection operation.
  1164. *
  1165. * @param op operation that lost the channel
  1166. */
  1167. static void
  1168. intersection_channel_death (struct Operation *op)
  1169. {
  1170. if (GNUNET_YES == op->state->channel_death_expected)
  1171. {
  1172. /* oh goodie, we are done! */
  1173. send_client_done_and_destroy (op);
  1174. }
  1175. else
  1176. {
  1177. /* sorry, channel went down early, too bad. */
  1178. _GSS_operation_destroy (op,
  1179. GNUNET_YES);
  1180. }
  1181. }
  1182. /**
  1183. * Get the table with implementing functions for set intersection.
  1184. *
  1185. * @return the operation specific VTable
  1186. */
  1187. const struct SetVT *
  1188. _GSS_intersection_vt ()
  1189. {
  1190. static const struct SetVT intersection_vt = {
  1191. .create = &intersection_set_create,
  1192. .add = &intersection_add,
  1193. .remove = &intersection_remove,
  1194. .destroy_set = &intersection_set_destroy,
  1195. .evaluate = &intersection_evaluate,
  1196. .accept = &intersection_accept,
  1197. .cancel = &intersection_op_cancel,
  1198. .channel_death = &intersection_channel_death,
  1199. };
  1200. return &intersection_vt;
  1201. }