gnunet-service-messenger_contact.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2020 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author Tobias Frisch
  18. * @file src/messenger/gnunet-service-messenger_contact.h
  19. * @brief GNUnet MESSENGER service
  20. */
  21. #ifndef GNUNET_SERVICE_MESSENGER_CONTACT_H
  22. #define GNUNET_SERVICE_MESSENGER_CONTACT_H
  23. #include "platform.h"
  24. #include "gnunet_crypto_lib.h"
  25. #include "gnunet_identity_service.h"
  26. struct GNUNET_MESSENGER_SrvContact
  27. {
  28. char *name;
  29. size_t rc;
  30. struct GNUNET_IDENTITY_PublicKey public_key;
  31. };
  32. /**
  33. * Creates and allocates a new contact with a given public <i>key</i> from an EGO.
  34. *
  35. * @param key Public key
  36. * @return New contact
  37. */
  38. struct GNUNET_MESSENGER_SrvContact*
  39. create_contact (const struct GNUNET_IDENTITY_PublicKey *key);
  40. /**
  41. * Destroys a contact and frees its memory fully.
  42. *
  43. * @param contact Contact
  44. */
  45. void
  46. destroy_contact (struct GNUNET_MESSENGER_SrvContact *contact);
  47. /**
  48. * Returns the current name of a given <i>contact</i> or NULL if no valid name was assigned yet.
  49. *
  50. * @param contact Contact
  51. * @return Name of the contact or NULL
  52. */
  53. const char*
  54. get_contact_name (const struct GNUNET_MESSENGER_SrvContact *contact);
  55. /**
  56. * Changes the current name of a given <i>contact</i> by copying it from the parameter <i>name</i>.
  57. *
  58. * @param contact Contact
  59. * @param name Valid name (may not be NULL!)
  60. */
  61. void
  62. set_contact_name (struct GNUNET_MESSENGER_SrvContact *contact, const char *name);
  63. /**
  64. * Returns the public key of a given <i>contact</i>.
  65. *
  66. * @param contact Contact
  67. * @return Public key of the contact
  68. */
  69. const struct GNUNET_IDENTITY_PublicKey*
  70. get_contact_key (const struct GNUNET_MESSENGER_SrvContact *contact);
  71. /**
  72. * Increases the reference counter of a given <i>contact</i> which is zero as default.
  73. *
  74. * @param contact Contact
  75. */
  76. void
  77. increase_contact_rc (struct GNUNET_MESSENGER_SrvContact *contact);
  78. /**
  79. * Decreases the reference counter if possible (can not underflow!) of a given <i>contact</i>
  80. * and returns GNUNET_YES if the counter is equal to zero, otherwise GNUNET_NO.
  81. *
  82. * @param contact Contact
  83. * @return GNUNET_YES or GNUNET_NO depending on the reference counter
  84. */
  85. int
  86. decrease_contact_rc (struct GNUNET_MESSENGER_SrvContact *contact);
  87. /**
  88. * Returns the resulting hashcode of the public key from a given <i>contact</i>.
  89. *
  90. * @param contact Contact
  91. * @return Hash of the contacts public key
  92. */
  93. const struct GNUNET_HashCode*
  94. get_contact_id_from_key (const struct GNUNET_MESSENGER_SrvContact *contact);
  95. #endif //GNUNET_SERVICE_MESSENGER_CONTACT_H