summaryrefslogtreecommitdiff
path: root/src/messenger/gnunet-service-messenger_service.h
blob: aa43fa4573cfe22a6c0f3ee4d99b951c9d58f288 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
   This file is part of GNUnet.
   Copyright (C) 2020--2021 GNUnet e.V.

   GNUnet is free software: you can redistribute it and/or modify it
   under the terms of the GNU Affero General Public License as published
   by the Free Software Foundation, either version 3 of the License,
   or (at your option) any later version.

   GNUnet is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

   SPDX-License-Identifier: AGPL3.0-or-later
 */
/**
 * @author Tobias Frisch
 * @file src/messenger/gnunet-service-messenger_service.h
 * @brief GNUnet MESSENGER service
 */

#ifndef GNUNET_SERVICE_MESSENGER_SERVICE_H
#define GNUNET_SERVICE_MESSENGER_SERVICE_H

#include "platform.h"
#include "gnunet_configuration_lib.h"
#include "gnunet_crypto_lib.h"
#include "gnunet_container_lib.h"
#include "gnunet_disk_lib.h"
#include "gnunet_identity_service.h"

#include "gnunet-service-messenger_ego_store.h"
#include "gnunet-service-messenger_list_handles.h"

#include "messenger_api_contact_store.h"
#include "gnunet-service-messenger_room.h"

#include "gnunet-service-messenger_member_session.h"

struct GNUNET_MESSENGER_Service
{
  const struct GNUNET_CONFIGURATION_Handle *config;
  struct GNUNET_SERVICE_Handle *service;

  struct GNUNET_SCHEDULER_Task *shutdown;

  char *dir;

  struct GNUNET_CADET_Handle *cadet;

  struct GNUNET_MESSENGER_EgoStore ego_store;
  struct GNUNET_MESSENGER_ContactStore contact_store;

  struct GNUNET_MESSENGER_ListHandles handles;

  struct GNUNET_CONTAINER_MultiHashMap *rooms;
};

/**
 * Creates and allocates a new service using a given <i>config</i> and a GNUnet service handle.
 *
 * @param[in] config Configuration
 * @param[in/out] service_handle GNUnet service handle
 * @return New service
 */
struct GNUNET_MESSENGER_Service*
create_service (const struct GNUNET_CONFIGURATION_Handle *config, struct GNUNET_SERVICE_Handle *service_handle);

/**
 * Destroys a <i>service</i> and frees its memory fully.
 *
 * @param[in/out] service Service
 */
void
destroy_service (struct GNUNET_MESSENGER_Service *service);

/**
 * Returns the used EGO-store of a given <i>service</i>.
 *
 * @param[in/out] service Service
 * @return EGO-store
 */
struct GNUNET_MESSENGER_EgoStore*
get_service_ego_store (struct GNUNET_MESSENGER_Service *service);

/**
 * Returns the used contact store of a given <i>service</i>.
 *
 * @param[in/out] service Service
 * @return Contact store
 */
struct GNUNET_MESSENGER_ContactStore*
get_service_contact_store (struct GNUNET_MESSENGER_Service *service);

/**
 * Creates and adds a new handle to a <i>service</i> using a given message queue.
 *
 * @param[in/out] service Service
 * @param[in/out] mq Message queue
 * @return New handle
 */
struct GNUNET_MESSENGER_SrvHandle*
add_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq);

/**
 * Removes a <i>handle</i> from a <i>service</i> and destroys it.
 *
 * @param[in/out] service Service
 * @param[in/out] handle Handle
 */
void
remove_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle);

/**
 * Tries to write the peer identity of the peer running a <i>service</i> on to the <i>peer</i>
 * parameter. The functions returns #GNUNET_OK on success, otherwise #GNUNET_SYSERR.
 *
 * @param[in] service Service
 * @param[out] peer Peer identity
 * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR
 */
int
get_service_peer_identity (const struct GNUNET_MESSENGER_Service *service, struct GNUNET_PeerIdentity *peer);

/**
 * Returns the room identified by a given <i>key</i> for a <i>service</i>. If the service doesn't know any room
 * using the given key, NULL gets returned.
 *
 * @param[in] service Service
 * @param[in] key Key of room
 * @return Room or NULL
 */
struct GNUNET_MESSENGER_SrvRoom*
get_service_room (const struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key);

/**
 * Tries to open a room using a given <i>key</i> for a <i>service</i> by a specific <i>handle</i>. The room will be
 * created if necessary. If the function is successful, it returns #GNUNET_YES, otherwise #GNUNET_NO.
 *
 * @param[in/out] service Service
 * @param[in/out] handle Handle
 * @param[in] key Key of room
 * @return #GNUNET_YES on success, otherwise #GNUNET_NO
 */
int
open_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle,
                   const struct GNUNET_HashCode *key);

/**
 * Tries to enter a room using a given <i>key</i> for a <i>service</i> by a specific <i>handle</i>. The room will
 * be created if necessary. If the function is successful, it returns #GNUNET_YES, otherwise #GNUNET_NO.
 *
 * The room will be entered through the peer identitied by the peer identity provided as <i>door</i> parameter and
 * a new connection will be made.
 *
 * @param[in/out] service Service
 * @param[in/out] handle Handle
 * @param[in] door Peer identity
 * @param[in] key Key of room
 * @return #GNUNET_YES on success, otherwise #GNUNET_NO
 */
int
entry_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle,
                    const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key);

/**
 * Tries to close a room using a given <i>key</i> for a <i>service</i> by a specific <i>handle</i>. The room will
 * be created if necessary. If the function is successful, it returns #GNUNET_YES, otherwise #GNUNET_NO.
 *
 * If the specific handle is currently the host of the room for this service, a new handle which is a member will
 * take its place. Otherwise the room will be destroyed for this service.
 *
 * @param[in/out] service Service
 * @param[in/out] handle Handle
 * @param[in] key Key of room
 * @return #GNUNET_YES on success, otherwise #GNUNET_NO
 */
int
close_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle,
                    const struct GNUNET_HashCode *key);

/**
 * Sends a received or sent <i>message</i> with a given <i>hash</i> to each handle of a <i>service</i> which
 * is currently member of a specific <i>room</i> for handling it in the client API.
 *
 * @param[in/out] service Service
 * @param[in/out] room Room
 * @param[in] session Member session
 * @param[in] message Message
 * @param[in] hash Hash of message
 */
void
handle_service_message (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room,
                        const struct GNUNET_MESSENGER_MemberSession *session,
                        const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash);

#endif //GNUNET_SERVICE_MESSENGER_SERVICE_H