GNUnet  0.11.x
Data Structures | Functions
gnunet-service-messenger_member.c File Reference

GNUnet MESSENGER service. More...

#include "gnunet-service-messenger_member.h"
#include "gnunet-service-messenger_member_session.h"
Include dependency graph for gnunet-service-messenger_member.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_ClosureSearchSession
 
struct  GNUNET_MESSENGER_ClosureIterateSessions
 

Functions

struct GNUNET_MESSENGER_Membercreate_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. More...
 
static int iterate_destroy_session (void *cls, const struct GNUNET_HashCode *key, void *value)
 
void destroy_member (struct GNUNET_MESSENGER_Member *member)
 Destroys a member and frees its memory fully. More...
 
const struct GNUNET_ShortHashCodeget_member_id (const struct GNUNET_MESSENGER_Member *member)
 Returns the current id of a given member. More...
 
static int callback_scan_for_sessions (void *cls, const 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 information can be read from the content of the given directory. More...
 
static int iterate_load_next_session (void *cls, const struct GNUNET_HashCode *key, void *value)
 
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 fully built session graph yet. More...
 
static int iterate_save_session (void *cls, const struct GNUNET_HashCode *key, void *value)
 
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. More...
 
static void sync_session_contact_from_next (struct GNUNET_MESSENGER_MemberSession *session, struct GNUNET_MESSENGER_MemberSession *next)
 
static int iterate_sync_session_contact (void *cls, const struct GNUNET_HashCode *key, void *value)
 
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 them. More...
 
struct GNUNET_MESSENGER_MemberSessionget_member_session (const struct GNUNET_MESSENGER_Member *member, const struct GNUNET_IDENTITY_PublicKey *public_key)
 Returns the member session of a member identified by a given public key. More...
 
static int iterate_search_session (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static struct GNUNET_MESSENGER_MemberSessiontry_member_session (struct GNUNET_MESSENGER_Member *member, const struct GNUNET_IDENTITY_PublicKey *public_key)
 
struct GNUNET_MESSENGER_MemberSessionget_member_session_of (struct GNUNET_MESSENGER_Member *member, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 Returns the member session of a member using a public key which can verify the signature of a given message and its hash. More...
 
void add_member_session (struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSENGER_MemberSession *session)
 Adds a given member session to its member. More...
 
void remove_member_session (struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSENGER_MemberSession *session)
 Removes a given member session from its member. More...
 
static int iterate_member_sessions_it (void *cls, const struct GNUNET_HashCode *key, void *value)
 
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 iterator callback with a selected closure. More...
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_member.c.

Function Documentation

◆ create_member()

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.

If the creation fails, NULL gets returned.

Parameters
[in/out]store Member store
[in]idMember id or NULL
Returns
New member or NULL

Definition at line 31 of file gnunet-service-messenger_member.c.

33 {
34  GNUNET_assert (store);
35 
37 
38  member->store = store;
39 
40  if (id)
41  GNUNET_memcpy(&(member->id), id, sizeof(member->id));
42  else if (GNUNET_YES != generate_free_member_id(&(member->id), store->members))
43  {
44  GNUNET_free (member);
45  return NULL;
46  }
47 
49 
50  return member;
51 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_NO
Definition: gnunet_common.h:94
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
int generate_free_member_id(struct GNUNET_ShortHashCode *id, const struct GNUNET_CONTAINER_MultiShortmap *members)
Tries to generate an unused member id and store it into the id parameter.
struct GNUNET_CONTAINER_MultiShortmap * members
struct GNUNET_CONTAINER_MultiHashMap * sessions
struct GNUNET_MESSENGER_MemberStore * store
struct GNUNET_ShortHashCode id

References generate_free_member_id(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_create(), GNUNET_free, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Member::id, GNUNET_MESSENGER_MemberStore::members, GNUNET_MESSENGER_Member::sessions, and GNUNET_MESSENGER_Member::store.

Referenced by add_store_member().

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

◆ iterate_destroy_session()

static int iterate_destroy_session ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 54 of file gnunet-service-messenger_member.c.

57 {
58  struct GNUNET_MESSENGER_MemberSession *session = value;
59  destroy_member_session(session);
60  return GNUNET_YES;
61 }
static char * value
Value of the record to add/remove.
void destroy_member_session(struct GNUNET_MESSENGER_MemberSession *session)
Destroys a member session and frees its memory fully.

References destroy_member_session(), GNUNET_YES, and value.

Referenced by destroy_member().

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

◆ destroy_member()

void destroy_member ( struct GNUNET_MESSENGER_Member member)

Destroys a member and frees its memory fully.

Parameters
[in/out]member Member

Definition at line 64 of file gnunet-service-messenger_member.c.

65 {
66  GNUNET_assert((member) && (member->sessions));
67 
70 
71  GNUNET_free (member);
72 }
static int iterate_destroy_session(void *cls, const struct GNUNET_HashCode *key, void *value)
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_free, iterate_destroy_session(), GNUNET_MESSENGER_MemberSession::member, and GNUNET_MESSENGER_Member::sessions.

Referenced by add_store_member(), and iterate_destroy_members().

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

◆ get_member_id()

const struct GNUNET_ShortHashCode* get_member_id ( const struct GNUNET_MESSENGER_Member member)

Returns the current id of a given member.

Parameters
[in]memberMember
Returns
Member id

Definition at line 75 of file gnunet-service-messenger_member.c.

76 {
77  GNUNET_assert (member);
78 
79  return &(member->id);
80 }

References GNUNET_assert, and GNUNET_MESSENGER_Member::id.

Referenced by add_store_member(), get_member_session_id(), and join_room().

Here is the caller graph for this function:

◆ callback_scan_for_sessions()

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

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

85 {
86  struct GNUNET_MESSENGER_Member *member = cls;
87 
89  {
90  char *directory;
91 
92  GNUNET_asprintf (&directory, "%s%c", filename, DIR_SEPARATOR);
93 
94  load_member_session(member, directory);
95  GNUNET_free (directory);
96  }
97 
98  return GNUNET_OK;
99 }
static char * filename
void load_member_session(struct GNUNET_MESSENGER_Member *member, const char *directory)
Loads data from a directory into a new allocated and created member session of a member if the requir...
@ GNUNET_OK
Definition: gnunet_common.h:95
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:404
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define DIR_SEPARATOR
Definition: platform.h:164

References DIR_SEPARATOR, filename, GNUNET_asprintf(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_OK, GNUNET_YES, and load_member_session().

Referenced by load_member().

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

◆ load_member()

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 information can be read from the content of the given directory.

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

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

104 {
105  GNUNET_assert ((store) && (directory));
106 
107  char *config_file;
108  GNUNET_asprintf (&config_file, "%s%s", directory, "member.cfg");
109 
110  struct GNUNET_MESSENGER_Member *member = NULL;
111 
113  goto free_config;
114 
116 
118  {
119  struct GNUNET_ShortHashCode id;
120 
121  if (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "member", "id", &id, sizeof(id)))
122  goto destroy_config;
123 
124  member = add_store_member(store, &id);
125  }
126 
127 destroy_config:
128 
130 
131 free_config:
133 
134  if (!member)
135  return;
136 
137  char *scan_dir;
138  GNUNET_asprintf (&scan_dir, "%s%s%c", directory, "sessions", DIR_SEPARATOR);
139 
142 
144 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static char * config_file
Set to the name of the config file used.
Definition: gnunet-arm.c:84
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
static int callback_scan_for_sessions(void *cls, const char *filename)
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.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_data(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, void *buf, size_t buf_size)
Get Crockford32-encoded fixed-size binary data from a configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Parse a configuration file, add all of the options in the file to the configuration environment.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:814
A 256-bit hashcode.

References add_store_member(), callback_scan_for_sessions(), cfg, config_file, DIR_SEPARATOR, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_data(), GNUNET_CONFIGURATION_parse(), GNUNET_DISK_directory_scan(), GNUNET_DISK_directory_test(), GNUNET_DISK_file_test(), GNUNET_free, GNUNET_OK, GNUNET_YES, id, find_typedefs::scan_dir(), and GNUNET_MESSENGER_Member::store.

Referenced by callback_scan_for_members().

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

◆ iterate_load_next_session()

static int iterate_load_next_session ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 147 of file gnunet-service-messenger_member.c.

150 {
151  const char* sessions_directory = cls;
152 
153  char* load_dir;
154  GNUNET_asprintf (&load_dir, "%s%s%c", sessions_directory, GNUNET_h2s(key), DIR_SEPARATOR);
155 
156  struct GNUNET_MESSENGER_MemberSession *session = value;
157 
159  load_member_session_next (session, load_dir);
160 
161  GNUNET_free (load_dir);
162  return GNUNET_YES;
163 }
struct GNUNET_HashCode key
The key used in the DHT.
void load_member_session_next(struct GNUNET_MESSENGER_MemberSession *session, const char *directory)
Loads the connection from one session to another through the next attribute.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).

References DIR_SEPARATOR, GNUNET_asprintf(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_h2s(), GNUNET_YES, key, load_member_session_next(), and value.

Referenced by load_member_next_sessions().

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

◆ load_member_next_sessions()

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 fully built session graph yet.

Parameters
[in/out]member Member
[in]directoryPath to a directory

Definition at line 166 of file gnunet-service-messenger_member.c.

168 {
169  GNUNET_assert ((member) && (directory));
170 
171  char* load_dir;
172  GNUNET_asprintf (&load_dir, "%s%s%c", directory, "sessions", DIR_SEPARATOR);
173 
175 
176  GNUNET_free(load_dir);
177 }
static int iterate_load_next_session(void *cls, const struct GNUNET_HashCode *key, void *value)

References DIR_SEPARATOR, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_free, iterate_load_next_session(), GNUNET_MESSENGER_MemberSession::member, and GNUNET_MESSENGER_Member::sessions.

Referenced by iterate_load_next_member_sessions().

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

◆ iterate_save_session()

static int iterate_save_session ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 180 of file gnunet-service-messenger_member.c.

183 {
184  const char* sessions_directory = cls;
185 
186  char* save_dir;
187  GNUNET_asprintf (&save_dir, "%s%s%c", sessions_directory, GNUNET_h2s(key), DIR_SEPARATOR);
188 
189  struct GNUNET_MESSENGER_MemberSession *session = value;
190 
191  if ((GNUNET_YES == GNUNET_DISK_directory_test (save_dir, GNUNET_NO)) ||
192  (GNUNET_OK == GNUNET_DISK_directory_create (save_dir)))
193  save_member_session (session, save_dir);
194 
195  GNUNET_free (save_dir);
196  return GNUNET_YES;
197 }
void save_member_session(struct GNUNET_MESSENGER_MemberSession *session, const char *directory)
Saves data from a member session into a directory which can be load to restore the member session com...
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_h2s(), GNUNET_NO, GNUNET_OK, GNUNET_YES, key, save_member_session(), and value.

Referenced by save_member().

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

◆ save_member()

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.

Parameters
[in]memberMember
[in]directoryPath to a directory

Definition at line 200 of file gnunet-service-messenger_member.c.

202 {
203  GNUNET_assert ((member) && (directory));
204 
205  char *config_file;
206  GNUNET_asprintf (&config_file, "%s%s", directory, "member.cfg");
207 
209 
210  char *id_data = GNUNET_STRINGS_data_to_string_alloc (&(member->id), sizeof(member->id));
211 
212  if (id_data)
213  {
214  GNUNET_CONFIGURATION_set_value_string (cfg, "member", "id", id_data);
215 
216  GNUNET_free(id_data);
217  }
218 
221 
223 
224  char* save_dir;
225  GNUNET_asprintf (&save_dir, "%s%s%c", directory, "sessions", DIR_SEPARATOR);
226 
227  if ((GNUNET_YES == GNUNET_DISK_directory_test (save_dir, GNUNET_NO)) ||
228  (GNUNET_OK == GNUNET_DISK_directory_create (save_dir)))
230 
231  GNUNET_free(save_dir);
232 }
static int iterate_save_session(void *cls, const struct GNUNET_HashCode *key, void *value)
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:750

References cfg, config_file, DIR_SEPARATOR, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_CONFIGURATION_write(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_DISK_directory_create(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_STRINGS_data_to_string_alloc(), GNUNET_YES, GNUNET_MESSENGER_Member::id, iterate_save_session(), GNUNET_MESSENGER_MemberSession::member, and GNUNET_MESSENGER_Member::sessions.

Referenced by iterate_save_members().

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

◆ sync_session_contact_from_next()

static void sync_session_contact_from_next ( struct GNUNET_MESSENGER_MemberSession session,
struct GNUNET_MESSENGER_MemberSession next 
)
static

Definition at line 235 of file gnunet-service-messenger_member.c.

237 {
238  GNUNET_assert((session) && (next));
239 
240  if (session == next)
241  return;
242 
243  if (next->next)
244  sync_session_contact_from_next (session, next->next);
245  else
246  session->contact = next->contact;
247 }
static void sync_session_contact_from_next(struct GNUNET_MESSENGER_MemberSession *session, struct GNUNET_MESSENGER_MemberSession *next)
struct GNUNET_MESSENGER_MemberSession * next

References GNUNET_MESSENGER_MemberSession::contact, GNUNET_assert, and GNUNET_MESSENGER_MemberSession::next.

Referenced by iterate_sync_session_contact().

Here is the caller graph for this function:

◆ iterate_sync_session_contact()

static int iterate_sync_session_contact ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

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

253 {
254  struct GNUNET_MESSENGER_MemberSession *session = value;
255 
256  if (session->next)
257  sync_session_contact_from_next (session, session->next);
258 
259  return GNUNET_YES;
260 }

References GNUNET_YES, GNUNET_MESSENGER_MemberSession::next, sync_session_contact_from_next(), and value.

Referenced by sync_member_contacts().

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

◆ sync_member_contacts()

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

Parameters
[in/out]member Member

Definition at line 263 of file gnunet-service-messenger_member.c.

264 {
265  GNUNET_assert ((member) && (member->sessions));
266 
268 }
static int iterate_sync_session_contact(void *cls, const struct GNUNET_HashCode *key, void *value)

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterate(), iterate_sync_session_contact(), GNUNET_MESSENGER_MemberSession::member, and GNUNET_MESSENGER_Member::sessions.

Referenced by iterate_sync_member_contacts().

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

◆ get_member_session()

struct GNUNET_MESSENGER_MemberSession* get_member_session ( const struct GNUNET_MESSENGER_Member member,
const struct GNUNET_IDENTITY_PublicKey public_key 
)

Returns the member session of a member identified by a given public key.

If the member does not provide a session with the given key, NULL gets returned.

Parameters
[in]memberMember
[in]public_keyPublic key of EGO
Returns
Member session

Definition at line 271 of file gnunet-service-messenger_member.c.

273 {
274  GNUNET_assert ((member) && (public_key));
275 
276  struct GNUNET_HashCode hash;
277  GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash);
278 
279  return GNUNET_CONTAINER_multihashmap_get(member->sessions, &hash);
280 }
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
A 512-bit hashcode.

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_MESSENGER_MemberSession::member, GNUNET_MESSENGER_MemberSession::public_key, and GNUNET_MESSENGER_Member::sessions.

Referenced by get_handle_member_session(), handle_get_message(), join_room_locally(), load_member_session_next(), solve_room_member_collisions(), and try_member_session().

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

◆ iterate_search_session()

static int iterate_search_session ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 290 of file gnunet-service-messenger_member.c.

293 {
294  struct GNUNET_MESSENGER_ClosureSearchSession* search = cls;
295  struct GNUNET_MESSENGER_MemberSession *session = value;
296 
297  if (GNUNET_OK != verify_member_session_as_sender(session, search->message, search->hash))
298  return GNUNET_YES;
299 
300  search->match = session;
301  return GNUNET_NO;
302 }
int verify_member_session_as_sender(const struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Verifies a given member session as sender of a selected message and its hash.
const struct GNUNET_MESSENGER_Message * message
struct GNUNET_MESSENGER_MemberSession * match

References GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_ClosureSearchSession::hash, GNUNET_MESSENGER_ClosureSearchSession::match, GNUNET_MESSENGER_ClosureSearchSession::message, value, and verify_member_session_as_sender().

Referenced by get_member_session_of().

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

◆ try_member_session()

static struct GNUNET_MESSENGER_MemberSession* try_member_session ( struct GNUNET_MESSENGER_Member member,
const struct GNUNET_IDENTITY_PublicKey public_key 
)
static

Definition at line 305 of file gnunet-service-messenger_member.c.

307 {
309 
310  if (session)
311  return session;
312 
314 
315  if (session)
316  add_member_session(member, session);
317 
318  return session;
319 }
struct GNUNET_MESSENGER_MemberSession * get_member_session(const struct GNUNET_MESSENGER_Member *member, const struct GNUNET_IDENTITY_PublicKey *public_key)
Returns the member session of a member identified by a given public key.
void add_member_session(struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSENGER_MemberSession *session)
Adds a given member session to its member.
struct GNUNET_MESSENGER_MemberSession * create_member_session(struct GNUNET_MESSENGER_Member *member, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Creates and allocates a new member session of a member with a given public key.

References add_member_session(), create_member_session(), get_member_session(), GNUNET_MESSENGER_MemberSession::member, and GNUNET_MESSENGER_MemberSession::public_key.

Referenced by get_member_session_of().

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

◆ get_member_session_of()

struct GNUNET_MESSENGER_MemberSession* get_member_session_of ( struct GNUNET_MESSENGER_Member member,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)

Returns the member session of a member using a public key which can verify the signature of a given message and its hash.

If the member does not provide a matching session, NULL gets returned.

Parameters
[in]memberMember
[in]messageMessage
[in]hashHash of message
Returns
Member session

Definition at line 322 of file gnunet-service-messenger_member.c.

325 {
326  GNUNET_assert ((member) && (message) && (hash) &&
327  (0 == GNUNET_memcmp(&(member->id), &(message->header.sender_id))));
328 
329  if (GNUNET_MESSENGER_KIND_INFO == message->header.kind)
330  return try_member_session(member, &(message->body.info.host_key));
331  else if (GNUNET_MESSENGER_KIND_JOIN == message->header.kind)
332  return try_member_session(member, &(message->body.join.key));
333 
335 
336  search.message = message;
337  search.hash = hash;
338 
339  search.match = NULL;
341 
342  return search.match;
343 }
static struct GNUNET_MESSENGER_MemberSession * try_member_session(struct GNUNET_MESSENGER_Member *member, const struct GNUNET_IDENTITY_PublicKey *public_key)
static int iterate_search_session(void *cls, const struct GNUNET_HashCode *key, void *value)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
struct GNUNET_MESSENGER_MessageJoin join
struct GNUNET_MESSENGER_MessageInfo info
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_IDENTITY_PublicKey host_key
The senders key to verify its signatures.
struct GNUNET_IDENTITY_PublicKey key
The senders public key to verify its signatures.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.

References GNUNET_MESSENGER_Message::body, GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_memcmp, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_ClosureSearchSession::hash, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageInfo::host_key, GNUNET_MESSENGER_Member::id, GNUNET_MESSENGER_MessageBody::info, iterate_search_session(), GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageJoin::key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_ClosureSearchSession::match, GNUNET_MESSENGER_MemberSession::member, GNUNET_MESSENGER_ClosureSearchSession::message, GNUNET_MESSENGER_MessageHeader::sender_id, GNUNET_MESSENGER_Member::sessions, and try_member_session().

Referenced by callback_found_message(), callback_room_handle_message(), check_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_member_session()

void add_member_session ( struct GNUNET_MESSENGER_Member member,
struct GNUNET_MESSENGER_MemberSession session 
)

Adds a given member session to its member.

Parameters
[in/out]member Member
[in/out]session Member session

Definition at line 346 of file gnunet-service-messenger_member.c.

348 {
349  if (!session)
350  return;
351 
352  GNUNET_assert((member) && (session->member == member));
353 
354  const struct GNUNET_IDENTITY_PublicKey *public_key = get_member_session_public_key(session);
355 
356  struct GNUNET_HashCode hash;
357  GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash);
358 
360  member->sessions, &hash, session,
362  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Adding a member session failed: %s\n",
363  GNUNET_h2s(&hash));
364 }
const struct GNUNET_IDENTITY_PublicKey * get_member_session_public_key(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the public key from an EGO of a given member session.
#define GNUNET_log(kind,...)
int 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_ERROR_TYPE_WARNING
An identity key as per LSD0001.

References get_member_session_public_key(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_OK, GNUNET_MESSENGER_MemberSession::member, and GNUNET_MESSENGER_Member::sessions.

Referenced by handle_session_switch(), load_member_session(), and try_member_session().

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

◆ remove_member_session()

void remove_member_session ( struct GNUNET_MESSENGER_Member member,
struct GNUNET_MESSENGER_MemberSession session 
)

Removes a given member session from its member.

Parameters
[in/out]member Member
[in/out]session Member session

Definition at line 367 of file gnunet-service-messenger_member.c.

369 {
370  GNUNET_assert ((member) && (session) && (session->member == member));
371 
372  const struct GNUNET_IDENTITY_PublicKey *public_key = get_member_session_public_key(session);
373 
374  struct GNUNET_HashCode hash;
375  GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash);
376 
377  if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(member->sessions, &hash, session))
378  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Removing a member session failed: %s\n",
379  GNUNET_h2s(&hash));
380 }
int 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.

References get_member_session_public_key(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_YES, GNUNET_MESSENGER_MemberSession::member, and GNUNET_MESSENGER_Member::sessions.

Referenced by remove_room_member_session().

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

◆ iterate_member_sessions_it()

static int iterate_member_sessions_it ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 388 of file gnunet-service-messenger_member.c.

References GNUNET_MESSENGER_ClosureIterateSessions::cls, get_member_session_public_key(), GNUNET_MESSENGER_ClosureIterateSessions::it, and value.

Referenced by iterate_member_sessions().

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

◆ iterate_member_sessions()

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 iterator callback with a selected closure.

The function will return the amount of member sessions it iterated through.

Parameters
[in/out]member Member
[in]itIterator callback
[in/out]cls Closure
Returns
Amount of sessions iterated through

Definition at line 399 of file gnunet-service-messenger_member.c.

402 {
403  GNUNET_assert ((member) && (member->sessions) && (it));
404 
406 
407  iterate.it = it;
408  iterate.cls = cls;
409 
411 }
static int iterate_member_sessions_it(void *cls, const struct GNUNET_HashCode *key, void *value)

References GNUNET_MESSENGER_ClosureIterateSessions::cls, GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_MESSENGER_ClosureIterateSessions::it, iterate_member_sessions_it(), GNUNET_MESSENGER_MemberSession::member, and GNUNET_MESSENGER_Member::sessions.

Referenced by iterate_store_members_it().

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