GNUnet 0.21.2
gnunet-service-messenger_member_session.c File Reference
Include dependency graph for gnunet-service-messenger_member_session.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_MemberSessionHistoryEntry
 

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...
 
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_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...
 
static void update_member_chain_history (struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash, enum GNUNET_GenericReturnValue ownership)
 
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...
 
static void clear_member_chain_history (struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash)
 
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...
 
static void load_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, const char *path)
 
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...
 
static struct GNUNET_MESSENGER_MemberSessionget_cycle_safe_next_session (struct GNUNET_MESSENGER_MemberSession *session, struct GNUNET_MESSENGER_MemberSession *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. More...
 
static enum GNUNET_GenericReturnValue iterate_save_member_session_history_hentries (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static void save_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, const char *path)
 
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 if ((! member) || (! pubkey) || (! (member->store)))
38 return NULL;
39
40 struct GNUNET_MESSENGER_MemberSession *session = GNUNET_new (struct
42 session->member = member;
43
44 GNUNET_memcpy (&(session->public_key), pubkey, sizeof(session->public_key));
45
47 get_member_session_key (session),
48 get_member_session_id (session),
49 &(session->context)
50 );
51
53 session->member->store);
54
55 session->contact = get_store_contact (
56 store,
59 );
60
61 if (! (session->contact))
62 {
63 GNUNET_free (session);
64 return NULL;
65 }
66
68
70
71 init_list_messages (&(session->messages));
72
73 session->prev = NULL;
74 session->next = NULL;
75
76 session->start = GNUNET_TIME_absolute_get ();
77
78 session->closed = GNUNET_NO;
79 session->completed = GNUNET_NO;
80
81 return session;
82}
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:

◆ check_member_session_completion()

static void check_member_session_completion ( struct GNUNET_MESSENGER_MemberSession session)
static

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

87{
88 GNUNET_assert (session);
89
91 "Check session history (%s) for completion.\n",
93
94 if (! session->messages.tail)
95 {
96 session->completed = GNUNET_YES;
97 goto completion;
98 }
99
100 const struct GNUNET_HashCode *start = &(session->messages.head->hash);
101 const struct GNUNET_HashCode *end = &(session->messages.tail->hash);
102
104 init_list_messages (&level);
105
106 add_to_list_messages (&level, end);
107
109 session->member->store->room);
110
113
114 while (level.head)
115 {
116 struct GNUNET_MESSENGER_ListMessage *element;
117
118 for (element = level.head; element; element = element->next)
119 {
121 store, &(element->hash), GNUNET_NO
122 );
123
124 if (! link)
125 continue;
126
127 add_to_list_messages (&list, &(link->first));
128
129 if (GNUNET_YES == link->multiple)
130 add_to_list_messages (&list, &(link->second));
131 }
132
133 clear_list_messages (&level);
134
135 for (element = list.head; element; element = element->next)
136 if (GNUNET_YES == check_member_session_history (session, &(element->hash),
137 GNUNET_YES))
138 break;
139
140 if (element)
141 if (0 != GNUNET_CRYPTO_hash_cmp (&(element->hash), start))
142 add_to_list_messages (&level, &(element->hash));
143 else
144 session->completed = GNUNET_YES;
145 else
146 copy_list_messages (&level, &list);
147
149 }
150
151completion:
153 {
154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Completed session history (%s)\n",
156
158 session->member->store);
159
160 if ((session->contact) && (GNUNET_YES == decrease_contact_rc (
161 session->contact)))
163 store,
164 session->contact,
166 );
167
168 session->contact = NULL;
169 }
170}
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
static int list
Set if we should print a list of currently running services.
Definition: gnunet-arm.c:69
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
void clear_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Clears the list of message hashes.
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.
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.
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.
const struct GNUNET_MESSENGER_MessageLink * get_store_message_link(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, enum GNUNET_GenericReturnValue deleted_only)
Returns the message link from a message store matching a given hash.
struct GNUNET_MESSENGER_MessageStore * get_srv_room_message_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used message store of a given room.
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
Definition: crypto_hash.c:221
#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_DEBUG
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.
A 512-bit hashcode.
struct GNUNET_MESSENGER_ListMessage * next
struct GNUNET_MESSENGER_ListMessage * head
struct GNUNET_MESSENGER_ListMessage * tail

References add_to_list_messages(), check_member_session_history(), clear_list_messages(), GNUNET_MESSENGER_MemberSession::completed, GNUNET_MESSENGER_MemberSession::contact, copy_list_messages(), decrease_contact_rc(), end, GNUNET_MESSENGER_MessageLink::first, get_member_contact_store(), get_member_session_context(), get_member_session_id(), get_srv_room_message_store(), get_store_message_link(), GNUNET_assert, GNUNET_CRYPTO_hash_cmp(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_sh2s(), GNUNET_YES, GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, init_list_messages(), is_member_session_completed(), list, GNUNET_MESSENGER_MemberSession::member, GNUNET_MESSENGER_MemberSession::messages, GNUNET_MESSENGER_MessageLink::multiple, GNUNET_MESSENGER_ListMessage::next, remove_store_contact(), GNUNET_MESSENGER_MemberStore::room, GNUNET_MESSENGER_MessageLink::second, start, GNUNET_MESSENGER_Member::store, and GNUNET_MESSENGER_ListMessages::tail.

Referenced by close_member_session(), switch_member_session(), and update_member_session_history().

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

◆ iterate_copy_history()

static enum GNUNET_GenericReturnValue iterate_copy_history ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

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

177{
179
182
183 return GNUNET_YES;
184}
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...

References GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_YES, GNUNET_MESSENGER_MemberSession::history, key, GNUNET_MESSENGER_MemberSession::next, and value.

Referenced by switch_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 188 of file gnunet-service-messenger_member_session.c.

191{
192 if ((! session) || (! message) || (! hash))
193 return NULL;
194
197
200
201 if (GNUNET_MESSENGER_KIND_ID == message->header.kind)
203 &(message->body.id.id));
204 else
205 next->member = session->member;
206
207 if (GNUNET_MESSENGER_KIND_KEY == message->header.kind)
208 GNUNET_memcpy (&(next->public_key), &(message->body.key.key),
209 sizeof(next->public_key));
210 else
212 sizeof(next->public_key));
213
217 &(next->context)
218 );
219
226 );
227
229
230 if (! (next->contact))
231 {
233 return NULL;
234 }
235
237
240 );
241
243 next);
244
246 copy_list_messages (&(next->messages), &(session->messages));
247
248 session->next = next;
249 next->prev = session;
250 next->next = NULL;
251
253
254 session->closed = GNUNET_YES;
257
259
260 return next;
261}
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.
@ 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(), 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_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 265 of file gnunet-service-messenger_member_session.c.

266{
267 GNUNET_assert (session);
268
270
271 clear_list_messages (&(session->messages));
272
274 session);
275
276 if ((contact) && (GNUNET_YES == decrease_contact_rc (contact)))
279 contact,
281 );
282
283 GNUNET_free (session);
284}
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.

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

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

290{
291 GNUNET_assert ((session) && (hash));
292
294 session->member->store);
296 store,
299 );
300
301 if (! contact)
302 return GNUNET_SYSERR;
303
304 if (contact == session->contact)
305 goto clear_messages;
306
307 session->contact = contact;
308 increase_contact_rc (session->contact);
309
310clear_messages:
311 clear_list_messages (&(session->messages));
312 add_to_list_messages (&(session->messages), hash);
313
314 session->next = NULL;
315 session->closed = GNUNET_NO;
316 session->completed = GNUNET_NO;
317
318 return GNUNET_OK;
319}
@ 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_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]sessionMember session

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

324{
325 GNUNET_assert (session);
326
327 session->closed = GNUNET_YES;
329}

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

334{
335 GNUNET_assert (session);
336
337 return session->closed;
338}

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

344{
345 GNUNET_assert (session);
346
347 return session->completed;
348}

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

353{
354 GNUNET_assert (session);
355
356 if (session->prev)
357 return get_member_session_start (session->prev);
358
359 return session->start;
360}
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 364 of file gnunet-service-messenger_member_session.c.

365{
366 GNUNET_assert ((session) && (session->member));
367
368 return get_member_store_key (session->member->store);
369}
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 373 of file gnunet-service-messenger_member_session.c.

374{
375 GNUNET_assert (session);
376
377 return get_member_id (session->member);
378}
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 382 of file gnunet-service-messenger_member_session.c.

384{
385 GNUNET_assert (session);
386
387 return &(session->public_key);
388}

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

394{
395 GNUNET_assert (session);
396
397 return &(session->context);
398}

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

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

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

415{
416 GNUNET_assert ((session) && (message) && (hash));
417
419 {
420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Check message (%s) using history!\n",
421 GNUNET_h2s (hash));
422
423 if (GNUNET_YES == check_member_session_history (session, hash, GNUNET_YES))
424 return GNUNET_OK;
425 else
426 return GNUNET_SYSERR;
427 }
428
429 if (0 != GNUNET_memcmp (get_member_session_id (session),
430 &(message->header.sender_id)))
431 return GNUNET_SYSERR;
432
433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Check message (%s) using key: %s\n",
434 GNUNET_h2s (hash),
437
438 return verify_message (message, hash, get_member_session_public_key (
439 session));
440}
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:568
#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).
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 444 of file gnunet-service-messenger_member_session.c.

448{
449 GNUNET_assert ((session) && (hash));
450
451 if (GNUNET_YES == ownership)
452 return (NULL != GNUNET_CONTAINER_multihashmap_get (session->history, hash)?
454 else
455 return GNUNET_CONTAINER_multihashmap_contains (session->history, hash);
456}
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_chain_history()

static void update_member_chain_history ( struct GNUNET_MESSENGER_MemberSession session,
const struct GNUNET_HashCode hash,
enum GNUNET_GenericReturnValue  ownership 
)
static

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

463{
464 GNUNET_assert ((session) && (hash));
465
467 (GNUNET_YES == ownership?
468 session : NULL),
470 && (session->next))
471 update_member_chain_history (session->next, hash, ownership);
472}
static void update_member_chain_history(struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash, enum GNUNET_GenericReturnValue ownership)

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_MemberSession::history, GNUNET_MESSENGER_MemberSession::next, and update_member_chain_history().

Referenced by update_member_chain_history(), and update_member_session_history().

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

479{
480 GNUNET_assert ((session) && (message) && (hash));
481
483 return;
484
486 "Updating sessions history (%s) += (%s)\n",
487 GNUNET_sh2s (get_member_session_id (session)), GNUNET_h2s (hash));
488
489 if (GNUNET_OK == verify_member_session_as_sender (session, message, hash))
490 {
491 if (GNUNET_YES == is_message_session_bound (message))
492 add_to_list_messages (&(session->messages), hash);
493
495 }
496 else
497 update_member_chain_history (session, hash, GNUNET_NO);
498
499 if (GNUNET_YES == session->closed)
501}
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_chain_history()

static void clear_member_chain_history ( struct GNUNET_MESSENGER_MemberSession session,
const struct GNUNET_HashCode hash 
)
static

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

507{
508 GNUNET_assert ((session) && (hash));
509
510 if ((0 < GNUNET_CONTAINER_multihashmap_remove_all (session->history, hash)) &&
511 (session->next))
512 clear_member_session_history (session->next, hash);
513}
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.
int GNUNET_CONTAINER_multihashmap_remove_all(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Remove all entries for the given key from the map.

References clear_member_session_history(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_remove_all(), GNUNET_MESSENGER_MemberSession::history, and GNUNET_MESSENGER_MemberSession::next.

Referenced by clear_member_session_history().

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

519{
520 GNUNET_assert ((session) && (hash));
521
522 clear_member_chain_history (session, hash);
523}
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_history()

static void load_member_session_history ( struct GNUNET_MESSENGER_MemberSession session,
const char *  path 
)
static

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

535{
536 GNUNET_assert ((session) && (path));
537
538 if (GNUNET_YES != GNUNET_DISK_file_test (path))
539 return;
540
543 );
544
546 path, GNUNET_DISK_OPEN_READ, permission
547 );
548
549 if (! handle)
550 return;
551
553
555 ssize_t len;
556
558
559 do {
560 len = GNUNET_DISK_file_read (handle, &(entry.hash), sizeof(entry.hash));
561
562 if (len != sizeof(entry.hash))
563 break;
564
565 len = GNUNET_DISK_file_read (handle, &(entry.ownership),
566 sizeof(entry.ownership));
567
568 if (len != sizeof(entry.ownership))
569 break;
570
571 status = GNUNET_CONTAINER_multihashmap_put (session->history, &(entry.hash),
572 (entry.ownership? session :
573 NULL),
575 } while (status == GNUNET_OK);
576
578}
static int status
The program status; 0 for success.
Definition: gnunet-nse.c:39
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1237
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
off_t GNUNET_DISK_file_seek(const struct GNUNET_DISK_FileHandle *h, off_t offset, enum GNUNET_DISK_Seek whence)
Move the read/write pointer in a file.
Definition: disk.c:205
GNUNET_DISK_AccessPermissions
File access permissions, UNIX-style.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:622
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
@ GNUNET_DISK_SEEK_SET
Seek an absolute position (from the start of the file).
GNUNET_GenericReturnValue
Named constants for return values.
Handle used to access files (and pipes).

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_file_seek(), GNUNET_DISK_file_test(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_DISK_SEEK_SET, GNUNET_OK, GNUNET_YES, handle, GNUNET_MESSENGER_MemberSessionHistoryEntry::hash, GNUNET_MESSENGER_MemberSession::history, GNUNET_MESSENGER_MemberSessionHistoryEntry::ownership, and status.

Referenced by load_member_session().

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

584{
585 GNUNET_assert ((member) && (directory));
586
587 char *config_file;
588 GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg");
589
590 struct GNUNET_MESSENGER_MemberSession *session = NULL;
591
593 goto free_config;
594
596 "Load session configuration of member: %s\n", config_file);
597
599
601 {
602 char *key_data;
603
605 "key", &key_data))
606 goto destroy_config;
607
609
610 enum GNUNET_GenericReturnValue key_return =
612
613 GNUNET_free (key_data);
614
615 if (GNUNET_OK != key_return)
616 goto destroy_config;
617
618 session = create_member_session (member, &key);
619
620 unsigned long long numeric_value;
621
623 "start",
624 &numeric_value))
625 session->start.abs_value_us = numeric_value;
626
628 "closed",
629 &numeric_value))
630 session->closed = (GNUNET_YES == numeric_value? GNUNET_YES : GNUNET_NO);
631
633 "completed",
634 &numeric_value))
635 session->completed = (GNUNET_YES == numeric_value? GNUNET_YES :
636 GNUNET_NO);
637 }
638
639destroy_config:
641
642free_config:
644
645 if (! session)
646 return;
647
648 char *history_file;
649 GNUNET_asprintf (&history_file, "%s%s", directory, "history.map");
650
651 load_member_session_history (session, history_file);
652 GNUNET_free (history_file);
653
654 char *messages_file;
655 GNUNET_asprintf (&messages_file, "%s%s", directory, "messages.list");
656
657 load_list_messages (&(session->messages), messages_file);
658 GNUNET_free (messages_file);
659
660 add_member_session (member, session);
661}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static char * config_file
Set to the name of the config file used.
Definition: gnunet-arm.c:84
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.
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.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Parse a configuration file, add all of the options in the file to the configuration environment.
enum GNUNET_GenericReturnValue GNUNET_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:588
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_CRYPTO_public_key_from_string(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, 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:

◆ get_cycle_safe_next_session()

static struct GNUNET_MESSENGER_MemberSession * get_cycle_safe_next_session ( struct GNUNET_MESSENGER_MemberSession session,
struct GNUNET_MESSENGER_MemberSession next 
)
static

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

667{
668 if (! next)
669 return NULL;
670
671 struct GNUNET_MESSENGER_MemberSession *check = next;
672
673 do {
674 if (check == session)
675 return NULL;
676
677 check = check->next;
678 } while (check);
679
680 return next;
681}

References GNUNET_MESSENGER_MemberSession::next.

Referenced by load_member_session_next().

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

687{
688 GNUNET_assert ((session) && (directory));
689
690 char *config_file;
691 GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg");
692
694 goto free_config;
695
697 "Load next session configuration of member: %s\n", config_file);
698
700
702 {
703 char *key_data;
704
706 "next_key",
707 &key_data))
708 goto destroy_config;
709
710 struct GNUNET_CRYPTO_PublicKey next_key;
711
712 enum GNUNET_GenericReturnValue key_return =
713 GNUNET_CRYPTO_public_key_from_string (key_data, &next_key);
714
715 GNUNET_free (key_data);
716
717 if (GNUNET_OK != key_return)
718 goto destroy_config;
719
721
722 if (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "session", "next_id",
723 &next_id, sizeof(next_id)))
724 goto destroy_config;
725
727 session->member->store, &next_id);
728
730 session, member? get_member_session (member, &next_key) : NULL
731 );
732
733 if (session->next)
734 session->next->prev = session;
735 }
736
737destroy_config:
739
740free_config:
742}
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_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_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:

◆ iterate_save_member_session_history_hentries()

static enum GNUNET_GenericReturnValue iterate_save_member_session_history_hentries ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

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

749{
750 struct GNUNET_DISK_FileHandle *handle = cls;
751 unsigned char ownership = value? GNUNET_YES : GNUNET_NO;
752
754 GNUNET_DISK_file_write (handle, &ownership, sizeof(ownership));
755
756 return GNUNET_YES;
757}
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:686

References GNUNET_DISK_file_write(), GNUNET_NO, GNUNET_YES, handle, key, and value.

Referenced by save_member_session_history().

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

◆ save_member_session_history()

static void save_member_session_history ( struct GNUNET_MESSENGER_MemberSession session,
const char *  path 
)
static

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

763{
764 GNUNET_assert ((session) && (path));
765
768 );
769
772 );
773
774 if (! handle)
775 return;
776
778
780 session->history,
782 handle
783 );
784
787}
static enum GNUNET_GenericReturnValue iterate_save_member_session_history_hentries(void *cls, const struct GNUNET_HashCode *key, void *value)
enum GNUNET_GenericReturnValue GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h)
Write file changes to disk.
Definition: disk.c:1427
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_seek(), GNUNET_DISK_file_sync(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_DISK_SEEK_SET, handle, GNUNET_MESSENGER_MemberSession::history, and iterate_save_member_session_history_hentries().

Referenced by save_member_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 791 of file gnunet-service-messenger_member_session.c.

793{
794 GNUNET_assert ((session) && (directory));
795
796 char *config_file;
797 GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg");
798
800 "Save session configuration of member: %s\n", config_file);
801
803
804 char *key_data = GNUNET_CRYPTO_public_key_to_string (
806
807 if (key_data)
808 {
809 GNUNET_CONFIGURATION_set_value_string (cfg, "session", "key", key_data);
810
811 GNUNET_free (key_data);
812 }
813
814 if (session->next)
815 {
817 session->next);
818
819 char *next_id_data = GNUNET_STRINGS_data_to_string_alloc (next_id,
820 sizeof(*next_id));
821
822 if (next_id_data)
823 {
824 GNUNET_CONFIGURATION_set_value_string (cfg, "session", "next_id",
825 next_id_data);
826
827 GNUNET_free (next_id_data);
828 }
829
832
833 if (key_data)
834 {
835 GNUNET_CONFIGURATION_set_value_string (cfg, "session", "next_key",
836 key_data);
837
838 GNUNET_free (key_data);
839 }
840 }
841
842 GNUNET_CONFIGURATION_set_value_number (cfg, "session", "start",
843 session->start.abs_value_us);
844
845 GNUNET_CONFIGURATION_set_value_number (cfg, "session", "closed",
846 session->closed);
847 GNUNET_CONFIGURATION_set_value_number (cfg, "session", "completed",
848 session->completed);
849
852
854
855 char *history_file;
856 GNUNET_asprintf (&history_file, "%s%s", directory, "history.map");
857
858 save_member_session_history (session, history_file);
859 GNUNET_free (history_file);
860
861 char *messages_file;
862 GNUNET_asprintf (&messages_file, "%s%s", directory, "messages.list");
863
864 save_list_messages (&(session->messages), messages_file);
865 GNUNET_free (messages_file);
866}
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:764

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_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: