GNUnet 0.22.2
gnunet-service-messenger_member_session.h File Reference
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_CRYPTO_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...
 
enum GNUNET_GenericReturnValue 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...
 
enum GNUNET_GenericReturnValue is_member_session_closed (const struct GNUNET_MESSENGER_MemberSession *session)
 Returns if the given member session has been closed. More...
 
enum GNUNET_GenericReturnValue 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_CRYPTO_PublicKeyget_member_session_public_key (const struct GNUNET_MESSENGER_MemberSession *session)
 Returns the public key 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...
 
enum GNUNET_GenericReturnValue 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...
 
enum GNUNET_GenericReturnValue check_member_session_history (const struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash, enum GNUNET_GenericReturnValue 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...
 

Function Documentation

◆ create_member_session()

struct GNUNET_MESSENGER_MemberSession * create_member_session ( struct GNUNET_MESSENGER_Member member,
const struct GNUNET_CRYPTO_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]memberMember
[in]pubkeyPublic key
Returns
New member session

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

36{
37 struct GNUNET_MESSENGER_MemberSession *session;
38
39 if ((! member) || (! pubkey) || (! (member->store)))
40 return NULL;
41
43 session->member = member;
44
45 GNUNET_memcpy (&(session->public_key), pubkey, sizeof(session->public_key));
46
48 get_member_session_key (session),
49 get_member_session_id (session),
50 &(session->context)
51 );
52
53 {
55
56 store = get_member_contact_store (member->store);
57
58 session->contact = get_store_contact (
59 store,
62 );
63 }
64
65 if (! (session->contact))
66 {
67 GNUNET_free (session);
68 return NULL;
69 }
70
72
74
75 init_list_messages (&(session->messages));
76
77 session->prev = NULL;
78 session->next = NULL;
79
80 session->start = GNUNET_TIME_absolute_get ();
81
82 session->closed = GNUNET_NO;
83 session->completed = GNUNET_NO;
84
85 return session;
86}
static struct GNUNET_CRYPTO_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_CRYPTO_PublicKey * get_member_session_public_key(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the public key of a given member session.
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_key(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the key of the room a given member session belongs to.
const struct GNUNET_HashCode * get_member_session_context(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the member context 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.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_NO
#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:111
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_CRYPTO_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]sessionOld member session
[in]messageMessage
[in]hashHash of message
Returns
New member session

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

236{
237 struct GNUNET_MESSENGER_MemberStore *store;
239
240 if ((! session) || (! message) || (! hash))
241 return NULL;
242
245
246 store = get_session_member_store (session);
248
249 if (GNUNET_MESSENGER_KIND_ID == message->header.kind)
250 {
251 next->member = add_store_member (store,
252 &(message->body.id.id));
253 if (! next->member)
254 {
256 "Failed to switch member session to ID: %s\n",
257 GNUNET_sh2s (&(message->body.id.id)));
258
260 return NULL;
261 }
262 }
263 else
264 next->member = session->member;
265
266 if (GNUNET_MESSENGER_KIND_KEY == message->header.kind)
267 GNUNET_memcpy (&(next->public_key), &(message->body.key.key),
268 sizeof(next->public_key));
269 else
271 sizeof(next->public_key));
272
276 &(next->context)
277 );
278
285 );
286
288
289 if (! (next->contact))
290 {
292 return NULL;
293 }
294
296
299 );
300
302 next);
303
305 copy_list_messages (&(next->messages), &(session->messages));
306
307 session->next = next;
308 next->prev = session;
309 next->next = NULL;
310
312
313 session->closed = GNUNET_YES;
316
318
319 return next;
320}
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 struct GNUNET_MESSENGER_MemberStore * get_session_member_store(const struct GNUNET_MESSENGER_MemberSession *session)
static void check_member_session_completion(struct GNUNET_MESSENGER_MemberSession *session)
static enum GNUNET_GenericReturnValue iterate_copy_history(void *cls, const struct GNUNET_HashCode *key, void *value)
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.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
#define GNUNET_log(kind,...)
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_ERROR
@ 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_CRYPTO_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_CRYPTO_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(), get_session_member_store(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CONTAINER_multihashmap_size(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_memcpy, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_KEY, GNUNET_new, GNUNET_NO, GNUNET_sh2s(), 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, and update_store_contact().

Referenced by handle_member_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]sessionMember session

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

325{
326 struct GNUNET_MESSENGER_MemberStore *store;
327 struct GNUNET_MESSENGER_Contact *contact;
328
329 GNUNET_assert (session);
330
332
333 clear_list_messages (&(session->messages));
334
335 store = get_session_member_store (session);
336 contact = get_member_session_contact (session);
337
338 if ((contact) && (GNUNET_YES == decrease_contact_rc (contact)))
341 contact,
343 );
344
345 GNUNET_free (session);
346}
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.
enum GNUNET_GenericReturnValue 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(), get_session_member_store(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_free, GNUNET_YES, GNUNET_MESSENGER_MemberSession::history, GNUNET_MESSENGER_MemberSession::messages, and remove_store_contact().

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

enum GNUNET_GenericReturnValue 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]sessionMember session
[in]hashHash of initial message (JOIN message!)
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

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

352{
353 struct GNUNET_MESSENGER_Contact *contact;
354
355 GNUNET_assert ((session) && (hash));
356
357 {
358 struct GNUNET_MESSENGER_MemberStore *member_store;
359 struct GNUNET_MESSENGER_ContactStore *store;
360
361 member_store = get_session_member_store (session);
362 store = get_member_contact_store (member_store);
363 contact = get_store_contact (
364 store,
367 );
368 }
369
370 if (! contact)
371 return GNUNET_SYSERR;
372
373 if (contact == session->contact)
374 goto clear_messages;
375
376 session->contact = contact;
377 increase_contact_rc (session->contact);
378
379clear_messages:
380 clear_list_messages (&(session->messages));
381 add_to_list_messages (&(session->messages), hash);
382
383 session->next = NULL;
384 session->closed = GNUNET_NO;
385 session->completed = GNUNET_NO;
386
387 return GNUNET_OK;
388}
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
@ GNUNET_SYSERR

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_session_member_store(), get_store_contact(), GNUNET_assert, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, increase_contact_rc(), GNUNET_MESSENGER_MemberSession::messages, and GNUNET_MESSENGER_MemberSession::next.

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]sessionMember session

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

393{
394 GNUNET_assert (session);
395
396 session->closed = GNUNET_YES;
398}

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

enum GNUNET_GenericReturnValue 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 402 of file gnunet-service-messenger_member_session.c.

403{
404 GNUNET_assert (session);
405
406 return session->closed;
407}

References GNUNET_MESSENGER_MemberSession::closed, and GNUNET_assert.

◆ is_member_session_completed()

enum GNUNET_GenericReturnValue 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 411 of file gnunet-service-messenger_member_session.c.

413{
414 GNUNET_assert (session);
415
416 return session->completed;
417}

References GNUNET_MESSENGER_MemberSession::completed, and GNUNET_assert.

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 421 of file gnunet-service-messenger_member_session.c.

422{
423 GNUNET_assert (session);
424
425 if (session->prev)
426 return get_member_session_start (session->prev);
427
428 return session->start;
429}
struct GNUNET_TIME_Absolute get_member_session_start(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the timestamp of the member session's start.

References get_member_session_start(), and GNUNET_assert.

Referenced by get_member_session_start(), and solve_srv_room_member_collisions().

Here is the call graph for this function:
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 433 of file gnunet-service-messenger_member_session.c.

434{
435 const struct GNUNET_MESSENGER_MemberStore *store;
436
437 GNUNET_assert ((session) && (session->member));
438
439 store = get_session_member_store (session);
440
441 return get_member_store_key (store);
442}
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(), get_session_member_store(), GNUNET_assert, and GNUNET_MESSENGER_MemberSession::member.

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 446 of file gnunet-service-messenger_member_session.c.

447{
448 GNUNET_assert (session);
449
450 return get_member_id (session->member);
451}
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 check_member_session_completion(), create_member_session(), delete_srv_room_message(), find_member_session_in_room(), iterate_notify_about_members(), notify_about_members(), remove_room_member_session(), request_room_message_step(), save_member_session(), send_message_join(), 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_CRYPTO_PublicKey * get_member_session_public_key ( const struct GNUNET_MESSENGER_MemberSession session)

Returns the public key of a given member session.

Parameters
[in]sessionMember session
Returns
Public key

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

457{
458 GNUNET_assert (session);
459
460 return &(session->public_key);
461}

References GNUNET_assert, and GNUNET_MESSENGER_MemberSession::public_key.

Referenced by add_member_session(), create_member_session(), handle_message_id(), iterate_member_sessions_it(), notify_srv_handle_message(), remove_member_session(), remove_room_member_session(), reset_member_session(), save_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 465 of file gnunet-service-messenger_member_session.c.

467{
468 GNUNET_assert (session);
469
470 return &(session->context);
471}

References GNUNET_MESSENGER_MemberSession::context, and GNUNET_assert.

Referenced by check_member_session_completion(), create_member_session(), destroy_member_session(), get_next_member_session_context(), 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 475 of file gnunet-service-messenger_member_session.c.

476{
477 GNUNET_assert (session);
478
479 return session->contact;
480}

References GNUNET_MESSENGER_MemberSession::contact, and GNUNET_assert.

Referenced by destroy_member_session(), and switch_member_session().

Here is the caller graph for this function:

◆ verify_member_session_as_sender()

enum GNUNET_GenericReturnValue 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 484 of file gnunet-service-messenger_member_session.c.

488{
489 GNUNET_assert ((session) && (message) && (hash));
490
492 {
493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Check message (%s) using history!\n",
494 GNUNET_h2s (hash));
495
496 if (GNUNET_YES == check_member_session_history (session, hash, GNUNET_YES))
497 return GNUNET_OK;
498 else
499 return GNUNET_SYSERR;
500 }
501
502 if (0 != GNUNET_memcmp (get_member_session_id (session),
503 &(message->header.sender_id)))
504 return GNUNET_SYSERR;
505
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Check message (%s) using key: %s\n",
507 GNUNET_h2s (hash),
510
511 return verify_message (message, hash, get_member_session_public_key (
512 session));
513}
enum GNUNET_GenericReturnValue check_member_session_history(const struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash, enum GNUNET_GenericReturnValue ownership)
Checks the history of a session for a specific message which is identified by its hash and if the own...
enum GNUNET_GenericReturnValue is_member_session_completed(const struct GNUNET_MESSENGER_MemberSession *session)
Returns if the given member session has been completed.
char * GNUNET_CRYPTO_public_key_to_string(const struct GNUNET_CRYPTO_PublicKey *key)
Creates a (Base32) string representation of the public key.
Definition: crypto_pkey.c:379
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
enum GNUNET_GenericReturnValue verify_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_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 check_member_session_history(), get_member_session_id(), get_member_session_public_key(), GNUNET_assert, GNUNET_CRYPTO_public_key_to_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcmp, GNUNET_OK, 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()

enum GNUNET_GenericReturnValue check_member_session_history ( const struct GNUNET_MESSENGER_MemberSession session,
const struct GNUNET_HashCode hash,
enum GNUNET_GenericReturnValue  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 517 of file gnunet-service-messenger_member_session.c.

521{
522 GNUNET_assert ((session) && (hash));
523
524 if (GNUNET_YES == ownership)
525 return (NULL != GNUNET_CONTAINER_multihashmap_get (session->history, hash)?
527 else
528 return GNUNET_CONTAINER_multihashmap_contains (session->history, hash);
529}
enum GNUNET_GenericReturnValue 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_srv_room_message(), notify_about_members(), recv_message_request(), request_room_message_step(), and verify_member_session_as_sender().

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]sessionMember session
[in]messageMessage
[in]hashHash of message

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

552{
553 GNUNET_assert ((session) && (message) && (hash));
554
556 return;
557
559 "Updating sessions history (%s) += (%s)\n",
560 GNUNET_sh2s (get_member_session_id (session)), GNUNET_h2s (hash));
561
562 if (GNUNET_OK == verify_member_session_as_sender (session, message, hash))
563 {
564 if (GNUNET_YES == is_message_session_bound (message))
565 add_to_list_messages (&(session->messages), hash);
566
568 }
569 else
570 update_member_chain_history (session, hash, GNUNET_NO);
571
572 if (GNUNET_YES == session->closed)
574}
static void update_member_chain_history(struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash, enum GNUNET_GenericReturnValue ownership)
enum GNUNET_GenericReturnValue 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.
enum GNUNET_GenericReturnValue 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]sessionMember session
[in]hashHash of message

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

592{
593 GNUNET_assert ((session) && (hash));
594
595 clear_member_chain_history (session, hash);
596}
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 655 of file gnunet-service-messenger_member_session.c.

657{
658 char *config_file;
659 struct GNUNET_MESSENGER_MemberSession *session;
661
662 GNUNET_assert ((member) && (directory));
663
664 GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg");
665
666 session = NULL;
667
669 goto free_config;
670
672 "Load session configuration of member: %s\n", config_file);
673
675
676 if (! cfg)
677 goto free_config;
678
680 {
682 enum GNUNET_GenericReturnValue key_result;
683 unsigned long long numeric_value;
684 char *key_data;
685
687 "key", &key_data))
688 goto destroy_config;
689
690 key_result = GNUNET_CRYPTO_public_key_from_string (key_data, &key);
691 GNUNET_free (key_data);
692
693 if (GNUNET_OK != key_result)
694 goto destroy_config;
695
696 session = create_member_session (member, &key);
697
699 "start",
700 &numeric_value))
701 session->start.abs_value_us = numeric_value;
702
704 "closed",
705 &numeric_value))
706 session->closed = (GNUNET_YES == numeric_value? GNUNET_YES : GNUNET_NO);
707
709 "completed",
710 &numeric_value))
711 session->completed = (GNUNET_YES == numeric_value? GNUNET_YES :
712 GNUNET_NO);
713 }
714
715destroy_config:
717
718free_config:
720
721 if (! session)
722 return;
723
724 {
725 char *history_file;
726 GNUNET_asprintf (&history_file, "%s%s", directory, "history.map");
727
728 load_member_session_history (session, history_file);
729 GNUNET_free (history_file);
730 }
731
732 {
733 char *messages_file;
734 GNUNET_asprintf (&messages_file, "%s%s", directory, "messages.list");
735
736 load_list_messages (&(session->messages), messages_file);
737 GNUNET_free (messages_file);
738 }
739
740 add_member_session (member, session);
741}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static char * config_file
Set to the name of the config file used.
Definition: gnunet-arm.c:83
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_CRYPTO_PublicKey *pubkey)
Creates and allocates a new member session of a member with a given public key.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
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.
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:506
GNUNET_GenericReturnValue
Named constants for return values.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_public_key_from_string(const char *str, struct GNUNET_CRYPTO_PublicKey *key)
Parses a (Base32) string representation of the public key.
Definition: crypto_pkey.c:399
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
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_CRYPTO_public_key_from_string(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_OS_project_data_gnunet(), 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]sessionMember session
[in]directoryPath to a directory

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

769{
771 char *config_file;
772
773
774 GNUNET_assert ((session) && (directory));
775
776 GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg");
777
779 goto free_config;
780
782 "Load next session configuration of member: %s\n", config_file);
783
785
786 if (! cfg)
787 goto free_config;
788
790 {
791 struct GNUNET_CRYPTO_PublicKey next_key;
792 enum GNUNET_GenericReturnValue key_result;
794 char *key_data;
795
797 "next_key",
798 &key_data))
799 goto destroy_config;
800
801 key_result = GNUNET_CRYPTO_public_key_from_string (key_data, &next_key);
802 GNUNET_free (key_data);
803
804 if (GNUNET_OK != key_result)
805 goto destroy_config;
806
807 if (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "session", "next_id",
808 &next_id, sizeof(next_id)))
809 goto destroy_config;
810
811 {
812 struct GNUNET_MESSENGER_MemberStore *store;
813 struct GNUNET_MESSENGER_Member *member;
814
816 member = get_store_member (store, &next_id);
817
819 session, member? get_member_session (member, &next_key) : NULL
820 );
821 }
822
823 if (session->next)
824 session->next->prev = session;
825 }
826
827destroy_config:
829
830free_config:
832}
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_CRYPTO_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_session_member_store(), 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_CRYPTO_public_key_from_string(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_YES, 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 890 of file gnunet-service-messenger_member_session.c.

892{
894 char *config_file;
895 char *key_data;
896
897 GNUNET_assert ((session) && (directory));
898
899 GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg");
900
902 "Save session configuration of member: %s\n", config_file);
903
905
906 if (! cfg)
907 goto free_config;
908
911
912 if (key_data)
913 {
914 GNUNET_CONFIGURATION_set_value_string (cfg, "session", "key", key_data);
915 GNUNET_free (key_data);
916 }
917
918 if (session->next)
919 {
921 session->next);
922
923 char *next_id_data = GNUNET_STRINGS_data_to_string_alloc (next_id,
924 sizeof(*next_id));
925
926 if (next_id_data)
927 {
928 GNUNET_CONFIGURATION_set_value_string (cfg, "session", "next_id",
929 next_id_data);
930 GNUNET_free (next_id_data);
931 }
932
935
936 if (key_data)
937 {
938 GNUNET_CONFIGURATION_set_value_string (cfg, "session", "next_key",
939 key_data);
940 GNUNET_free (key_data);
941 }
942 }
943
944 GNUNET_CONFIGURATION_set_value_number (cfg, "session", "start",
945 session->start.abs_value_us);
946
947 GNUNET_CONFIGURATION_set_value_number (cfg, "session", "closed",
948 session->closed);
949 GNUNET_CONFIGURATION_set_value_number (cfg, "session", "completed",
950 session->completed);
951
954
955free_config:
957
958 {
959 char *history_file;
960 GNUNET_asprintf (&history_file, "%s%s", directory, "history.map");
961
962 save_member_session_history (session, history_file);
963 GNUNET_free (history_file);
964 }
965
966 {
967 char *messages_file;
968 GNUNET_asprintf (&messages_file, "%s%s", directory, "messages.list");
969
970 save_list_messages (&(session->messages), messages_file);
971 GNUNET_free (messages_file);
972 }
973}
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_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:787

References GNUNET_TIME_Absolute::abs_value_us, cfg, GNUNET_MESSENGER_MemberSession::closed, GNUNET_MESSENGER_MemberSession::completed, config_file, get_member_session_id(), get_member_session_public_key(), GNUNET_asprintf(), GNUNET_assert, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_set_value_number(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_CONFIGURATION_write(), GNUNET_CRYPTO_public_key_to_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_OS_project_data_gnunet(), GNUNET_STRINGS_data_to_string_alloc(), GNUNET_MESSENGER_MemberSession::messages, GNUNET_MESSENGER_MemberSession::next, next_id, save_list_messages(), save_member_session_history(), and GNUNET_MESSENGER_MemberSession::start.

Referenced by iterate_save_session().

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