GNUnet debian-0.24.3-23-g589b01d60
messenger_api_epoch_membership.h File Reference
Include dependency graph for messenger_api_epoch_membership.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_EpochMembership
 

Typedefs

typedef enum GNUNET_GenericReturnValue(* GNUNET_MESSENGER_MembershipCallback) (void *cls, const struct GNUNET_MESSENGER_Contact *member)
 

Functions

struct GNUNET_MESSENGER_EpochMembershipcreate_epoch_membership (uint32_t size)
 Creates and allocates a new membership for subgroups of an epoch with specified size. More...
 
void destroy_epoch_membership (struct GNUNET_MESSENGER_EpochMembership *membership)
 Destroys and frees resources of a given membership. More...
 
uint32_t get_epoch_membership_size (const struct GNUNET_MESSENGER_EpochMembership *membership)
 Returns the size of a given epoch membership. More...
 
uint32_t get_epoch_membership_count (const struct GNUNET_MESSENGER_EpochMembership *membership)
 Returns the current amount of individual members inside a given epoch membership. More...
 
enum GNUNET_GenericReturnValue is_epoch_membership_completed (const struct GNUNET_MESSENGER_EpochMembership *membership)
 Returns whether a given epoch membership is complete, meaning that all of its intended members have provided an own announcement to it. More...
 
enum GNUNET_GenericReturnValue is_epoch_membership_member (const struct GNUNET_MESSENGER_EpochMembership *membership, const struct GNUNET_MESSENGER_Contact *contact)
 Returns whether a specific contact is announced member of a given epoch membership. More...
 
enum GNUNET_GenericReturnValue get_epoch_membership_member_hash (const struct GNUNET_MESSENGER_EpochMembership *membership, struct GNUNET_HashCode *hash, enum GNUNET_GenericReturnValue other)
 Provides an announcement hash of a member from a given epoch membership. More...
 
uint32_t get_epoch_membership_member_position (const struct GNUNET_MESSENGER_EpochMembership *membership)
 Returns the index position of the client inside a given epoch in relation to its list of members. More...
 
enum GNUNET_GenericReturnValue confirm_epoch_membership_announcment (struct GNUNET_MESSENGER_EpochMembership *membership, const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_Contact *contact, enum GNUNET_GenericReturnValue sent)
 Adds an announcement message with its hash to a given epoch membership as confirmation for a specific contact. More...
 
enum GNUNET_GenericReturnValue revoke_epoch_membership_announcement (struct GNUNET_MESSENGER_EpochMembership *membership, const struct GNUNET_HashCode *hash, struct GNUNET_MESSENGER_Contact *contact)
 Drops an announcement message with a provided hash from a given epoch membership to revoke the confirmed membership of a specific contact. More...
 
int iterate_epoch_membership_members (const struct GNUNET_MESSENGER_EpochMembership *membership, GNUNET_MESSENGER_MembershipCallback callback, void *cls)
 Iterate through all confirmed members of a given epoch membership and pass them through a provided callback with a custom closure. More...
 

Typedef Documentation

◆ GNUNET_MESSENGER_MembershipCallback

typedef enum GNUNET_GenericReturnValue(* GNUNET_MESSENGER_MembershipCallback) (void *cls, const struct GNUNET_MESSENGER_Contact *member)

Definition at line 1 of file messenger_api_epoch_membership.h.

Function Documentation

◆ create_epoch_membership()

struct GNUNET_MESSENGER_EpochMembership * create_epoch_membership ( uint32_t  size)

Creates and allocates a new membership for subgroups of an epoch with specified size.

Parameters
[in]sizeMaximum size or 0
Returns
New membership

Definition at line 31 of file messenger_api_epoch_membership.c.

32{
33 struct GNUNET_MESSENGER_EpochMembership *membership;
34
35 membership = GNUNET_new (struct GNUNET_MESSENGER_EpochMembership);
36
37 if (! membership)
38 return NULL;
39
40 membership->size = size;
41 membership->count = 0;
43 GNUNET_NO);
44
45 memset (&(membership->announcement), 0, sizeof (membership->announcement));
46
47 return membership;
48}
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
@ GNUNET_NO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static unsigned int size
Size of the "table".
Definition: peer.c:68
struct GNUNET_CONTAINER_MultiHashMap * members

References GNUNET_MESSENGER_EpochMembership::announcement, GNUNET_MESSENGER_EpochMembership::count, GNUNET_CONTAINER_multihashmap_create(), GNUNET_new, GNUNET_NO, GNUNET_MESSENGER_EpochMembership::members, size, and GNUNET_MESSENGER_EpochMembership::size.

Referenced by create_epoch_announcement(), and create_epoch_group().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_epoch_membership()

void destroy_epoch_membership ( struct GNUNET_MESSENGER_EpochMembership membership)

Destroys and frees resources of a given membership.

Parameters
[in,out]membershipMembership

Definition at line 52 of file messenger_api_epoch_membership.c.

53{
54 GNUNET_assert (membership);
55
57
58 GNUNET_free (membership);
59}
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_free, and GNUNET_MESSENGER_EpochMembership::members.

Referenced by destroy_epoch_announcement(), and destroy_epoch_group().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_epoch_membership_size()

uint32_t get_epoch_membership_size ( const struct GNUNET_MESSENGER_EpochMembership membership)

Returns the size of a given epoch membership.

Parameters
[in]membershipMembership
Returns
Maximum size of membership or 0

Definition at line 63 of file messenger_api_epoch_membership.c.

65{
66 GNUNET_assert (membership);
67
68 return membership->size;
69}

References GNUNET_assert, and GNUNET_MESSENGER_EpochMembership::size.

Referenced by is_epoch_membership_completed().

Here is the caller graph for this function:

◆ get_epoch_membership_count()

uint32_t get_epoch_membership_count ( const struct GNUNET_MESSENGER_EpochMembership membership)

Returns the current amount of individual members inside a given epoch membership.

Parameters
[in]membershipMembership
Returns
Amount of members

Definition at line 73 of file messenger_api_epoch_membership.c.

75{
76 GNUNET_assert (membership);
77
78 return membership->count;
79}

References GNUNET_MESSENGER_EpochMembership::count, and GNUNET_assert.

Referenced by get_epoch_announcement_members_count(), get_epoch_group_members_count(), get_epoch_membership_member_position(), get_epoch_position_factor(), and is_epoch_membership_completed().

Here is the caller graph for this function:

◆ is_epoch_membership_completed()

enum GNUNET_GenericReturnValue is_epoch_membership_completed ( const struct GNUNET_MESSENGER_EpochMembership membership)

Returns whether a given epoch membership is complete, meaning that all of its intended members have provided an own announcement to it.

Parameters
[in]membershipMembership
Returns
GNUNET_YES if membership is complete, otherwise GNUNET_NO

Definition at line 83 of file messenger_api_epoch_membership.c.

85{
86 uint32_t size;
87
88 GNUNET_assert (membership);
89
90 size = get_epoch_membership_size (membership);
91
92 if (! size)
93 return GNUNET_NO;
94
95 if (get_epoch_membership_count (membership) >= size)
96 return GNUNET_YES;
97 else
98 return GNUNET_NO;
99}
@ GNUNET_YES
uint32_t get_epoch_membership_size(const struct GNUNET_MESSENGER_EpochMembership *membership)
Returns the size of a given epoch membership.
uint32_t get_epoch_membership_count(const struct GNUNET_MESSENGER_EpochMembership *membership)
Returns the current amount of individual members inside a given epoch membership.

References get_epoch_membership_count(), get_epoch_membership_size(), GNUNET_assert, GNUNET_NO, GNUNET_YES, and size.

Referenced by is_epoch_announcement_completed(), and is_epoch_group_completed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_epoch_membership_member()

enum GNUNET_GenericReturnValue is_epoch_membership_member ( const struct GNUNET_MESSENGER_EpochMembership membership,
const struct GNUNET_MESSENGER_Contact contact 
)

Returns whether a specific contact is announced member of a given epoch membership.

Parameters
[in]membershipMembership
[in]contactContact
Returns
GNUNET_YES if the contact is a member, otherwise GNUNET_NO

Definition at line 124 of file messenger_api_epoch_membership.c.

127{
128 const struct GNUNET_MESSENGER_Contact *search;
129
130 GNUNET_assert (membership);
131
132 if (! contact)
133 return GNUNET_CONTAINER_multihashmap_contains (membership->members, &(
134 membership->announcement));
135
136 search = contact;
137
140 &search);
141
142 return search == contact? GNUNET_NO : GNUNET_YES;
143}
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
static enum GNUNET_GenericReturnValue it_search_epoch_member(void *cls, const struct GNUNET_HashCode *hash, void *value)

References GNUNET_MESSENGER_EpochMembership::announcement, GNUNET_assert, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_NO, GNUNET_YES, it_search_epoch_member(), and GNUNET_MESSENGER_EpochMembership::members.

Referenced by get_epoch_membership_member_hash(), get_epoch_membership_member_position(), is_epoch_announcement_announced(), is_epoch_announcement_member(), is_epoch_group_announced(), and is_epoch_group_member().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_epoch_membership_member_hash()

enum GNUNET_GenericReturnValue get_epoch_membership_member_hash ( const struct GNUNET_MESSENGER_EpochMembership membership,
struct GNUNET_HashCode hash,
enum GNUNET_GenericReturnValue  other 
)

Provides an announcement hash of a member from a given epoch membership.

Depending on a flag it provides some hash of another member or the clients own announcement.

Parameters
[in]membershipMembership
[out]hashHash of announcement
[in]otherOther flag
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

Definition at line 147 of file messenger_api_epoch_membership.c.

151{
154
155 GNUNET_assert ((membership) && (hash));
156
157 if (GNUNET_NO == other)
158 {
159 if (GNUNET_YES != is_epoch_membership_member (membership, NULL))
160 return GNUNET_SYSERR;
161
162 GNUNET_memcpy (hash, &(membership->announcement), sizeof (membership->
163 announcement));
164 return GNUNET_OK;
165 }
166
168 membership->members);
169
170 if (! iterator)
171 return GNUNET_SYSERR;
172
175 hash, NULL))
176 {
177 if (0 != GNUNET_CRYPTO_hash_cmp (hash, &(membership->announcement)))
178 {
180 break;
181 }
182 }
183
185 return result;
186}
static int result
Global testing status.
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
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.
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.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_SYSERR
enum GNUNET_GenericReturnValue is_epoch_membership_member(const struct GNUNET_MESSENGER_EpochMembership *membership, const struct GNUNET_MESSENGER_Contact *contact)
Returns whether a specific contact is announced member of a given epoch membership.

References GNUNET_MESSENGER_EpochMembership::announcement, GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterator_create(), GNUNET_CONTAINER_multihashmap_iterator_destroy(), GNUNET_CONTAINER_multihashmap_iterator_next(), GNUNET_CRYPTO_hash_cmp(), GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, is_epoch_membership_member(), GNUNET_MESSENGER_EpochMembership::members, and result.

Referenced by get_epoch_announcement_member_hash(), and get_epoch_group_member_hash().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_epoch_membership_member_position()

uint32_t get_epoch_membership_member_position ( const struct GNUNET_MESSENGER_EpochMembership membership)

Returns the index position of the client inside a given epoch in relation to its list of members.

Every member of an epoch gets a unique position that depends on the hash of their announcement message.

Parameters
[in]membershipMembership
Returns
Member position

Definition at line 190 of file messenger_api_epoch_membership.c.

193{
195 struct GNUNET_HashCode hash;
196 uint32_t position;
197
198 GNUNET_assert (membership);
199
200 position = get_epoch_membership_count (membership);
201
202 if (GNUNET_YES != is_epoch_membership_member (membership, NULL))
203 return position;
204
206
207 if (! iter)
208 return position;
209
210 position = 0;
211
213 NULL))
214 if (0 < GNUNET_CRYPTO_hash_cmp (&(membership->announcement), &hash))
215 position++;
216
218 return position;
219}
A 512-bit hashcode.

References GNUNET_MESSENGER_EpochMembership::announcement, get_epoch_membership_count(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterator_create(), GNUNET_CONTAINER_multihashmap_iterator_destroy(), GNUNET_CONTAINER_multihashmap_iterator_next(), GNUNET_CRYPTO_hash_cmp(), GNUNET_YES, is_epoch_membership_member(), and GNUNET_MESSENGER_EpochMembership::members.

Referenced by get_epoch_group_member_position().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ confirm_epoch_membership_announcment()

enum GNUNET_GenericReturnValue confirm_epoch_membership_announcment ( struct GNUNET_MESSENGER_EpochMembership membership,
const struct GNUNET_HashCode hash,
const struct GNUNET_MESSENGER_Message message,
struct GNUNET_MESSENGER_Contact contact,
enum GNUNET_GenericReturnValue  sent 
)

Adds an announcement message with its hash to a given epoch membership as confirmation for a specific contact.

An additional flag specifies whether the message has been sent by the client or not.

Parameters
[in,out]membershipMembership
[in]hashHash of message
[in]messageMessage
[in,out]contactContact
[in]sentSent flag
Returns
GNUNET_YES on success, GNUNET_SYSERR on internal failure, otherwise GNUNET_NO

Definition at line 263 of file messenger_api_epoch_membership.c.

270{
272
274 (membership) &&
275 (hash) &&
276 (message) &&
278 (contact));
279
281 hash))
282 return GNUNET_NO;
283
284 confirmation.members = membership->members;
285 confirmation.hash = hash;
286 confirmation.contact = contact;
287
290 &confirmation);
291
292 if ((confirmation.hash) &&
294 confirmation.members, confirmation.hash,
295 confirmation.contact,
297 return GNUNET_SYSERR;
298
299 if (GNUNET_YES == sent)
300 GNUNET_memcpy (&(membership->announcement), hash,
301 sizeof (membership->announcement));
302
303 membership->count++;
304 return GNUNET_YES;
305}
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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
@ GNUNET_MESSENGER_KIND_ANNOUNCEMENT
The announcement kind.
static enum GNUNET_GenericReturnValue it_update_epoch_member(void *cls, const struct GNUNET_HashCode *key, void *value)
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_MESSENGER_MessageHeader header
Header.

References GNUNET_MESSENGER_EpochMembership::announcement, GNUNET_MESSENGER_EpochMemberConfirmation::contact, GNUNET_MESSENGER_EpochMembership::count, GNUNET_assert, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_memcpy, GNUNET_MESSENGER_KIND_ANNOUNCEMENT, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, GNUNET_MESSENGER_EpochMemberConfirmation::hash, GNUNET_MESSENGER_Message::header, it_update_epoch_member(), GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_EpochMemberConfirmation::members, and GNUNET_MESSENGER_EpochMembership::members.

Referenced by confirm_epoch_announcement_member(), and confirm_epoch_group_member().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ revoke_epoch_membership_announcement()

enum GNUNET_GenericReturnValue revoke_epoch_membership_announcement ( struct GNUNET_MESSENGER_EpochMembership membership,
const struct GNUNET_HashCode hash,
struct GNUNET_MESSENGER_Contact contact 
)

Drops an announcement message with a provided hash from a given epoch membership to revoke the confirmed membership of a specific contact.

Parameters
[in,out]membershipMembership
[in]hashHash of message
[in,out]contactContact
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 309 of file messenger_api_epoch_membership.c.

313{
314 GNUNET_assert ((membership) && (hash) && (contact));
315
316 if (! membership->count)
317 return GNUNET_NO;
318
320 hash))
321 return GNUNET_NO;
322
324 hash, contact))
325 return GNUNET_NO;
326
327 if (0 == GNUNET_memcmp (hash, &(membership->announcement)))
328 memset (&(membership->announcement), 0, sizeof (membership->announcement));
329
330 membership->count--;
331 return GNUNET_YES;
332}
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.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.

References GNUNET_MESSENGER_EpochMembership::announcement, GNUNET_MESSENGER_EpochMemberConfirmation::contact, GNUNET_MESSENGER_EpochMembership::count, GNUNET_assert, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_memcmp, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_EpochMemberConfirmation::hash, and GNUNET_MESSENGER_EpochMembership::members.

Referenced by revoke_epoch_announcement_member().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_epoch_membership_members()

int iterate_epoch_membership_members ( const struct GNUNET_MESSENGER_EpochMembership membership,
GNUNET_MESSENGER_MembershipCallback  callback,
void *  cls 
)

Iterate through all confirmed members of a given epoch membership and pass them through a provided callback with a custom closure.

Parameters
[in]membershipMembership
[in]callbackIteration callback or NULL
[in]clsClosure or NULL
Returns
Amount of iterations

Definition at line 362 of file messenger_api_epoch_membership.c.

366{
368
369 GNUNET_assert (membership);
370
371 iteration.callback = callback;
372 iteration.cls = cls;
373
376 &iteration);
377}
static enum GNUNET_GenericReturnValue it_iterate_epoch_member(void *cls, const struct GNUNET_HashCode *key, void *value)
GNUNET_MESSENGER_MembershipCallback callback

References GNUNET_MESSENGER_EpochMemberIteration::callback, GNUNET_MESSENGER_EpochMemberIteration::cls, GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterate(), it_iterate_epoch_member(), and GNUNET_MESSENGER_EpochMembership::members.

Referenced by is_epoch_group_compatible(), is_epoch_group_missing_announcement(), and is_epoch_group_subgroup_of().

Here is the call graph for this function:
Here is the caller graph for this function: