2 This file is part of GNUnet
3 Copyright (C) 2013, 2014, 2016 GNUnet e.V.
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.
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.
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/>.
20 * @author Simon Dieterle
21 * @author Andreas Fuchs
22 * @author Christian Grothoff
25 * API to the conversation service
27 * @defgroup conversation Conversation service
28 * One-to-one voice communication over CADET
30 * NOTE: This API is deliberately deceptively simple; the idea
31 * is that advanced features (such as answering machines) will
32 * be done with a separate service (an answering machine service)
33 * with its own APIs; the speaker/microphone abstractions are
34 * used to facilitate plugging in custom logic for implementing
35 * such a service later by creating "software" versions of
36 * speakers and microphones that record to disk or play a file.
37 * Notifications about missed calls should similarly be done
38 * using a separate service; CONVERSATION is supposed to be just
39 * the "bare bones" voice service.
41 * As this is supposed to be a "secure" service, caller ID is of
42 * course provided as part of the basic implementation, as only the
43 * CONVERSATION service can know for sure who it is that we are
48 #ifndef GNUNET_CONVERSATION_SERVICE_H
49 #define GNUNET_CONVERSATION_SERVICE_H
54 #if 0 /* keep Emacsens' auto-indent happy */
59 #include "gnunet_util_lib.h"
60 #include "gnunet_identity_service.h"
61 #include "gnunet_namestore_service.h"
62 #include "gnunet_speaker_lib.h"
63 #include "gnunet_microphone_lib.h"
67 * Version of the conversation API.
69 #define GNUNET_CONVERSATION_VERSION 0x00000004
72 * Handle to identify a particular caller. A caller is an entity that
73 * initiate a call to a phone. This struct identifies the caller to
74 * the user operating the phone. The entity that initiated the call
75 * will have a `struct GNUNET_CONVERSATION_Call`.
77 struct GNUNET_CONVERSATION_Caller;
80 GNUNET_NETWORK_STRUCT_BEGIN
83 * A phone record specifies which peer is hosting a given user and
84 * may also specify the phone line that is used (typically zero).
85 * The version is also right now always zero.
87 struct GNUNET_CONVERSATION_PhoneRecord
91 * Version of the phone record, for now always one. We may
92 * use other versions for anonymously hosted phone lines in
95 uint32_t version GNUNET_PACKED;
98 * Reserved. In v1. always zero.
100 uint32_t reserved GNUNET_PACKED;
103 * Identity of the peer hosting the phone service.
105 struct GNUNET_PeerIdentity peer;
108 * Phone line (CADET port) to connect to.
110 struct GNUNET_HashCode line_port;
114 GNUNET_NETWORK_STRUCT_END
117 * Information about active callers to a phone.
119 enum GNUNET_CONVERSATION_PhoneEventCode
122 * We are the callee and the phone is ringing.
123 * We should accept the call or hang up.
125 GNUNET_CONVERSATION_EC_PHONE_RING,
128 * The conversation was terminated by the caller.
129 * We must no longer use the caller's handle.
131 GNUNET_CONVERSATION_EC_PHONE_HUNG_UP
137 * Function called with an event emitted by a phone.
140 * @param code type of the event
141 * @param caller handle for the caller
142 * @param caller_id public key of the caller (in GNS)
145 (*GNUNET_CONVERSATION_PhoneEventHandler)(void *cls,
146 enum GNUNET_CONVERSATION_PhoneEventCode code,
147 struct GNUNET_CONVERSATION_Caller *caller,
148 const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id);
152 * Information about the current status of a call. Each call
153 * progresses from ring over ready to terminated. Steps may
156 enum GNUNET_CONVERSATION_CallerEventCode
160 * We are the callee and the caller suspended the call. Note that
161 * both sides can independently suspend and resume calls; a call is
162 * only "working" of both sides are active.
164 GNUNET_CONVERSATION_EC_CALLER_SUSPEND,
167 * We are the callee and the caller resumed the call. Note that
168 * both sides can independently suspend and resume calls; a call is
169 * only "working" of both sides are active.
171 GNUNET_CONVERSATION_EC_CALLER_RESUME
177 * Function called with an event emitted by a caller.
178 * These events are only generated after the phone is
182 * @param code type of the event for this caller
185 (*GNUNET_CONVERSATION_CallerEventHandler)(void *cls,
186 enum GNUNET_CONVERSATION_CallerEventCode code);
190 * A phone is a device that can ring to signal an incoming call and
191 * that you can pick up to answer the call and hang up to terminate
192 * the call. You can also hang up a ringing phone immediately
193 * (without picking it up) to stop it from ringing. Phones have
194 * caller ID. You can ask the phone for its record and make that
195 * record available (via GNS) to enable others to call you.
196 * Multiple phones maybe connected to the same line (the line is
197 * something rather internal to a phone and not obvious from it).
198 * You can only have one conversation per phone at any time.
200 struct GNUNET_CONVERSATION_Phone;
204 * Create a new phone.
206 * @param cfg configuration for the phone; specifies the phone service and
207 * which line the phone is to be connected to
208 * @param ego ego to use for name resolution (when determining caller ID)
209 * @param event_handler how to notify the owner of the phone about events
210 * @param event_handler_cls closure for @a event_handler
212 struct GNUNET_CONVERSATION_Phone *
213 GNUNET_CONVERSATION_phone_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
214 const struct GNUNET_IDENTITY_Ego *ego,
215 GNUNET_CONVERSATION_PhoneEventHandler event_handler,
216 void *event_handler_cls);
220 * Fill in a namestore record with the contact information
221 * for this phone. Note that the filled in "data" value
222 * is only valid until the phone is destroyed.
224 * @param phone phone to create a record for
225 * @param rd namestore record to fill in
228 GNUNET_CONVERSATION_phone_get_record (struct GNUNET_CONVERSATION_Phone *phone,
229 struct GNUNET_GNSRECORD_Data *rd);
233 * Picks up a (ringing) phone call. This will connect the speaker
234 * to the microphone of the other party, and vice versa.
236 * @param caller handle that identifies which caller should be answered
237 * @param event_handler how to notify about events by the caller
238 * @param event_handler_cls closure for @a event_handler
239 * @param speaker speaker to use
240 * @param mic microphone to use
243 GNUNET_CONVERSATION_caller_pick_up (struct GNUNET_CONVERSATION_Caller *caller,
244 GNUNET_CONVERSATION_CallerEventHandler event_handler,
245 void *event_handler_cls,
246 struct GNUNET_SPEAKER_Handle *speaker,
247 struct GNUNET_MICROPHONE_Handle *mic);
251 * Pause conversation of an active call. This will disconnect the speaker
252 * and the microphone. The call can later be resumed with
253 * #GNUNET_CONVERSATION_caller_resume.
255 * @param caller call to suspend
258 GNUNET_CONVERSATION_caller_suspend (struct GNUNET_CONVERSATION_Caller *caller);
262 * Resume suspended conversation of a phone.
264 * @param caller call to resume
265 * @param speaker speaker to use
266 * @param mic microphone to use
269 GNUNET_CONVERSATION_caller_resume (struct GNUNET_CONVERSATION_Caller *caller,
270 struct GNUNET_SPEAKER_Handle *speaker,
271 struct GNUNET_MICROPHONE_Handle *mic);
275 * Hang up up a (possibly ringing or paused) phone. This will notify
276 * the caller that we are no longer interested in talking with them.
278 * @param caller who should we hang up on
281 GNUNET_CONVERSATION_caller_hang_up (struct GNUNET_CONVERSATION_Caller *caller);
287 * @param phone phone to destroy
290 GNUNET_CONVERSATION_phone_destroy (struct GNUNET_CONVERSATION_Phone *phone);
293 /* *********************** CALL API ************************ */
296 * Handle for an outgoing call.
298 struct GNUNET_CONVERSATION_Call;
302 * Information about the current status of a call.
304 enum GNUNET_CONVERSATION_CallEventCode
308 * We are the caller and are now ringing the other party (GNS lookup
311 GNUNET_CONVERSATION_EC_CALL_RINGING,
314 * We are the caller and are now ready to talk as the callee picked up.
316 GNUNET_CONVERSATION_EC_CALL_PICKED_UP,
319 * We are the caller and failed to locate a phone record in GNS.
320 * After this invocation, the respective call handle will be
321 * automatically destroyed and the client must no longer call
322 * #GNUNET_CONVERSATION_call_stop or any other function on the
325 GNUNET_CONVERSATION_EC_CALL_GNS_FAIL,
328 * We are the caller and the callee called
329 * #GNUNET_CONVERSATION_caller_hang_up. After this invocation, the
330 * respective call handle will be automatically destroyed and the
331 * client must no longer call #GNUNET_CONVERSATION_call_stop.
333 GNUNET_CONVERSATION_EC_CALL_HUNG_UP,
336 * We are the caller and the callee suspended the call. Note that
337 * both sides can independently suspend and resume calls; a call is
338 * only "working" of both sides are active.
340 GNUNET_CONVERSATION_EC_CALL_SUSPENDED,
343 * We are the caller and the callee suspended the call. Note that
344 * both sides can independently suspend and resume calls; a call is
345 * only "working" of both sides are active.
347 GNUNET_CONVERSATION_EC_CALL_RESUMED,
350 * We had an error handing the call, and are now restarting it
351 * (back to lookup). This happens, for example, if the peer
352 * is restarted during a call.
354 GNUNET_CONVERSATION_EC_CALL_ERROR
360 * Function called with an event emitted for a call.
363 * @param code type of the event on the call
366 (*GNUNET_CONVERSATION_CallEventHandler)(void *cls,
367 enum GNUNET_CONVERSATION_CallEventCode code);
371 * Call the phone of another user.
373 * @param cfg configuration to use, specifies our phone service
374 * @param caller_id identity of the caller
375 * @param callee GNS name of the callee (used to locate the callee's record)
376 * @param speaker speaker to use (will be used automatically immediately once the
377 * #GNUNET_CONVERSATION_EC_CALL_PICKED_UP event is generated); we will NOT generate
378 * a ring tone on the speaker
379 * @param mic microphone to use (will be used automatically immediately once the
380 * #GNUNET_CONVERSATION_EC_CALL_PICKED_UP event is generated)
381 * @param event_handler how to notify the owner of the phone about events
382 * @param event_handler_cls closure for @a event_handler
383 * @return handle for the call
385 struct GNUNET_CONVERSATION_Call *
386 GNUNET_CONVERSATION_call_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
387 struct GNUNET_IDENTITY_Ego *caller_id,
389 struct GNUNET_SPEAKER_Handle *speaker,
390 struct GNUNET_MICROPHONE_Handle *mic,
391 GNUNET_CONVERSATION_CallEventHandler event_handler,
392 void *event_handler_cls);
396 * Pause a call. Temporarily suspends the use of speaker and
399 * @param call call to pause
402 GNUNET_CONVERSATION_call_suspend (struct GNUNET_CONVERSATION_Call *call);
406 * Resumes a call after #GNUNET_CONVERSATION_call_suspend.
408 * @param call call to resume
409 * @param speaker speaker to use
410 * @param mic microphone to use
413 GNUNET_CONVERSATION_call_resume (struct GNUNET_CONVERSATION_Call *call,
414 struct GNUNET_SPEAKER_Handle *speaker,
415 struct GNUNET_MICROPHONE_Handle *mic);
419 * Terminate a call. The call may be ringing or ready at this time.
421 * @param call call to terminate
424 GNUNET_CONVERSATION_call_stop (struct GNUNET_CONVERSATION_Call *call);
427 #if 0 /* keep Emacsens' auto-indent happy */
436 /** @} */ /* end of group */