GNUnet  0.10.x
Macros | Functions
gnunet-service-rps_sampler_elem.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet-service-rps_sampler_elem.h"
#include <inttypes.h>
#include "rps-test_util.h"
Include dependency graph for gnunet-service-rps_sampler_elem.c:

Go to the source code of this file.

Macros

#define LOG(kind, ...)   GNUNET_log_from(kind, "rps-sampler_elem", __VA_ARGS__)
 

Functions

void RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_elem)
 Reinitialise a previously initialised sampler element. More...
 
struct RPS_SamplerElementRPS_sampler_elem_create (void)
 Create a sampler element and initialise it. More...
 
void RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem)
 Destroy a sampler element. More...
 
void RPS_sampler_elem_next (struct RPS_SamplerElement *sampler_elem, const struct GNUNET_PeerIdentity *new_ID)
 Update a sampler element with a PeerID. More...
 
void RPS_sampler_elem_set (struct RPS_SamplerElement *sampler_elem, struct GNUNET_CRYPTO_AuthKey auth_key)
 Set the min-wise independent function of the given sampler element. More...
 

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from(kind, "rps-sampler_elem", __VA_ARGS__)

Definition at line 35 of file gnunet-service-rps_sampler_elem.c.

Referenced by RPS_sampler_elem_next().

Function Documentation

◆ RPS_sampler_elem_reinit()

void RPS_sampler_elem_reinit ( struct RPS_SamplerElement sampler_elem)

Reinitialise a previously initialised sampler element.

Parameters
sampler_elThe sampler element to (re-) initialise

Definition at line 50 of file gnunet-service-rps_sampler_elem.c.

References RPS_SamplerElement::auth_key, RPS_SamplerElement::birth, EMPTY, GNUNET_CRYPTO_HASH_LENGTH, GNUNET_CRYPTO_QUALITY_STRONG, GNUNET_CRYPTO_random_block(), GNUNET_TIME_absolute_get(), GNUNET_TIME_UNIT_FOREVER_ABS, RPS_SamplerElement::is_empty, GNUNET_CRYPTO_AuthKey::key, RPS_SamplerElement::last_client_request, RPS_SamplerElement::num_change, and RPS_SamplerElement::num_peers.

Referenced by RPS_sampler_elem_create(), RPS_sampler_reinitialise_by_value(), and sampler_mod_get_rand_peer().

51 {
52  sampler_elem->is_empty = EMPTY;
53 
54  // I guess I don't need to call GNUNET_CRYPTO_hmac_derive_key()...
56  &(sampler_elem->auth_key.key),
58 
60 
61  sampler_elem->birth = GNUNET_TIME_absolute_get();
62  sampler_elem->num_peers = 0;
63  sampler_elem->num_change = 0;
64 }
uint32_t num_peers
How many times a PeerID was put in this sampler.
struct GNUNET_TIME_Absolute birth
&#39;Birth&#39;
#define GNUNET_CRYPTO_HASH_LENGTH
Length of a hash value.
struct GNUNET_TIME_Absolute last_client_request
Time of last request.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
enum RPS_SamplerEmpty is_empty
Flag that indicates that we are not holding a valid PeerID right now.
unsigned char key[(512/8)]
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct GNUNET_CRYPTO_AuthKey auth_key
Min-wise linear permutation used by this sampler.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
uint32_t num_change
How many times this sampler changed the peer_id.
High-quality operations are desired.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RPS_sampler_elem_create()

struct RPS_SamplerElement* RPS_sampler_elem_create ( void  )

Create a sampler element and initialise it.

In this implementation this means choosing an auth_key for later use in a hmac at random.

Returns
a newly created RPS_SamplerElement which currently holds no id.

Definition at line 76 of file gnunet-service-rps_sampler_elem.c.

References GNUNET_new, and RPS_sampler_elem_reinit().

Referenced by file_name_cb(), and sampler_resize().

77 {
78  struct RPS_SamplerElement *s;
79 
80  s = GNUNET_new(struct RPS_SamplerElement);
81 
83 
84  return s;
85 }
A sampler element sampling one PeerID at a time.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void RPS_sampler_elem_reinit(struct RPS_SamplerElement *sampler_elem)
Reinitialise a previously initialised sampler element.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RPS_sampler_elem_destroy()

void RPS_sampler_elem_destroy ( struct RPS_SamplerElement sampler_elem)

Destroy a sampler element.

Parameters
sampler_elemthe element to destroy

Definition at line 94 of file gnunet-service-rps_sampler_elem.c.

References GNUNET_free.

Referenced by file_name_cb(), and sampler_resize().

95 {
96  GNUNET_free(sampler_elem);
97 }
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ RPS_sampler_elem_next()

void RPS_sampler_elem_next ( struct RPS_SamplerElement sampler_elem,
const struct GNUNET_PeerIdentity new_ID 
)

Update a sampler element with a PeerID.

Parameters
sampler_elemThe sampler element to update
new_IDThe PeerID to update with

Definition at line 107 of file gnunet-service-rps_sampler_elem.c.

References RPS_SamplerElement::auth_key, EMPTY, GNUNET_CRYPTO_hash_cmp(), GNUNET_CRYPTO_hmac(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_memcmp, RPS_SamplerElement::is_empty, LOG, NOT_EMPTY, RPS_SamplerElement::num_change, RPS_SamplerElement::num_peers, RPS_SamplerElement::peer_id, and RPS_SamplerElement::peer_id_hash.

Referenced by file_name_cb(), and RPS_sampler_update().

109 {
110  struct GNUNET_HashCode other_hash;
111 
112  sampler_elem->num_peers++;
113 
114  if (0 == GNUNET_memcmp(new_ID, &(sampler_elem->peer_id)))
115  {
116  LOG(GNUNET_ERROR_TYPE_DEBUG, "Have already PeerID %s\n",
117  GNUNET_i2s(&(sampler_elem->peer_id)));
118  }
119  else
120  {
121  GNUNET_CRYPTO_hmac(&sampler_elem->auth_key,
122  new_ID,
123  sizeof(struct GNUNET_PeerIdentity),
124  &other_hash);
125 
126  if (EMPTY == sampler_elem->is_empty)
127  {
129  "Got PeerID %s; Simply accepting (was empty previously).\n",
130  GNUNET_i2s(new_ID));
131  sampler_elem->peer_id = *new_ID;
132  sampler_elem->peer_id_hash = other_hash;
133 
134  sampler_elem->num_change++;
135  }
136  else if (0 > GNUNET_CRYPTO_hash_cmp(&other_hash, &sampler_elem->peer_id_hash))
137  {
138  LOG(GNUNET_ERROR_TYPE_DEBUG, "Discarding old PeerID %s\n",
139  GNUNET_i2s(&sampler_elem->peer_id));
140  sampler_elem->peer_id = *new_ID;
141  sampler_elem->peer_id_hash = other_hash;
142 
143  sampler_elem->num_change++;
144  }
145  else
146  {
147  LOG(GNUNET_ERROR_TYPE_DEBUG, "Keeping old PeerID %s\n",
148  GNUNET_i2s(&sampler_elem->peer_id));
149  }
150  }
151  sampler_elem->is_empty = NOT_EMPTY;
152 }
uint32_t num_peers
How many times a PeerID was put in this sampler.
void GNUNET_CRYPTO_hmac(const struct GNUNET_CRYPTO_AuthKey *key, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104)
Definition: crypto_hash.c:418
#define LOG(kind,...)
enum RPS_SamplerEmpty is_empty
Flag that indicates that we are not holding a valid PeerID right now.
struct GNUNET_PeerIdentity peer_id
The PeerID this sampler currently samples.
A 512-bit hashcode.
struct GNUNET_HashCode peer_id_hash
The according hash value of this PeerID.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
The identity of the host (wraps the signing key of the peer).
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
Definition: crypto_hash.c:278
struct GNUNET_CRYPTO_AuthKey auth_key
Min-wise linear permutation used by this sampler.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
uint32_t num_change
How many times this sampler changed the peer_id.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RPS_sampler_elem_set()

void RPS_sampler_elem_set ( struct RPS_SamplerElement sampler_elem,
struct GNUNET_CRYPTO_AuthKey  auth_key 
)

Set the min-wise independent function of the given sampler element.

Parameters
sampler_elemthe sampler element
auth_keythe key to use

Definition at line 161 of file gnunet-service-rps_sampler_elem.c.

References RPS_SamplerElement::auth_key.

Referenced by file_name_cb().

163 {
164  sampler_elem->auth_key = auth_key;
165 }
struct GNUNET_CRYPTO_AuthKey auth_key
Min-wise linear permutation used by this sampler.
Here is the caller graph for this function: