two-peer set intersection More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_statistics_service.h"
#include "gnunet-service-set.h"
#include "gnunet_block_lib.h"
#include "gnunet-service-set_protocol.h"
#include "gnunet-service-set_intersection.h"
#include <gcrypt.h>
Go to the source code of this file.
Data Structures | |
struct | OperationState |
State of an evaluate operation with another peer. More... | |
struct | SetState |
Extra state required for efficient set intersection. More... | |
Enumerations | |
enum | IntersectionOperationPhase { PHASE_INITIAL , PHASE_COUNT_SENT , PHASE_BF_EXCHANGE , PHASE_MUST_SEND_DONE , PHASE_DONE_RECEIVED , PHASE_FINISHED , PHASE_INITIAL , PHASE_COUNT_SENT , PHASE_BF_EXCHANGE , PHASE_MUST_SEND_DONE , PHASE_DONE_RECEIVED , PHASE_FINISHED } |
Current phase we are in for a intersection operation. More... | |
Functions | |
static void | send_client_removed_element (struct Operation *op, struct GNUNET_SET_Element *element) |
If applicable in the current operation mode, send a result message to the client indicating we removed an element. More... | |
static int | filtered_map_initialization (void *cls, const struct GNUNET_HashCode *key, void *value) |
Fills the "my_elements" hashmap with all relevant elements. More... | |
static int | iterator_bf_reduce (void *cls, const struct GNUNET_HashCode *key, void *value) |
Removes elements from our hashmap if they are not contained within the provided remote bloomfilter. More... | |
static int | iterator_bf_create (void *cls, const struct GNUNET_HashCode *key, void *value) |
Create initial bloomfilter based on all the elements given. More... | |
static void | fail_intersection_operation (struct Operation *op) |
Inform the client that the intersection operation has failed, and proceed to destroy the evaluate operation. More... | |
static void | send_bloomfilter (struct Operation *op) |
Send a bloomfilter to our peer. More... | |
static void | send_client_done_and_destroy (void *cls) |
Signal to the client that the operation has finished and destroy the operation. More... | |
static void | finished_local_operations (void *cls) |
Remember that we are done dealing with the local client AND have sent the other peer our message that we are done, so we are not just waiting for the channel to die before telling the local client that we are done as our last act. More... | |
static void | send_p2p_done (struct Operation *op) |
Notify the other peer that we are done. More... | |
static void | send_remaining_elements (void *cls) |
Send all elements in the full result iterator. More... | |
static int | initialize_map_unfiltered (void *cls, const struct GNUNET_HashCode *key, void *value) |
Fills the "my_elements" hashmap with the initial set of (non-deleted) elements from the set of the specification. More... | |
static void | send_element_count (struct Operation *op) |
Send our element count to the peer, in case our element count is lower than theirs. More... | |
static void | begin_bf_exchange (struct Operation *op) |
We go first, initialize our map with all elements and send the first Bloom filter. More... | |
void | handle_intersection_p2p_element_info (void *cls, const struct IntersectionElementInfoMessage *msg) |
Handle the initial struct IntersectionElementInfoMessage from a remote peer. More... | |
static void | process_bf (struct Operation *op) |
Process a Bloomfilter once we got all the chunks. More... | |
int | check_intersection_p2p_bf (void *cls, const struct BFMessage *msg) |
Check an BF message from a remote peer. More... | |
void | handle_intersection_p2p_bf (void *cls, const struct BFMessage *msg) |
Handle an BF message from a remote peer. More... | |
static int | filter_all (void *cls, const struct GNUNET_HashCode *key, void *value) |
Remove all elements from our hashmap. More... | |
void | handle_intersection_p2p_done (void *cls, const struct IntersectionDoneMessage *idm) |
Handle a done message from a remote peer. More... | |
static struct OperationState * | intersection_evaluate (struct Operation *op, const struct GNUNET_MessageHeader *opaque_context) |
Initiate a set intersection operation with a remote peer. More... | |
static struct OperationState * | intersection_accept (struct Operation *op) |
Accept an intersection operation request from a remote peer. More... | |
static void | intersection_op_cancel (struct Operation *op) |
Destroy the intersection operation. More... | |
static struct SetState * | intersection_set_create () |
Create a new set supporting the intersection operation. More... | |
static void | intersection_add (struct SetState *set_state, struct ElementEntry *ee) |
Add the element from the given element message to the set. More... | |
static void | intersection_set_destroy (struct SetState *set_state) |
Destroy a set that supports the intersection operation. More... | |
static void | intersection_remove (struct SetState *set_state, struct ElementEntry *element) |
Remove the element given in the element message from the set. More... | |
static void | intersection_channel_death (struct Operation *op) |
Callback for channel death for the intersection operation. More... | |
const struct SetVT * | _GSS_intersection_vt () |
Get the table with implementing functions for set intersection. More... | |
two-peer set intersection
Definition in file gnunet-service-set_intersection.c.
Current phase we are in for a intersection operation.
Definition at line 39 of file gnunet-service-set_intersection.c.
|
static |
If applicable in the current operation mode, send a result message to the client indicating we removed an element.
op | intersection operation |
element | element to send |
Definition at line 209 of file gnunet-service-set_intersection.c.
References _GSS_statistics, GNUNET_SET_Element::data, GNUNET_SET_ResultMessage::element_type, GNUNET_SET_Element::element_type, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_SET_RESULT, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_SET_RESULT_REMOVED, GNUNET_SET_STATUS_OK, GNUNET_STATISTICS_update(), op, GNUNET_SET_ResultMessage::request_id, GNUNET_SET_ResultMessage::result_status, and GNUNET_SET_Element::size.
Referenced by filter_all(), filtered_map_initialization(), and iterator_bf_reduce().
|
static |
Fills the "my_elements" hashmap with all relevant elements.
cls | the struct Operation * we are performing |
key | current key code |
value | the struct ElementEntry * from the hash map |
Definition at line 253 of file gnunet-service-set_intersection.c.
References _GSS_is_element_of_operation(), ElementEntry::element, ElementEntry::element_hash, GNUNET_BLOCK_mingle_hash(), GNUNET_break, GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CRYPTO_hash_xor(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_YES, op, send_client_removed_element(), GNUNET_SET_Element::size, and value.
Referenced by process_bf().
|
static |
Removes elements from our hashmap if they are not contained within the provided remote bloomfilter.
cls | closure with the struct Operation * |
key | current key code |
value | value in the hash map |
Definition at line 325 of file gnunet-service-set_intersection.c.
References ElementEntry::element, ElementEntry::element_hash, GNUNET_assert, GNUNET_BLOCK_mingle_hash(), GNUNET_break, GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CRYPTO_hash_xor(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_YES, op, send_client_removed_element(), GNUNET_SET_Element::size, and value.
Referenced by process_bf().
|
static |
Create initial bloomfilter based on all the elements given.
cls | the struct Operation * |
key | current key code |
value | the struct ElementEntry to process |
Definition at line 380 of file gnunet-service-set_intersection.c.
References ElementEntry::element_hash, GNUNET_BLOCK_mingle_hash(), GNUNET_CONTAINER_bloomfilter_add(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_YES, op, and value.
Referenced by send_bloomfilter().
|
static |
Inform the client that the intersection operation has failed, and proceed to destroy the evaluate operation.
op | the intersection operation to fail |
Definition at line 408 of file gnunet-service-set_intersection.c.
References _GSS_operation_destroy(), _GSS_statistics, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSAGE_TYPE_SET_RESULT, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_NO, GNUNET_SET_STATUS_FAILURE, GNUNET_STATISTICS_update(), GNUNET_YES, msg, and op.
Referenced by handle_intersection_p2p_bf(), handle_intersection_p2p_done(), handle_intersection_p2p_element_info(), and process_bf().
|
static |
Send a bloomfilter to our peer.
After the result done message has been sent to the client, destroy the evaluate operation.
op | intersection operation |
Definition at line 443 of file gnunet-service-set_intersection.c.
References _GSS_statistics, GNUNET_assert, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_bloomfilter_get_raw_data(), GNUNET_CONTAINER_bloomfilter_init(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_SYSERR, iterator_bf_create(), msg, and op.
Referenced by begin_bf_exchange(), and process_bf().
|
static |
Signal to the client that the operation has finished and destroy the operation.
cls | operation to destroy |
Definition at line 545 of file gnunet-service-set_intersection.c.
References _GSS_operation_destroy(), _GSS_statistics, GNUNET_SET_ResultMessage::element_type, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_SET_RESULT, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_NO, GNUNET_SET_STATUS_DONE, GNUNET_STATISTICS_update(), GNUNET_YES, op, GNUNET_SET_ResultMessage::request_id, and GNUNET_SET_ResultMessage::result_status.
Referenced by handle_intersection_p2p_done(), intersection_channel_death(), and send_remaining_elements().
|
static |
Remember that we are done dealing with the local client AND have sent the other peer our message that we are done, so we are not just waiting for the channel to die before telling the local client that we are done as our last act.
cls | the struct Operation . |
Definition at line 578 of file gnunet-service-set_intersection.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_YES, op, and PHASE_FINISHED.
Referenced by send_p2p_done().
|
static |
Notify the other peer that we are done.
Once this message is out, we still need to notify the local client that we are done.
op | operation to notify for. |
Definition at line 597 of file gnunet-service-set_intersection.c.
References IntersectionDoneMessage::element_xor_hash, IntersectionDoneMessage::final_element_count, finished_local_operations(), GNUNET_assert, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, GNUNET_MQ_msg, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_NO, op, and PHASE_MUST_SEND_DONE.
Referenced by process_bf(), and send_remaining_elements().
|
static |
Send all elements in the full result iterator.
cls | the struct Operation * |
Definition at line 622 of file gnunet-service-set_intersection.c.
References GNUNET_SET_Element::data, ElementEntry::element, ElementEntry::element_hash, GNUNET_SET_ResultMessage::element_type, GNUNET_SET_Element::element_type, GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterator_destroy(), GNUNET_CONTAINER_multihashmap_iterator_next(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_SET_RESULT, GNUNET_MQ_msg_extra, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_NO, GNUNET_SET_STATUS_OK, op, PHASE_DONE_RECEIVED, PHASE_FINISHED, PHASE_MUST_SEND_DONE, GNUNET_SET_ResultMessage::request_id, res, GNUNET_SET_ResultMessage::result_status, send_client_done_and_destroy(), send_p2p_done(), send_remaining_elements(), and GNUNET_SET_Element::size.
Referenced by handle_intersection_p2p_done(), process_bf(), and send_remaining_elements().
|
static |
Fills the "my_elements" hashmap with the initial set of (non-deleted) elements from the set of the specification.
cls | closure with the struct Operation * |
key | current key code for the element |
value | value in the hash map with the struct ElementEntry * |
Definition at line 693 of file gnunet-service-set_intersection.c.
References _GSS_is_element_of_operation(), ElementEntry::element, ElementEntry::element_hash, GNUNET_break, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CRYPTO_hash_xor(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_YES, op, GNUNET_SET_Element::size, and value.
Referenced by begin_bf_exchange().
|
static |
Send our element count to the peer, in case our element count is lower than theirs.
op | intersection operation |
Definition at line 725 of file gnunet-service-set_intersection.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, GNUNET_MQ_msg, GNUNET_MQ_send(), msg, and op.
Referenced by intersection_accept().
|
static |
We go first, initialize our map with all elements and send the first Bloom filter.
op | operation to start exchange for |
Definition at line 747 of file gnunet-service-set_intersection.c.
References GNUNET_CONTAINER_multihashmap_iterate(), initialize_map_unfiltered(), op, PHASE_BF_EXCHANGE, and send_bloomfilter().
Referenced by handle_intersection_p2p_element_info(), and intersection_accept().
void handle_intersection_p2p_element_info | ( | void * | cls, |
const struct IntersectionElementInfoMessage * | msg | ||
) |
Handle the initial struct IntersectionElementInfoMessage
from a remote peer.
cls | the intersection operation |
msg | the header of the message |
Definition at line 758 of file gnunet-service-set_intersection.c.
References begin_bf_exchange(), fail_intersection_operation(), GNUNET_break, GNUNET_break_op, GNUNET_CADET_receive_done(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SET_OPERATION_INTERSECTION, msg, op, PHASE_COUNT_SENT, and PHASE_INITIAL.
|
static |
Process a Bloomfilter once we got all the chunks.
op | the intersection operation |
Definition at line 797 of file gnunet-service-set_intersection.c.
References fail_intersection_operation(), filtered_map_initialization(), GNUNET_break_op, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CONTAINER_multihashmap_iterator_create(), GNUNET_CONTAINER_multihashmap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcmp, GNUNET_SET_RESULT_FULL, iterator_bf_reduce(), op, PHASE_BF_EXCHANGE, PHASE_COUNT_SENT, PHASE_DONE_RECEIVED, PHASE_FINISHED, PHASE_INITIAL, PHASE_MUST_SEND_DONE, send_bloomfilter(), send_p2p_done(), and send_remaining_elements().
Referenced by handle_intersection_p2p_bf().
int check_intersection_p2p_bf | ( | void * | cls, |
const struct BFMessage * | msg | ||
) |
Check an BF message from a remote peer.
cls | the intersection operation |
msg | the header of the message |
Definition at line 884 of file gnunet-service-set_intersection.c.
References GNUNET_break_op, GNUNET_OK, GNUNET_SET_OPERATION_INTERSECTION, GNUNET_SYSERR, and op.
void handle_intersection_p2p_bf | ( | void * | cls, |
const struct BFMessage * | msg | ||
) |
Handle an BF message from a remote peer.
cls | the intersection operation |
msg | the header of the message |
Definition at line 905 of file gnunet-service-set_intersection.c.
References Operation::bf_bits_per_element, fail_intersection_operation(), GNUNET_break_op, GNUNET_CADET_receive_done(), GNUNET_CONTAINER_bloomfilter_init(), GNUNET_free, GNUNET_malloc, GNUNET_memcpy, msg, op, PHASE_BF_EXCHANGE, PHASE_COUNT_SENT, PHASE_INITIAL, process_bf(), and GNUNET_MessageHeader::size.
|
static |
Remove all elements from our hashmap.
cls | closure with the struct Operation * |
key | current key code |
value | value in the hash map |
Definition at line 1005 of file gnunet-service-set_intersection.c.
References ElementEntry::element, ElementEntry::element_hash, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CRYPTO_hash_xor(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_YES, op, send_client_removed_element(), GNUNET_SET_Element::size, and value.
Referenced by handle_intersection_p2p_done().
void handle_intersection_p2p_done | ( | void * | cls, |
const struct IntersectionDoneMessage * | idm | ||
) |
Handle a done message from a remote peer.
cls | the intersection operation |
idm | the message |
Definition at line 1038 of file gnunet-service-set_intersection.c.
References IntersectionDoneMessage::element_xor_hash, fail_intersection_operation(), filter_all(), IntersectionDoneMessage::final_element_count, GNUNET_assert, GNUNET_break_op, GNUNET_CADET_receive_done(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CONTAINER_multihashmap_iterator_create(), GNUNET_CONTAINER_multihashmap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcmp, GNUNET_NO, GNUNET_SET_OPERATION_INTERSECTION, GNUNET_SET_RESULT_FULL, op, PHASE_BF_EXCHANGE, PHASE_DONE_RECEIVED, PHASE_FINISHED, send_client_done_and_destroy(), and send_remaining_elements().
|
static |
Initiate a set intersection operation with a remote peer.
op | operation that is created, should be initialized to begin the evaluation |
opaque_context | message to be transmitted to the listener to convince it to accept, may be NULL |
Definition at line 1106 of file gnunet-service-set_intersection.c.
References GNUNET_break, GNUNET_CONTAINER_multihashmap_create(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, GNUNET_MQ_msg_nested_mh, GNUNET_MQ_send(), GNUNET_new, GNUNET_SET_OPERATION_INTERSECTION, GNUNET_YES, msg, op, PHASE_COUNT_SENT, PHASE_INITIAL, and state.
Referenced by _GSS_intersection_vt().
|
static |
Accept an intersection operation request from a remote peer.
Only initializes the private operation state.
op | operation that will be accepted as an intersection operation |
Definition at line 1154 of file gnunet-service-set_intersection.c.
References begin_bf_exchange(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MIN, GNUNET_new, GNUNET_YES, op, PHASE_COUNT_SENT, PHASE_INITIAL, send_element_count(), and state.
Referenced by _GSS_intersection_vt().
|
static |
Destroy the intersection operation.
Only things specific to the intersection operation are destroyed.
op | intersection operation to destroy |
Definition at line 1190 of file gnunet-service-set_intersection.c.
References GNUNET_assert, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterator_destroy(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, and op.
Referenced by _GSS_intersection_vt().
|
static |
Create a new set supporting the intersection operation.
Definition at line 1228 of file gnunet-service-set_intersection.c.
References SetState::current_set_element_count, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and GNUNET_new.
Referenced by _GSS_intersection_vt().
|
static |
Add the element from the given element message to the set.
set_state | state of the set want to add to |
ee | the element to add to the set |
Definition at line 1248 of file gnunet-service-set_intersection.c.
References SetState::current_set_element_count.
Referenced by _GSS_intersection_vt().
|
static |
Destroy a set that supports the intersection operation.
set_state | the set to destroy |
Definition at line 1261 of file gnunet-service-set_intersection.c.
References GNUNET_free.
Referenced by _GSS_intersection_vt().
|
static |
Remove the element given in the element message from the set.
set_state | state of the set to remove from |
element | set element to remove |
Definition at line 1274 of file gnunet-service-set_intersection.c.
References SetState::current_set_element_count, and GNUNET_assert.
Referenced by _GSS_intersection_vt().
|
static |
Callback for channel death for the intersection operation.
op | operation that lost the channel |
Definition at line 1288 of file gnunet-service-set_intersection.c.
References _GSS_operation_destroy(), GNUNET_YES, op, and send_client_done_and_destroy().
Referenced by _GSS_intersection_vt().
const struct SetVT * _GSS_intersection_vt | ( | void | ) |
Get the table with implementing functions for set intersection.
Definition at line 1310 of file gnunet-service-set_intersection.c.
References SetVT::create, intersection_accept(), intersection_add(), intersection_channel_death(), intersection_evaluate(), intersection_op_cancel(), intersection_remove(), intersection_set_create(), and intersection_set_destroy().
Referenced by handle_client_copy_lazy_connect(), and handle_client_create_set().