GNUnet  0.10.x
Functions
gnunet-service-set_intersection.h File Reference

two-peer set operations More...

#include "gnunet-service-set.h"
Include dependency graph for gnunet-service-set_intersection.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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...
 
void handle_intersection_p2p_element_info (void *cls, const struct IntersectionElementInfoMessage *msg)
 Handle the initial struct IntersectionElementInfoMessage from a remote peer. More...
 
void handle_intersection_p2p_done (void *cls, const struct IntersectionDoneMessage *idm)
 Handle a done message from a remote peer. More...
 

Detailed Description

two-peer set operations

Author
Florian Dold
Christian Grothoff

Definition in file gnunet-service-set_intersection.h.

Function Documentation

◆ check_intersection_p2p_bf()

int check_intersection_p2p_bf ( void *  cls,
const struct BFMessage msg 
)

Check an BF message from a remote peer.

Parameters
clsthe intersection operation
msgthe header of the message
Returns
GNUNET_OK if msg is well-formed

Definition at line 881 of file gnunet-service-set_intersection.c.

References GNUNET_break_op, GNUNET_OK, GNUNET_SET_OPERATION_INTERSECTION, GNUNET_SYSERR, op, Set::operation, and Operation::set.

883 {
884  struct Operation *op = cls;
885 
887  {
888  GNUNET_break_op (0);
889  return GNUNET_SYSERR;
890  }
891  return GNUNET_OK;
892 }
struct Set * set
Set associated with the operation, NULL until the spec has been associated with a set...
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
enum GNUNET_SET_OperationType operation
Type of operation supported for this set.
Operation context used to execute a set operation.
Set intersection, only return elements that are in both sets.
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139

◆ handle_intersection_p2p_bf()

void handle_intersection_p2p_bf ( void *  cls,
const struct BFMessage msg 
)

Handle an BF message from a remote peer.

Parameters
clsthe intersection operation
msgthe header of the message

Definition at line 902 of file gnunet-service-set_intersection.c.

References OperationState::bf_bits_per_element, OperationState::bf_data, OperationState::bf_data_offset, OperationState::bf_data_size, BFMessage::bits_per_element, BFMessage::bloomfilter_total_length, Operation::channel, BFMessage::element_xor_hash, fail_intersection_operation(), GNUNET_break_op, GNUNET_CADET_receive_done(), GNUNET_CONTAINER_bloomfilter_init(), GNUNET_free, GNUNET_malloc, GNUNET_memcpy, BFMessage::header, op, OperationState::other_xor, OperationState::phase, PHASE_BF_EXCHANGE, PHASE_COUNT_SENT, PHASE_INITIAL, process_bf(), OperationState::remote_bf, Operation::remote_element_count, OperationState::salt, BFMessage::sender_element_count, BFMessage::sender_mutator, GNUNET_MessageHeader::size, and Operation::state.

904 {
905  struct Operation *op = cls;
906  uint32_t bf_size;
907  uint32_t chunk_size;
908  uint32_t bf_bits_per_element;
909 
910  switch (op->state->phase)
911  {
912  case PHASE_INITIAL:
913  GNUNET_break_op (0);
915  return;
916  case PHASE_COUNT_SENT:
917  case PHASE_BF_EXCHANGE:
918  bf_size = ntohl (msg->bloomfilter_total_length);
919  bf_bits_per_element = ntohl (msg->bits_per_element);
920  chunk_size = htons (msg->header.size) - sizeof (struct BFMessage);
921  op->state->other_xor = msg->element_xor_hash;
922  if (bf_size == chunk_size)
923  {
924  if (NULL != op->state->bf_data)
925  {
926  GNUNET_break_op (0);
928  return;
929  }
930  /* single part, done here immediately */
931  op->state->remote_bf
932  = GNUNET_CONTAINER_bloomfilter_init ((const char*) &msg[1],
933  bf_size,
934  bf_bits_per_element);
935  op->state->salt = ntohl (msg->sender_mutator);
936  op->remote_element_count = ntohl (msg->sender_element_count);
937  process_bf (op);
938  break;
939  }
940  /* multipart chunk */
941  if (NULL == op->state->bf_data)
942  {
943  /* first chunk, initialize */
944  op->state->bf_data = GNUNET_malloc (bf_size);
945  op->state->bf_data_size = bf_size;
946  op->state->bf_bits_per_element = bf_bits_per_element;
947  op->state->bf_data_offset = 0;
948  op->state->salt = ntohl (msg->sender_mutator);
949  op->remote_element_count = ntohl (msg->sender_element_count);
950  }
951  else
952  {
953  /* increment */
954  if ( (op->state->bf_data_size != bf_size) ||
955  (op->state->bf_bits_per_element != bf_bits_per_element) ||
956  (op->state->bf_data_offset + chunk_size > bf_size) ||
957  (op->state->salt != ntohl (msg->sender_mutator)) ||
958  (op->remote_element_count != ntohl (msg->sender_element_count)) )
959  {
960  GNUNET_break_op (0);
962  return;
963  }
964  }
966  (const char*) &msg[1],
967  chunk_size);
968  op->state->bf_data_offset += chunk_size;
969  if (op->state->bf_data_offset == bf_size)
970  {
971  /* last chunk, run! */
972  op->state->remote_bf
974  bf_size,
975  bf_bits_per_element);
976  GNUNET_free (op->state->bf_data);
977  op->state->bf_data = NULL;
978  op->state->bf_data_size = 0;
979  process_bf (op);
980  }
981  break;
982  default:
983  GNUNET_break_op (0);
985  return;
986  }
988 }
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init(const char *data, size_t size, unsigned int k)
Create a Bloom filter from raw bits.
We are just starting.
static void fail_intersection_operation(struct Operation *op)
Inform the client that the intersection operation has failed, and proceed to destroy the evaluate ope...
uint32_t bf_data_size
size of the bloomfilter in bf_data.
uint32_t salt
Salt currently used for BF construction (by us or the other peer, depending on where we are in the co...
uint32_t sender_element_count
Number of elements the sender still has in the set.
struct GNUNET_CADET_Channel * channel
Channel to the peer.
uint32_t bf_bits_per_element
size of the bloomfilter
static void process_bf(struct Operation *op)
Process a Bloomfilter once we got all the chunks.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF.
We have initialized our set and are now reducing it by exchanging Bloom filters until one party notic...
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
uint32_t bloomfilter_total_length
Total length of the bloomfilter data.
#define GNUNET_memcpy(dst, src, n)
uint32_t bf_data_offset
How many bytes of bf_data are valid?
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
enum IntersectionOperationPhase phase
Current state of the operation.
Bloom filter messages exchanged for set intersection calculation.
struct GNUNET_HashCode element_xor_hash
XOR of all hashes over all elements remaining in the set.
char * bf_data
For multipart BF transmissions, we have to store the bloomfilter-data until we fully received it...
Operation context used to execute a set operation.
uint32_t bits_per_element
Number of bits (k-value) used in encoding the bloomfilter.
We have send the number of our elements to the other peer, but did not setup our element set yet...
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Send an ack on the channel to confirm the processing of a message.
Definition: cadet_api.c:955
struct GNUNET_HashCode other_xor
XOR of the keys of all of the elements (remaining) in the other peer's set.
struct GNUNET_CONTAINER_BloomFilter * remote_bf
The bf we currently receive.
uint32_t remote_element_count
Remote peers element count.
struct OperationState * state
Operation-specific operation state.
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
uint32_t sender_mutator
Mutator used with this bloomfilter.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ handle_intersection_p2p_element_info()

void handle_intersection_p2p_element_info ( void *  cls,
const struct IntersectionElementInfoMessage msg 
)

Handle the initial struct IntersectionElementInfoMessage from a remote peer.

Parameters
clsthe intersection operation
mhthe header of the message

Definition at line 762 of file gnunet-service-set_intersection.c.

References begin_bf_exchange(), Operation::channel, fail_intersection_operation(), GNUNET_break, GNUNET_break_op, GNUNET_CADET_receive_done(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SET_OPERATION_INTERSECTION, OperationState::my_element_count, op, Set::operation, OperationState::phase, PHASE_COUNT_SENT, PHASE_INITIAL, OperationState::remote_bf, Operation::remote_element_count, IntersectionElementInfoMessage::sender_element_count, Operation::set, and Operation::state.

764 {
765  struct Operation *op = cls;
766 
768  {
769  GNUNET_break_op (0);
771  return;
772  }
773  op->remote_element_count = ntohl (msg->sender_element_count);
775  "Received remote element count (%u), I have %u\n",
777  op->state->my_element_count);
778  if ( ( (PHASE_INITIAL != op->state->phase) &&
779  (PHASE_COUNT_SENT != op->state->phase) ) ||
781  (0 == op->state->my_element_count) ||
782  (0 == op->remote_element_count) )
783  {
784  GNUNET_break_op (0);
786  return;
787  }
788  GNUNET_break (NULL == op->state->remote_bf);
789  begin_bf_exchange (op);
791 }
We are just starting.
struct Set * set
Set associated with the operation, NULL until the spec has been associated with a set...
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 begin_bf_exchange(struct Operation *op)
We go first, initialize our map with all elements and send the first Bloom filter.
struct GNUNET_CADET_Channel * channel
Channel to the peer.
uint32_t my_element_count
Current element count contained within my_elements.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
enum IntersectionOperationPhase phase
Current state of the operation.
uint32_t sender_element_count
mutator used with this bloomfilter.
enum GNUNET_SET_OperationType operation
Type of operation supported for this set.
Operation context used to execute a set operation.
We have send the number of our elements to the other peer, but did not setup our element set yet...
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Send an ack on the channel to confirm the processing of a message.
Definition: cadet_api.c:955
struct GNUNET_CONTAINER_BloomFilter * remote_bf
The bf we currently receive.
#define GNUNET_log(kind,...)
Set intersection, only return elements that are in both sets.
uint32_t remote_element_count
Remote peers element count.
struct OperationState * state
Operation-specific operation state.
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
Here is the call graph for this function:

◆ handle_intersection_p2p_done()

void handle_intersection_p2p_done ( void *  cls,
const struct IntersectionDoneMessage idm 
)

Handle a done message from a remote peer.

Parameters
clsthe intersection operation
mhthe message

Definition at line 1033 of file gnunet-service-set_intersection.c.

References Operation::channel, OperationState::client_done_sent, IntersectionDoneMessage::element_xor_hash, fail_intersection_operation(), filter_all(), IntersectionDoneMessage::final_element_count, OperationState::full_result_iter, 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, OperationState::my_element_count, OperationState::my_elements, OperationState::my_xor, op, Set::operation, OperationState::phase, PHASE_BF_EXCHANGE, PHASE_DONE_RECEIVED, PHASE_FINISHED, Operation::result_mode, send_client_done_and_destroy(), send_remaining_elements(), Operation::set, and Operation::state.

1035 {
1036  struct Operation *op = cls;
1037 
1039  {
1040  GNUNET_break_op (0);
1042  return;
1043  }
1044  if (PHASE_BF_EXCHANGE != op->state->phase)
1045  {
1046  /* wrong phase to conclude? FIXME: Or should we allow this
1047  if the other peer has _initially_ already an empty set? */
1048  GNUNET_break_op (0);
1050  return;
1051  }
1052  if (0 == ntohl (idm->final_element_count))
1053  {
1054  /* other peer determined empty set is the intersection,
1055  remove all elements */
1057  &filter_all,
1058  op);
1059  }
1060  if ( (op->state->my_element_count != ntohl (idm->final_element_count)) ||
1061  (0 != GNUNET_memcmp (&op->state->my_xor,
1062  &idm->element_xor_hash)) )
1063  {
1064  /* Other peer thinks we are done, but we disagree on the result! */
1065  GNUNET_break_op (0);
1067  return;
1068  }
1070  "Got IntersectionDoneMessage, have %u elements in intersection\n",
1071  op->state->my_element_count);
1074 
1077  {
1079  "Sending full result set to client (%u elements)\n",
1081  op->state->full_result_iter
1084  return;
1085  }
1086  op->state->phase = PHASE_FINISHED;
1088 }
enum GNUNET_SET_ResultMode result_mode
When are elements sent to the client, and which elements are sent?
uint32_t final_element_count
Final number of elements in intersection.
struct Set * set
Set associated with the operation, NULL until the spec has been associated with a set...
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
static void fail_intersection_operation(struct Operation *op)
Inform the client that the intersection operation has failed, and proceed to destroy the evaluate ope...
struct GNUNET_CONTAINER_MultiHashMapIterator * GNUNET_CONTAINER_multihashmap_iterator_create(const struct GNUNET_CONTAINER_MultiHashMap *map)
Create an iterator for a multihashmap.
static void send_remaining_elements(void *cls)
Send all elements in the full result iterator.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CADET_Channel * channel
Channel to the peer.
static void send_client_done_and_destroy(void *cls)
Signal to the client that the operation has finished and destroy the operation.
We have initialized our set and are now reducing it by exchanging Bloom filters until one party notic...
uint32_t my_element_count
Current element count contained within my_elements.
#define GNUNET_NO
Definition: gnunet_common.h:81
static int filter_all(void *cls, const struct GNUNET_HashCode *key, void *value)
Remove all elements from our hashmap.
int client_done_sent
Did we send the client that we are done?
Client gets every element in the resulting set.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
The protocol is over.
enum IntersectionOperationPhase phase
Current state of the operation.
struct GNUNET_HashCode element_xor_hash
XOR of all hashes over all elements remaining in the set.
enum GNUNET_SET_OperationType operation
Type of operation supported for this set.
Operation context used to execute a set operation.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
We have received the P2P DONE message, and must finish with the local client before terminating the c...
struct GNUNET_CONTAINER_MultiHashMapIterator * full_result_iter
Iterator for sending the final set of my_elements to the client.
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Send an ack on the channel to confirm the processing of a message.
Definition: cadet_api.c:955
#define GNUNET_log(kind,...)
Set intersection, only return elements that are in both sets.
struct OperationState * state
Operation-specific operation state.
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_HashCode my_xor
XOR of the keys of all of the elements (remaining) in my set.
struct GNUNET_CONTAINER_MultiHashMap * my_elements
Remaining elements in the intersection operation.
Here is the call graph for this function: