gnunet_conversation_service.h 13 KB

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