218 "Sending removed element (size %u) to client\n",
221 "# Element removed messages sent",
263 "FIMA called for %s:%u\n",
270 "Reduced initialization, not starting with %s:%u (wrong generation)\n",
281 "Testing mingled hash %s with salt %u\n",
292 "Reduced initialization, not starting with %s:%u\n",
297 op->state->my_element_count++;
302 "Filtered initialization of my_elements, adding %s:%u\n",
337 "Testing mingled hash %s with salt %u\n",
345 op->state->my_element_count--;
350 "Bloom filter reduction of my_elements, removing %s:%u\n",
363 "Bloom filter reduction of my_elements, keeping %s:%u\n",
392 "Initializing BF with hash %s with salt %u\n",
414 "Intersection operation failed\n");
416 "# Intersection operations failed",
419 if (NULL !=
op->state->my_elements)
422 op->state->my_elements = NULL;
427 msg->request_id = htonl (
op->client_request_id);
428 msg->element_type = htons (0);
448 uint32_t bf_elementbits;
457 bf_elementbits = 2 + ceil (log2 ((
double)
458 (
op->remote_element_count
459 / (
double)
op->state->my_element_count)));
460 if (bf_elementbits < 1)
463 bf_size = ceil ((
double) (
op->state->my_element_count
464 * bf_elementbits / log (2)));
466 "Sending Bloom filter (%u) of size %u bytes\n",
467 (
unsigned int) bf_elementbits,
468 (
unsigned int) bf_size);
480 "# Intersection Bloom filters sent",
483 chunk_size = 60 * 1024 -
sizeof(
struct BFMessage);
484 if (bf_size <= chunk_size)
487 chunk_size = bf_size;
496 msg->sender_element_count = htonl (
op->state->my_element_count);
497 msg->bloomfilter_total_length = htonl (bf_size);
498 msg->bits_per_element = htonl (bf_elementbits);
499 msg->sender_mutator = htonl (
op->state->salt);
500 msg->element_xor_hash =
op->state->my_xor;
513 while (offset < bf_size)
515 if (bf_size - chunk_size < offset)
516 chunk_size = bf_size - offset;
523 offset += chunk_size;
524 msg->sender_element_count = htonl (
op->state->my_element_count);
525 msg->bloomfilter_total_length = htonl (bf_size);
526 msg->bits_per_element = htonl (bf_elementbits);
527 msg->sender_mutator = htonl (
op->state->salt);
528 msg->element_xor_hash =
op->state->my_xor;
534 op->state->local_bf = NULL;
552 "Intersection succeeded, sending DONE to local client\n");
554 "# Intersection operations succeeded",
583 "DONE sent to other peer, now waiting for other end to close the channel\n");
633 op->state->full_result_iter,
639 "Sending done and destroy because iterator ran out\n");
641 op->state->full_result_iter);
642 op->state->full_result_iter = NULL;
661 "Sending element %s:%u to client (full set)\n",
706 "Initial full initialization of my_elements, adding %s:%u\n",
731 "Sending our element count (%u)\n",
732 op->state->my_element_count);
735 msg->sender_element_count = htonl (
op->state->my_element_count);
770 op->remote_element_count = ntohl (
msg->sender_element_count);
772 "Received remote element count (%u), I have %u\n",
773 op->remote_element_count,
774 op->state->my_element_count);
777 (
op->state->my_element_count >
op->remote_element_count) ||
778 (0 ==
op->state->my_element_count) ||
779 (0 ==
op->remote_element_count))
800 "Received BF in phase %u, foreign count is %u, my element count is %u/%u\n",
802 op->remote_element_count,
803 op->state->my_element_count,
805 switch (
op->state->phase)
815 op->state->my_element_count = 0;
844 op->state->remote_bf = NULL;
846 if ((0 ==
op->state->my_element_count) ||
847 ((
op->state->my_element_count ==
op->remote_element_count) &&
849 &
op->state->other_xor))))
854 "Intersection succeeded, sending DONE to other peer\n");
856 op->state->local_bf = NULL;
860 "Sending full result set (%u elements)\n",
862 op->state->full_result_iter
864 op->state->my_elements);
913 switch (
op->state->phase)
922 bf_size = ntohl (
msg->bloomfilter_total_length);
925 op->state->other_xor =
msg->element_xor_hash;
926 if (bf_size == chunk_size)
928 if (NULL !=
op->state->bf_data)
938 bf_bits_per_element);
939 op->state->salt = ntohl (
msg->sender_mutator);
940 op->remote_element_count = ntohl (
msg->sender_element_count);
945 if (NULL ==
op->state->bf_data)
949 op->state->bf_data_size = bf_size;
950 op->state->bf_bits_per_element = bf_bits_per_element;
951 op->state->bf_data_offset = 0;
952 op->state->salt = ntohl (
msg->sender_mutator);
953 op->remote_element_count = ntohl (
msg->sender_element_count);
958 if ((
op->state->bf_data_size != bf_size) ||
959 (
op->state->bf_bits_per_element != bf_bits_per_element) ||
960 (
op->state->bf_data_offset + chunk_size > bf_size) ||
961 (
op->state->salt != ntohl (
msg->sender_mutator)) ||
962 (
op->remote_element_count != ntohl (
msg->sender_element_count)))
970 (
const char *) &
msg[1],
972 op->state->bf_data_offset += chunk_size;
973 if (
op->state->bf_data_offset == bf_size)
979 bf_bits_per_element);
981 op->state->bf_data = NULL;
982 op->state->bf_data_size = 0;
1013 op->state->my_element_count--;
1016 &
op->state->my_xor);
1018 "Final reduction of my_elements, removing %s:%u\n",
1075 "Got IntersectionDoneMessage, have %u elements in intersection\n",
1076 op->state->my_element_count);
1084 "Sending full result set to client (%u elements)\n",
1086 op->state->full_result_iter
1123 "Initiating intersection operation evaluation\n");
1127 state->my_element_count =
op->set->state->current_set_element_count;
1133 msg->element_count = htonl (
state->my_element_count);
1137 if (NULL != opaque_context)
1139 "Sent op request with context message\n");
1142 "Sent op request without context message\n");
1159 "Accepting set intersection operation\n");
1162 state->my_element_count
1163 =
op->set->state->current_set_element_count;
1166 op->remote_element_count),
1169 if (
op->remote_element_count <
state->my_element_count)
1194 if (NULL !=
op->state->remote_bf)
1197 op->state->remote_bf = NULL;
1199 if (NULL !=
op->state->local_bf)
1202 op->state->local_bf = NULL;
1204 if (NULL !=
op->state->my_elements)
1207 op->state->my_elements = NULL;
1209 if (NULL !=
op->state->full_result_iter)
1212 op->state->full_result_iter);
1213 op->state->full_result_iter = NULL;
1218 "Destroying intersection op state done\n");
1233 "Intersection set created\n");
1312 static const struct SetVT intersection_vt = {
1323 return &intersection_vt;
struct GNUNET_MessageHeader * msg
static struct GNUNET_ARM_Operation * op
Current operation.
struct GNUNET_HashCode key
The key used in the DHT.
static char * res
Currently read line or NULL on EOF.
static char * value
Value of the record to add/remove.
enum State state
current state of profiling
int _GSS_is_element_of_operation(struct ElementEntry *ee, struct Operation *op)
Is element ee part of the set used by op?
struct GNUNET_STATISTICS_Handle * _GSS_statistics
Statistics handle.
void _GSS_operation_destroy(struct Operation *op, int gc)
Destroy the given operation.
common components for the implementation the different set operations
const struct SetVT * _GSS_intersection_vt()
Get the table with implementing functions for set intersection.
static void intersection_remove(struct SetState *set_state, struct ElementEntry *element)
Remove the element given in the element message from the set.
void handle_intersection_p2p_bf(void *cls, const struct BFMessage *msg)
Handle an BF message from a remote peer.
void handle_intersection_p2p_element_info(void *cls, const struct IntersectionElementInfoMessage *msg)
Handle the initial struct IntersectionElementInfoMessage from a remote peer.
IntersectionOperationPhase
Current phase we are in for a intersection operation.
@ PHASE_INITIAL
We are just starting.
@ PHASE_DONE_RECEIVED
We have received the P2P DONE message, and must finish with the local client before terminating the c...
@ PHASE_FINISHED
The protocol is over.
@ PHASE_BF_EXCHANGE
We have initialized our set and are now reducing it by exchanging Bloom filters until one party notic...
@ PHASE_COUNT_SENT
We have send the number of our elements to the other peer, but did not setup our element set yet.
@ PHASE_MUST_SEND_DONE
We must next send the P2P DONE message (after finishing mostly with the local client).
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.
static struct SetState * intersection_set_create()
Create a new set supporting the intersection operation.
static void begin_bf_exchange(struct Operation *op)
We go first, initialize our map with all elements and send the first Bloom filter.
static void intersection_set_destroy(struct SetState *set_state)
Destroy a set that supports the intersection operation.
static int filter_all(void *cls, const struct GNUNET_HashCode *key, void *value)
Remove all elements from our hashmap.
static int filtered_map_initialization(void *cls, const struct GNUNET_HashCode *key, void *value)
Fills the "my_elements" hashmap with all relevant elements.
static void send_p2p_done(struct Operation *op)
Notify the other peer that we are done.
static void send_remaining_elements(void *cls)
Send all elements in the full result iterator.
void handle_intersection_p2p_done(void *cls, const struct IntersectionDoneMessage *idm)
Handle a done message from a remote peer.
static void fail_intersection_operation(struct Operation *op)
Inform the client that the intersection operation has failed, and proceed to destroy the evaluate ope...
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...
int check_intersection_p2p_bf(void *cls, const struct BFMessage *msg)
Check an BF message from a remote peer.
static struct OperationState * intersection_evaluate(struct Operation *op, const struct GNUNET_MessageHeader *opaque_context)
Initiate a set intersection operation with a remote peer.
static void send_client_done_and_destroy(void *cls)
Signal to the client that the operation has finished and destroy the operation.
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 sp...
static void send_bloomfilter(struct Operation *op)
Send a bloomfilter to our peer.
static void intersection_op_cancel(struct Operation *op)
Destroy the intersection operation.
static void process_bf(struct Operation *op)
Process a Bloomfilter once we got all the chunks.
static void send_element_count(struct Operation *op)
Send our element count to the peer, in case our element count is lower than theirs.
static void intersection_add(struct SetState *set_state, struct ElementEntry *ee)
Add the element from the given element message to the set.
static void intersection_channel_death(struct Operation *op)
Callback for channel death for the intersection operation.
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 remove...
static struct OperationState * intersection_accept(struct Operation *op)
Accept an intersection operation request from a remote peer.
static int iterator_bf_create(void *cls, const struct GNUNET_HashCode *key, void *value)
Create initial bloomfilter based on all the elements given.
Peer-to-Peer messages for gnunet set.
Library for data block manipulation.
API to create, modify and access statistics.
void GNUNET_BLOCK_mingle_hash(const struct GNUNET_HashCode *in, uint32_t mingle_number, struct GNUNET_HashCode *hc)
Mingle hash with the mingle_number to produce different bits.
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init(const char *data, size_t size, unsigned int k)
Create a Bloom filter from raw bits.
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
bool GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_bloomfilter_get_raw_data(const struct GNUNET_CONTAINER_BloomFilter *bf, char *data, size_t size)
Copy the raw data of this Bloom filter into the given data array.
void GNUNET_CONTAINER_bloomfilter_free(struct GNUNET_CONTAINER_BloomFilter *bf)
Free the space associated with a filter in memory, flush to drive if needed (do not free the space on...
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Indicate readiness to receive the next message on a channel.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
void GNUNET_CRYPTO_hash_xor(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
compute result = a ^ b
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_iterator_next(struct GNUNET_CONTAINER_MultiHashMapIterator *iter, struct GNUNET_HashCode *key, const void **value)
Retrieve the next element from the hash map at the iterator's position.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
void GNUNET_CONTAINER_multihashmap_iterator_destroy(struct GNUNET_CONTAINER_MultiHashMapIterator *iter)
Destroy a multihashmap iterator.
struct GNUNET_CONTAINER_MultiHashMapIterator * GNUNET_CONTAINER_multihashmap_iterator_create(const struct GNUNET_CONTAINER_MultiHashMap *map)
Create an iterator for a multihashmap.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg_nested_mh(mvar, type, mh)
Allocate a GNUNET_MQ_Envelope, and append a payload message after the given message struct.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
#define GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST
Request a set operation from a remote peer.
#define GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE
Intersection operation is done.
#define GNUNET_MESSAGE_TYPE_SET_RESULT
Create an empty set.
#define GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO
Information about the element count for intersection.
#define GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF
Bloom filter message for intersection exchange started by Bob.
@ GNUNET_SET_STATUS_OK
Everything went ok, we are transmitting an element of the result (in set, or to be removed from set,...
@ GNUNET_SET_STATUS_FAILURE
The other peer refused to to the operation with us, or something went wrong.
@ GNUNET_SET_STATUS_DONE
Success, all elements have been sent (and received).
@ GNUNET_SET_RESULT_REMOVED
Client gets only elements that have been removed from the set.
@ GNUNET_SET_RESULT_FULL
Client gets every element in the resulting set.
@ GNUNET_SET_OPERATION_INTERSECTION
Set intersection, only return elements that are in both sets.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
Bloom filter messages exchanged for set intersection calculation.
Information about an element element in the set.
struct GNUNET_SET_Element element
The actual element.
struct GNUNET_HashCode element_hash
Hash of the element.
Cursor into a multihashmap.
Internal representation of the hash map.
uint16_t size
Number of bytes in the buffer pointed to by data.
const void * data
Actual data of the element.
uint16_t element_type
Application-specific element type.
Message sent by the service to the client to indicate an element that is removed (set intersection) o...
uint32_t request_id
id the result belongs to
uint16_t result_status
Was the evaluation successful? Contains an enum GNUNET_SET_Status in NBO.
uint16_t element_type
Type of the element attached to the message, if any.
Last message, send to confirm the final set.
uint32_t final_element_count
Final number of elements in intersection.
struct GNUNET_HashCode element_xor_hash
XOR of all hashes over all elements remaining in the set.
During intersection, the first (and possibly second) message send it the number of elements in the se...
State of an evaluate operation with another peer.
uint32_t bf_bits_per_element
size of the bloomfilter
struct GNUNET_CONTAINER_MultiHashMap * my_elements
Remaining elements in the intersection operation.
uint32_t salt
Salt currently used for BF construction (by us or the other peer, depending on where we are in the co...
struct GNUNET_CONTAINER_BloomFilter * local_bf
BF of the set's element.
struct OperationState * next
Evaluate operations are held in a linked list.
unsigned int generation_created
Generation in which the operation handle was created.
uint32_t bf_data_offset
How many bytes of bf_data are valid?
struct GNUNET_HashCode my_xor
XOR of the keys of all of the elements (remaining) in my set.
enum IntersectionOperationPhase phase
Current state of the operation.
char * bf_data
For multipart BF transmissions, we have to store the bloomfilter-data until we fully received it.
struct GNUNET_HashCode other_xor
XOR of the keys of all of the elements (remaining) in the other peer's set.
uint32_t my_element_count
Current element count contained within my_elements.
struct GNUNET_CONTAINER_MultiHashMapIterator * full_result_iter
Iterator for sending the final set of my_elements to the client.
int channel_death_expected
Set whenever we reach the state where the death of the channel is perfectly find and should NOT resul...
uint32_t bf_data_size
size of the bloomfilter in bf_data.
struct GNUNET_CONTAINER_BloomFilter * remote_bf
The bf we currently receive.
struct OperationState * prev
Evaluate operations are held in a linked list.
int client_done_sent
Did we send the client that we are done?
Operation context used to execute a set operation.
uint32_t bf_bits_per_element
size of the bloomfilter
Extra state required for efficient set intersection.
uint32_t current_set_element_count
Number of currently valid elements in the set which have not been removed.
Dispatch table for a specific set operation.
SetCreateImpl create
Callback for the set creation.