GNUnet  0.20.0
gnunet-service-messenger_member_store.c File Reference

GNUnet MESSENGER service. More...

Include dependency graph for gnunet-service-messenger_member_store.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_ClosureIterateMembers
 

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...
 
static int iterate_destroy_members (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
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...
 
static int callback_scan_for_members (void *cls, const char *filename)
 
static int iterate_load_next_member_sessions (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
 
static int iterate_sync_member_contacts (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
 
void load_member_store (struct GNUNET_MESSENGER_MemberStore *store, const char *directory)
 Loads members from a directory into a member store. More...
 
static int iterate_save_members (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
 
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...
 
static int iterate_store_members_it (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
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...
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_member_store.c.

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 34 of file gnunet-service-messenger_member_store.c.

36 {
37  GNUNET_assert ((store) && (room));
38 
39  store->room = room;
41 }
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:

◆ iterate_destroy_members()

static int iterate_destroy_members ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)
static

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

47 {
48  struct GNUNET_MESSENGER_Member *member = value;
49  destroy_member(member);
50  return GNUNET_YES;
51 }
static char * value
Value of the record to add/remove.
void destroy_member(struct GNUNET_MESSENGER_Member *member)
Destroys a member and frees its memory fully.
@ GNUNET_YES

References destroy_member(), GNUNET_YES, and value.

Referenced by clear_member_store().

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 54 of file gnunet-service-messenger_member_store.c.

55 {
56  GNUNET_assert ((store) && (store->members));
57 
60 }
static int iterate_destroy_members(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
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.

References GNUNET_assert, GNUNET_CONTAINER_multishortmap_destroy(), GNUNET_CONTAINER_multishortmap_iterate(), iterate_destroy_members(), GNUNET_MESSENGER_MemberStore::members, 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 64 of file gnunet-service-messenger_member_store.c.

65 {
66  GNUNET_assert ((store) && (store->room));
67 
68  struct GNUNET_MESSENGER_SrvRoom *room = store->room;
69 
70  return get_service_contact_store(room->service);
71 }
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 74 of file gnunet-service-messenger_member_store.c.

75 {
76  GNUNET_assert (store);
77 
78  return get_srv_room_key((const struct GNUNET_MESSENGER_SrvRoom*) store->room);
79 }
const struct GNUNET_HashCode * get_srv_room_key(const struct GNUNET_MESSENGER_SrvRoom *room)
Returns the shared secret you need to access a room.

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:

◆ callback_scan_for_members()

static int callback_scan_for_members ( void *  cls,
const char *  filename 
)
static

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

84 {
85  struct GNUNET_MESSENGER_MemberStore *store = cls;
86 
88  {
89  char *directory;
90 
91  GNUNET_asprintf (&directory, "%s%c", filename, DIR_SEPARATOR);
92 
93  load_member(store, directory);
94 
95  GNUNET_free(directory);
96  }
97 
98  return GNUNET_OK;
99 }
static char * filename
void load_member(struct GNUNET_MESSENGER_MemberStore *store, const char *directory)
Loads data from a directory into a new allocated and created member of a store if the required inform...
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
@ GNUNET_OK
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 DIR_SEPARATOR, filename, GNUNET_asprintf(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_OK, GNUNET_YES, and load_member().

Referenced by load_member_store().

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

◆ iterate_load_next_member_sessions()

static int iterate_load_next_member_sessions ( void *  cls,
const struct GNUNET_ShortHashCode id,
void *  value 
)
static

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

105 {
106  const char *sync_dir = cls;
107 
108  struct GNUNET_MESSENGER_Member *member = value;
109 
110  if (!member)
111  return GNUNET_YES;
112 
113  char *member_dir;
114  GNUNET_asprintf (&member_dir, "%s%s%c", sync_dir, GNUNET_sh2s(id), DIR_SEPARATOR);
115 
116  if (GNUNET_YES == GNUNET_DISK_directory_test (member_dir, GNUNET_YES))
117  load_member_next_sessions (member, member_dir);
118 
119  GNUNET_free(member_dir);
120  return GNUNET_YES;
121 }
void load_member_next_sessions(const struct GNUNET_MESSENGER_Member *member, const char *directory)
Loads data about next sessions from a directory into an empty loaded member which does not contain a ...
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).

References DIR_SEPARATOR, GNUNET_asprintf(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_sh2s(), GNUNET_YES, load_member_next_sessions(), and value.

Referenced by load_member_store().

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

◆ iterate_sync_member_contacts()

static int iterate_sync_member_contacts ( void *  cls,
const struct GNUNET_ShortHashCode id,
void *  value 
)
static

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

127 {
128  struct GNUNET_MESSENGER_Member *member = value;
129 
130  if (!member)
131  return GNUNET_YES;
132 
133  sync_member_contacts (member);
134  return GNUNET_YES;
135 }
void sync_member_contacts(struct GNUNET_MESSENGER_Member *member)
Synchronizes contacts between all sessions from a given member and other sessions which are linked to...

References GNUNET_YES, sync_member_contacts(), and value.

Referenced by load_member_store().

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 138 of file gnunet-service-messenger_member_store.c.

140 {
141  GNUNET_assert ((store) && (directory));
142 
143  char *scan_dir;
144  GNUNET_asprintf (&scan_dir, "%s%s%c", directory, "members", DIR_SEPARATOR);
145 
148 
151 
153 }
static int iterate_sync_member_contacts(void *cls, const struct GNUNET_ShortHashCode *id, void *value)
static int iterate_load_next_member_sessions(void *cls, const struct GNUNET_ShortHashCode *id, void *value)
static int callback_scan_for_members(void *cls, const char *filename)
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:814

References callback_scan_for_members(), DIR_SEPARATOR, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_DISK_directory_scan(), GNUNET_DISK_directory_test(), GNUNET_free, 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:

◆ iterate_save_members()

static int iterate_save_members ( void *  cls,
const struct GNUNET_ShortHashCode id,
void *  value 
)
static

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

159 {
160  const char *save_dir = cls;
161 
162  struct GNUNET_MESSENGER_Member *member = value;
163 
164  if (!member)
165  return GNUNET_YES;
166 
167  char *member_dir;
168  GNUNET_asprintf (&member_dir, "%s%s%c", save_dir, GNUNET_sh2s(id), DIR_SEPARATOR);
169 
170  if ((GNUNET_YES == GNUNET_DISK_directory_test (member_dir, GNUNET_NO)) ||
171  (GNUNET_OK == GNUNET_DISK_directory_create (member_dir)))
172  save_member(member, member_dir);
173 
174  GNUNET_free(member_dir);
175  return GNUNET_YES;
176 }
void save_member(struct GNUNET_MESSENGER_Member *member, const char *directory)
Saves data from a member into a directory which can be load to restore the member completely.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:496

References DIR_SEPARATOR, GNUNET_asprintf(), GNUNET_DISK_directory_create(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_sh2s(), GNUNET_YES, save_member(), and value.

Referenced by save_member_store().

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 179 of file gnunet-service-messenger_member_store.c.

181 {
182  GNUNET_assert ((store) && (directory));
183 
184  char* save_dir;
185  GNUNET_asprintf (&save_dir, "%s%s%c", directory, "members", DIR_SEPARATOR);
186 
187  if ((GNUNET_YES == GNUNET_DISK_directory_test (save_dir, GNUNET_NO)) ||
188  (GNUNET_OK == GNUNET_DISK_directory_create (save_dir)))
190 
191  GNUNET_free(save_dir);
192 }
static int iterate_save_members(void *cls, const struct GNUNET_ShortHashCode *id, void *value)

References DIR_SEPARATOR, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_DISK_directory_create(), GNUNET_DISK_directory_test(), GNUNET_free, 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 195 of file gnunet-service-messenger_member_store.c.

197 {
198  GNUNET_assert ((store) && (store->members) && (id));
199 
200  return GNUNET_CONTAINER_multishortmap_get (store->members, id);
201 }
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 member does not provide a matching session, NULL gets returned.

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

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

206 {
207  if ((GNUNET_MESSENGER_KIND_INFO == message->header.kind) ||
208  (GNUNET_MESSENGER_KIND_JOIN == message->header.kind))
209  return add_store_member(store, &(message->header.sender_id));
210  else
211  return get_store_member(store, &(message->header.sender_id));
212 }
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.
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.
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
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_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageHeader::sender_id, and GNUNET_MESSENGER_Member::store.

Referenced by callback_found_message(), callback_room_handle_message(), check_srv_room_peer_status(), 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 215 of file gnunet-service-messenger_member_store.c.

217 {
218  GNUNET_assert ((store) && (store->members));
219 
220  struct GNUNET_MESSENGER_Member *member = id? get_store_member(store, id) : NULL;
221 
222  if (member)
223  return member;
224 
225  member = create_member(store, id);
226 
227  if (!member)
228  return NULL;
229 
232  {
233  destroy_member(member);
234  return NULL;
235  }
236 
237  return member;
238 }
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.
const struct GNUNET_ShortHashCode * get_member_id(const struct GNUNET_MESSENGER_Member *member)
Returns the current id of a given member.
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...
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_OK, GNUNET_MESSENGER_MemberStore::members, and GNUNET_MESSENGER_Member::store.

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

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

◆ iterate_store_members_it()

static int iterate_store_members_it ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)
static

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

249 {
251  struct GNUNET_MESSENGER_Member *member = value;
252 
253  return iterate_member_sessions(member, iterate->it, iterate->cls);
254 }
int iterate_member_sessions(struct GNUNET_MESSENGER_Member *member, GNUNET_MESSENGER_MemberIteratorCallback it, void *cls)
Iterate through all member sessions currently connected to a given member and call the provided itera...

References GNUNET_MESSENGER_ClosureIterateMembers::cls, GNUNET_MESSENGER_ClosureIterateMembers::it, iterate_member_sessions(), and value.

Referenced by iterate_store_members().

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 257 of file gnunet-service-messenger_member_store.c.

260 {
261  GNUNET_assert ((store) && (store->members) && (it));
262 
264 
265  iterate.it = it;
266  iterate.cls = cls;
267 
269 }
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(), join_room_locally(), and recv_message_info().

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