diff options
Diffstat (limited to 'src/service/messenger/gnunet-service-messenger_member_store.h')
-rw-r--r-- | src/service/messenger/gnunet-service-messenger_member_store.h | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/src/service/messenger/gnunet-service-messenger_member_store.h b/src/service/messenger/gnunet-service-messenger_member_store.h new file mode 100644 index 000000000..0acb8ef9c --- /dev/null +++ b/src/service/messenger/gnunet-service-messenger_member_store.h | |||
@@ -0,0 +1,159 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020--2023 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 | */ | ||
20 | /** | ||
21 | * @author Tobias Frisch | ||
22 | * @file src/messenger/gnunet-service-messenger_member_store.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_MEMBER_STORE_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_MEMBER_STORE_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "gnunet_identity_service.h" | ||
32 | #include "messenger_api_message.h" | ||
33 | |||
34 | struct GNUNET_MESSENGER_SrvRoom; | ||
35 | |||
36 | struct GNUNET_MESSENGER_Member; | ||
37 | struct GNUNET_MESSENGER_MemberSession; | ||
38 | |||
39 | struct GNUNET_MESSENGER_MemberStore | ||
40 | { | ||
41 | struct GNUNET_MESSENGER_SrvRoom *room; | ||
42 | |||
43 | struct GNUNET_CONTAINER_MultiShortmap *members; | ||
44 | }; | ||
45 | |||
46 | typedef int (*GNUNET_MESSENGER_MemberIteratorCallback) ( | ||
47 | void *cls, | ||
48 | const struct GNUNET_CRYPTO_PublicKey *public_key, | ||
49 | struct GNUNET_MESSENGER_MemberSession *session); | ||
50 | |||
51 | /** | ||
52 | * Initializes a member <i>store</i> as fully empty connected to a <i>room</i>. | ||
53 | * | ||
54 | * @param[out] store Member store | ||
55 | * @param room Room | ||
56 | */ | ||
57 | void | ||
58 | init_member_store (struct GNUNET_MESSENGER_MemberStore *store, | ||
59 | struct GNUNET_MESSENGER_SrvRoom *room); | ||
60 | |||
61 | /** | ||
62 | * Clears a member <i>store</i>, wipes its content and deallocates its memory. | ||
63 | * | ||
64 | * @param[in,out] store Member store | ||
65 | */ | ||
66 | void | ||
67 | clear_member_store (struct GNUNET_MESSENGER_MemberStore *store); | ||
68 | |||
69 | /** | ||
70 | * Returns the used contact store of a given member <i>store</i>. | ||
71 | * | ||
72 | * @param[in,out] store Member store | ||
73 | * @return Contact store | ||
74 | */ | ||
75 | struct GNUNET_MESSENGER_ContactStore* | ||
76 | get_member_contact_store (struct GNUNET_MESSENGER_MemberStore *store); | ||
77 | |||
78 | /** | ||
79 | * Returns the shared secret you need to access a room of the <i>store</i>. | ||
80 | * | ||
81 | * @param[in] store Member store | ||
82 | * @return Shared secret | ||
83 | */ | ||
84 | const struct GNUNET_HashCode* | ||
85 | get_member_store_key (const struct GNUNET_MESSENGER_MemberStore *store); | ||
86 | |||
87 | /** | ||
88 | * Loads members from a directory into a member <i>store</i>. | ||
89 | * | ||
90 | * @param[out] store Member store | ||
91 | * @param[in] directory Path to a directory | ||
92 | */ | ||
93 | void | ||
94 | load_member_store (struct GNUNET_MESSENGER_MemberStore *store, | ||
95 | const char *directory); | ||
96 | |||
97 | /** | ||
98 | * Saves members from a member <i>store</i> into a directory. | ||
99 | * | ||
100 | * @param[in] store Member store | ||
101 | * @param[in] directory Path to a directory | ||
102 | */ | ||
103 | void | ||
104 | save_member_store (struct GNUNET_MESSENGER_MemberStore *store, | ||
105 | const char *directory); | ||
106 | |||
107 | /** | ||
108 | * Returns the member in a <i>store</i> identified by a given <i>id</i>. If the <i>store</i> | ||
109 | * does not contain a member with the given <i>id</i>, NULL gets returned. | ||
110 | * | ||
111 | * @param[in] store Member store | ||
112 | * @param[in] id Member id | ||
113 | * @return Member or NULL | ||
114 | */ | ||
115 | struct GNUNET_MESSENGER_Member* | ||
116 | get_store_member (const struct GNUNET_MESSENGER_MemberStore *store, | ||
117 | const struct GNUNET_ShortHashCode *id); | ||
118 | |||
119 | /** | ||
120 | * Returns the member of a <i>store</i> using a sender id of a given <i>message</i>. | ||
121 | * | ||
122 | * If the message is a peer message or the member does not provide a matching session, | ||
123 | * NULL gets returned. | ||
124 | * | ||
125 | * @param[in,out] store Member store | ||
126 | * @param[in] message Message | ||
127 | * @return Member or NULL | ||
128 | */ | ||
129 | struct GNUNET_MESSENGER_Member* | ||
130 | get_store_member_of (struct GNUNET_MESSENGER_MemberStore *store, | ||
131 | const struct GNUNET_MESSENGER_Message *message); | ||
132 | |||
133 | /** | ||
134 | * Adds a member to a <i>store</i> under a specific <i>id</i> and returns it on success. | ||
135 | * | ||
136 | * @param[in,out] store Member store | ||
137 | * @param[in] id Member id | ||
138 | * @return Member or NULL | ||
139 | */ | ||
140 | struct GNUNET_MESSENGER_Member* | ||
141 | add_store_member (struct GNUNET_MESSENGER_MemberStore *store, | ||
142 | const struct GNUNET_ShortHashCode *id); | ||
143 | |||
144 | /** | ||
145 | * Iterate through all member sessions currently connected to the members of the given | ||
146 | * member <i>store</i> and call the provided iterator callback with a selected closure. | ||
147 | * The function will return the amount of members it iterated through. | ||
148 | * | ||
149 | * @param[in,out] store Member store | ||
150 | * @param[in] it Iterator callback | ||
151 | * @param[in,out] cls Closure | ||
152 | * @return Amount of members iterated through | ||
153 | */ | ||
154 | int | ||
155 | iterate_store_members (struct GNUNET_MESSENGER_MemberStore *store, | ||
156 | GNUNET_MESSENGER_MemberIteratorCallback it, | ||
157 | void *cls); | ||
158 | |||
159 | #endif //GNUNET_SERVICE_MESSENGER_MEMBER_STORE_H | ||