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

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

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().

32 {
33  GNUNET_assert (store);
34 
36 
37  member->store = store;
38 
39  if (id)
40  GNUNET_memcpy(&(member->id), id, sizeof(member->id));
41  else if (GNUNET_YES != generate_free_member_id(&(member->id), store->members))
42  {
43  GNUNET_free (member);
44  return NULL;
45  }
46 
48 
49  return member;
50 }
struct GNUNET_CONTAINER_MultiShortmap * members
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_ShortHashCode id
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_MESSENGER_MemberStore * store
struct GNUNET_CONTAINER_MultiHashMap * sessions
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
#define GNUNET_free(ptr)
Wrapper around free.
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 53 of file gnunet-service-messenger_member.c.

References destroy_member_session(), GNUNET_YES, and value.

Referenced by destroy_member().

54 {
55  struct GNUNET_MESSENGER_MemberSession *session = value;
56  destroy_member_session(session);
57  return GNUNET_YES;
58 }
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.
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

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

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

Referenced by add_store_member(), and iterate_destroy_members().

62 {
63  GNUNET_assert((member) && (member->sessions));
64 
67 
68  GNUNET_free (member);
69 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
static int iterate_destroy_session(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_CONTAINER_MultiHashMap * sessions
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_free(ptr)
Wrapper around free.
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 72 of file gnunet-service-messenger_member.c.

References GNUNET_assert, and GNUNET_MESSENGER_Member::id.

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

73 {
74  GNUNET_assert (member);
75 
76  return &(member->id);
77 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_ShortHashCode id
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 80 of file gnunet-service-messenger_member.c.

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

Referenced by load_member().

81 {
82  struct GNUNET_MESSENGER_Member *member = cls;
83 
85  {
86  char *directory;
87 
88  GNUNET_asprintf (&directory, "%s%c", filename, DIR_SEPARATOR);
89 
90  load_member_session(member, directory);
91  }
92 
93  return GNUNET_OK;
94 }
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...
static char * filename
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define DIR_SEPARATOR
Definition: platform.h:164
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
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 97 of file gnunet-service-messenger_member.c.

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, and find_typedefs::scan_dir().

Referenced by callback_scan_for_members().

98 {
99  GNUNET_assert ((store) && (directory));
100 
101  char *config_file;
102  GNUNET_asprintf (&config_file, "%s%s", directory, "member.cfg");
103 
104  struct GNUNET_MESSENGER_Member *member = NULL;
105 
106  if (GNUNET_YES != GNUNET_DISK_file_test (config_file))
107  goto free_config;
108 
110 
111  if (GNUNET_OK == GNUNET_CONFIGURATION_parse (cfg, config_file))
112  {
113  struct GNUNET_ShortHashCode id;
114 
115  if (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "member", "id", &id, sizeof(id)))
116  goto destroy_config;
117 
118  member = add_store_member(store, &id);
119  }
120 
121 destroy_config:
122 
124 
125 free_config:
126  GNUNET_free(config_file);
127 
128  if (!member)
129  return;
130 
131  char *scan_dir;
132  GNUNET_asprintf (&scan_dir, "%s%s%c", directory, "sessions", DIR_SEPARATOR);
133 
136 
137  GNUNET_free(scan_dir);
138 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
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...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:814
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.
A 256-bit hashcode.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define DIR_SEPARATOR
Definition: platform.h:164
configuration data
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.
static int callback_scan_for_sessions(void *cls, const char *filename)
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
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
#define GNUNET_free(ptr)
Wrapper around free.
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 141 of file gnunet-service-messenger_member.c.

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

Referenced by load_member_next_sessions().

142 {
143  const char* sessions_directory = cls;
144 
145  char* load_dir;
146  GNUNET_asprintf (&load_dir, "%s%s%c", sessions_directory, GNUNET_h2s(key), DIR_SEPARATOR);
147 
148  struct GNUNET_MESSENGER_MemberSession *session = value;
149 
151  load_member_session_next (session, load_dir);
152 
153  GNUNET_free (load_dir);
154  return GNUNET_YES;
155 }
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
static char * value
Value of the record to add/remove.
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.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define DIR_SEPARATOR
Definition: platform.h:164
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
#define GNUNET_free(ptr)
Wrapper around free.
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

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

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

Referenced by iterate_load_next_member_sessions().

159 {
160  GNUNET_assert ((member) && (directory));
161 
162  char* load_dir;
163  GNUNET_asprintf (&load_dir, "%s%s%c", directory, "sessions", DIR_SEPARATOR);
164 
166 
167  GNUNET_free(load_dir);
168 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int iterate_load_next_session(void *cls, const struct GNUNET_HashCode *key, void *value)
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define DIR_SEPARATOR
Definition: platform.h:164
struct GNUNET_CONTAINER_MultiHashMap * sessions
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_free(ptr)
Wrapper around free.
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 171 of file gnunet-service-messenger_member.c.

References DIR_SEPARATOR, GNUNET_asprintf(), GNUNET_DISK_directory_create(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_h2s(), GNUNET_NO, GNUNET_OK, GNUNET_YES, save_member_session(), and value.

Referenced by save_member().

172 {
173  const char* sessions_directory = cls;
174 
175  char* save_dir;
176  GNUNET_asprintf (&save_dir, "%s%s%c", sessions_directory, GNUNET_h2s(key), DIR_SEPARATOR);
177 
178  struct GNUNET_MESSENGER_MemberSession *session = value;
179 
180  if ((GNUNET_YES == GNUNET_DISK_directory_test (save_dir, GNUNET_NO)) ||
181  (GNUNET_OK == GNUNET_DISK_directory_create (save_dir)))
182  save_member_session (session, save_dir);
183 
184  GNUNET_free (save_dir);
185  return GNUNET_YES;
186 }
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
static char * value
Value of the record to add/remove.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:496
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...
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define DIR_SEPARATOR
Definition: platform.h:164
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
#define GNUNET_free(ptr)
Wrapper around free.
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 189 of file gnunet-service-messenger_member.c.

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(), and GNUNET_MESSENGER_Member::sessions.

Referenced by iterate_save_members().

190 {
191  GNUNET_assert ((member) && (directory));
192 
193  char *config_file;
194  GNUNET_asprintf (&config_file, "%s%s", directory, "member.cfg");
195 
197 
198  char *id_data = GNUNET_STRINGS_data_to_string_alloc (&(member->id), sizeof(member->id));
199 
200  if (id_data)
201  {
202  GNUNET_CONFIGURATION_set_value_string (cfg, "member", "id", id_data);
203 
204  GNUNET_free(id_data);
205  }
206 
207  GNUNET_CONFIGURATION_write (cfg, config_file);
209 
210  GNUNET_free(config_file);
211 
212  char* save_dir;
213  GNUNET_asprintf (&save_dir, "%s%s%c", directory, "sessions", DIR_SEPARATOR);
214 
215  if ((GNUNET_YES == GNUNET_DISK_directory_test (save_dir, GNUNET_NO)) ||
216  (GNUNET_OK == GNUNET_DISK_directory_create (save_dir)))
218 
219  GNUNET_free(save_dir);
220 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static char * config_file
Set to the name of the config file used.
Definition: gnunet-arm.c:84
static int iterate_save_session(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
struct GNUNET_ShortHashCode id
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
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_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:496
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define DIR_SEPARATOR
Definition: platform.h:164
configuration data
struct GNUNET_CONTAINER_MultiHashMap * sessions
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
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
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
#define GNUNET_free(ptr)
Wrapper around free.
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 223 of file gnunet-service-messenger_member.c.

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

Referenced by iterate_sync_session_contact().

224 {
225  GNUNET_assert((session) && (next));
226 
227  if (session == next)
228  return;
229 
230  if (next->next)
231  sync_session_contact_from_next (session, next->next);
232  else
233  session->contact = next->contact;
234 }
static void sync_session_contact_from_next(struct GNUNET_MESSENGER_MemberSession *session, struct GNUNET_MESSENGER_MemberSession *next)
struct GNUNET_MESSENGER_MemberSession * next
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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 237 of file gnunet-service-messenger_member.c.

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

Referenced by sync_member_contacts().

238 {
239  struct GNUNET_MESSENGER_MemberSession *session = value;
240 
241  if (session->next)
242  sync_session_contact_from_next (session, session->next);
243 
244  return GNUNET_YES;
245 }
static void sync_session_contact_from_next(struct GNUNET_MESSENGER_MemberSession *session, struct GNUNET_MESSENGER_MemberSession *next)
struct GNUNET_MESSENGER_MemberSession * next
static char * value
Value of the record to add/remove.
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

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

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

Referenced by iterate_sync_member_contacts().

249 {
250  GNUNET_assert ((member) && (member->sessions));
251 
253 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int iterate_sync_session_contact(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_CONTAINER_MultiHashMap * sessions
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
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 256 of file gnunet-service-messenger_member.c.

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), 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().

257 {
258  GNUNET_assert ((member) && (public_key));
259 
260  struct GNUNET_HashCode hash;
261  GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash);
262 
263  return GNUNET_CONTAINER_multihashmap_get(member->sessions, &hash);
264 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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.
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
A 512-bit hashcode.
struct GNUNET_CONTAINER_MultiHashMap * sessions
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 274 of file gnunet-service-messenger_member.c.

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().

275 {
276  struct GNUNET_MESSENGER_ClosureSearchSession* search = cls;
277  struct GNUNET_MESSENGER_MemberSession *session = value;
278 
279  if (GNUNET_OK != verify_member_session_as_sender(session, search->message, search->hash))
280  return GNUNET_YES;
281 
282  search->match = session;
283  return GNUNET_NO;
284 }
static char * value
Value of the record to add/remove.
struct GNUNET_MESSENGER_MemberSession * match
const struct GNUNET_MESSENGER_Message * message
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.
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 287 of file gnunet-service-messenger_member.c.

References add_member_session(), create_member_session(), and get_member_session().

Referenced by get_member_session_of().

288 {
289  struct GNUNET_MESSENGER_MemberSession* session = get_member_session(member, public_key);
290 
291  if (session)
292  return session;
293 
294  session = create_member_session(member, public_key);
295 
296  if (session)
297  add_member_session(member, session);
298 
299  return session;
300 }
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.
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.
void add_member_session(struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSENGER_MemberSession *session)
Adds a given member session to its member.
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 303 of file gnunet-service-messenger_member.c.

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_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().

305 {
306  GNUNET_assert ((member) && (message) && (hash) &&
307  (0 == GNUNET_memcmp(&(member->id), &(message->header.sender_id))));
308 
309  if (GNUNET_MESSENGER_KIND_INFO == message->header.kind)
310  return try_member_session(member, &(message->body.info.host_key));
311  else if (GNUNET_MESSENGER_KIND_JOIN == message->header.kind)
312  return try_member_session(member, &(message->body.join.key));
313 
315 
316  search.message = message;
317  search.hash = hash;
318 
319  search.match = NULL;
321 
322  return search.match;
323 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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_ShortHashCode id
struct GNUNET_MESSENGER_MessageBody body
Body.
const struct GNUNET_MESSENGER_Message * message
static int iterate_search_session(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_MESSENGER_MessageInfo info
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
struct GNUNET_CONTAINER_MultiHashMap * sessions
static struct GNUNET_MESSENGER_MemberSession * try_member_session(struct GNUNET_MESSENGER_Member *member, const struct GNUNET_IDENTITY_PublicKey *public_key)
struct GNUNET_MESSENGER_MessageJoin join
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
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

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

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().

327 {
328  if (!session)
329  return;
330 
331  GNUNET_assert((member) && (session->member == member));
332 
333  const struct GNUNET_IDENTITY_PublicKey *public_key = get_member_session_public_key(session);
334 
335  struct GNUNET_HashCode hash;
336  GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash);
337 
339  member->sessions, &hash, session,
341  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Adding a member session failed: %s\n",
342  GNUNET_h2s(&hash));
343 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
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
A 512-bit hashcode.
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.
An identity key as per LSD0001.
struct GNUNET_CONTAINER_MultiHashMap * sessions
#define GNUNET_log(kind,...)
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.
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

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

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().

347 {
348  GNUNET_assert ((member) && (session) && (session->member == member));
349 
350  const struct GNUNET_IDENTITY_PublicKey *public_key = get_member_session_public_key(session);
351 
352  struct GNUNET_HashCode hash;
353  GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash);
354 
355  if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(member->sessions, &hash, session))
356  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Removing a member session failed: %s\n",
357  GNUNET_h2s(&hash));
358 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
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
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.
A 512-bit hashcode.
An identity key as per LSD0001.
struct GNUNET_CONTAINER_MultiHashMap * sessions
#define GNUNET_log(kind,...)
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.
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 366 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().

367 {
369  struct GNUNET_MESSENGER_MemberSession *session = value;
370 
371  return iterate->it (iterate->cls, get_member_session_public_key(session), session);
372 }
static char * value
Value of the record to add/remove.
GNUNET_MESSENGER_MemberIteratorCallback it
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.
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

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

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

Referenced by iterate_store_members_it().

376 {
377  GNUNET_assert ((member) && (member->sessions) && (it));
378 
380 
381  iterate.it = it;
382  iterate.cls = cls;
383 
385 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int iterate_member_sessions_it(void *cls, const struct GNUNET_HashCode *key, void *value)
GNUNET_MESSENGER_MemberIteratorCallback it
struct GNUNET_CONTAINER_MultiHashMap * sessions
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
Here is the call graph for this function:
Here is the caller graph for this function: