GNUnet 0.21.1
gnunet-service-messenger_member_store.h File Reference
Include dependency graph for gnunet-service-messenger_member_store.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_MemberStore
 

Typedefs

typedef enum GNUNET_GenericReturnValue(* GNUNET_MESSENGER_MemberIteratorCallback) (void *cls, const struct GNUNET_CRYPTO_PublicKey *public_key, struct GNUNET_MESSENGER_MemberSession *session)
 

Functions

void init_member_store (struct GNUNET_MESSENGER_MemberStore *store, struct GNUNET_MESSENGER_SrvRoom *room)
 Initializes a member store as fully empty connected to a room. More...
 
void clear_member_store (struct GNUNET_MESSENGER_MemberStore *store)
 Clears a member store, wipes its content and deallocates its memory. More...
 
struct GNUNET_MESSENGER_ContactStoreget_member_contact_store (struct GNUNET_MESSENGER_MemberStore *store)
 Returns the used contact store of a given member store. More...
 
const struct GNUNET_HashCodeget_member_store_key (const struct GNUNET_MESSENGER_MemberStore *store)
 Returns the shared secret you need to access a room of the store. More...
 
void load_member_store (struct GNUNET_MESSENGER_MemberStore *store, const char *directory)
 Loads members from a directory into a member store. More...
 
void save_member_store (struct GNUNET_MESSENGER_MemberStore *store, const char *directory)
 Saves members from a member store into a directory. More...
 
struct GNUNET_MESSENGER_Memberget_store_member (const struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id)
 Returns the member in a store identified by a given id. More...
 
struct GNUNET_MESSENGER_Memberget_store_member_of (struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_MESSENGER_Message *message)
 Returns the member of a store using a sender id of a given message. More...
 
struct GNUNET_MESSENGER_Memberadd_store_member (struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id)
 Adds a member to a store under a specific id and returns it on success. More...
 
int iterate_store_members (struct GNUNET_MESSENGER_MemberStore *store, GNUNET_MESSENGER_MemberIteratorCallback it, void *cls)
 Iterate through all member sessions currently connected to the members of the given member store and call the provided iterator callback with a selected closure. More...
 

Typedef Documentation

◆ GNUNET_MESSENGER_MemberIteratorCallback

typedef enum GNUNET_GenericReturnValue(* GNUNET_MESSENGER_MemberIteratorCallback) (void *cls, const struct GNUNET_CRYPTO_PublicKey *public_key, struct GNUNET_MESSENGER_MemberSession *session)

Definition at line 1 of file gnunet-service-messenger_member_store.h.

Function Documentation

◆ init_member_store()

void init_member_store ( struct GNUNET_MESSENGER_MemberStore store,
struct GNUNET_MESSENGER_SrvRoom room 
)

Initializes a member store as fully empty connected to a room.

Parameters
[out]storeMember store
roomRoom

Definition at line 36 of file gnunet-service-messenger_member_store.c.

38{
39 GNUNET_assert ((store) && (room));
40
41 store->room = room;
43}
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_MultiShortmap * members

References GNUNET_assert, GNUNET_CONTAINER_multishortmap_create(), GNUNET_NO, GNUNET_MESSENGER_MemberStore::members, and GNUNET_MESSENGER_MemberStore::room.

Referenced by create_srv_room().

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

◆ clear_member_store()

void clear_member_store ( struct GNUNET_MESSENGER_MemberStore store)

Clears a member store, wipes its content and deallocates its memory.

Parameters
[in,out]storeMember store

Definition at line 58 of file gnunet-service-messenger_member_store.c.

59{
60 GNUNET_assert ((store) && (store->members));
61
62 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Clear member store of room: %s\n",
64
68}
static enum GNUNET_GenericReturnValue iterate_destroy_members(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
const struct GNUNET_HashCode * get_srv_room_key(const struct GNUNET_MESSENGER_SrvRoom *room)
Returns the shared secret you need to access a room.
int GNUNET_CONTAINER_multishortmap_iterate(struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map.
void GNUNET_CONTAINER_multishortmap_destroy(struct GNUNET_CONTAINER_MultiShortmap *map)
Destroy a hash map.
#define GNUNET_log(kind,...)
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG

References get_srv_room_key(), GNUNET_assert, GNUNET_CONTAINER_multishortmap_destroy(), GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, iterate_destroy_members(), GNUNET_MESSENGER_MemberStore::members, GNUNET_MESSENGER_MemberStore::room, and GNUNET_MESSENGER_Member::store.

Referenced by destroy_srv_room().

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

◆ get_member_contact_store()

struct GNUNET_MESSENGER_ContactStore * get_member_contact_store ( struct GNUNET_MESSENGER_MemberStore store)

Returns the used contact store of a given member store.

Parameters
[in,out]storeMember store
Returns
Contact store

Definition at line 72 of file gnunet-service-messenger_member_store.c.

73{
74 GNUNET_assert ((store) && (store->room));
75
76 struct GNUNET_MESSENGER_SrvRoom *room = store->room;
77
79}
struct GNUNET_MESSENGER_ContactStore * get_service_contact_store(struct GNUNET_MESSENGER_Service *service)
Returns the used contact store of a given service.
struct GNUNET_MESSENGER_Service * service

References get_service_contact_store(), GNUNET_assert, GNUNET_MESSENGER_MemberStore::room, and GNUNET_MESSENGER_SrvRoom::service.

Referenced by check_member_session_completion(), create_member_session(), destroy_member_session(), reset_member_session(), and switch_member_session().

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

◆ get_member_store_key()

const struct GNUNET_HashCode * get_member_store_key ( const struct GNUNET_MESSENGER_MemberStore store)

Returns the shared secret you need to access a room of the store.

Parameters
[in]storeMember store
Returns
Shared secret

Definition at line 83 of file gnunet-service-messenger_member_store.c.

84{
85 GNUNET_assert (store);
86
87 return get_srv_room_key ((const struct
89}

References get_srv_room_key(), GNUNET_assert, and GNUNET_MESSENGER_MemberStore::room.

Referenced by get_member_session_key().

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

◆ load_member_store()

void load_member_store ( struct GNUNET_MESSENGER_MemberStore store,
const char *  directory 
)

Loads members from a directory into a member store.

Parameters
[out]storeMember store
[in]directoryPath to a directory

Definition at line 153 of file gnunet-service-messenger_member_store.c.

155{
156 GNUNET_assert ((store) && (directory));
157
158 char *scan_dir;
159 GNUNET_asprintf (&scan_dir, "%s%s%c", directory, "members", DIR_SEPARATOR);
160
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Load member store from directory: %s\n",
162 scan_dir);
163
166
169 scan_dir);
172
174}
static enum GNUNET_GenericReturnValue callback_scan_for_members(void *cls, const char *filename)
static enum GNUNET_GenericReturnValue iterate_load_next_member_sessions(void *cls, const struct GNUNET_ShortHashCode *id, void *value)
static enum GNUNET_GenericReturnValue iterate_sync_member_contacts(void *cls, const struct GNUNET_ShortHashCode *id, void *value)
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:403
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:814
@ GNUNET_OK
@ GNUNET_YES
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.
#define DIR_SEPARATOR
Definition: platform.h:165

References callback_scan_for_members(), DIR_SEPARATOR, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_DISK_directory_scan(), GNUNET_DISK_directory_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_YES, iterate_load_next_member_sessions(), iterate_sync_member_contacts(), GNUNET_MESSENGER_MemberStore::members, find_typedefs::scan_dir(), and GNUNET_MESSENGER_Member::store.

Referenced by load_srv_room().

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

◆ save_member_store()

void save_member_store ( struct GNUNET_MESSENGER_MemberStore store,
const char *  directory 
)

Saves members from a member store into a directory.

Parameters
[in]storeMember store
[in]directoryPath to a directory

Definition at line 203 of file gnunet-service-messenger_member_store.c.

205{
206 GNUNET_assert ((store) && (directory));
207
208 char *save_dir;
209 GNUNET_asprintf (&save_dir, "%s%s%c", directory, "members", DIR_SEPARATOR);
210
211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Save member store to directory: %s\n",
212 save_dir);
213
214 if ((GNUNET_YES == GNUNET_DISK_directory_test (save_dir, GNUNET_NO)) ||
217 iterate_save_members, save_dir);
218
219 GNUNET_free (save_dir);
220}
static enum GNUNET_GenericReturnValue iterate_save_members(void *cls, const struct GNUNET_ShortHashCode *id, void *value)
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:496

References DIR_SEPARATOR, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_DISK_directory_create(), GNUNET_DISK_directory_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_YES, iterate_save_members(), GNUNET_MESSENGER_MemberStore::members, and GNUNET_MESSENGER_Member::store.

Referenced by save_srv_room().

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

◆ get_store_member()

struct GNUNET_MESSENGER_Member * get_store_member ( const struct GNUNET_MESSENGER_MemberStore store,
const struct GNUNET_ShortHashCode id 
)

Returns the member in a store identified by a given id.

If the store does not contain a member with the given id, NULL gets returned.

Parameters
[in]storeMember store
[in]idMember id
Returns
Member or NULL

Definition at line 224 of file gnunet-service-messenger_member_store.c.

226{
227 GNUNET_assert ((store) && (store->members) && (id));
228
230}
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.

References GNUNET_assert, GNUNET_CONTAINER_multishortmap_get(), GNUNET_MESSENGER_MemberStore::members, and GNUNET_MESSENGER_Member::store.

Referenced by add_store_member(), get_handle_member_session(), get_store_member_of(), handle_get_message(), load_member_session_next(), and solve_srv_room_member_collisions().

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

◆ get_store_member_of()

struct GNUNET_MESSENGER_Member * get_store_member_of ( struct GNUNET_MESSENGER_MemberStore store,
const struct GNUNET_MESSENGER_Message message 
)

Returns the member of a store using a sender id of a given message.

If the message is a peer message or the member does not provide a matching session, NULL gets returned.

Parameters
[in,out]storeMember store
[in]messageMessage
Returns
Member or NULL

Definition at line 234 of file gnunet-service-messenger_member_store.c.

236{
237 GNUNET_assert ((store) && (message));
238
239 if (GNUNET_YES == is_peer_message (message))
240 return NULL;
241
242 if (GNUNET_MESSENGER_KIND_JOIN == message->header.kind)
243 return add_store_member (store, &(message->header.sender_id));
244 else
245 return get_store_member (store, &(message->header.sender_id));
246}
struct GNUNET_MESSENGER_Member * add_store_member(struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id)
Adds a member to a store under a specific id and returns it on success.
struct GNUNET_MESSENGER_Member * get_store_member(const struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id)
Returns the member in a store identified by a given id.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
enum GNUNET_GenericReturnValue is_peer_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message can be sent by the service without usage of a clients priv...
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_MESSENGER_MessageHeader header
Header.

References add_store_member(), get_store_member(), GNUNET_assert, GNUNET_MESSENGER_KIND_JOIN, GNUNET_YES, GNUNET_MESSENGER_Message::header, is_peer_message(), GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageHeader::sender_id, and GNUNET_MESSENGER_Member::store.

Referenced by callback_found_message(), callback_room_handle_message(), handle_room_messages(), and recv_message_request().

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

◆ add_store_member()

struct GNUNET_MESSENGER_Member * add_store_member ( struct GNUNET_MESSENGER_MemberStore store,
const struct GNUNET_ShortHashCode id 
)

Adds a member to a store under a specific id and returns it on success.

Parameters
[in,out]storeMember store
[in]idMember id
Returns
Member or NULL

Definition at line 250 of file gnunet-service-messenger_member_store.c.

252{
253 GNUNET_assert ((store) && (store->members));
254
255 struct GNUNET_MESSENGER_Member *member = id? get_store_member (store, id) :
256 NULL;
257
258 if (member)
259 return member;
260
261 member = create_member (store, id);
262
263 if (! member)
264 return NULL;
265
267 get_member_id (member),
268 member,
270 {
271 destroy_member (member);
272 return NULL;
273 }
274
275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added store member with id: %s\n",
276 GNUNET_sh2s (get_member_id (member)));
277
278 return member;
279}
const struct GNUNET_ShortHashCode * get_member_id(const struct GNUNET_MESSENGER_Member *member)
Returns the current id of a given member.
void destroy_member(struct GNUNET_MESSENGER_Member *member)
Destroys a member and frees its memory fully.
struct GNUNET_MESSENGER_Member * create_member(struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id)
Creates and allocates a new member of a room with an optionally defined or random id.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *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...
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
struct GNUNET_MESSENGER_MemberStore * store

References create_member(), destroy_member(), get_member_id(), get_store_member(), GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_multishortmap_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, GNUNET_sh2s(), GNUNET_MESSENGER_MemberStore::members, and GNUNET_MESSENGER_Member::store.

Referenced by get_store_member_of(), join_room_locally(), load_member(), open_srv_room(), send_message_join(), and switch_member_session().

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

◆ iterate_store_members()

int iterate_store_members ( struct GNUNET_MESSENGER_MemberStore store,
GNUNET_MESSENGER_MemberIteratorCallback  it,
void *  cls 
)

Iterate through all member sessions currently connected to the members of the given member store and call the provided iterator callback with a selected closure.

The function will return the amount of members it iterated through.

Parameters
[in,out]storeMember store
[in]itIterator callback
[in,out]clsClosure
Returns
Amount of members iterated through

Definition at line 301 of file gnunet-service-messenger_member_store.c.

304{
305 GNUNET_assert ((store) && (store->members) && (it));
306
308
309 iterate.it = it;
310 iterate.cls = cls;
311
314 &iterate);
315}
static int iterate_store_members_it(void *cls, const struct GNUNET_ShortHashCode *key, void *value)

References GNUNET_MESSENGER_ClosureIterateMembers::cls, GNUNET_assert, GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_MESSENGER_ClosureIterateMembers::it, iterate_store_members_it(), GNUNET_MESSENGER_MemberStore::members, and GNUNET_MESSENGER_Member::store.

Referenced by callback_room_handle_message(), initialize_service_handle(), recv_message_info(), and send_message_join().

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