GNUnet 0.28.0-dev.2-27-gc87478450
 
Loading...
Searching...
No Matches
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.
 
struct RPS_SamplerElementRPS_sampler_elem_create (void)
 Create a sampler element and initialise it.
 
void RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem)
 Destroy a sampler element.
 
void RPS_sampler_elem_next (struct RPS_SamplerElement *sampler_elem, const struct GNUNET_PeerIdentity *new_ID)
 Update a sampler element with a PeerID.
 
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.
 

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()...
55 GNUNET_CRYPTO_random_block (&(sampler_elem->auth_key.key),
57
59
60 sampler_elem->birth = GNUNET_TIME_absolute_get ();
61 sampler_elem->num_peers = 0;
62 sampler_elem->num_change = 0;
63}
void GNUNET_CRYPTO_random_block(void *buffer, size_t length)
Fill block with a random values.
#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_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 75 of file gnunet-service-rps_sampler_elem.c.

76{
77 struct RPS_SamplerElement *s;
78
79 s = GNUNET_new (struct RPS_SamplerElement);
80
82
83 return s;
84}
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 93 of file gnunet-service-rps_sampler_elem.c.

94{
95 GNUNET_free (sampler_elem);
96}
#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 106 of file gnunet-service-rps_sampler_elem.c.

108{
109 struct GNUNET_HashCode other_hash;
110
111 sampler_elem->num_peers++;
112
113 if (0 == GNUNET_memcmp (new_ID, &(sampler_elem->peer_id)))
114 {
115 LOG (GNUNET_ERROR_TYPE_DEBUG, "Have already PeerID %s\n",
116 GNUNET_i2s (&(sampler_elem->peer_id)));
117 }
118 else
119 {
120 GNUNET_CRYPTO_hmac (&sampler_elem->auth_key,
121 new_ID,
122 sizeof(struct GNUNET_PeerIdentity),
123 &other_hash);
124
125 if (EMPTY == sampler_elem->is_empty)
126 {
128 "Got PeerID %s; Simply accepting (was empty previously).\n",
129 GNUNET_i2s (new_ID));
130 sampler_elem->peer_id = *new_ID;
131 sampler_elem->peer_id_hash = other_hash;
132
133 sampler_elem->num_change++;
134 }
135 else if (0 > GNUNET_CRYPTO_hash_cmp (&other_hash,
136 &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}
#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)
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.
#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 162 of file gnunet-service-rps_sampler_elem.c.

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

References RPS_SamplerElement::auth_key.