gnunet_conversation_service.h (13803B)
1 /* 2 This file is part of GNUnet 3 Copyright (C) 2013, 2014, 2016 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 /** 22 * @addtogroup conversation_l2 Conversation service and libraries 23 * @{ 24 * 25 * @author Simon Dieterle 26 * @author Andreas Fuchs 27 * @author Christian Grothoff 28 * 29 * @file 30 * API to the conversation service 31 * 32 * @defgroup conversation Conversation service 33 * One-to-one voice communication over CADET 34 * 35 * NOTE: This API is deliberately deceptively simple; the idea 36 * is that advanced features (such as answering machines) will 37 * be done with a separate service (an answering machine service) 38 * with its own APIs; the speaker/microphone abstractions are 39 * used to facilitate plugging in custom logic for implementing 40 * such a service later by creating "software" versions of 41 * speakers and microphones that record to disk or play a file. 42 * Notifications about missed calls should similarly be done 43 * using a separate service; CONVERSATION is supposed to be just 44 * the "bare bones" voice service. 45 * 46 * As this is supposed to be a "secure" service, caller ID is of 47 * course provided as part of the basic implementation, as only the 48 * CONVERSATION service can know for sure who it is that we are 49 * talking to. 50 * 51 * @{ 52 */ 53 #ifndef GNUNET_CONVERSATION_SERVICE_H 54 #define GNUNET_CONVERSATION_SERVICE_H 55 56 #ifdef __cplusplus 57 extern "C" 58 { 59 #if 0 /* keep Emacsens' auto-indent happy */ 60 } 61 #endif 62 #endif 63 64 65 #include "gnunet_util_lib.h" 66 #include "gnunet_identity_service.h" 67 #include "gnunet_namestore_service.h" 68 #include "gnunet_speaker_lib.h" 69 #include "gnunet_microphone_lib.h" 70 71 72 /** 73 * Version of the conversation API. 74 */ 75 #define GNUNET_CONVERSATION_VERSION 0x00000004 76 77 /** 78 * Handle to identify a particular caller. A caller is an entity that 79 * initiate a call to a phone. This struct identifies the caller to 80 * the user operating the phone. The entity that initiated the call 81 * will have a `struct GNUNET_CONVERSATION_Call`. 82 */ 83 struct GNUNET_CONVERSATION_Caller; 84 85 86 GNUNET_NETWORK_STRUCT_BEGIN 87 88 /** 89 * A phone record specifies which peer is hosting a given user and 90 * may also specify the phone line that is used (typically zero). 91 * The version is also right now always zero. 92 */ 93 struct GNUNET_CONVERSATION_PhoneRecord 94 { 95 /** 96 * Version of the phone record, for now always one. We may 97 * use other versions for anonymously hosted phone lines in 98 * the future. 99 */ 100 uint32_t version GNUNET_PACKED; 101 102 /** 103 * Reserved. In v1. always zero. 104 */ 105 uint32_t reserved GNUNET_PACKED; 106 107 /** 108 * Identity of the peer hosting the phone service. 109 */ 110 struct GNUNET_PeerIdentity peer; 111 112 /** 113 * Phone line (CADET port) to connect to. 114 */ 115 struct GNUNET_HashCode line_port; 116 }; 117 118 GNUNET_NETWORK_STRUCT_END 119 120 /** 121 * Information about active callers to a phone. 122 */ 123 enum GNUNET_CONVERSATION_PhoneEventCode 124 { 125 /** 126 * We are the callee and the phone is ringing. 127 * We should accept the call or hang up. 128 */ 129 GNUNET_CONVERSATION_EC_PHONE_RING, 130 131 /** 132 * The conversation was terminated by the caller. 133 * We must no longer use the caller's handle. 134 */ 135 GNUNET_CONVERSATION_EC_PHONE_HUNG_UP 136 }; 137 138 139 /** 140 * Function called with an event emitted by a phone. 141 * 142 * @param cls closure 143 * @param code type of the event 144 * @param caller handle for the caller 145 * @param caller_id public key of the caller (in GNS) 146 */ 147 typedef void 148 (*GNUNET_CONVERSATION_PhoneEventHandler)(void *cls, 149 enum GNUNET_CONVERSATION_PhoneEventCode 150 code, 151 struct GNUNET_CONVERSATION_Caller * 152 caller, 153 const struct 154 GNUNET_CRYPTO_BlindablePublicKey * 155 caller_id); 156 157 158 /** 159 * Information about the current status of a call. Each call 160 * progresses from ring over ready to terminated. Steps may 161 * be skipped. 162 */ 163 enum GNUNET_CONVERSATION_CallerEventCode 164 { 165 /** 166 * We are the callee and the caller suspended the call. Note that 167 * both sides can independently suspend and resume calls; a call is 168 * only "working" of both sides are active. 169 */ 170 GNUNET_CONVERSATION_EC_CALLER_SUSPEND, 171 172 /** 173 * We are the callee and the caller resumed the call. Note that 174 * both sides can independently suspend and resume calls; a call is 175 * only "working" of both sides are active. 176 */ 177 GNUNET_CONVERSATION_EC_CALLER_RESUME 178 }; 179 180 181 /** 182 * Function called with an event emitted by a caller. 183 * These events are only generated after the phone is 184 * picked up. 185 * 186 * @param cls closure 187 * @param code type of the event for this caller 188 */ 189 typedef void 190 (*GNUNET_CONVERSATION_CallerEventHandler)(void *cls, 191 enum 192 GNUNET_CONVERSATION_CallerEventCode 193 code); 194 195 196 /** 197 * A phone is a device that can ring to signal an incoming call and 198 * that you can pick up to answer the call and hang up to terminate 199 * the call. You can also hang up a ringing phone immediately 200 * (without picking it up) to stop it from ringing. Phones have 201 * caller ID. You can ask the phone for its record and make that 202 * record available (via GNS) to enable others to call you. 203 * Multiple phones maybe connected to the same line (the line is 204 * something rather internal to a phone and not obvious from it). 205 * You can only have one conversation per phone at any time. 206 */ 207 struct GNUNET_CONVERSATION_Phone; 208 209 210 /** 211 * Create a new phone. 212 * 213 * @param cfg configuration for the phone; specifies the phone service and 214 * which line the phone is to be connected to 215 * @param ego ego to use for name resolution (when determining caller ID) 216 * @param event_handler how to notify the owner of the phone about events 217 * @param event_handler_cls closure for @a event_handler 218 */ 219 struct GNUNET_CONVERSATION_Phone * 220 GNUNET_CONVERSATION_phone_create (const struct GNUNET_CONFIGURATION_Handle *cfg, 221 const struct GNUNET_IDENTITY_Ego *ego, 222 GNUNET_CONVERSATION_PhoneEventHandler 223 event_handler, 224 void *event_handler_cls); 225 226 227 /** 228 * Fill in a namestore record with the contact information 229 * for this phone. Note that the filled in "data" value 230 * is only valid until the phone is destroyed. 231 * 232 * @param phone phone to create a record for 233 * @param rd namestore record to fill in 234 */ 235 void 236 GNUNET_CONVERSATION_phone_get_record (struct GNUNET_CONVERSATION_Phone *phone, 237 struct GNUNET_GNSRECORD_Data *rd); 238 239 240 /** 241 * Picks up a (ringing) phone call. This will connect the speaker 242 * to the microphone of the other party, and vice versa. 243 * 244 * @param caller handle that identifies which caller should be answered 245 * @param event_handler how to notify about events by the caller 246 * @param event_handler_cls closure for @a event_handler 247 * @param speaker speaker to use 248 * @param mic microphone to use 249 */ 250 void 251 GNUNET_CONVERSATION_caller_pick_up (struct GNUNET_CONVERSATION_Caller *caller, 252 GNUNET_CONVERSATION_CallerEventHandler 253 event_handler, 254 void *event_handler_cls, 255 struct GNUNET_SPEAKER_Handle *speaker, 256 struct GNUNET_MICROPHONE_Handle *mic); 257 258 259 /** 260 * Pause conversation of an active call. This will disconnect the speaker 261 * and the microphone. The call can later be resumed with 262 * #GNUNET_CONVERSATION_caller_resume. 263 * 264 * @param caller call to suspend 265 */ 266 void 267 GNUNET_CONVERSATION_caller_suspend (struct GNUNET_CONVERSATION_Caller *caller); 268 269 270 /** 271 * Resume suspended conversation of a phone. 272 * 273 * @param caller call to resume 274 * @param speaker speaker to use 275 * @param mic microphone to use 276 */ 277 void 278 GNUNET_CONVERSATION_caller_resume (struct GNUNET_CONVERSATION_Caller *caller, 279 struct GNUNET_SPEAKER_Handle *speaker, 280 struct GNUNET_MICROPHONE_Handle *mic); 281 282 283 /** 284 * Hang up up a (possibly ringing or paused) phone. This will notify 285 * the caller that we are no longer interested in talking with them. 286 * 287 * @param caller who should we hang up on 288 */ 289 void 290 GNUNET_CONVERSATION_caller_hang_up (struct GNUNET_CONVERSATION_Caller *caller); 291 292 293 /** 294 * Destroys a phone. 295 * 296 * @param phone phone to destroy 297 */ 298 void 299 GNUNET_CONVERSATION_phone_destroy (struct GNUNET_CONVERSATION_Phone *phone); 300 301 302 /* *********************** CALL API ************************ */ 303 304 /** 305 * Handle for an outgoing call. 306 */ 307 struct GNUNET_CONVERSATION_Call; 308 309 310 /** 311 * Information about the current status of a call. 312 */ 313 enum GNUNET_CONVERSATION_CallEventCode 314 { 315 /** 316 * We are the caller and are now ringing the other party (GNS lookup 317 * succeeded). 318 */ 319 GNUNET_CONVERSATION_EC_CALL_RINGING, 320 321 /** 322 * We are the caller and are now ready to talk as the callee picked up. 323 */ 324 GNUNET_CONVERSATION_EC_CALL_PICKED_UP, 325 326 /** 327 * We are the caller and failed to locate a phone record in GNS. 328 * After this invocation, the respective call handle will be 329 * automatically destroyed and the client must no longer call 330 * #GNUNET_CONVERSATION_call_stop or any other function on the 331 * call object. 332 */ 333 GNUNET_CONVERSATION_EC_CALL_GNS_FAIL, 334 335 /** 336 * We are the caller and the callee called 337 * #GNUNET_CONVERSATION_caller_hang_up. After this invocation, the 338 * respective call handle will be automatically destroyed and the 339 * client must no longer call #GNUNET_CONVERSATION_call_stop. 340 */ 341 GNUNET_CONVERSATION_EC_CALL_HUNG_UP, 342 343 /** 344 * We are the caller and the callee suspended the call. Note that 345 * both sides can independently suspend and resume calls; a call is 346 * only "working" of both sides are active. 347 */ 348 GNUNET_CONVERSATION_EC_CALL_SUSPENDED, 349 350 /** 351 * We are the caller and the callee suspended the call. Note that 352 * both sides can independently suspend and resume calls; a call is 353 * only "working" of both sides are active. 354 */ 355 GNUNET_CONVERSATION_EC_CALL_RESUMED, 356 357 /** 358 * We had an error handing the call, and are now restarting it 359 * (back to lookup). This happens, for example, if the peer 360 * is restarted during a call. 361 */ 362 GNUNET_CONVERSATION_EC_CALL_ERROR 363 }; 364 365 366 /** 367 * Function called with an event emitted for a call. 368 * 369 * @param cls closure 370 * @param code type of the event on the call 371 */ 372 typedef void 373 (*GNUNET_CONVERSATION_CallEventHandler)(void *cls, 374 enum GNUNET_CONVERSATION_CallEventCode 375 code); 376 377 378 /** 379 * Call the phone of another user. 380 * 381 * @param cfg configuration to use, specifies our phone service 382 * @param caller_id identity of the caller 383 * @param callee GNS name of the callee (used to locate the callee's record) 384 * @param speaker speaker to use (will be used automatically immediately once the 385 * #GNUNET_CONVERSATION_EC_CALL_PICKED_UP event is generated); we will NOT generate 386 * a ring tone on the speaker 387 * @param mic microphone to use (will be used automatically immediately once the 388 * #GNUNET_CONVERSATION_EC_CALL_PICKED_UP event is generated) 389 * @param event_handler how to notify the owner of the phone about events 390 * @param event_handler_cls closure for @a event_handler 391 * @return handle for the call 392 */ 393 struct GNUNET_CONVERSATION_Call * 394 GNUNET_CONVERSATION_call_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 395 struct GNUNET_IDENTITY_Ego *caller_id, 396 const char *callee, 397 struct GNUNET_SPEAKER_Handle *speaker, 398 struct GNUNET_MICROPHONE_Handle *mic, 399 GNUNET_CONVERSATION_CallEventHandler 400 event_handler, 401 void *event_handler_cls); 402 403 404 /** 405 * Pause a call. Temporarily suspends the use of speaker and 406 * microphone. 407 * 408 * @param call call to pause 409 */ 410 void 411 GNUNET_CONVERSATION_call_suspend (struct GNUNET_CONVERSATION_Call *call); 412 413 414 /** 415 * Resumes a call after #GNUNET_CONVERSATION_call_suspend. 416 * 417 * @param call call to resume 418 * @param speaker speaker to use 419 * @param mic microphone to use 420 */ 421 void 422 GNUNET_CONVERSATION_call_resume (struct GNUNET_CONVERSATION_Call *call, 423 struct GNUNET_SPEAKER_Handle *speaker, 424 struct GNUNET_MICROPHONE_Handle *mic); 425 426 427 /** 428 * Terminate a call. The call may be ringing or ready at this time. 429 * 430 * @param call call to terminate 431 */ 432 void 433 GNUNET_CONVERSATION_call_stop (struct GNUNET_CONVERSATION_Call *call); 434 435 436 #if 0 /* keep Emacsens' auto-indent happy */ 437 { 438 #endif 439 #ifdef __cplusplus 440 } 441 #endif 442 443 #endif 444 445 /** @} */ /* end of group */ 446 447 /** @} */ /* end of group addition */