gnunet-service-messenger_handle.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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_handle.h
  19. * @brief GNUnet MESSENGER service
  20. */
  21. #ifndef GNUNET_SERVICE_MESSENGER_HANDLE_H
  22. #define GNUNET_SERVICE_MESSENGER_HANDLE_H
  23. #include "platform.h"
  24. #include "gnunet_cadet_service.h"
  25. #include "gnunet_container_lib.h"
  26. #include "gnunet_crypto_lib.h"
  27. #include "gnunet_identity_service.h"
  28. #include "gnunet_peer_lib.h"
  29. #include "gnunet_mq_lib.h"
  30. #include "gnunet-service-messenger_service.h"
  31. #include "messenger_api_ego.h"
  32. #include "messenger_api_message.h"
  33. struct GNUNET_MESSENGER_SrvHandle
  34. {
  35. struct GNUNET_MESSENGER_Service *service;
  36. struct GNUNET_MQ_Handle *mq;
  37. char *name;
  38. struct GNUNET_IDENTITY_Operation *operation;
  39. struct GNUNET_MESSENGER_Ego *ego;
  40. struct GNUNET_CONTAINER_MultiHashMap *member_ids;
  41. };
  42. /**
  43. * Creates and allocates a new handle related to a <i>service</i> and using a given <i>mq</i> (message queue).
  44. *
  45. * @param service MESSENGER Service
  46. * @param mq Message queue
  47. * @return New handle
  48. */
  49. struct GNUNET_MESSENGER_SrvHandle*
  50. create_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq);
  51. /**
  52. * Destroys a handle and frees its memory fully.
  53. *
  54. * @param handle Handle
  55. */
  56. void
  57. destroy_handle (struct GNUNET_MESSENGER_SrvHandle *handle);
  58. /**
  59. * Writes the path of the directory for a given <i>handle</i> using a specific <i>name</i> to the parameter
  60. * <i>dir</i>. This directory will be used to store data regarding the handle and its messages.
  61. *
  62. * @param handle Handle
  63. * @param name Potential name of the handle
  64. * @param dir[out] Path to store data
  65. */
  66. void
  67. get_handle_data_subdir (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name, char **dir);
  68. /**
  69. * Returns the member id of a given <i>handle</i> in a specific <i>room</i>.
  70. *
  71. * If the handle is not a member of the specific <i>room</i>, NULL gets returned.
  72. *
  73. * @param handle Handle
  74. * @param key Key of a room
  75. * @return Member id or NULL
  76. */
  77. const struct GNUNET_ShortHashCode*
  78. get_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key);
  79. /**
  80. * Changes the member id of a given <i>handle</i> in a specific <i>room</i> to match a <i>unique_id</i>.
  81. *
  82. * The client connected to the <i>handle</i> will be informed afterwards automatically.
  83. *
  84. * @param handle Handle
  85. * @param key Key of a room
  86. * @param unique_id Unique member id
  87. */
  88. void
  89. change_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key,
  90. const struct GNUNET_ShortHashCode *unique_id);
  91. /**
  92. * Returns the EGO used by a given <i>handle</i>.
  93. *
  94. * @param handle Handle
  95. * @return EGO keypair
  96. */
  97. struct GNUNET_MESSENGER_Ego*
  98. get_handle_ego (struct GNUNET_MESSENGER_SrvHandle *handle);
  99. /**
  100. * Tries to set the name and EGO key of a <i>handle</i> initially by looking up a specific <i>name</i>.
  101. *
  102. * @param handle Handle
  103. * @param name Name (optionally: valid EGO name)
  104. */
  105. void
  106. setup_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name);
  107. /**
  108. * Tries to change the keypair of an EGO of a <i>handle</i> under the same name and informs all rooms
  109. * about the change automatically.
  110. *
  111. * @param handle Handle
  112. * @return GNUNET_OK on success, otherwise GNUNET_SYSERR
  113. */
  114. int
  115. update_handle (struct GNUNET_MESSENGER_SrvHandle *handle);
  116. /**
  117. * Tries to rename the handle which implies renaming the EGO its using and moving all related data into
  118. * the directory fitting to the changed <i>name</i>.
  119. *
  120. * The client connected to the <i>handle</i> will be informed afterwards automatically.
  121. *
  122. * @param handle Handle
  123. * @param name New name
  124. * @return GNUNET_OK on success, otherwise GNUNET_NO
  125. */
  126. int
  127. set_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name);
  128. /**
  129. * Makes a given <i>handle</i> a member of the room using a specific <i>key</i> and opens the
  130. * room from the handles service.
  131. *
  132. * @param handle Handle
  133. * @param key Key of a room
  134. * @return GNUNET_YES on success, otherwise GNUNET_NO
  135. */
  136. int
  137. open_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key);
  138. /**
  139. * Makes a given <i>handle</i> a member of the room using a specific <i>key</i> and enters the room
  140. * through a tunnel to a peer identified by a given <i>door</i> (peer identity).
  141. *
  142. * @param handle Handle
  143. * @param door Peer identity
  144. * @param key Key of a room
  145. * @return GNUNET_YES on success, otherwise GNUNET_NO
  146. */
  147. int
  148. entry_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door,
  149. const struct GNUNET_HashCode *key);
  150. /**
  151. * Removes the membership of the room using a specific <i>key</i> and closes it if no other handle
  152. * from this service is still a member of it.
  153. *
  154. * @param handle Handle
  155. * @param key Key of a room
  156. * @return GNUNET_YES on success, otherwise GNUNET_NO
  157. */
  158. int
  159. close_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key);
  160. /**
  161. * Sends a <i>message</i> from a given <i>handle</i> to the room using a specific <i>key</i>.
  162. *
  163. * @param handle Handle
  164. * @param key Key of a room
  165. * @param message Message
  166. * @return GNUNET_YES on success, otherwise GNUNET_NO
  167. */
  168. int
  169. send_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key,
  170. struct GNUNET_MESSENGER_Message *message);
  171. /**
  172. * Loads member ids and other potential configuration from a given <i>handle</i> which
  173. * depends on the given name the <i>handle</i> uses.
  174. *
  175. * @param handle Handle
  176. */
  177. void
  178. load_handle_configuration(struct GNUNET_MESSENGER_SrvHandle *handle);
  179. /**
  180. * Saves member ids and other potential configuration from a given <i>handle</i> which
  181. * depends on the given name the <i>handle</i> uses.
  182. *
  183. * @param handle Handle
  184. */
  185. void
  186. save_handle_configuration(struct GNUNET_MESSENGER_SrvHandle *handle);
  187. #endif //GNUNET_SERVICE_MESSENGER_HANDLE_H