GNUnet 0.22.2
gnunet-service-rps_sampler_elem.h File Reference

sampler element implementation More...

#include <inttypes.h>
Include dependency graph for gnunet-service-rps_sampler_elem.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  RPS_SamplerElement
 A sampler element sampling one PeerID at a time. More...
 

Enumerations

enum  RPS_SamplerEmpty { NOT_EMPTY = 0x0 , EMPTY = 0x1 }
 Used to indicate whether a sampler element is empty. More...
 

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...
 

Detailed Description

sampler element implementation

Author
Julius Bünger

Definition in file gnunet-service-rps_sampler_elem.h.

Enumeration Type Documentation

◆ RPS_SamplerEmpty

Used to indicate whether a sampler element is empty.

Enumerator
NOT_EMPTY 
EMPTY 

Definition at line 40 of file gnunet-service-rps_sampler_elem.h.

41{
42 NOT_EMPTY = 0x0,
43 EMPTY = 0x1
44};

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
sampler_elemThe sampler element to (re-) initialise

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

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}
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
@ GNUNET_CRYPTO_QUALITY_STRONG
High-quality operations are desired.
#define GNUNET_CRYPTO_HASH_LENGTH
Length of a hash value.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
unsigned char key[(512/8)]
struct GNUNET_TIME_Absolute last_client_request
Time of last request.
struct GNUNET_TIME_Absolute birth
'Birth'
struct GNUNET_CRYPTO_AuthKey auth_key
Min-wise linear permutation used by this sampler.
uint32_t num_peers
How many times a PeerID was put in this sampler.
uint32_t num_change
How many times this sampler changed the peer_id.
enum RPS_SamplerEmpty is_empty
Flag that indicates that we are not holding a valid PeerID right now.

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().

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.

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

References GNUNET_new, and RPS_sampler_elem_reinit().

Referenced by sampler_resize().

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.

95{
96 GNUNET_free (sampler_elem);
97}
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_free.

Referenced by sampler_resize().

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.

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,
137 &sampler_elem->peer_id_hash))
138 {
139 LOG (GNUNET_ERROR_TYPE_DEBUG, "Discarding old PeerID %s\n",
140 GNUNET_i2s (&sampler_elem->peer_id));
141 sampler_elem->peer_id = *new_ID;
142 sampler_elem->peer_id_hash = other_hash;
143
144 sampler_elem->num_change++;
145 }
146 else
147 {
148 LOG (GNUNET_ERROR_TYPE_DEBUG, "Keeping old PeerID %s\n",
149 GNUNET_i2s (&sampler_elem->peer_id));
150 }
151 }
152 sampler_elem->is_empty = NOT_EMPTY;
153}
#define LOG(kind,...)
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:327
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:218
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_HashCode peer_id_hash
The according hash value of this PeerID.
struct GNUNET_PeerIdentity peer_id
The PeerID this sampler currently samples.

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 RPS_sampler_update().

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 163 of file gnunet-service-rps_sampler_elem.c.

165{
166 sampler_elem->auth_key = auth_key;
167}

References RPS_SamplerElement::auth_key.