GNUnet  0.17.6
gnunet-service-messenger_member_session.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2021--2022 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
27 
30 
32 
35  const struct GNUNET_IDENTITY_PublicKey *pubkey)
36 {
37  if ((!member) || (!pubkey) || (!(member->store)))
38  return NULL;
39 
41  session->member = member;
42 
43  GNUNET_memcpy(&(session->public_key), pubkey, sizeof(session->public_key));
44 
46  get_member_session_key (session),
47  get_member_session_id (session),
48  &(session->context)
49  );
50 
52 
53  session->contact = get_store_contact(
54  store,
57  );
58 
59  if (!(session->contact))
60  {
61  GNUNET_free(session);
62  return NULL;
63  }
64 
65  increase_contact_rc (session->contact);
66 
68 
69  init_list_messages(&(session->messages));
70 
71  session->prev = NULL;
72  session->next = NULL;
73 
74  session->start = GNUNET_TIME_absolute_get();
75 
76  session->closed = GNUNET_NO;
77  session->completed = GNUNET_NO;
78 
79  return session;
80 }
81 
82 static void
84 {
85  GNUNET_assert (session);
86 
87  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Check session history (%s) for completion.\n",
89 
90  if (!session->messages.tail)
91  {
92  session->completed = GNUNET_YES;
93  goto completion;
94  }
95 
96  const struct GNUNET_HashCode* start = &(session->messages.head->hash);
97  const struct GNUNET_HashCode* end = &(session->messages.tail->hash);
98 
99  struct GNUNET_MESSENGER_ListMessages level;
100  init_list_messages(&level);
101 
102  add_to_list_messages(&level, end);
103 
105 
108 
109  while (level.head)
110  {
111  struct GNUNET_MESSENGER_ListMessage *element;
112 
113  for (element = level.head; element; element = element->next)
114  {
116  store, &(element->hash), GNUNET_NO
117  );
118 
119  if (!link)
120  continue;
121 
122  add_to_list_messages(&list, &(link->first));
123 
124  if (GNUNET_YES == link->multiple)
125  add_to_list_messages(&list, &(link->second));
126  }
127 
128  clear_list_messages(&level);
129 
130  for (element = list.head; element; element = element->next)
131  if (GNUNET_YES == check_member_session_history(session, &(element->hash), GNUNET_YES))
132  break;
133 
134  if (element)
135  if (0 != GNUNET_CRYPTO_hash_cmp(&(element->hash), start))
136  add_to_list_messages(&level, &(element->hash));
137  else
138  session->completed = GNUNET_YES;
139  else
140  copy_list_messages(&level, &list);
141 
143  }
144 
145 completion:
146  if (GNUNET_YES == is_member_session_completed(session))
147  {
148  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Completed session history (%s)\n",
150 
152 
154 
155  if ((session->contact) && (GNUNET_YES == decrease_contact_rc (session->contact)))
157  store,
158  session->contact,
160  );
161 
162  session->contact = NULL;
163  }
164 }
165 
166 static int
168  const struct GNUNET_HashCode *key,
169  void *value)
170 {
171  struct GNUNET_MESSENGER_MemberSession *next = cls;
172 
175 
176  return GNUNET_YES;
177 }
178 
181  const struct GNUNET_MESSENGER_Message *message,
182  const struct GNUNET_HashCode *hash)
183 {
184  if ((!session) || (!message) || (!hash))
185  return NULL;
186 
188  (GNUNET_MESSENGER_KIND_KEY == message->header.kind));
189 
191 
192  if (GNUNET_MESSENGER_KIND_ID == message->header.kind)
193  next->member = add_store_member(session->member->store, &(message->body.id.id));
194  else
195  next->member = session->member;
196 
197  if (GNUNET_MESSENGER_KIND_KEY == message->header.kind)
198  GNUNET_memcpy(&(next->public_key), &(message->body.key.key), sizeof(next->public_key));
199  else
201 
205  &(next->context)
206  );
207 
214  );
215 
217 
218  if (!(next->contact))
219  {
220  GNUNET_free(next);
221  return NULL;
222  }
223 
225 
228  );
229 
231 
233  copy_list_messages(&(next->messages), &(session->messages));
234 
235  session->next = next;
236  next->prev = session;
237  next->next = NULL;
238 
240 
241  session->closed = GNUNET_YES;
242  next->closed = GNUNET_NO;
244 
246 
247  return next;
248 }
249 
250 void
252 {
253  GNUNET_assert (session);
254 
256 
257  clear_list_messages (&(session->messages));
258 
259  struct GNUNET_MESSENGER_Contact *contact = get_member_session_contact (session);
260 
261  if ((contact) && (GNUNET_YES == decrease_contact_rc (contact)))
264  contact,
266  );
267 
268  GNUNET_free(session);
269 }
270 
271 int
273  const struct GNUNET_HashCode *hash)
274 {
275  GNUNET_assert ((session) && (hash));
276 
279  store,
280  get_member_session_context (session),
282  );
283 
284  if (!contact)
285  return GNUNET_SYSERR;
286 
287  if (contact == session->contact)
288  goto clear_messages;
289 
290  session->contact = contact;
291  increase_contact_rc (session->contact);
292 
293 clear_messages:
294  clear_list_messages(&(session->messages));
295  add_to_list_messages(&(session->messages), hash);
296 
297  session->next = NULL;
298  session->closed = GNUNET_NO;
299  session->completed = GNUNET_NO;
300 
301  return GNUNET_OK;
302 }
303 
304 void
306 {
307  GNUNET_assert (session);
308 
309  session->closed = GNUNET_YES;
311 }
312 
313 int
315 {
316  GNUNET_assert(session);
317 
318  return session->closed;
319 }
320 
321 int
323 {
324  GNUNET_assert(session);
325 
326  return session->completed;
327 }
328 
331 {
332  GNUNET_assert(session);
333 
334  if (session->prev)
335  return get_member_session_start(session->prev);
336 
337  return session->start;
338 }
339 
340 const struct GNUNET_HashCode*
342 {
343  GNUNET_assert((session) && (session->member));
344 
345  return get_member_store_key(session->member->store);
346 }
347 
348 const struct GNUNET_ShortHashCode*
350 {
351  GNUNET_assert(session);
352 
353  return get_member_id(session->member);
354 }
355 
356 const struct GNUNET_IDENTITY_PublicKey*
358 {
359  GNUNET_assert(session);
360 
361  return &(session->public_key);
362 }
363 
364 const struct GNUNET_HashCode*
366 {
367  GNUNET_assert(session);
368 
369  return &(session->context);
370 }
371 
374 {
375  GNUNET_assert (session);
376 
377  return session->contact;
378 }
379 
381  const struct GNUNET_MESSENGER_Message *message,
382  const struct GNUNET_HashCode *hash)
383 {
384  GNUNET_assert((session) && (message) && (hash));
385 
386  if (GNUNET_YES == is_member_session_completed(session))
387  return GNUNET_SYSERR;
388 
389  if (0 != GNUNET_memcmp(get_member_session_id(session), &(message->header.sender_id)))
390  return GNUNET_SYSERR;
391 
392  return verify_message(message, hash, get_member_session_public_key(session));
393 }
394 
395 int
397  const struct GNUNET_HashCode *hash, int ownership)
398 {
399  GNUNET_assert((session) && (hash));
400 
401  if (GNUNET_YES == ownership)
402  return (NULL != GNUNET_CONTAINER_multihashmap_get(session->history, hash)? GNUNET_YES : GNUNET_NO);
403  else
404  return GNUNET_CONTAINER_multihashmap_contains(session->history, hash);
405 }
406 
407 static void
409  const struct GNUNET_HashCode *hash, int ownership)
410 {
411  GNUNET_assert ((session) && (hash));
412 
413  if ((GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(session->history, hash, (GNUNET_YES == ownership? session : NULL),
415  update_member_chain_history (session->next, hash, ownership);
416 }
417 
418 void
420  const struct GNUNET_MESSENGER_Message *message,
421  const struct GNUNET_HashCode *hash)
422 {
423  GNUNET_assert((session) && (message) && (hash));
424 
425  if (GNUNET_YES == is_member_session_completed(session))
426  return;
427 
428  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Updating sessions history (%s) += (%s)\n",
429  GNUNET_sh2s(get_member_session_id(session)), GNUNET_h2s(hash));
430 
431  if (GNUNET_OK == verify_member_session_as_sender (session, message, hash))
432  {
433  if (GNUNET_YES == is_message_session_bound (message))
434  add_to_list_messages(&(session->messages), hash);
435 
436  update_member_chain_history (session, hash, GNUNET_YES);
437  }
438  else
439  update_member_chain_history (session, hash, GNUNET_NO);
440 
441  if (GNUNET_YES == session->closed)
443 }
444 
445 static void
447  const struct GNUNET_HashCode *hash)
448 {
449  GNUNET_assert ((session) && (hash));
450 
451  if ((0 < GNUNET_CONTAINER_multihashmap_remove_all(session->history, hash)) && (session->next))
452  clear_member_session_history(session->next, hash);
453 }
454 
455 void
457  const struct GNUNET_HashCode *hash)
458 {
459  GNUNET_assert((session) && (hash));
460 
461  clear_member_chain_history (session, hash);
462 }
463 
465 {
466  struct GNUNET_HashCode hash;
467  unsigned char ownership;
468 };
469 
470 static void
472  const char *path)
473 {
474  GNUNET_assert((session) && (path));
475 
476  if (GNUNET_YES != GNUNET_DISK_file_test (path))
477  return;
478 
480 
482  path, GNUNET_DISK_OPEN_READ, permission
483  );
484 
485  if (!handle)
486  return;
487 
489 
491  ssize_t len;
492 
493  int status;
494 
495  do {
496  len = GNUNET_DISK_file_read(handle, &(entry.hash), sizeof(entry.hash));
497 
498  if (len != sizeof(entry.hash))
499  break;
500 
501  len = GNUNET_DISK_file_read(handle, &(entry.ownership), sizeof(entry.ownership));
502 
503  if (len != sizeof(entry.ownership))
504  break;
505 
506  status = GNUNET_CONTAINER_multihashmap_put(session->history, &(entry.hash), (entry.ownership? session : NULL),
508  } while (status == GNUNET_OK);
509 
511 }
512 
513 void
515  const char *directory)
516 {
517  GNUNET_assert ((member) && (directory));
518 
519  char *config_file;
520  GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg");
521 
522  struct GNUNET_MESSENGER_MemberSession *session = NULL;
523 
525  goto free_config;
526 
527  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Load session configuration of member: %s\n", config_file);
528 
530 
532  {
533  char *key_data;
534 
535  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "session", "key", &key_data))
536  goto destroy_config;
537 
539 
541 
542  GNUNET_free(key_data);
543 
544  if (GNUNET_OK != key_return)
545  goto destroy_config;
546 
547  session = create_member_session(member, &key);
548 
549  unsigned long long numeric_value;
550 
551  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "session", "start", &numeric_value))
552  session->start.abs_value_us = numeric_value;
553 
554  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "session", "closed", &numeric_value))
555  session->closed = (GNUNET_YES == numeric_value? GNUNET_YES : GNUNET_NO);
556 
557  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "session", "completed", &numeric_value))
558  session->completed = (GNUNET_YES == numeric_value? GNUNET_YES : GNUNET_NO);
559  }
560 
561 destroy_config:
563 
564 free_config:
566 
567  if (!session)
568  return;
569 
570  char *history_file;
571  GNUNET_asprintf (&history_file, "%s%s", directory, "history.map");
572 
573  load_member_session_history (session, history_file);
574  GNUNET_free(history_file);
575 
576  char *messages_file;
577  GNUNET_asprintf (&messages_file, "%s%s", directory, "messages.list");
578 
579  load_list_messages(&(session->messages), messages_file);
580  GNUNET_free(messages_file);
581 
582  add_member_session(member, session);
583 }
584 
585 static struct GNUNET_MESSENGER_MemberSession*
588 {
589  if (!next)
590  return NULL;
591 
592  struct GNUNET_MESSENGER_MemberSession *check = next;
593 
594  do {
595  if (check == session)
596  return NULL;
597 
598  check = check->next;
599  } while (check);
600 
601  return next;
602 }
603 
604 void
606  const char *directory)
607 {
608  GNUNET_assert ((session) && (directory));
609 
610  char *config_file;
611  GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg");
612 
614  goto free_config;
615 
616  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Load next session configuration of member: %s\n", config_file);
617 
619 
621  {
622  char *key_data;
623 
624  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "session", "next_key", &key_data))
625  goto destroy_config;
626 
627  struct GNUNET_IDENTITY_PublicKey next_key;
628 
629  enum GNUNET_GenericReturnValue key_return = GNUNET_IDENTITY_public_key_from_string(key_data, &next_key);
630 
631  GNUNET_free(key_data);
632 
633  if (GNUNET_OK != key_return)
634  goto destroy_config;
635 
637 
638  if (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "session", "next_id", &next_id, sizeof(next_id)))
639  goto destroy_config;
640 
641  struct GNUNET_MESSENGER_Member *member = get_store_member(session->member->store, &next_id);
642 
644  session, member? get_member_session (member, &next_key) : NULL
645  );
646 
647  if (session->next)
648  session->next->prev = session;
649  }
650 
651 destroy_config:
653 
654 free_config:
656 }
657 
658 static int
660  const struct GNUNET_HashCode *key,
661  void *value)
662 {
663  struct GNUNET_DISK_FileHandle *handle = cls;
664  unsigned char ownership = value? GNUNET_YES : GNUNET_NO;
665 
666  GNUNET_DISK_file_write(handle, key, sizeof(*key));
667  GNUNET_DISK_file_write(handle, &ownership, sizeof(ownership));
668 
669  return GNUNET_YES;
670 }
671 
672 static void
674  const char *path)
675 {
676  GNUNET_assert((session) && (path));
677 
679 
682  );
683 
684  if (!handle)
685  return;
686 
688 
690  session->history,
692  handle
693  );
694 
697 }
698 
699 void
701  const char *directory)
702 {
703  GNUNET_assert ((session) && (directory));
704 
705  char *config_file;
706  GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg");
707 
708  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Save session configuration of member: %s\n", config_file);
709 
711 
713 
714  if (key_data)
715  {
716  GNUNET_CONFIGURATION_set_value_string (cfg, "session", "key", key_data);
717 
718  GNUNET_free(key_data);
719  }
720 
721  if (session->next)
722  {
723  const struct GNUNET_ShortHashCode *next_id = get_member_session_id(session->next);
724 
725  char *next_id_data = GNUNET_STRINGS_data_to_string_alloc (next_id, sizeof(*next_id));
726 
727  if (next_id_data)
728  {
729  GNUNET_CONFIGURATION_set_value_string (cfg, "session", "next_id", next_id_data);
730 
731  GNUNET_free(next_id_data);
732  }
733 
735 
736  if (key_data)
737  {
738  GNUNET_CONFIGURATION_set_value_string (cfg, "session", "next_key", key_data);
739 
740  GNUNET_free(key_data);
741  }
742  }
743 
744  GNUNET_CONFIGURATION_set_value_number(cfg, "session", "start", session->start.abs_value_us);
745 
746  GNUNET_CONFIGURATION_set_value_number (cfg, "session", "closed", session->closed);
747  GNUNET_CONFIGURATION_set_value_number (cfg, "session", "completed", session->completed);
748 
751 
753 
754  char *history_file;
755  GNUNET_asprintf (&history_file, "%s%s", directory, "history.map");
756 
757  save_member_session_history (session, history_file);
758  GNUNET_free(history_file);
759 
760  char *messages_file;
761  GNUNET_asprintf (&messages_file, "%s%s", directory, "messages.list");
762 
763  save_list_messages(&(session->messages), messages_file);
764  GNUNET_free(messages_file);
765 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
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
static char * config_file
Set to the name of the config file used.
Definition: gnunet-arm.c:84
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
uint16_t status
See PRISM_STATUS_*-constants.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
static struct GNUNET_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
static char * value
Value of the record to add/remove.
static char * next_id
Command-line option for namespace publishing: identifier for updates to this publication.
void clear_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Clears the list of message hashes.
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 init_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Initializes list of message hashes as empty list.
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 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.
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.
struct GNUNET_MESSENGER_MemberSession * get_member_session(const struct GNUNET_MESSENGER_Member *member, const struct GNUNET_IDENTITY_PublicKey *public_key)
Returns the member session of a member identified by a given public key.
void add_member_session(struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSENGER_MemberSession *session)
Adds a given member session to its member.
const struct GNUNET_ShortHashCode * get_member_id(const struct GNUNET_MESSENGER_Member *member)
Returns the current id of a given member.
static int iterate_copy_history(void *cls, const struct GNUNET_HashCode *key, void *value)
static void update_member_chain_history(struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash, int ownership)
const struct GNUNET_HashCode * get_member_session_key(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the key of the room a given member session belongs to.
const struct GNUNET_ShortHashCode * get_member_session_id(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the member id of a given member session.
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.
const struct GNUNET_HashCode * get_member_session_context(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the member context of a given member session.
void destroy_member_session(struct GNUNET_MESSENGER_MemberSession *session)
Destroys a member session and frees its memory fully.
int check_member_session_history(const struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash, int ownership)
Checks the history of a session for a specific message which is identified by its hash and if the own...
int reset_member_session(struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash)
Resets a given member session which re-opens a member session for new usage.
static int iterate_save_member_session_history_hentries(void *cls, const struct GNUNET_HashCode *key, void *value)
static void clear_member_chain_history(struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash)
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.
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.
struct GNUNET_TIME_Absolute get_member_session_start(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the timestamp of the member session's start.
static void load_member_session_history(struct GNUNET_MESSENGER_MemberSession *session, const char *path)
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.
int is_member_session_completed(const struct GNUNET_MESSENGER_MemberSession *session)
Returns if the given member session has been completed.
const struct GNUNET_IDENTITY_PublicKey * get_member_session_public_key(const struct GNUNET_MESSENGER_MemberSession *session)
Returns the public key from an EGO of a given member session.
static void check_member_session_completion(struct GNUNET_MESSENGER_MemberSession *session)
int verify_member_session_as_sender(const struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Verifies a given member session as sender of a selected message and its hash.
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 me...
static struct GNUNET_MESSENGER_MemberSession * get_cycle_safe_next_session(struct GNUNET_MESSENGER_MemberSession *session, struct GNUNET_MESSENGER_MemberSession *next)
void load_member_session(struct GNUNET_MESSENGER_Member *member, const char *directory)
Loads data from a directory into a new allocated and created member session of a member if the requir...
struct GNUNET_MESSENGER_Contact * get_member_session_contact(struct GNUNET_MESSENGER_MemberSession *session)
Returns the contact which is connected to a given member session.
int is_member_session_closed(const struct GNUNET_MESSENGER_MemberSession *session)
Returns if the given member session has been closed.
void save_member_session(struct GNUNET_MESSENGER_MemberSession *session, const char *directory)
Saves data from a member session into a directory which can be load to restore the member session com...
static void save_member_session_history(struct GNUNET_MESSENGER_MemberSession *session, const char *path)
struct GNUNET_MESSENGER_MemberSession * create_member_session(struct GNUNET_MESSENGER_Member *member, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Creates and allocates a new member session of a member with a given public key.
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.
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.
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_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.
const struct GNUNET_MESSENGER_MessageLink * get_store_message_link(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, int 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.
GNUnet MESSENGER service.
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.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
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_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_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
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:1235
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
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
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:206
GNUNET_DISK_AccessPermissions
File access permissions, UNIX-style.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h)
Write file changes to disk.
Definition: disk.c:1425
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1306
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_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ 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).
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:220
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).
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.
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.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
unsigned int GNUNET_CONTAINER_multihashmap_clear(struct GNUNET_CONTAINER_MultiHashMap *map)
Remove all entries from the map.
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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_public_key_from_string(const char *str, struct GNUNET_IDENTITY_PublicKey *key)
Parses a (Base32) string representation of the public key.
char * GNUNET_IDENTITY_public_key_to_string(const struct GNUNET_IDENTITY_PublicKey *key)
Creates a (Base32) string representation of the public key.
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:96
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_YES
@ GNUNET_NO
Definition: gnunet_common.h:98
@ GNUNET_SYSERR
Definition: gnunet_common.h:97
#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).
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
@ GNUNET_MESSENGER_KIND_KEY
The key kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.
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
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:110
int decrease_contact_rc(struct GNUNET_MESSENGER_Contact *contact)
Decreases the reference counter if possible (can not underflow!) of a given contact and returns GNUNE...
void increase_contact_rc(struct GNUNET_MESSENGER_Contact *contact)
Increases the reference counter of a given contact which is zero as default.
void get_context_from_member(const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *id, struct GNUNET_HashCode *context)
Calculates the context hash of a member in a room and returns it.
struct GNUNET_MESSENGER_Contact * get_store_contact(struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Returns a contact using a specific public key.
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.
void update_store_contact(struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET_MESSENGER_Contact *contact, const struct GNUNET_HashCode *context, const struct GNUNET_HashCode *next_context, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Moves a contact from the store to another location matching a given public key and member context.
messenger api: client implementation of GNUnet MESSENGER service
int is_message_session_bound(const struct GNUNET_MESSENGER_Message *message)
Returns if the message should be bound to a member session.
int verify_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_IDENTITY_PublicKey *key)
Verifies the signature of a given message and its hash with a specific public key.
Handle used to access files (and pipes).
A 512-bit hashcode.
An identity key as per LSD0001.
struct GNUNET_MESSENGER_ListMessage * next
struct GNUNET_MESSENGER_ListMessage * head
struct GNUNET_MESSENGER_ListMessage * tail
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
struct GNUNET_MESSENGER_MessageId id
struct GNUNET_MESSENGER_MessageKey key
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
struct GNUNET_IDENTITY_PublicKey key
The new public key which replaces the current senders public key.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.
A 256-bit hashcode.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.