GNUnet  0.11.x
Data Structures | Functions
gnunet-service-messenger_member_session.h File Reference

GNUnet MESSENGER service. More...

#include "platform.h"
#include "gnunet_crypto_lib.h"
#include "gnunet_container_lib.h"
#include "gnunet_identity_service.h"
#include "gnunet_time_lib.h"
#include "gnunet-service-messenger_member.h"
#include "messenger_api_contact.h"
Include dependency graph for gnunet-service-messenger_member_session.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_MemberSession
 

Functions

struct GNUNET_MESSENGER_MemberSessioncreate_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. More...
 
struct GNUNET_MESSENGER_MemberSessionswitch_member_session (struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 Creates and allocates a new member session closing and replacing a given other session of the same member. More...
 
void destroy_member_session (struct GNUNET_MESSENGER_MemberSession *session)
 Destroys a member session and frees its memory fully. More...
 
int reset_member_session (struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash)
 Resets a given member session which re-opens a member session for new usage. More...
 
void close_member_session (struct GNUNET_MESSENGER_MemberSession *session)
 Closes a given member session which opens the request for completion of the given member session. More...
 
int is_member_session_closed (const struct GNUNET_MESSENGER_MemberSession *session)
 Returns if the given member session has been closed. More...
 
int is_member_session_completed (const struct GNUNET_MESSENGER_MemberSession *session)
 Returns if the given member session has been completed. More...
 
struct GNUNET_TIME_Absolute get_member_session_start (const struct GNUNET_MESSENGER_MemberSession *session)
 Returns the timestamp of the member session's start. More...
 
const struct GNUNET_HashCodeget_member_session_key (const struct GNUNET_MESSENGER_MemberSession *session)
 Returns the key of the room a given member session belongs to. More...
 
const struct GNUNET_ShortHashCodeget_member_session_id (const struct GNUNET_MESSENGER_MemberSession *session)
 Returns the member id of a given member session. More...
 
const struct GNUNET_IDENTITY_PublicKeyget_member_session_public_key (const struct GNUNET_MESSENGER_MemberSession *session)
 Returns the public key from an EGO of a given member session. More...
 
const struct GNUNET_HashCodeget_member_session_context (const struct GNUNET_MESSENGER_MemberSession *session)
 Returns the member context of a given member session. More...
 
struct GNUNET_MESSENGER_Contactget_member_session_contact (struct GNUNET_MESSENGER_MemberSession *session)
 Returns the contact which is connected to a given member session. More...
 
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. More...
 
int check_member_session_history (const struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash, int ownership)
 Checks the history of a session for a specific message which is identified by its hash and if the ownership flag is set, if the message is owned by the sessions contact. More...
 
void update_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 Adds a given message to the history of a session using the messages hash. More...
 
void clear_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash)
 Removes a message from the history of a session using the messages hash. More...
 
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 required information can be read from the content of the given directory. More...
 
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. More...
 
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 completely. More...
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_member_session.h.

Function Documentation

◆ create_member_session()

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.

If the creation fails, NULL gets returned.

Parameters
[in/out]member Member
[in]pubkeyPublic key of EGO
Returns
New member session

Definition at line 34 of file gnunet-service-messenger_member_session.c.

36 {
37  if ((!member) || (!pubkey) || (!(member->store)))
38  return NULL;
39 
41  session->member = member;
42 
43  GNUNET_memcpy(&(session->public_key), pubkey, sizeof(session->public_key));
44 
46  get_member_session_key (session),
47  get_member_session_id (session),
48  &(session->context)
49  );
50 
52 
53  session->contact = get_store_contact(
54  store,
57  );
58 
59  if (!(session->contact))
60  {
61  GNUNET_free(session);
62  return NULL;
63  }
64 
65  increase_contact_rc (session->contact);
66 
68 
69  init_list_messages(&(session->messages));
70 
71  session->prev = NULL;
72  session->next = NULL;
73 
74  session->start = GNUNET_TIME_absolute_get();
75 
76  session->closed = GNUNET_NO;
77  session->completed = GNUNET_NO;
78 
79  return session;
80 }
static struct GNUNET_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
void init_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Initializes list of message hashes as empty list.
const struct GNUNET_HashCode * get_member_session_key(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the key of the room a given member session belongs to.
const struct GNUNET_ShortHashCode * get_member_session_id(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the member id of a given member session.
const struct GNUNET_HashCode * get_member_session_context(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the member context of a given member session.
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.
struct GNUNET_MESSENGER_ContactStore * get_member_contact_store(struct GNUNET_MESSENGER_MemberStore *store)
Returns the used contact store of a given member store.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ 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_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:94
void increase_contact_rc(struct GNUNET_MESSENGER_Contact *contact)
Increases the reference counter of a given contact which is zero as default.
void get_context_from_member(const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *id, struct GNUNET_HashCode *context)
Calculates the context hash of a member in a room and returns it.
struct GNUNET_MESSENGER_Contact * get_store_contact(struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Returns a contact using a specific public key.
struct GNUNET_CONTAINER_MultiHashMap * history
struct GNUNET_MESSENGER_MemberSession * prev
struct GNUNET_MESSENGER_MemberSession * next
struct GNUNET_MESSENGER_ListMessages messages
struct GNUNET_MESSENGER_MemberStore * store

References GNUNET_MESSENGER_MemberSession::closed, GNUNET_MESSENGER_MemberSession::completed, GNUNET_MESSENGER_MemberSession::contact, GNUNET_MESSENGER_MemberSession::context, get_context_from_member(), get_member_contact_store(), get_member_session_context(), get_member_session_id(), get_member_session_key(), get_member_session_public_key(), get_store_contact(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_free, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_TIME_absolute_get(), GNUNET_MESSENGER_MemberSession::history, increase_contact_rc(), init_list_messages(), GNUNET_MESSENGER_MemberSession::member, GNUNET_MESSENGER_MemberSession::messages, GNUNET_MESSENGER_MemberSession::next, GNUNET_MESSENGER_MemberSession::prev, pubkey, GNUNET_MESSENGER_MemberSession::public_key, GNUNET_MESSENGER_MemberSession::start, and GNUNET_MESSENGER_Member::store.

Referenced by load_member_session(), and try_member_session().

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

◆ switch_member_session()

struct GNUNET_MESSENGER_MemberSession* switch_member_session ( struct GNUNET_MESSENGER_MemberSession session,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)

Creates and allocates a new member session closing and replacing a given other session of the same member.

The new session could have significant changes to the members public key or its member id depending on the used message to switch session. The new session will be linked to the old one.

Parameters
[in/out]session Old member session
[in]messageMessage
[in]hashHash of message
Returns
New member session

Definition at line 174 of file gnunet-service-messenger_member_session.c.

177 {
178  if ((!session) || (!message) || (!hash))
179  return NULL;
180 
182  (GNUNET_MESSENGER_KIND_KEY == message->header.kind));
183 
185 
186  if (GNUNET_MESSENGER_KIND_ID == message->header.kind)
187  next->member = add_store_member(session->member->store, &(message->body.id.id));
188  else
189  next->member = session->member;
190 
191  if (GNUNET_MESSENGER_KIND_KEY == message->header.kind)
192  GNUNET_memcpy(&(next->public_key), &(message->body.key.key), sizeof(next->public_key));
193  else
195 
199  &(next->context)
200  );
201 
208  );
209 
211 
212  if (!(next->contact))
213  {
214  GNUNET_free(next);
215  return NULL;
216  }
217 
219 
222  );
223 
225 
227  copy_list_messages(&(next->messages), &(session->messages));
228 
229  session->next = next;
230  next->prev = session;
231  next->next = NULL;
232 
234 
235  session->closed = GNUNET_YES;
236  next->closed = GNUNET_NO;
238 
240 
241  return next;
242 }
void copy_list_messages(struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_MESSENGER_ListMessages *origin)
Copies all message hashes from an origin to another list.
static int iterate_copy_history(void *cls, const struct GNUNET_HashCode *key, void *value)
static void check_member_session_completion(struct GNUNET_MESSENGER_MemberSession *session)
struct GNUNET_MESSENGER_Contact * get_member_session_contact(struct GNUNET_MESSENGER_MemberSession *session)
Returns the contact which is connected to a given member session.
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_YES
Definition: gnunet_common.h:97
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
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_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_MESSENGER_KIND_KEY
The key kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.
void update_store_contact(struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET_MESSENGER_Contact *contact, const struct GNUNET_HashCode *context, const struct GNUNET_HashCode *next_context, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Moves a contact from the store to another location matching a given public key and member context.
struct GNUNET_MESSENGER_MessageId id
struct GNUNET_MESSENGER_MessageKey key
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
struct GNUNET_IDENTITY_PublicKey key
The new public key which replaces the current senders public key.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.

References add_store_member(), GNUNET_MESSENGER_Message::body, check_member_session_completion(), GNUNET_MESSENGER_MemberSession::closed, GNUNET_MESSENGER_MemberSession::completed, GNUNET_MESSENGER_MemberSession::contact, GNUNET_MESSENGER_MemberSession::context, copy_list_messages(), get_context_from_member(), get_member_contact_store(), get_member_session_contact(), get_member_session_context(), get_member_session_id(), get_member_session_key(), get_member_session_public_key(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CONTAINER_multihashmap_size(), GNUNET_free, GNUNET_memcpy, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_KEY, GNUNET_new, GNUNET_NO, GNUNET_TIME_absolute_get(), GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MemberSession::history, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, increase_contact_rc(), init_list_messages(), iterate_copy_history(), GNUNET_MESSENGER_MessageKey::key, GNUNET_MESSENGER_MessageBody::key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MemberSession::member, GNUNET_MESSENGER_MemberSession::messages, GNUNET_MESSENGER_MemberSession::next, GNUNET_MESSENGER_MemberSession::prev, GNUNET_MESSENGER_MemberSession::public_key, GNUNET_MESSENGER_MemberSession::start, GNUNET_MESSENGER_Member::store, and update_store_contact().

Referenced by handle_session_switch().

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

◆ destroy_member_session()

void destroy_member_session ( struct GNUNET_MESSENGER_MemberSession session)

Destroys a member session and frees its memory fully.

Parameters
[in/out]session Member session

Definition at line 245 of file gnunet-service-messenger_member_session.c.

246 {
247  GNUNET_assert (session);
248 
250 
251  clear_list_messages (&(session->messages));
252 
253  struct GNUNET_MESSENGER_Contact *contact = get_member_session_contact (session);
254 
255  if ((contact) && (GNUNET_YES == decrease_contact_rc (contact)))
258  contact,
260  );
261 
262  GNUNET_free(session);
263 }
void clear_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Clears the list of message hashes.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
int decrease_contact_rc(struct GNUNET_MESSENGER_Contact *contact)
Decreases the reference counter if possible (can not underflow!) of a given contact and returns GNUNE...
void remove_store_contact(struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET_MESSENGER_Contact *contact, const struct GNUNET_HashCode *context)
Removes a contact from the store which uses a given member context.

References clear_list_messages(), decrease_contact_rc(), get_member_contact_store(), get_member_session_contact(), get_member_session_context(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_free, GNUNET_YES, GNUNET_MESSENGER_MemberSession::history, GNUNET_MESSENGER_MemberSession::member, GNUNET_MESSENGER_MemberSession::messages, remove_store_contact(), and GNUNET_MESSENGER_Member::store.

Referenced by iterate_destroy_session(), and remove_room_member_session().

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

◆ reset_member_session()

int reset_member_session ( struct GNUNET_MESSENGER_MemberSession session,
const struct GNUNET_HashCode hash 
)

Resets a given member session which re-opens a member session for new usage.

Every connection to other sessions will be be dropped. The member sessions messages will be cleared but old history from uncompleted sessions however can be reused!

Parameters
[in/out]session Member session
[in]hashHash of initial message (JOIN message!)
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 266 of file gnunet-service-messenger_member_session.c.

268 {
269  GNUNET_assert ((session) && (hash));
270 
273  store,
274  get_member_session_context (session),
276  );
277 
278  if (!contact)
279  return GNUNET_SYSERR;
280 
281  if (contact == session->contact)
282  goto clear_messages;
283 
284  session->contact = contact;
285  increase_contact_rc (session->contact);
286 
287 clear_messages:
288  clear_list_messages(&(session->messages));
289  add_to_list_messages(&(session->messages), hash);
290 
291  session->next = NULL;
292  session->closed = GNUNET_NO;
293  session->completed = GNUNET_NO;
294 
295  return GNUNET_OK;
296 }
void add_to_list_messages(struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash)
Adds a specific hash from a message to the end of the list.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_SYSERR
Definition: gnunet_common.h:93

References add_to_list_messages(), clear_list_messages(), GNUNET_MESSENGER_MemberSession::closed, GNUNET_MESSENGER_MemberSession::completed, GNUNET_MESSENGER_MemberSession::contact, get_member_contact_store(), get_member_session_context(), get_member_session_public_key(), get_store_contact(), GNUNET_assert, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, increase_contact_rc(), GNUNET_MESSENGER_MemberSession::member, GNUNET_MESSENGER_MemberSession::messages, GNUNET_MESSENGER_MemberSession::next, and GNUNET_MESSENGER_Member::store.

Referenced by handle_message_join().

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

◆ close_member_session()

void close_member_session ( struct GNUNET_MESSENGER_MemberSession session)

Closes a given member session which opens the request for completion of the given member session.

Closing a session may complete a session and can't be used without a reset! (

See also
reset_member_session() )
Parameters
[in/out]session Member session

Definition at line 299 of file gnunet-service-messenger_member_session.c.

300 {
301  GNUNET_assert (session);
302 
303  session->closed = GNUNET_YES;
305 }

References check_member_session_completion(), GNUNET_MESSENGER_MemberSession::closed, GNUNET_assert, and GNUNET_YES.

Referenced by handle_message_leave().

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

◆ is_member_session_closed()

int is_member_session_closed ( const struct GNUNET_MESSENGER_MemberSession session)

Returns if the given member session has been closed.

Parameters
[in]sessionMember session
Returns
GNUNET_YES or GNUNET_NO

Definition at line 308 of file gnunet-service-messenger_member_session.c.

309 {
310  GNUNET_assert(session);
311 
312  return session->closed;
313 }

References GNUNET_MESSENGER_MemberSession::closed, and GNUNET_assert.

Referenced by check_room_peer_status().

Here is the caller graph for this function:

◆ is_member_session_completed()

int is_member_session_completed ( const struct GNUNET_MESSENGER_MemberSession session)

Returns if the given member session has been completed.

A completed member session can't verify any message as its own and it won't add any message to its history.

Parameters
[in]sessionMember session
Returns
GNUNET_YES or GNUNET_NO

Definition at line 316 of file gnunet-service-messenger_member_session.c.

317 {
318  GNUNET_assert(session);
319 
320  return session->completed;
321 }

Referenced by check_member_session_completion(), iterate_forward_members(), iterate_notify_about_members(), iterate_update_member_sessions(), update_member_session_history(), and verify_member_session_as_sender().

Here is the caller graph for this function:

◆ get_member_session_start()

struct GNUNET_TIME_Absolute get_member_session_start ( const struct GNUNET_MESSENGER_MemberSession session)

Returns the timestamp of the member session's start.

Parameters
[in]sessionMember session
Returns
Absolute timestamp

Definition at line 316 of file gnunet-service-messenger_member_session.c.

325 {
326  GNUNET_assert(session);
327 
328  if (session->prev)
329  return get_member_session_start(session->prev);
330 
331  return session->start;
332 }
struct GNUNET_TIME_Absolute get_member_session_start(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the timestamp of the member session's start.

References GNUNET_MESSENGER_MemberSession::completed, and GNUNET_assert.

Referenced by solve_room_member_collisions().

Here is the caller graph for this function:

◆ get_member_session_key()

const struct GNUNET_HashCode* get_member_session_key ( const struct GNUNET_MESSENGER_MemberSession session)

Returns the key of the room a given member session belongs to.

Parameters
[in]sessionMember session
Returns
Key of room

Definition at line 335 of file gnunet-service-messenger_member_session.c.

336 {
337  GNUNET_assert((session) && (session->member));
338 
339  return get_member_store_key(session->member->store);
340 }
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.

References get_member_store_key(), GNUNET_assert, GNUNET_MESSENGER_MemberSession::member, and GNUNET_MESSENGER_Member::store.

Referenced by create_member_session(), and switch_member_session().

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

◆ get_member_session_id()

const struct GNUNET_ShortHashCode* get_member_session_id ( const struct GNUNET_MESSENGER_MemberSession session)

Returns the member id of a given member session.

Parameters
[in]sessionMember session
Returns
Member id

Definition at line 343 of file gnunet-service-messenger_member_session.c.

344 {
345  GNUNET_assert(session);
346 
347  return get_member_id(session->member);
348 }
const struct GNUNET_ShortHashCode * get_member_id(const struct GNUNET_MESSENGER_Member *member)
Returns the current id of a given member.

References get_member_id(), GNUNET_assert, and GNUNET_MESSENGER_MemberSession::member.

Referenced by create_member_session(), delete_room_message(), remove_room_member_session(), switch_member_session(), update_member_session_history(), and verify_member_session_as_sender().

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

◆ get_member_session_public_key()

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.

Parameters
[in]sessionMember session
Returns
Public key of EGO

Definition at line 351 of file gnunet-service-messenger_member_session.c.

352 {
353  GNUNET_assert(session);
354 
355  return &(session->public_key);
356 }

References GNUNET_assert, and GNUNET_MESSENGER_MemberSession::public_key.

Referenced by add_member_session(), create_member_session(), handle_message_id(), iterate_member_sessions_it(), remove_member_session(), remove_room_member_session(), reset_member_session(), switch_member_session(), and verify_member_session_as_sender().

Here is the caller graph for this function:

◆ get_member_session_context()

const struct GNUNET_HashCode* get_member_session_context ( const struct GNUNET_MESSENGER_MemberSession session)

Returns the member context of a given member session.

Parameters
[in]sessionMember session
Returns
Member context as hash

Definition at line 359 of file gnunet-service-messenger_member_session.c.

360 {
361  GNUNET_assert(session);
362 
363  return &(session->context);
364 }

References GNUNET_MESSENGER_MemberSession::context, and GNUNET_assert.

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

Here is the caller graph for this function:

◆ get_member_session_contact()

struct GNUNET_MESSENGER_Contact* get_member_session_contact ( struct GNUNET_MESSENGER_MemberSession session)

Returns the contact which is connected to a given member session.

Parameters
[in]sessionMember session
Returns
Contact

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

368 {
369  GNUNET_assert (session);
370 
371  return session->contact;
372 }

References GNUNET_MESSENGER_MemberSession::contact, and GNUNET_assert.

Referenced by destroy_member_session(), handle_message_name(), and switch_member_session().

Here is the caller graph for this function:

◆ verify_member_session_as_sender()

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.

The function returns GNUNET_OK if the message session is verified as sender, otherwise GNUNET_SYSERR.

See also
is_member_session_completed() for verification.
Parameters
[in]sessionMember session
[in]messageMessage
[in]hashHash of message
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

Definition at line 374 of file gnunet-service-messenger_member_session.c.

377 {
378  GNUNET_assert((session) && (message) && (hash));
379 
380  if (GNUNET_YES == is_member_session_completed(session))
381  return GNUNET_SYSERR;
382 
383  if (0 != GNUNET_memcmp(get_member_session_id(session), &(message->header.sender_id)))
384  return GNUNET_SYSERR;
385 
386  return verify_message(message, hash, get_member_session_public_key(session));
387 }
int is_member_session_completed(const struct GNUNET_MESSENGER_MemberSession *session)
Returns if the given member session has been completed.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
int verify_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_IDENTITY_PublicKey *key)
Verifies the signature of a given message and its hash with a specific public key.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.

References get_member_session_id(), get_member_session_public_key(), GNUNET_assert, GNUNET_memcmp, GNUNET_SYSERR, GNUNET_YES, GNUNET_MESSENGER_Message::header, is_member_session_completed(), GNUNET_MESSENGER_MessageHeader::sender_id, and verify_message().

Referenced by iterate_search_session(), and update_member_session_history().

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

◆ check_member_session_history()

int check_member_session_history ( const struct GNUNET_MESSENGER_MemberSession session,
const struct GNUNET_HashCode hash,
int  ownership 
)

Checks the history of a session for a specific message which is identified by its hash and if the ownership flag is set, if the message is owned by the sessions contact.

Parameters
[in]sessionMember session
[in]hashHash of message
[in]ownershipOwnership flag
Returns
GNUNET_YES if found, otherwise GNUNET_NO

Definition at line 390 of file gnunet-service-messenger_member_session.c.

392 {
393  GNUNET_assert((session) && (hash));
394 
395  if (GNUNET_YES == ownership)
396  return (NULL != GNUNET_CONTAINER_multihashmap_get(session->history, hash)? GNUNET_YES : GNUNET_NO);
397  else
398  return GNUNET_CONTAINER_multihashmap_contains(session->history, hash);
399 }
int GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
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.

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_NO, GNUNET_YES, and GNUNET_MESSENGER_MemberSession::history.

Referenced by check_member_session_completion(), delete_room_message(), notify_about_members(), recv_message_request(), and request_room_message_step().

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

◆ update_member_session_history()

void update_member_session_history ( struct GNUNET_MESSENGER_MemberSession session,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)

Adds a given message to the history of a session using the messages hash.

The ownership will be set automatically.

See also
is_member_session_completed() for updating a history.
Parameters
[in/out]session Member session
[in]messageMessage
[in]hashHash of message

Definition at line 413 of file gnunet-service-messenger_member_session.c.

416 {
417  GNUNET_assert((session) && (message) && (hash));
418 
419  if (GNUNET_YES == is_member_session_completed(session))
420  return;
421 
422  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Updating sessions history (%s) += (%s)\n",
423  GNUNET_sh2s(get_member_session_id(session)), GNUNET_h2s(hash));
424 
425  if (GNUNET_OK == verify_member_session_as_sender (session, message, hash))
426  {
427  if (GNUNET_YES == is_message_session_bound (message))
428  add_to_list_messages(&(session->messages), hash);
429 
430  update_member_chain_history (session, hash, GNUNET_YES);
431  }
432  else
433  update_member_chain_history (session, hash, GNUNET_NO);
434 
435  if (GNUNET_YES == session->closed)
437 }
static void update_member_chain_history(struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash, int ownership)
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.
#define GNUNET_log(kind,...)
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
int is_message_session_bound(const struct GNUNET_MESSENGER_Message *message)
Returns if the message should be bound to a member session.

References add_to_list_messages(), check_member_session_completion(), GNUNET_MESSENGER_MemberSession::closed, get_member_session_id(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_sh2s(), GNUNET_YES, is_member_session_completed(), is_message_session_bound(), GNUNET_MESSENGER_MemberSession::messages, update_member_chain_history(), and verify_member_session_as_sender().

Referenced by iterate_update_member_sessions().

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

◆ clear_member_session_history()

void clear_member_session_history ( struct GNUNET_MESSENGER_MemberSession session,
const struct GNUNET_HashCode hash 
)

Removes a message from the history of a session using the messages hash.

Parameters
[in/out]session Member session
[in]hashHash of message

Definition at line 450 of file gnunet-service-messenger_member_session.c.

452 {
453  GNUNET_assert((session) && (hash));
454 
455  clear_member_chain_history (session, hash);
456 }
static void clear_member_chain_history(struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash)

References clear_member_chain_history(), and GNUNET_assert.

Referenced by clear_member_chain_history().

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

◆ load_member_session()

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

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

Definition at line 508 of file gnunet-service-messenger_member_session.c.

510 {
511  GNUNET_assert ((member) && (directory));
512 
513  char *config_file;
514  GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg");
515 
516  struct GNUNET_MESSENGER_MemberSession *session = NULL;
517 
519  goto free_config;
520 
521  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Load session configuration of member: %s\n", config_file);
522 
524 
526  {
527  char *key_data;
528 
529  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "session", "key", &key_data))
530  goto destroy_config;
531 
533 
535 
536  GNUNET_free(key_data);
537 
538  if (GNUNET_OK != key_return)
539  goto destroy_config;
540 
541  session = create_member_session(member, &key);
542 
543  unsigned long long numeric_value;
544 
545  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "session", "start", &numeric_value))
546  session->start.abs_value_us = numeric_value;
547 
548  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "session", "closed", &numeric_value))
549  session->closed = (GNUNET_YES == numeric_value? GNUNET_YES : GNUNET_NO);
550 
551  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "session", "completed", &numeric_value))
552  session->completed = (GNUNET_YES == numeric_value? GNUNET_YES : GNUNET_NO);
553  }
554 
555 destroy_config:
557 
558 free_config:
560 
561  if (!session)
562  return;
563 
564  char *history_file;
565  GNUNET_asprintf (&history_file, "%s%s", directory, "history.map");
566 
567  load_member_session_history (session, history_file);
568  GNUNET_free(history_file);
569 
570  char *messages_file;
571  GNUNET_asprintf (&messages_file, "%s%s", directory, "messages.list");
572 
573  load_list_messages(&(session->messages), messages_file);
574  GNUNET_free(messages_file);
575 
576  add_member_session(member, session);
577 }
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
struct GNUNET_HashCode key
The key used in the DHT.
void load_list_messages(struct GNUNET_MESSENGER_ListMessages *messages, const char *path)
Loads the list of message hashes from a file under a given path.
void add_member_session(struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSENGER_MemberSession *session)
Adds a given member session to its member.
static void load_member_session_history(struct GNUNET_MESSENGER_MemberSession *session, const char *path)
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.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:92
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
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_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
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
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_public_key_from_string(const char *str, struct GNUNET_IDENTITY_PublicKey *key)
Parses a (Base32) string representation of the public key.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
An identity key as per LSD0001.
uint64_t abs_value_us
The actual value.

References GNUNET_TIME_Absolute::abs_value_us, add_member_session(), cfg, GNUNET_MESSENGER_MemberSession::closed, GNUNET_MESSENGER_MemberSession::completed, config_file, create_member_session(), GNUNET_asprintf(), GNUNET_assert, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_parse(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_IDENTITY_public_key_from_string(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_YES, key, load_list_messages(), load_member_session_history(), GNUNET_MESSENGER_MemberSession::messages, and GNUNET_MESSENGER_MemberSession::start.

Referenced by callback_scan_for_sessions().

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

◆ load_member_session_next()

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.

Necessary information will be loaded from a configuration file inside of a given directory.

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

Definition at line 599 of file gnunet-service-messenger_member_session.c.

601 {
602  GNUNET_assert ((session) && (directory));
603 
604  char *config_file;
605  GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg");
606 
608  goto free_config;
609 
610  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Load next session configuration of member: %s\n", config_file);
611 
613 
615  {
616  char *key_data;
617 
618  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "session", "next_key", &key_data))
619  goto destroy_config;
620 
621  struct GNUNET_IDENTITY_PublicKey next_key;
622 
623  enum GNUNET_GenericReturnValue key_return = GNUNET_IDENTITY_public_key_from_string(key_data, &next_key);
624 
625  GNUNET_free(key_data);
626 
627  if (GNUNET_OK != key_return)
628  goto destroy_config;
629 
631 
632  if (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "session", "next_id", &next_id, sizeof(next_id)))
633  goto destroy_config;
634 
635  struct GNUNET_MESSENGER_Member *member = get_store_member(session->member->store, &next_id);
636 
638  session, member? get_member_session (member, &next_key) : NULL
639  );
640 
641  if (session->next)
642  session->next->prev = session;
643  }
644 
645 destroy_config:
647 
648 free_config:
650 }
static char * next_id
Command-line option for namespace publishing: identifier for updates to this publication.
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.
static struct GNUNET_MESSENGER_MemberSession * get_cycle_safe_next_session(struct GNUNET_MESSENGER_MemberSession *session, struct GNUNET_MESSENGER_MemberSession *next)
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.
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.

References cfg, config_file, get_cycle_safe_next_session(), get_member_session(), get_store_member(), GNUNET_asprintf(), GNUNET_assert, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_data(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_parse(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_IDENTITY_public_key_from_string(), GNUNET_log, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_MemberSession::member, GNUNET_MESSENGER_MemberSession::next, next_id, GNUNET_MESSENGER_MemberSession::prev, and GNUNET_MESSENGER_Member::store.

Referenced by iterate_load_next_session().

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

◆ save_member_session()

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

Parameters
[in]sessionMember session
[in]directoryPath to a directory

Definition at line 694 of file gnunet-service-messenger_member_session.c.

696 {
697  GNUNET_assert ((session) && (directory));
698 
699  char *config_file;
700  GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg");
701 
702  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Save session configuration of member: %s\n", config_file);
703 
705 
707 
708  if (key_data)
709  {
710  GNUNET_CONFIGURATION_set_value_string (cfg, "session", "key", key_data);
711 
712  GNUNET_free(key_data);
713  }
714 
715  if (session->next)
716  {
717  const struct GNUNET_ShortHashCode *next_id = get_member_session_id(session->next);
718 
719  char *next_id_data = GNUNET_STRINGS_data_to_string_alloc (next_id, sizeof(*next_id));
720 
721  if (next_id_data)
722  {
723  GNUNET_CONFIGURATION_set_value_string (cfg, "session", "next_id", next_id_data);
724 
725  GNUNET_free(next_id_data);
726  }
727 
729 
730  if (key_data)
731  {
732  GNUNET_CONFIGURATION_set_value_string (cfg, "session", "next_key", key_data);
733 
734  GNUNET_free(key_data);
735  }
736  }
737 
738  GNUNET_CONFIGURATION_set_value_number(cfg, "session", "start", session->start.abs_value_us);
739 
740  GNUNET_CONFIGURATION_set_value_number (cfg, "session", "closed", session->closed);
741  GNUNET_CONFIGURATION_set_value_number (cfg, "session", "completed", session->completed);
742 
745 
747 
748  char *history_file;
749  GNUNET_asprintf (&history_file, "%s%s", directory, "history.map");
750 
751  save_member_session_history (session, history_file);
752  GNUNET_free(history_file);
753 
754  char *messages_file;
755  GNUNET_asprintf (&messages_file, "%s%s", directory, "messages.list");
756 
757  save_list_messages(&(session->messages), messages_file);
758  GNUNET_free(messages_file);
759 }
void save_list_messages(const struct GNUNET_MESSENGER_ListMessages *messages, const char *path)
Saves the list of message hashes to a file under a given path.
static void save_member_session_history(struct GNUNET_MESSENGER_MemberSession *session, const char *path)
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.
void GNUNET_CONFIGURATION_set_value_number(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long number)
Set a configuration value that should be a number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
char * GNUNET_IDENTITY_public_key_to_string(const struct GNUNET_IDENTITY_PublicKey *key)
Creates a (Base32) string representation of the public key.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:737

Referenced by iterate_save_session().

Here is the caller graph for this function: