GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
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.
 
static struct GNUNET_MESSENGER_MemberStoreget_session_member_store (const struct GNUNET_MESSENGER_MemberSession *session)
 
static struct GNUNET_MESSENGER_SrvRoomget_session_room (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_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.
 
void destroy_member_session (struct GNUNET_MESSENGER_MemberSession *session)
 Destroys a member session and frees its memory fully.
 
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.
 
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.
 
enum GNUNET_GenericReturnValue is_member_session_closed (const struct GNUNET_MESSENGER_MemberSession *session)
 Returns if the given member session has been closed.
 
enum GNUNET_GenericReturnValue is_member_session_completed (const struct GNUNET_MESSENGER_MemberSession *session)
 Returns if the given member session has been completed.
 
struct GNUNET_TIME_Absolute get_member_session_start (const struct GNUNET_MESSENGER_MemberSession *session)
 Returns the timestamp of the member session's start.
 
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.
 
const struct GNUNET_ShortHashCodeget_member_session_id (const struct GNUNET_MESSENGER_MemberSession *session)
 Returns the member id of a given member session.
 
const struct GNUNET_CRYPTO_PublicKeyget_member_session_public_key (const struct GNUNET_MESSENGER_MemberSession *session)
 Returns the public key of a given member session.
 
const struct GNUNET_HashCodeget_member_session_context (const struct GNUNET_MESSENGER_MemberSession *session)
 Returns the member context of a given member session.
 
struct GNUNET_MESSENGER_Contactget_member_session_contact (struct GNUNET_MESSENGER_MemberSession *session)
 Returns the contact which is connected to a given member session.
 
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 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.
 
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.
 
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.
 
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.
 
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.
 
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.
 

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
42 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create new member session!\n");
43
45 session->member = member;
46
47 GNUNET_memcpy (&(session->public_key), pubkey, sizeof(session->public_key));
48
50 get_member_session_key (session),
51 get_member_session_id (session),
52 &(session->context));
53
54 {
56
57 store = get_member_contact_store (member->store);
58
59 session->contact = get_store_contact (
60 store,
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_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_NO
@ GNUNET_ERROR_TYPE_DEBUG
#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_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, 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:

◆ get_session_member_store()

static struct GNUNET_MESSENGER_MemberStore * get_session_member_store ( const struct GNUNET_MESSENGER_MemberSession session)
static

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

91{
92 struct GNUNET_MESSENGER_Member *member;
93
94 GNUNET_assert (session);
95
96 member = session->member;
97
98 GNUNET_assert (member);
99
100 return member->store;
101}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

References GNUNET_assert, GNUNET_MESSENGER_MemberSession::member, and GNUNET_MESSENGER_Member::store.

Referenced by check_member_session_completion(), destroy_member_session(), get_member_session_key(), get_session_room(), load_member_session_next(), reset_member_session(), and switch_member_session().

Here is the caller graph for this function:

◆ get_session_room()

static struct GNUNET_MESSENGER_SrvRoom * get_session_room ( const struct GNUNET_MESSENGER_MemberSession session)
static

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

106{
107 struct GNUNET_MESSENGER_MemberStore *store;
108
109 GNUNET_assert (session);
110
111 store = get_session_member_store (session);
112
113 GNUNET_assert (store);
114
115 return store->room;
116}
static struct GNUNET_MESSENGER_MemberStore * get_session_member_store(const struct GNUNET_MESSENGER_MemberSession *session)

References get_session_member_store(), GNUNET_assert, and GNUNET_MESSENGER_MemberStore::room.

Referenced by check_member_session_completion().

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

121{
122 const struct GNUNET_HashCode *start;
123 const struct GNUNET_HashCode *end;
124 struct GNUNET_MESSENGER_MessageStore *msg_store;
125 struct GNUNET_CONTAINER_MultiHashMap *completion;
128
129 GNUNET_assert (session);
130
132 "Check session history (%s) for completion.\n",
134
135 if (! session->messages.tail)
136 {
137 session->completed = GNUNET_YES;
138 goto completion;
139 }
140 else if (GNUNET_YES == session->completed)
141 goto completion;
142
143 start = &(session->messages.head->hash);
144 end = &(session->messages.tail->hash);
145
146 msg_store = get_srv_room_message_store (get_session_room (session));
148
149 if (! completion)
150 goto completion;
151
152 init_list_messages (&level);
153 add_to_list_messages (&level, end);
154
156
157 while (level.head)
158 {
159 struct GNUNET_MESSENGER_ListMessage *element;
160
161 for (element = level.head; element; element = element->next)
162 {
163 const struct GNUNET_MESSENGER_MessageLink *link;
164
166 msg_store, &(element->hash),
167 GNUNET_NO);
168
169 if (! link)
170 continue;
171
173 link->first)))
174 {
175 add_to_list_messages (&list, &(link->first));
176 GNUNET_CONTAINER_multihashmap_put (completion, &(link->first), NULL,
178 }
179
180 if ((GNUNET_YES == link->multiple) &&
182 link->second)
183 )))
184 {
185 add_to_list_messages (&list, &(link->second));
186 GNUNET_CONTAINER_multihashmap_put (completion, &(link->second), NULL,
188 }
189 }
190
191 clear_list_messages (&level);
192
193 for (element = list.head; element; element = element->next)
194 {
195 if (GNUNET_YES != check_member_session_history (session, &(element->hash),
196 GNUNET_YES))
197 continue;
198
199 if (0 == GNUNET_CRYPTO_hash_cmp (&(element->hash), start))
200 {
201 session->completed = GNUNET_YES;
202 break;
203 }
204 }
205
206 if (GNUNET_YES != session->completed)
207 copy_list_messages (&level, &list);
208
210 }
211
213
214completion:
216 {
217 struct GNUNET_MESSENGER_MemberStore *member_store;
218 struct GNUNET_MESSENGER_ContactStore *store;
219
220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Completed session history (%s)\n",
222
223 member_store = get_session_member_store (session);
224 store = get_member_contact_store (member_store);
225
226 if ((session->contact) && (GNUNET_YES == decrease_contact_rc (
227 session->contact)))
229 store,
230 session->contact,
232
233 session->contact = NULL;
234 }
235}
static int start
Set if we are to start default services (including ARM).
Definition gnunet-arm.c:38
static int list
Set if we should print a list of currently running services.
Definition gnunet-arm.c:68
static int end
Set if we are to shutdown all services (including ARM).
Definition gnunet-arm.c:33
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.
static struct GNUNET_MESSENGER_SrvRoom * get_session_room(const struct GNUNET_MESSENGER_MemberSession *session)
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.
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).
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.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
@ GNUNET_YES
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
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.
Internal representation of the hash map.
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_session_member_store(), get_session_room(), get_srv_room_message_store(), get_store_message_link(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, 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::messages, GNUNET_MESSENGER_MessageLink::multiple, GNUNET_MESSENGER_ListMessage::next, remove_store_contact(), GNUNET_MESSENGER_MessageLink::second, start, 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 239 of file gnunet-service-messenger_member_session.c.

242{
244
245 GNUNET_assert ((cls) && (key));
246
247 next = cls;
248
251
252 return GNUNET_YES;
253}
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.

References GNUNET_assert, 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 257 of file gnunet-service-messenger_member_session.c.

260{
261 struct GNUNET_MESSENGER_MemberStore *store;
263
264 if ((! session) || (! message) || (! hash))
265 return NULL;
266
269
270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Switch member session!\n");
271
272 store = get_session_member_store (session);
274
275 if (GNUNET_MESSENGER_KIND_ID == message->header.kind)
276 {
277 next->member = add_store_member (store,
278 &(message->body.id.id));
279 if (! next->member)
280 {
282 "Failed to switch member session to ID: %s\n",
283 GNUNET_sh2s (&(message->body.id.id)));
284
286 return NULL;
287 }
288 }
289 else
290 next->member = session->member;
291
292 if (GNUNET_MESSENGER_KIND_KEY == message->header.kind)
293 GNUNET_memcpy (&(next->public_key), &(message->body.key.key),
294 sizeof(next->public_key));
295 else
297 sizeof(next->public_key));
298
302 &(next->context));
303
310
312
313 if (! (next->contact))
314 {
316 return NULL;
317 }
318
320
323 GNUNET_NO);
324
326 next);
327
329 copy_list_messages (&(next->messages), &(session->messages));
330
331 session->next = next;
332 next->prev = session;
333 next->next = NULL;
334
336
337 session->closed = GNUNET_YES;
340
342
343 return next;
344}
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_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_DEBUG, 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 348 of file gnunet-service-messenger_member_session.c.

349{
350 struct GNUNET_MESSENGER_MemberStore *store;
351 struct GNUNET_MESSENGER_Contact *contact;
352
353 GNUNET_assert (session);
354
356
357 clear_list_messages (&(session->messages));
358
359 store = get_session_member_store (session);
360 contact = get_member_session_contact (session);
361
362 if ((contact) && (GNUNET_YES == decrease_contact_rc (contact)))
365 contact,
367
368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Free member session!\n");
369 GNUNET_free (session);
370}

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_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, 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 374 of file gnunet-service-messenger_member_session.c.

376{
377 struct GNUNET_MESSENGER_Contact *contact;
378
379 GNUNET_assert ((session) && (hash));
380
381 {
382 struct GNUNET_MESSENGER_MemberStore *member_store;
383 struct GNUNET_MESSENGER_ContactStore *store;
384
385 member_store = get_session_member_store (session);
386 store = get_member_contact_store (member_store);
387 contact = get_store_contact (
388 store,
391 }
392
393 if (! contact)
394 return GNUNET_SYSERR;
395
396 if (contact == session->contact)
397 goto clear_messages;
398
399 session->contact = contact;
400 increase_contact_rc (session->contact);
401
402clear_messages:
403 clear_list_messages (&(session->messages));
404 add_to_list_messages (&(session->messages), hash);
405
406 session->next = NULL;
407 session->closed = GNUNET_NO;
408 session->completed = GNUNET_NO;
409
410 return GNUNET_OK;
411}
@ 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 415 of file gnunet-service-messenger_member_session.c.

416{
417 GNUNET_assert (session);
418
419 session->closed = GNUNET_YES;
421}

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

426{
427 GNUNET_assert (session);
428
429 return session->closed;
430}

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

436{
437 GNUNET_assert (session);
438
439 return session->completed;
440}

References GNUNET_MESSENGER_MemberSession::completed, and GNUNET_assert.

Referenced by check_member_session_completion(), iterate_epoch_session_members(), 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 444 of file gnunet-service-messenger_member_session.c.

445{
446 GNUNET_assert (session);
447
448 if (session->prev)
449 return get_member_session_start (session->prev);
450
451 return session->start;
452}
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 456 of file gnunet-service-messenger_member_session.c.

457{
458 const struct GNUNET_MESSENGER_MemberStore *store;
459
460 GNUNET_assert ((session) && (session->member));
461
462 store = get_session_member_store (session);
463
464 return get_member_store_key (store);
465}
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 469 of file gnunet-service-messenger_member_session.c.

470{
471 GNUNET_assert (session);
472
473 return get_member_id (session->member);
474}
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_epoch_session_members(), iterate_notify_about_members(), notify_about_members(), remove_room_member_session(), request_room_message_step(), save_member_session(), send_message_join(), switch_member_session(), traverse_epoch_session_message(), 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 478 of file gnunet-service-messenger_member_session.c.

480{
481 GNUNET_assert (session);
482
483 return &(session->public_key);
484}

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

490{
491 GNUNET_assert (session);
492
493 return &(session->context);
494}

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

499{
500 GNUNET_assert (session);
501
502 return session->contact;
503}

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

511{
512 GNUNET_assert ((session) && (message) && (hash));
513
515 {
516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Check message (%s) using history!\n",
517 GNUNET_h2s (hash));
518
519 if (GNUNET_YES == check_member_session_history (session, hash, GNUNET_YES))
520 return GNUNET_OK;
521 else
522 return GNUNET_SYSERR;
523 }
524
525 if (0 != GNUNET_memcmp (get_member_session_id (session),
526 &(message->header.sender_id)))
527 return GNUNET_SYSERR;
528
529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Check message (%s) using key: %s\n",
530 GNUNET_h2s (hash),
533
534 return verify_message (message, hash, get_member_session_public_key (
535 session));
536}
char * GNUNET_CRYPTO_public_key_to_string(const struct GNUNET_CRYPTO_PublicKey *key)
Creates a (Base32) string representation of the public key.
#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 540 of file gnunet-service-messenger_member_session.c.

544{
545 GNUNET_assert ((session) && (hash));
546
547 if (GNUNET_YES == ownership)
548 return (NULL != GNUNET_CONTAINER_multihashmap_get (session->history, hash)?
550 else
551 return GNUNET_CONTAINER_multihashmap_contains (session->history, hash);
552}
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 556 of file gnunet-service-messenger_member_session.c.

559{
560 GNUNET_assert ((session) && (hash));
561
563 (GNUNET_YES == ownership?
564 session : NULL),
566 && (session->next))
567 update_member_chain_history (session->next, hash, ownership);
568}
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 572 of file gnunet-service-messenger_member_session.c.

575{
576 GNUNET_assert ((session) && (message) && (hash));
577
579 return;
580
582 "Updating sessions history (%s) += (%s)\n",
583 GNUNET_sh2s (get_member_session_id (session)), GNUNET_h2s (hash));
584
585 if (GNUNET_OK == verify_member_session_as_sender (session, message, hash))
586 {
587 if (GNUNET_YES == is_message_session_bound (message))
588 add_to_list_messages (&(session->messages), hash);
589
591 }
592 else
593 update_member_chain_history (session, hash, GNUNET_NO);
594
595 if (GNUNET_YES == session->closed)
597}
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 601 of file gnunet-service-messenger_member_session.c.

603{
604 GNUNET_assert ((session) && (hash));
605
606 if ((0 < GNUNET_CONTAINER_multihashmap_remove_all (session->history, hash)) &&
607 (session->next))
608 clear_member_session_history (session->next, hash);
609}
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 613 of file gnunet-service-messenger_member_session.c.

615{
616 GNUNET_assert ((session) && (hash));
617
618 clear_member_chain_history (session, hash);
619}
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 629 of file gnunet-service-messenger_member_session.c.

631{
634
635 GNUNET_assert ((session) && (path));
636
637 if (GNUNET_YES != GNUNET_DISK_file_test (path))
638 return;
639
640 {
641 enum GNUNET_DISK_AccessPermissions permission;
642
645 }
646
647 if (! handle)
648 return;
649
651
652 do {
654 ssize_t len;
655
656 len = GNUNET_DISK_file_read (handle, &(entry.hash), sizeof(entry.hash));
657
658 if (len != sizeof(entry.hash))
659 break;
660
661 len = GNUNET_DISK_file_read (handle, &(entry.ownership),
662 sizeof(entry.ownership));
663
664 if (len != sizeof(entry.ownership))
665 break;
666
667 status = GNUNET_CONTAINER_multihashmap_put (session->history, &(entry.hash),
668 (entry.ownership? session :
669 NULL),
671 } while (status == GNUNET_OK);
672
674}
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:1258
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:533
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:219
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:1332
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:673
@ 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 678 of file gnunet-service-messenger_member_session.c.

680{
681 char *config_file;
682 struct GNUNET_MESSENGER_MemberSession *session;
684
685 GNUNET_assert ((member) && (directory));
686
687 GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg");
688
689 session = NULL;
690
692 goto free_config;
693
695 "Load session configuration of member: %s\n", config_file);
696
698
699 if (! cfg)
700 goto free_config;
701
703 {
705 enum GNUNET_GenericReturnValue key_result;
706 unsigned long long numeric_value;
707 char *key_data;
708
710 "key", &key_data))
711 goto destroy_config;
712
713 key_result = GNUNET_CRYPTO_public_key_from_string (key_data, &key);
714 GNUNET_free (key_data);
715
716 if (GNUNET_OK != key_result)
717 goto destroy_config;
718
719 session = create_member_session (member, &key);
720
722 "start",
723 &numeric_value))
724 session->start.abs_value_us = numeric_value;
725
727 "closed",
728 &numeric_value))
729 session->closed = (GNUNET_YES == numeric_value? GNUNET_YES : GNUNET_NO);
730
732 "completed",
733 &numeric_value))
734 session->completed = (GNUNET_YES == numeric_value? GNUNET_YES :
735 GNUNET_NO);
736 }
737
738destroy_config:
740
741free_config:
743
744 if (! session)
745 return;
746
747 {
748 char *history_file;
749 GNUNET_asprintf (&history_file, "%s%s", directory, "history.map");
750
751 load_member_session_history (session, history_file);
752 GNUNET_free (history_file);
753 }
754
755 {
756 char *messages_file;
757 GNUNET_asprintf (&messages_file, "%s%s", directory, "messages.list");
758
759 load_list_messages (&(session->messages), messages_file);
760 GNUNET_free (messages_file);
761 }
762
763 add_member_session (member, session);
764}
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
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_CRYPTO_public_key_from_string(const char *str, struct GNUNET_CRYPTO_PublicKey *key)
Parses a (Base32) string representation of the public key.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
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:

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

770{
771 struct GNUNET_MESSENGER_MemberSession *check;
772
773 if (! next)
774 return NULL;
775
776 for (check = next; check; check = check->next)
777 if (check == session)
778 return NULL;
779
780 return next;
781}

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

787{
789 char *config_file;
790
791
792 GNUNET_assert ((session) && (directory));
793
794 GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg");
795
797 goto free_config;
798
800 "Load next session configuration of member: %s\n", config_file);
801
803
804 if (! cfg)
805 goto free_config;
806
808 {
809 struct GNUNET_CRYPTO_PublicKey next_key;
810 enum GNUNET_GenericReturnValue key_result;
812 char *key_data;
813
815 "next_key",
816 &key_data))
817 goto destroy_config;
818
819 key_result = GNUNET_CRYPTO_public_key_from_string (key_data, &next_key);
820 GNUNET_free (key_data);
821
822 if (GNUNET_OK != key_result)
823 goto destroy_config;
824
825 if (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "session", "next_id",
826 &next_id, sizeof(next_id)))
827 goto destroy_config;
828
829 {
830 struct GNUNET_MESSENGER_MemberStore *store;
831 struct GNUNET_MESSENGER_Member *member;
832
834 member = get_store_member (store, &next_id);
835
837 session,
838 member? get_member_session (member, &next_key) : NULL);
839 }
840
841 if (session->next)
842 session->next->prev = session;
843 }
844
845destroy_config:
847
848free_config:
850}
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:

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

857{
859 unsigned char ownership;
860
861 GNUNET_assert ((cls) && (key));
862
863 handle = cls;
864 ownership = value? GNUNET_YES : GNUNET_NO;
865
867 GNUNET_DISK_file_write (handle, &ownership, sizeof(ownership));
868
869 return GNUNET_YES;
870}
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:710

References GNUNET_assert, 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 874 of file gnunet-service-messenger_member_session.c.

876{
878
879 GNUNET_assert ((session) && (path));
880
881 {
882 enum GNUNET_DISK_AccessPermissions permission;
883
885
887 path,
889 permission);
890 }
891
892 if (! handle)
893 return;
894
896
898 session->history,
900 handle);
901
904}
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:1451
@ 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 908 of file gnunet-service-messenger_member_session.c.

910{
912 char *config_file;
913 char *key_data;
914
915 GNUNET_assert ((session) && (directory));
916
917 GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg");
918
920 "Save session configuration of member: %s\n", config_file);
921
923
924 if (! cfg)
925 goto free_config;
926
929
930 if (key_data)
931 {
932 GNUNET_CONFIGURATION_set_value_string (cfg, "session", "key", key_data);
933 GNUNET_free (key_data);
934 }
935
936 if (session->next)
937 {
939 session->next);
940
941 char *next_id_data = GNUNET_STRINGS_data_to_string_alloc (next_id,
942 sizeof(*next_id));
943
944 if (next_id_data)
945 {
946 GNUNET_CONFIGURATION_set_value_string (cfg, "session", "next_id",
947 next_id_data);
948 GNUNET_free (next_id_data);
949 }
950
953
954 if (key_data)
955 {
956 GNUNET_CONFIGURATION_set_value_string (cfg, "session", "next_key",
957 key_data);
958 GNUNET_free (key_data);
959 }
960 }
961
962 GNUNET_CONFIGURATION_set_value_number (cfg, "session", "start",
963 session->start.abs_value_us);
964
965 GNUNET_CONFIGURATION_set_value_number (cfg, "session", "closed",
966 session->closed);
967 GNUNET_CONFIGURATION_set_value_number (cfg, "session", "completed",
968 session->completed);
969
972
973free_config:
975
976 {
977 char *history_file;
978 GNUNET_asprintf (&history_file, "%s%s", directory, "history.map");
979
980 save_member_session_history (session, history_file);
981 GNUNET_free (history_file);
982 }
983
984 {
985 char *messages_file;
986 GNUNET_asprintf (&messages_file, "%s%s", directory, "messages.list");
987
988 save_list_messages (&(session->messages), messages_file);
989 GNUNET_free (messages_file);
990 }
991}
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:807

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: