agent.h 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749
  1. /*
  2. * This file is part of the Nice GLib ICE library.
  3. *
  4. * (C) 2006-2010 Collabora Ltd.
  5. * Contact: Youness Alaoui
  6. * (C) 2006-2010 Nokia Corporation. All rights reserved.
  7. * Contact: Kai Vehmanen
  8. *
  9. * The contents of this file are subject to the Mozilla Public License Version
  10. * 1.1 (the "License"); you may not use this file except in compliance with
  11. * the License. You may obtain a copy of the License at
  12. * http://www.mozilla.org/MPL/
  13. *
  14. * Software distributed under the License is distributed on an "AS IS" basis,
  15. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  16. * for the specific language governing rights and limitations under the
  17. * License.
  18. *
  19. * The Original Code is the Nice GLib ICE library.
  20. *
  21. * The Initial Developers of the Original Code are Collabora Ltd and Nokia
  22. * Corporation. All Rights Reserved.
  23. *
  24. * Contributors:
  25. * Dafydd Harries, Collabora Ltd.
  26. * Youness Alaoui, Collabora Ltd.
  27. * Kai Vehmanen, Nokia
  28. *
  29. * Alternatively, the contents of this file may be used under the terms of the
  30. * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
  31. * case the provisions of LGPL are applicable instead of those above. If you
  32. * wish to allow use of your version of this file only under the terms of the
  33. * LGPL and not to allow others to use your version of this file under the
  34. * MPL, indicate your decision by deleting the provisions above and replace
  35. * them with the notice and other provisions required by the LGPL. If you do
  36. * not delete the provisions above, a recipient may use your version of this
  37. * file under either the MPL or the LGPL.
  38. */
  39. #ifndef __LIBNICE_AGENT_H__
  40. #define __LIBNICE_AGENT_H__
  41. /**
  42. * SECTION:agent
  43. * @short_description: ICE agent API implementation
  44. * @see_also: #NiceCandidate, #NiceAddress
  45. * @include: agent.h
  46. * @stability: Stable
  47. *
  48. * The #NiceAgent is your main object when using libnice.
  49. * It is the agent that will take care of everything relating to ICE.
  50. * It will take care of discovering your local candidates and do
  51. * connectivity checks to create a stream of data between you and your peer.
  52. *
  53. * A #NiceAgent must always be used with a #GMainLoop running the #GMainContext
  54. * passed into nice_agent_new() (or nice_agent_new_reliable()). Without the
  55. * #GMainContext being iterated, the agent’s timers will not fire, etc.
  56. *
  57. * Streams and their components are referenced by integer IDs (with respect to a
  58. * given #NiceAgent). These IDs are guaranteed to be positive (i.e. non-zero)
  59. * for valid streams/components.
  60. *
  61. * To complete the ICE connectivity checks, the user must either register
  62. * an I/O callback (with nice_agent_attach_recv()) or call nice_agent_recv_messages()
  63. * in a loop on a dedicated thread.
  64. * Technically, #NiceAgent does not poll the streams on its own, since
  65. * user data could arrive at any time; to receive STUN packets
  66. * required for establishing ICE connectivity, it is backpiggying
  67. * on the facility chosen by the user. #NiceAgent will handle all STUN
  68. * packets internally; they're never actually passed to the I/O callback
  69. * or returned from nice_agent_recv_messages() and related functions.
  70. *
  71. * Each stream can receive data in one of two ways: using
  72. * nice_agent_attach_recv() or nice_agent_recv_messages() (and the derived
  73. * #NiceInputStream and #NiceIOStream classes accessible using
  74. * nice_agent_get_io_stream()). nice_agent_attach_recv() is non-blocking: it
  75. * takes a user-provided callback function and attaches the stream’s socket to
  76. * the provided #GMainContext, invoking the callback in that context for every
  77. * packet received. nice_agent_recv_messages() instead blocks on receiving a
  78. * packet, and writes it directly into a user-provided buffer. This reduces the
  79. * number of callback invokations and (potentially) buffer copies required to
  80. * receive packets. nice_agent_recv_messages() (or #NiceInputStream) is designed
  81. * to be used in a blocking loop in a separate thread.
  82. *
  83. * <example>
  84. * <title>Simple example on how to use libnice</title>
  85. * <programlisting>
  86. * guint stream_id;
  87. * gchar buffer[] = "hello world!";
  88. * gchar *ufrag = NULL, *pwd = NULL;
  89. * gchar *remote_ufrag, *remote_pwd;
  90. * GSList *lcands = NULL;
  91. *
  92. * // Create a nice agent, passing in the global default GMainContext.
  93. * NiceAgent *agent = nice_agent_new (NULL, NICE_COMPATIBILITY_RFC5245);
  94. * spawn_thread_to_run_main_loop (g_main_loop_new (NULL, FALSE));
  95. *
  96. * // Connect the signals
  97. * g_signal_connect (G_OBJECT (agent), "candidate-gathering-done",
  98. * G_CALLBACK (cb_candidate_gathering_done), NULL);
  99. * g_signal_connect (G_OBJECT (agent), "component-state-changed",
  100. * G_CALLBACK (cb_component_state_changed), NULL);
  101. * g_signal_connect (G_OBJECT (agent), "new-selected-pair",
  102. * G_CALLBACK (cb_new_selected_pair), NULL);
  103. *
  104. * // Create a new stream with one component and start gathering candidates
  105. * stream_id = nice_agent_add_stream (agent, 1);
  106. * nice_agent_gather_candidates (agent, stream_id);
  107. *
  108. * // Attach I/O callback the component to ensure that:
  109. * // 1) agent gets its STUN packets (not delivered to cb_nice_recv)
  110. * // 2) you get your own data
  111. * nice_agent_attach_recv (agent, stream_id, 1, NULL,
  112. * cb_nice_recv, NULL);
  113. *
  114. * // ... Wait until the signal candidate-gathering-done is fired ...
  115. * lcands = nice_agent_get_local_candidates(agent, stream_id, 1);
  116. * nice_agent_get_local_credentials(agent, stream_id, &ufrag, &pwd);
  117. *
  118. * // ... Send local candidates and credentials to the peer
  119. *
  120. * // Set the peer's remote credentials and remote candidates
  121. * nice_agent_set_remote_credentials (agent, stream_id, remote_ufrag, remote_pwd);
  122. * nice_agent_set_remote_candidates (agent, stream_id, 1, rcands);
  123. *
  124. * // ... Wait until the signal new-selected-pair is fired ...
  125. * // Send our message!
  126. * nice_agent_send (agent, stream_id, 1, sizeof(buffer), buffer);
  127. *
  128. * // Anything received will be received through the cb_nice_recv callback.
  129. * // You must be running a GMainLoop on the global default GMainContext in
  130. * // another thread for this to work.
  131. *
  132. * // Destroy the object
  133. * g_object_unref(agent);
  134. *
  135. * </programlisting>
  136. * </example>
  137. *
  138. * Refer to the examples in the examples/ subdirectory of the libnice source for
  139. * more complete examples.
  140. *
  141. */
  142. #include <glib-object.h>
  143. #include <gio/gio.h>
  144. /**
  145. * NiceAgent:
  146. *
  147. * The #NiceAgent is the main GObject of the libnice library and represents
  148. * the ICE agent.
  149. */
  150. typedef struct _NiceAgent NiceAgent;
  151. #include "address.h"
  152. #include "candidate.h"
  153. #include "debug.h"
  154. G_BEGIN_DECLS
  155. /**
  156. * NiceInputMessage:
  157. * @buffers: (array length=n_buffers): unowned array of #GInputVector buffers to
  158. * store data in for this message
  159. * @n_buffers: number of #GInputVectors in @buffers, or -1 to indicate @buffers
  160. * is %NULL-terminated
  161. * @from: (allow-none): return location to store the address of the peer who
  162. * transmitted the message, or %NULL
  163. * @length: total number of valid bytes contiguously stored in @buffers
  164. *
  165. * Represents a single message received off the network. For reliable
  166. * connections, this is essentially just an array of buffers (specifically,
  167. * @from can be ignored). for non-reliable connections, it represents a single
  168. * packet as received from the OS.
  169. *
  170. * @n_buffers may be -1 to indicate that @buffers is terminated by a
  171. * #GInputVector with a %NULL buffer pointer.
  172. *
  173. * By providing arrays of #NiceInputMessages to functions like
  174. * nice_agent_recv_messages(), multiple messages may be received with a single
  175. * call, which is more efficient than making multiple calls in a loop. In this
  176. * manner, nice_agent_recv_messages() is analogous to recvmmsg(); and
  177. * #NiceInputMessage to struct mmsghdr.
  178. *
  179. * Since: 0.1.5
  180. */
  181. typedef struct {
  182. GInputVector *buffers;
  183. gint n_buffers; /* may be -1 to indicate @buffers is NULL-terminated */
  184. NiceAddress *from; /* return location for address of message sender */
  185. gsize length; /* sum of the lengths of @buffers */
  186. } NiceInputMessage;
  187. /**
  188. * NiceOutputMessage:
  189. * @buffers: (array length=n_buffers): unowned array of #GOutputVector buffers
  190. * which contain data to transmit for this message
  191. * @n_buffers: number of #GOutputVectors in @buffers, or -1 to indicate @buffers
  192. * is %NULL-terminated
  193. *
  194. * Represents a single message to transmit on the network. For
  195. * reliable connections, this is essentially just an array of
  196. * buffer. for non-reliable connections, it represents a single packet
  197. * to send to the OS.
  198. *
  199. * @n_buffers may be -1 to indicate that @buffers is terminated by a
  200. * #GOutputVector with a %NULL buffer pointer.
  201. *
  202. * By providing arrays of #NiceOutputMessages to functions like
  203. * nice_agent_send_messages_nonblocking(), multiple messages may be transmitted
  204. * with a single call, which is more efficient than making multiple calls in a
  205. * loop. In this manner, nice_agent_send_messages_nonblocking() is analogous to
  206. * sendmmsg(); and #NiceOutputMessage to struct mmsghdr.
  207. *
  208. * Since: 0.1.5
  209. */
  210. typedef struct {
  211. GOutputVector *buffers;
  212. gint n_buffers;
  213. } NiceOutputMessage;
  214. #define NICE_TYPE_AGENT nice_agent_get_type()
  215. #define NICE_AGENT(obj) \
  216. (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
  217. NICE_TYPE_AGENT, NiceAgent))
  218. #define NICE_AGENT_CLASS(klass) \
  219. (G_TYPE_CHECK_CLASS_CAST ((klass), \
  220. NICE_TYPE_AGENT, NiceAgentClass))
  221. #define NICE_IS_AGENT(obj) \
  222. (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
  223. NICE_TYPE_AGENT))
  224. #define NICE_IS_AGENT_CLASS(klass) \
  225. (G_TYPE_CHECK_CLASS_TYPE ((klass), \
  226. NICE_TYPE_AGENT))
  227. #define NICE_AGENT_GET_CLASS(obj) \
  228. (G_TYPE_INSTANCE_GET_CLASS ((obj), \
  229. NICE_TYPE_AGENT, NiceAgentClass))
  230. typedef struct _NiceAgentClass NiceAgentClass;
  231. struct _NiceAgentClass
  232. {
  233. GObjectClass parent_class;
  234. };
  235. GType nice_agent_get_type (void);
  236. /**
  237. * NICE_AGENT_MAX_REMOTE_CANDIDATES:
  238. *
  239. * A hard limit for the number of remote candidates. This
  240. * limit is enforced to protect against malevolent remote
  241. * clients.
  242. */
  243. #define NICE_AGENT_MAX_REMOTE_CANDIDATES 25
  244. /**
  245. * NiceComponentState:
  246. * @NICE_COMPONENT_STATE_DISCONNECTED: No activity scheduled
  247. * @NICE_COMPONENT_STATE_GATHERING: Gathering local candidates
  248. * @NICE_COMPONENT_STATE_CONNECTING: Establishing connectivity
  249. * @NICE_COMPONENT_STATE_CONNECTED: At least one working candidate pair
  250. * @NICE_COMPONENT_STATE_READY: ICE concluded, candidate pair selection
  251. * is now final
  252. * @NICE_COMPONENT_STATE_FAILED: Connectivity checks have been completed,
  253. * but connectivity was not established
  254. * @NICE_COMPONENT_STATE_LAST: Dummy state
  255. *
  256. * An enum representing the state of a component.
  257. * <para> See also: #NiceAgent::component-state-changed </para>
  258. */
  259. typedef enum
  260. {
  261. NICE_COMPONENT_STATE_DISCONNECTED,
  262. NICE_COMPONENT_STATE_GATHERING,
  263. NICE_COMPONENT_STATE_CONNECTING,
  264. NICE_COMPONENT_STATE_CONNECTED,
  265. NICE_COMPONENT_STATE_READY,
  266. NICE_COMPONENT_STATE_FAILED,
  267. NICE_COMPONENT_STATE_LAST
  268. } NiceComponentState;
  269. /**
  270. * NiceComponentType:
  271. * @NICE_COMPONENT_TYPE_RTP: RTP Component type
  272. * @NICE_COMPONENT_TYPE_RTCP: RTCP Component type
  273. *
  274. * Convenience enum representing the type of a component for use as the
  275. * component_id for RTP/RTCP usages.
  276. <example>
  277. <title>Example of use.</title>
  278. <programlisting>
  279. nice_agent_send (agent, stream_id, NICE_COMPONENT_TYPE_RTP, len, buf);
  280. </programlisting>
  281. </example>
  282. */
  283. typedef enum
  284. {
  285. NICE_COMPONENT_TYPE_RTP = 1,
  286. NICE_COMPONENT_TYPE_RTCP = 2
  287. } NiceComponentType;
  288. /**
  289. * NiceCompatibility:
  290. * @NICE_COMPATIBILITY_RFC5245: Use compatibility with the RFC5245 ICE-UDP specs
  291. * and RFC6544 ICE-TCP specs
  292. * @NICE_COMPATIBILITY_GOOGLE: Use compatibility for Google Talk specs
  293. * @NICE_COMPATIBILITY_MSN: Use compatibility for MSN Messenger specs
  294. * @NICE_COMPATIBILITY_WLM2009: Use compatibility with Windows Live Messenger
  295. * 2009
  296. * @NICE_COMPATIBILITY_OC2007: Use compatibility with Microsoft Office Communicator 2007
  297. * @NICE_COMPATIBILITY_OC2007R2: Use compatibility with Microsoft Office Communicator 2007 R2
  298. * @NICE_COMPATIBILITY_DRAFT19: Use compatibility for ICE Draft 19 specs
  299. * @NICE_COMPATIBILITY_LAST: Dummy last compatibility mode
  300. *
  301. * An enum to specify which compatible specifications the #NiceAgent should use.
  302. * Use with nice_agent_new()
  303. *
  304. * <warning>@NICE_COMPATIBILITY_DRAFT19 is deprecated and should not be used
  305. * in newly-written code. It is kept for compatibility reasons and
  306. * represents the same compatibility as @NICE_COMPATIBILITY_RFC5245 </warning>
  307. <note>
  308. <para>
  309. If @NICE_COMPATIBILITY_RFC5245 compatibility mode is used for a non-reliable
  310. agent, then ICE-UDP will be used with higher priority and ICE-TCP will also
  311. be used when the UDP connectivity fails. If it is used with a reliable agent,
  312. then ICE-UDP will be used with the TCP-Over-UDP (#PseudoTcpSocket) if ICE-TCP
  313. fails and ICE-UDP succeeds.
  314. </para>
  315. </note>
  316. *
  317. */
  318. typedef enum
  319. {
  320. NICE_COMPATIBILITY_RFC5245 = 0,
  321. NICE_COMPATIBILITY_DRAFT19 = NICE_COMPATIBILITY_RFC5245,
  322. NICE_COMPATIBILITY_GOOGLE,
  323. NICE_COMPATIBILITY_MSN,
  324. NICE_COMPATIBILITY_WLM2009,
  325. NICE_COMPATIBILITY_OC2007,
  326. NICE_COMPATIBILITY_OC2007R2,
  327. NICE_COMPATIBILITY_LAST = NICE_COMPATIBILITY_OC2007R2,
  328. } NiceCompatibility;
  329. /**
  330. * NiceProxyType:
  331. * @NICE_PROXY_TYPE_NONE: Do not use a proxy
  332. * @NICE_PROXY_TYPE_SOCKS5: Use a SOCKS5 proxy
  333. * @NICE_PROXY_TYPE_HTTP: Use an HTTP proxy
  334. * @NICE_PROXY_TYPE_LAST: Dummy last proxy type
  335. *
  336. * An enum to specify which proxy type to use for relaying.
  337. * Note that the proxies will only be used with TCP TURN relaying.
  338. * <para> See also: #NiceAgent:proxy-type </para>
  339. *
  340. * Since: 0.0.4
  341. */
  342. typedef enum
  343. {
  344. NICE_PROXY_TYPE_NONE = 0,
  345. NICE_PROXY_TYPE_SOCKS5,
  346. NICE_PROXY_TYPE_HTTP,
  347. NICE_PROXY_TYPE_LAST = NICE_PROXY_TYPE_HTTP,
  348. } NiceProxyType;
  349. /**
  350. * NiceNominationMode:
  351. * @NICE_NOMINATION_MODE_AGGRESSIVE: Aggressive nomination mode
  352. * @NICE_NOMINATION_MODE_REGULAR: Regular nomination mode
  353. *
  354. * An enum to specity the kind of nomination mode to use by
  355. * the agent, as described in RFC 5245. Two modes exists,
  356. * regular and aggressive. They differ by the way the controlling
  357. * agent chooses to put the USE-CANDIDATE attribute in its STUN
  358. * messages. The aggressive mode is supposed to nominate a pair
  359. * faster, than the regular mode, potentially causing the nominated
  360. * pair to change until the connection check completes.
  361. *
  362. * Since: 0.1.15
  363. */
  364. typedef enum
  365. {
  366. NICE_NOMINATION_MODE_REGULAR = 0,
  367. NICE_NOMINATION_MODE_AGGRESSIVE,
  368. } NiceNominationMode;
  369. /**
  370. * NiceAgentOption:
  371. * @NICE_AGENT_OPTION_NONE: No enabled options (Since: 0.1.19)
  372. * @NICE_AGENT_OPTION_REGULAR_NOMINATION: Enables regular nomination, default
  373. * is aggrssive mode (see #NiceNominationMode).
  374. * @NICE_AGENT_OPTION_RELIABLE: Enables reliable mode, possibly using PseudoTCP, * see nice_agent_new_reliable().
  375. * @NICE_AGENT_OPTION_LITE_MODE: Enable lite mode
  376. * @NICE_AGENT_OPTION_ICE_TRICKLE: Enable ICE trickle mode
  377. * @NICE_AGENT_OPTION_SUPPORT_RENOMINATION: Enable renomination triggered by NOMINATION STUN attribute
  378. * proposed here: https://tools.ietf.org/html/draft-thatcher-ice-renomination-00
  379. * @NICE_AGENT_OPTION_CONSENT_FRESHNESS: Enable RFC 7675 consent freshness support. (Since: 0.1.19)
  380. * @NICE_AGENT_OPTION_BYTESTREAM_TCP: Use bytestream mode for reliable TCP connections. (Since: 0.1.20)
  381. *
  382. * These are options that can be passed to nice_agent_new_full(). They set
  383. * various properties on the agent. Not including them sets the property to
  384. * the other value.
  385. *
  386. * Since: 0.1.15
  387. */
  388. typedef enum {
  389. NICE_AGENT_OPTION_NONE = 0,
  390. NICE_AGENT_OPTION_REGULAR_NOMINATION = 1 << 0,
  391. NICE_AGENT_OPTION_RELIABLE = 1 << 1,
  392. NICE_AGENT_OPTION_LITE_MODE = 1 << 2,
  393. NICE_AGENT_OPTION_ICE_TRICKLE = 1 << 3,
  394. NICE_AGENT_OPTION_SUPPORT_RENOMINATION = 1 << 4,
  395. NICE_AGENT_OPTION_CONSENT_FRESHNESS = 1 << 5,
  396. NICE_AGENT_OPTION_BYTESTREAM_TCP = 1 << 6,
  397. } NiceAgentOption;
  398. /**
  399. * NiceAgentRecvFunc:
  400. * @agent: The #NiceAgent Object
  401. * @stream_id: The id of the stream
  402. * @component_id: The id of the component of the stream
  403. * which received the data
  404. * @len: The length of the data
  405. * @buf: The buffer containing the data received
  406. * @user_data: The user data set in nice_agent_attach_recv()
  407. *
  408. * Callback function when data is received on a component
  409. *
  410. */
  411. typedef void (*NiceAgentRecvFunc) (
  412. NiceAgent *agent, guint stream_id, guint component_id, guint len,
  413. gchar *buf, gpointer user_data);
  414. /**
  415. * nice_agent_new:
  416. * @ctx: The Glib Mainloop Context to use for timers
  417. * @compat: The compatibility mode of the agent
  418. *
  419. * Create a new #NiceAgent.
  420. * The returned object must be freed with g_object_unref()
  421. *
  422. * Returns: The new agent GObject
  423. */
  424. NiceAgent *
  425. nice_agent_new (GMainContext *ctx, NiceCompatibility compat);
  426. /**
  427. * nice_agent_new_reliable:
  428. * @ctx: The Glib Mainloop Context to use for timers
  429. * @compat: The compatibility mode of the agent
  430. *
  431. * Create a new #NiceAgent in reliable mode. If the connectivity is established
  432. * through ICE-UDP, then a #PseudoTcpSocket will be transparently used to
  433. * ensure reliability of the messages.
  434. * The returned object must be freed with g_object_unref()
  435. * <para> See also: #NiceAgent::reliable-transport-writable </para>
  436. *
  437. * Since: 0.0.11
  438. *
  439. * Returns: The new agent GObject
  440. */
  441. NiceAgent *
  442. nice_agent_new_reliable (GMainContext *ctx, NiceCompatibility compat);
  443. /**
  444. * nice_agent_new_full:
  445. * @ctx: The Glib Mainloop Context to use for timers
  446. * @compat: The compatibility mode of the agent
  447. * @flags: Flags to set the properties
  448. *
  449. * Create a new #NiceAgent with parameters that must be be defined at
  450. * construction time.
  451. * The returned object must be freed with g_object_unref()
  452. * <para> See also: #NiceNominationMode and #NiceAgentOption</para>
  453. *
  454. * Since: 0.1.15
  455. *
  456. * Returns: The new agent GObject
  457. */
  458. NiceAgent *
  459. nice_agent_new_full (GMainContext *ctx,
  460. NiceCompatibility compat,
  461. NiceAgentOption flags);
  462. /**
  463. * nice_agent_add_local_address:
  464. * @agent: The #NiceAgent Object
  465. * @addr: The address to listen to
  466. * If the port is 0, then a random port will be chosen by the system
  467. *
  468. * Add a local address from which to derive local host candidates for
  469. * candidate gathering.
  470. * <para>
  471. * Since 0.0.5, if this method is not called, libnice will automatically
  472. * discover the local addresses available
  473. * </para>
  474. *
  475. * See also: nice_agent_gather_candidates()
  476. * Returns: %TRUE on success, %FALSE on fatal (memory allocation) errors
  477. */
  478. gboolean
  479. nice_agent_add_local_address (NiceAgent *agent, NiceAddress *addr);
  480. /**
  481. * nice_agent_add_stream:
  482. * @agent: The #NiceAgent Object
  483. * @n_components: The number of components to add to the stream
  484. *
  485. * Adds a data stream to @agent containing @n_components components. The
  486. * returned stream ID is guaranteed to be positive on success.
  487. *
  488. * Returns: The ID of the new stream, 0 on failure
  489. **/
  490. guint
  491. nice_agent_add_stream (
  492. NiceAgent *agent,
  493. guint n_components);
  494. /**
  495. * nice_agent_remove_stream:
  496. * @agent: The #NiceAgent Object
  497. * @stream_id: The ID of the stream to remove
  498. *
  499. * Remove and free a previously created data stream from @agent. If any I/O
  500. * streams have been created using nice_agent_get_io_stream(), they should be
  501. * closed completely using g_io_stream_close() before this is called, or they
  502. * will get broken pipe errors.
  503. *
  504. **/
  505. void
  506. nice_agent_remove_stream (
  507. NiceAgent *agent,
  508. guint stream_id);
  509. /**
  510. * nice_agent_set_port_range:
  511. * @agent: The #NiceAgent Object
  512. * @stream_id: The ID of the stream
  513. * @component_id: The ID of the component
  514. * @min_port: The minimum port to use
  515. * @max_port: The maximum port to use
  516. *
  517. * Sets a preferred port range for allocating host candidates.
  518. * <para>
  519. * If a local host candidate cannot be created on that port
  520. * range, then the nice_agent_gather_candidates() call will fail.
  521. * </para>
  522. * <para>
  523. * This MUST be called before nice_agent_gather_candidates()
  524. * </para>
  525. *
  526. */
  527. void
  528. nice_agent_set_port_range (
  529. NiceAgent *agent,
  530. guint stream_id,
  531. guint component_id,
  532. guint min_port,
  533. guint max_port);
  534. /**
  535. * nice_agent_set_relay_info:
  536. * @agent: The #NiceAgent Object
  537. * @stream_id: The ID of the stream
  538. * @component_id: The ID of the component
  539. * @server_ip: The IP address of the TURN server
  540. * @server_port: The port of the TURN server
  541. * @username: The TURN username to use for the allocate
  542. * @password: The TURN password to use for the allocate
  543. * @type: The type of relay to use
  544. *
  545. * Sets the settings for using a relay server during the candidate discovery.
  546. * This may be called multiple times to add multiple relay servers to the
  547. * discovery process; one TCP and one UDP, for example.
  548. *
  549. * Returns: %TRUE if the TURN settings were accepted.
  550. * %FALSE if the address was invalid.
  551. */
  552. gboolean nice_agent_set_relay_info(
  553. NiceAgent *agent,
  554. guint stream_id,
  555. guint component_id,
  556. const gchar *server_ip,
  557. guint server_port,
  558. const gchar *username,
  559. const gchar *password,
  560. NiceRelayType type);
  561. /**
  562. * nice_agent_gather_candidates:
  563. * @agent: The #NiceAgent object
  564. * @stream_id: The ID of the stream to start
  565. *
  566. * Allocate and start listening on local candidate ports and start the remote
  567. * candidate gathering process.
  568. * Once done, #NiceAgent::candidate-gathering-done is called for the stream.
  569. * As soon as this function is called, #NiceAgent::new-candidate signals may be
  570. * emitted, even before this function returns.
  571. *
  572. * nice_agent_get_local_candidates() will only return non-empty results after
  573. * calling this function.
  574. *
  575. * <para>See also: nice_agent_add_local_address()</para>
  576. * <para>See also: nice_agent_set_port_range()</para>
  577. *
  578. * Returns: %FALSE if the stream ID is invalid or if a host candidate couldn't
  579. * be allocated on the requested interfaces/ports; %TRUE otherwise
  580. *
  581. <note>
  582. <para>
  583. Local addresses can be previously set with nice_agent_add_local_address()
  584. </para>
  585. <para>
  586. Since 0.0.5, If no local address was previously added, then the nice agent
  587. will automatically detect the local address using
  588. nice_interfaces_get_local_ips()
  589. </para>
  590. </note>
  591. */
  592. gboolean
  593. nice_agent_gather_candidates (
  594. NiceAgent *agent,
  595. guint stream_id);
  596. /**
  597. * nice_agent_set_remote_credentials:
  598. * @agent: The #NiceAgent Object
  599. * @stream_id: The ID of the stream
  600. * @ufrag: nul-terminated string containing an ICE username fragment
  601. * (length must be between 22 and 256 chars)
  602. * @pwd: nul-terminated string containing an ICE password
  603. * (length must be between 4 and 256 chars)
  604. *
  605. * Sets the remote credentials for stream @stream_id.
  606. *
  607. <note>
  608. <para>
  609. Stream credentials do not override per-candidate credentials if set
  610. </para>
  611. <para>
  612. Due to the native of peer-reflexive candidates, any agent using a per-stream
  613. credentials (RFC5245, WLM2009, OC2007R2 and DRAFT19) instead of
  614. per-candidate credentials (GOOGLE, MSN, OC2007), must
  615. use the nice_agent_set_remote_credentials() API instead of setting the
  616. username and password on the candidates.
  617. </para>
  618. </note>
  619. *
  620. * Returns: %TRUE on success, %FALSE on error.
  621. */
  622. gboolean
  623. nice_agent_set_remote_credentials (
  624. NiceAgent *agent,
  625. guint stream_id,
  626. const gchar *ufrag, const gchar *pwd);
  627. /**
  628. * nice_agent_set_local_credentials:
  629. * @agent: The #NiceAgent Object
  630. * @stream_id: The ID of the stream
  631. * @ufrag: nul-terminated string containing an ICE username fragment
  632. * (length must be between 22 and 256 chars)
  633. * @pwd: nul-terminated string containing an ICE password
  634. * (length must be between 4 and 256 chars)
  635. *
  636. * Sets the local credentials for stream @stream_id.
  637. *
  638. <note>
  639. <para>
  640. This is only effective before ICE negotiation has started.
  641. </para>
  642. </note>
  643. *
  644. * Since 0.1.11
  645. * Returns: %TRUE on success, %FALSE on error.
  646. */
  647. gboolean
  648. nice_agent_set_local_credentials (
  649. NiceAgent *agent,
  650. guint stream_id,
  651. const gchar *ufrag,
  652. const gchar *pwd);
  653. /**
  654. * nice_agent_get_local_credentials:
  655. * @agent: The #NiceAgent Object
  656. * @stream_id: The ID of the stream
  657. * @ufrag: (out callee-allocates): return location for a nul-terminated string
  658. * containing an ICE username fragment; must be freed with g_free()
  659. * @pwd: (out callee-allocates): return location for a nul-terminated string
  660. * containing an ICE password; must be freed with g_free()
  661. *
  662. * Gets the local credentials for stream @stream_id. This may be called any time
  663. * after creating a stream using nice_agent_add_stream().
  664. *
  665. * An error will be returned if this is called for a non-existent stream, or if
  666. * either of @ufrag or @pwd are %NULL.
  667. *
  668. * Returns: %TRUE on success, %FALSE on error.
  669. */
  670. gboolean
  671. nice_agent_get_local_credentials (
  672. NiceAgent *agent,
  673. guint stream_id,
  674. gchar **ufrag, gchar **pwd);
  675. /**
  676. * nice_agent_set_remote_candidates:
  677. * @agent: The #NiceAgent Object
  678. * @stream_id: The ID of the stream the candidates are for
  679. * @component_id: The ID of the component the candidates are for
  680. * @candidates: (element-type NiceCandidate) (transfer none): a #GSList of
  681. * #NiceCandidate items describing each candidate to add
  682. *
  683. * Sets, adds or updates the remote candidates for a component of a stream.
  684. *
  685. <note>
  686. <para>
  687. NICE_AGENT_MAX_REMOTE_CANDIDATES is the absolute maximum limit
  688. for remote candidates.
  689. </para>
  690. <para>
  691. You must first call nice_agent_gather_candidates() and wait for the
  692. #NiceAgent::candidate-gathering-done signale before
  693. calling nice_agent_set_remote_candidates()
  694. </para>
  695. <para>
  696. Since 0.1.3, there is no need to wait for the candidate-gathering-done signal.
  697. Remote candidates can be set even while gathering local candidates.
  698. Newly discovered local candidates will automatically be paired with
  699. existing remote candidates.
  700. </para>
  701. </note>
  702. *
  703. * Returns: The number of candidates added, negative on errors (memory
  704. * allocation error or invalid component)
  705. **/
  706. int
  707. nice_agent_set_remote_candidates (
  708. NiceAgent *agent,
  709. guint stream_id,
  710. guint component_id,
  711. const GSList *candidates);
  712. /**
  713. * nice_agent_send:
  714. * @agent: The #NiceAgent Object
  715. * @stream_id: The ID of the stream to send to
  716. * @component_id: The ID of the component to send to
  717. * @len: The length of the buffer to send
  718. * @buf: The buffer of data to send
  719. *
  720. * Sends a data payload over a stream's component.
  721. *
  722. <note>
  723. <para>
  724. Component state MUST be NICE_COMPONENT_STATE_READY, or as a special case,
  725. in any state if component was in READY state before and was then restarted
  726. </para>
  727. <para>
  728. In reliable mode, the -1 error value means either that you are not yet
  729. connected or that the send buffer is full (equivalent to EWOULDBLOCK).
  730. In both cases, you simply need to wait for the
  731. #NiceAgent::reliable-transport-writable signal to be fired before resending
  732. the data.
  733. </para>
  734. <para>
  735. In non-reliable mode, it will virtually never happen with UDP sockets, but
  736. it might happen if the active candidate is a TURN-TCP connection that got
  737. disconnected.
  738. </para>
  739. <para>
  740. In both reliable and non-reliable mode, a -1 error code could also mean that
  741. the stream_id and/or component_id are invalid.
  742. </para>
  743. </note>
  744. *
  745. * Returns: The number of bytes sent, or negative error code
  746. */
  747. gint
  748. nice_agent_send (
  749. NiceAgent *agent,
  750. guint stream_id,
  751. guint component_id,
  752. guint len,
  753. const gchar *buf);
  754. /**
  755. * nice_agent_send_messages_nonblocking:
  756. * @agent: a #NiceAgent
  757. * @stream_id: the ID of the stream to send to
  758. * @component_id: the ID of the component to send to
  759. * @messages: (array length=n_messages): array of messages to send, of at least
  760. * @n_messages entries in length
  761. * @n_messages: number of entries in @messages
  762. * @cancellable: (allow-none): a #GCancellable to cancel the operation from
  763. * another thread, or %NULL
  764. * @error: (allow-none): return location for a #GError, or %NULL
  765. *
  766. * Sends multiple messages on the socket identified by the given
  767. * stream/component pair. Transmission is non-blocking, so a
  768. * %G_IO_ERROR_WOULD_BLOCK error may be returned if the send buffer is full.
  769. *
  770. * As with nice_agent_send(), the given component must be in
  771. * %NICE_COMPONENT_STATE_READY or, as a special case, in any state if it was
  772. * previously ready and was then restarted.
  773. *
  774. * On success, the number of messages written to the socket will be returned,
  775. * which may be less than @n_messages if transmission would have blocked
  776. * part-way through. Zero will be returned if @n_messages is zero, or if
  777. * transmission would have blocked on the first message.
  778. *
  779. * In reliable mode, it is instead recommended to use
  780. * nice_agent_send(). The return value can be less than @n_messages
  781. * or 0 even if it is still possible to send a partial message. In
  782. * this case, "nice-agent-writable" will never be triggered, so the
  783. * application would have to use nice_agent_sent() to fill the buffer or have
  784. * to retry sending at a later point.
  785. *
  786. * On failure, -1 will be returned and @error will be set. If the #NiceAgent is
  787. * reliable and the socket is not yet connected, %G_IO_ERROR_BROKEN_PIPE will be
  788. * returned; if the write buffer is full, %G_IO_ERROR_WOULD_BLOCK will be
  789. * returned. In both cases, wait for the #NiceAgent::reliable-transport-writable
  790. * signal before trying again. If the given @stream_id or @component_id are
  791. * invalid or not yet connected, %G_IO_ERROR_BROKEN_PIPE will be returned.
  792. * %G_IO_ERROR_FAILED will be returned for other errors.
  793. *
  794. * Returns: the number of messages sent (may be zero), or -1 on error
  795. *
  796. * Since: 0.1.5
  797. */
  798. gint
  799. nice_agent_send_messages_nonblocking (
  800. NiceAgent *agent,
  801. guint stream_id,
  802. guint component_id,
  803. const NiceOutputMessage *messages,
  804. guint n_messages,
  805. GCancellable *cancellable,
  806. GError **error);
  807. /**
  808. * nice_agent_get_local_candidates:
  809. * @agent: The #NiceAgent Object
  810. * @stream_id: The ID of the stream
  811. * @component_id: The ID of the component
  812. *
  813. * Retrieve from the agent the list of all local candidates
  814. * for a stream's component
  815. *
  816. <note>
  817. <para>
  818. The caller owns the returned GSList as well as the candidates contained
  819. within it.
  820. To get full results, the client should wait for the
  821. #NiceAgent::candidate-gathering-done signal.
  822. </para>
  823. </note>
  824. *
  825. * Returns: (element-type NiceCandidate) (transfer full): a #GSList of
  826. * #NiceCandidate objects representing the local candidates of @agent
  827. **/
  828. GSList *
  829. nice_agent_get_local_candidates (
  830. NiceAgent *agent,
  831. guint stream_id,
  832. guint component_id);
  833. /**
  834. * nice_agent_get_remote_candidates:
  835. * @agent: The #NiceAgent Object
  836. * @stream_id: The ID of the stream
  837. * @component_id: The ID of the component
  838. *
  839. * Get a list of the remote candidates set on a stream's component
  840. *
  841. <note>
  842. <para>
  843. The caller owns the returned GSList as well as the candidates contained
  844. within it.
  845. </para>
  846. <para>
  847. The list of remote candidates can change during processing.
  848. The client should register for the #NiceAgent::new-remote-candidate signal
  849. to get notified of new remote candidates.
  850. </para>
  851. </note>
  852. *
  853. * Returns: (element-type NiceCandidate) (transfer full): a #GSList of
  854. * #NiceCandidates objects representing the remote candidates set on the @agent
  855. **/
  856. GSList *
  857. nice_agent_get_remote_candidates (
  858. NiceAgent *agent,
  859. guint stream_id,
  860. guint component_id);
  861. /**
  862. * nice_agent_restart:
  863. * @agent: The #NiceAgent Object
  864. *
  865. * Restarts the session as defined in ICE draft 19. This function
  866. * needs to be called both when initiating (ICE spec section 9.1.1.1.
  867. * "ICE Restarts"), as well as when reacting (spec section 9.2.1.1.
  868. * "Detecting ICE Restart") to a restart.
  869. *
  870. * If consent-freshness has been enabled on @agent, as specified in RFC7675
  871. * then restarting streams will restore the local consent.
  872. *
  873. * Returns: %TRUE on success %FALSE on error
  874. **/
  875. gboolean
  876. nice_agent_restart (
  877. NiceAgent *agent);
  878. /**
  879. * nice_agent_restart_stream:
  880. * @agent: The #NiceAgent Object
  881. * @stream_id: The ID of the stream
  882. *
  883. * Restarts a single stream as defined in RFC 5245. This function
  884. * needs to be called both when initiating (ICE spec section 9.1.1.1.
  885. * "ICE Restarts"), as well as when reacting (spec section 9.2.1.1.
  886. * "Detecting ICE Restart") to a restart.
  887. *
  888. * Unlike nice_agent_restart(), this applies to a single stream. It also
  889. * does not generate a new tie breaker.
  890. *
  891. * If consent-freshness has been enabled on @agent, as specified in RFC7675
  892. * then restart @stream_id will restore the local consent for that stream.
  893. *
  894. * Returns: %TRUE on success %FALSE on error
  895. *
  896. * Since: 0.1.6
  897. **/
  898. gboolean
  899. nice_agent_restart_stream (
  900. NiceAgent *agent,
  901. guint stream_id);
  902. /**
  903. * nice_agent_attach_recv: (skip)
  904. * @agent: The #NiceAgent Object
  905. * @stream_id: The ID of stream
  906. * @component_id: The ID of the component
  907. * @ctx: The Glib Mainloop Context to use for listening on the component
  908. * @func: The callback function to be called when data is received on
  909. * the stream's component (will not be called for STUN messages that
  910. * should be handled by #NiceAgent itself)
  911. * @data: user data associated with the callback
  912. *
  913. * Attaches the stream's component's sockets to the Glib Mainloop Context in
  914. * order to be notified whenever data becomes available for a component,
  915. * and to enable #NiceAgent to receive STUN messages (during the
  916. * establishment of ICE connectivity).
  917. *
  918. * This must not be used in combination with nice_agent_recv_messages() (or
  919. * #NiceIOStream or #NiceInputStream) on the same stream/component pair.
  920. *
  921. * Calling nice_agent_attach_recv() with a %NULL @func will detach any existing
  922. * callback and cause reception to be paused for the given stream/component
  923. * pair. You must iterate the previously specified #GMainContext sufficiently to
  924. * ensure all pending I/O callbacks have been received before calling this
  925. * function to unset @func, otherwise data loss of received packets may occur.
  926. *
  927. * Returns: %TRUE on success, %FALSE if the stream or component IDs are invalid.
  928. */
  929. gboolean
  930. nice_agent_attach_recv (
  931. NiceAgent *agent,
  932. guint stream_id,
  933. guint component_id,
  934. GMainContext *ctx,
  935. NiceAgentRecvFunc func,
  936. gpointer data);
  937. /**
  938. * nice_agent_recv:
  939. * @agent: a #NiceAgent
  940. * @stream_id: the ID of the stream to receive on
  941. * @component_id: the ID of the component to receive on
  942. * @buf: (array length=buf_len) (out caller-allocates): caller-allocated buffer
  943. * to write the received data into, of length at least @buf_len
  944. * @buf_len: (in): length of @buf
  945. * @cancellable: (allow-none): a #GCancellable to allow the operation to be
  946. * cancelled from another thread, or %NULL
  947. * @error: (allow-none): return location for a #GError, or %NULL
  948. *
  949. * A single-message version of nice_agent_recv_messages().
  950. *
  951. * Returns: the number of bytes written to @buf on success (guaranteed to be
  952. * greater than 0 unless @buf_len is 0), 0 if in reliable mode and the remote
  953. * peer closed the stream, or -1 on error
  954. *
  955. * Since: 0.1.5
  956. */
  957. gssize
  958. nice_agent_recv (
  959. NiceAgent *agent,
  960. guint stream_id,
  961. guint component_id,
  962. guint8 *buf,
  963. gsize buf_len,
  964. GCancellable *cancellable,
  965. GError **error);
  966. /**
  967. * nice_agent_recv_messages:
  968. * @agent: a #NiceAgent
  969. * @stream_id: the ID of the stream to receive on
  970. * @component_id: the ID of the component to receive on
  971. * @messages: (array length=n_messages) (out caller-allocates): caller-allocated
  972. * array of #NiceInputMessages to write the received messages into, of length at
  973. * least @n_messages
  974. * @n_messages: number of entries in @messages
  975. * @cancellable: (allow-none): a #GCancellable to allow the operation to be
  976. * cancelled from another thread, or %NULL
  977. * @error: (allow-none): return location for a #GError, or %NULL
  978. *
  979. * Block on receiving data from the given stream/component combination on
  980. * @agent, returning only once exactly @n_messages messages have been received
  981. * and written into @messages, the stream is closed by the other end or by
  982. * calling nice_agent_remove_stream(), or @cancellable is cancelled.
  983. *
  984. * Any STUN packets received will not be added to @messages; instead,
  985. * they'll be passed for processing to #NiceAgent itself. Since #NiceAgent
  986. * does not poll for messages on its own, it's therefore essential to keep
  987. * calling this function for ICE connection establishment to work.
  988. *
  989. * In the non-error case, in reliable mode, this will block until all buffers in
  990. * all @n_messages have been filled with received data (i.e. @messages is
  991. * treated as a large, flat array of buffers). In non-reliable mode, it will
  992. * block until @n_messages messages have been received, each of which does not
  993. * have to fill all the buffers in its #NiceInputMessage. In the non-reliable
  994. * case, each #NiceInputMessage must have enough buffers to contain an entire
  995. * message (65536 bytes), or any excess data may be silently dropped.
  996. *
  997. * For each received message, #NiceInputMessage::length will be set to the
  998. * number of valid bytes stored in the message’s buffers. The bytes are stored
  999. * sequentially in the buffers; there are no gaps apart from at the end of the
  1000. * buffer array (in non-reliable mode). If non-%NULL on input,
  1001. * #NiceInputMessage::from will have the address of the sending peer stored in
  1002. * it. The base addresses, sizes, and number of buffers in each message will not
  1003. * be modified in any case.
  1004. *
  1005. * This must not be used in combination with nice_agent_attach_recv() on the
  1006. * same stream/component pair.
  1007. *
  1008. * If the stream/component pair doesn’t exist, or if a suitable candidate socket
  1009. * hasn’t yet been selected for it, a %G_IO_ERROR_BROKEN_PIPE error will be
  1010. * returned. A %G_IO_ERROR_CANCELLED error will be returned if the operation was
  1011. * cancelled. %G_IO_ERROR_FAILED will be returned for other errors.
  1012. *
  1013. * Returns: the number of valid messages written to @messages on success
  1014. * (guaranteed to be greater than 0 unless @n_messages is 0), 0 if the remote
  1015. * peer closed the stream, or -1 on error
  1016. *
  1017. * Since: 0.1.5
  1018. */
  1019. gint
  1020. nice_agent_recv_messages (
  1021. NiceAgent *agent,
  1022. guint stream_id,
  1023. guint component_id,
  1024. NiceInputMessage *messages,
  1025. guint n_messages,
  1026. GCancellable *cancellable,
  1027. GError **error);
  1028. /**
  1029. * nice_agent_recv_nonblocking:
  1030. * @agent: a #NiceAgent
  1031. * @stream_id: the ID of the stream to receive on
  1032. * @component_id: the ID of the component to receive on
  1033. * @buf: (array length=buf_len) (out caller-allocates): caller-allocated buffer
  1034. * to write the received data into, of length at least @buf_len
  1035. * @buf_len: (in): length of @buf
  1036. * @cancellable: (allow-none): a #GCancellable to allow the operation to be
  1037. * cancelled from another thread, or %NULL
  1038. * @error: (allow-none): return location for a #GError, or %NULL
  1039. *
  1040. * A single-message version of nice_agent_recv_messages_nonblocking().
  1041. *
  1042. * Returns: the number of bytes received into @buf on success (guaranteed to be
  1043. * greater than 0 unless @buf_len is 0), 0 if in reliable mode and the remote
  1044. * peer closed the stream, or -1 on error
  1045. *
  1046. * Since: 0.1.5
  1047. */
  1048. gssize
  1049. nice_agent_recv_nonblocking (
  1050. NiceAgent *agent,
  1051. guint stream_id,
  1052. guint component_id,
  1053. guint8 *buf,
  1054. gsize buf_len,
  1055. GCancellable *cancellable,
  1056. GError **error);
  1057. /**
  1058. * nice_agent_recv_messages_nonblocking:
  1059. * @agent: a #NiceAgent
  1060. * @stream_id: the ID of the stream to receive on
  1061. * @component_id: the ID of the component to receive on
  1062. * @messages: (array length=n_messages) (out caller-allocates): caller-allocated
  1063. * array of #NiceInputMessages to write the received messages into, of length at
  1064. * least @n_messages
  1065. * @n_messages: number of entries in @messages
  1066. * @cancellable: (allow-none): a #GCancellable to allow the operation to be
  1067. * cancelled from another thread, or %NULL
  1068. * @error: (allow-none): return location for a #GError, or %NULL
  1069. *
  1070. * Try to receive data from the given stream/component combination on @agent,
  1071. * without blocking. If receiving data would block, -1 is returned and
  1072. * %G_IO_ERROR_WOULD_BLOCK is set in @error. If any other error occurs, -1 is
  1073. * returned and @error is set accordingly. Otherwise, 0 is returned if (and only
  1074. * if) @n_messages is 0. In all other cases, the number of valid messages stored
  1075. * in @messages is returned, and will be greater than 0.
  1076. *
  1077. * This function behaves similarly to nice_agent_recv_messages(), except that it
  1078. * will not block on filling (in reliable mode) or receiving (in non-reliable
  1079. * mode) exactly @n_messages messages. In reliable mode, it will receive bytes
  1080. * into @messages until it would block; in non-reliable mode, it will receive
  1081. * messages until it would block.
  1082. *
  1083. * Any STUN packets received will not be added to @messages; instead,
  1084. * they'll be passed for processing to #NiceAgent itself. Since #NiceAgent
  1085. * does not poll for messages on its own, it's therefore essential to keep
  1086. * calling this function for ICE connection establishment to work.
  1087. *
  1088. * As this function is non-blocking, @cancellable is included only for parity
  1089. * with nice_agent_recv_messages(). If @cancellable is cancelled before this
  1090. * function is called, a %G_IO_ERROR_CANCELLED error will be returned
  1091. * immediately.
  1092. *
  1093. * This must not be used in combination with nice_agent_attach_recv() on the
  1094. * same stream/component pair.
  1095. *
  1096. * Returns: the number of valid messages written to @messages on success
  1097. * (guaranteed to be greater than 0 unless @n_messages is 0), 0 if in reliable
  1098. * mode and the remote peer closed the stream, or -1 on error
  1099. *
  1100. * Since: 0.1.5
  1101. */
  1102. gint
  1103. nice_agent_recv_messages_nonblocking (
  1104. NiceAgent *agent,
  1105. guint stream_id,
  1106. guint component_id,
  1107. NiceInputMessage *messages,
  1108. guint n_messages,
  1109. GCancellable *cancellable,
  1110. GError **error);
  1111. /**
  1112. * nice_agent_set_selected_pair:
  1113. * @agent: The #NiceAgent Object
  1114. * @stream_id: The ID of the stream
  1115. * @component_id: The ID of the component
  1116. * @lfoundation: The local foundation of the candidate to use
  1117. * @rfoundation: The remote foundation of the candidate to use
  1118. *
  1119. * Sets the selected candidate pair for media transmission
  1120. * for a given stream's component. Calling this function will
  1121. * disable all further ICE processing (connection check,
  1122. * state machine updates, etc). Note that keepalives will
  1123. * continue to be sent.
  1124. *
  1125. * Returns: %TRUE on success, %FALSE if the candidate pair cannot be found
  1126. */
  1127. gboolean
  1128. nice_agent_set_selected_pair (
  1129. NiceAgent *agent,
  1130. guint stream_id,
  1131. guint component_id,
  1132. const gchar *lfoundation,
  1133. const gchar *rfoundation);
  1134. /**
  1135. * nice_agent_get_selected_pair:
  1136. * @agent: The #NiceAgent Object
  1137. * @stream_id: The ID of the stream
  1138. * @component_id: The ID of the component
  1139. * @local: The local selected candidate
  1140. * @remote: The remote selected candidate
  1141. *
  1142. * Retreive the selected candidate pair for media transmission
  1143. * for a given stream's component.
  1144. *
  1145. * Returns: %TRUE on success, %FALSE if there is no selected candidate pair
  1146. */
  1147. gboolean
  1148. nice_agent_get_selected_pair (
  1149. NiceAgent *agent,
  1150. guint stream_id,
  1151. guint component_id,
  1152. NiceCandidate **local,
  1153. NiceCandidate **remote);
  1154. /**
  1155. * nice_agent_get_selected_socket:
  1156. * @agent: The #NiceAgent Object
  1157. * @stream_id: The ID of the stream
  1158. * @component_id: The ID of the component
  1159. *
  1160. * Retreive the local socket associated with the selected candidate pair
  1161. * for media transmission for a given stream's component.
  1162. *
  1163. * This is useful for adding ICE support to legacy applications that already
  1164. * have a protocol that maintains a connection. If the socket is duplicated
  1165. * before unrefing the agent, the application can take over and continue to use
  1166. * it. New applications are encouraged to use the built in libnice stream
  1167. * handling instead and let libnice handle the connection maintenance.
  1168. *
  1169. * Users of this method are encouraged to not use a TURN relay or any kind
  1170. * of proxy, as in this case, the socket will not be available to the
  1171. * application because the packets are encapsulated.
  1172. *
  1173. * Returns: (transfer full) (nullable): pointer to the #GSocket, or %NULL if
  1174. * there is no selected candidate or if the selected candidate is a relayed
  1175. * candidate.
  1176. *
  1177. * Since: 0.1.5
  1178. */
  1179. GSocket *
  1180. nice_agent_get_selected_socket (
  1181. NiceAgent *agent,
  1182. guint stream_id,
  1183. guint component_id);
  1184. /**
  1185. * nice_agent_set_selected_remote_candidate:
  1186. * @agent: The #NiceAgent Object
  1187. * @stream_id: The ID of the stream
  1188. * @component_id: The ID of the component
  1189. * @candidate: The #NiceCandidate to select
  1190. *
  1191. * Sets the selected remote candidate for media transmission
  1192. * for a given stream's component. This is used to force the selection of
  1193. * a specific remote candidate even when connectivity checks are failing
  1194. * (e.g. non-ICE compatible candidates).
  1195. * Calling this function will disable all further ICE processing
  1196. * (connection check, state machine updates, etc). Note that keepalives will
  1197. * continue to be sent.
  1198. *
  1199. * Returns: %TRUE on success, %FALSE on failure
  1200. */
  1201. gboolean
  1202. nice_agent_set_selected_remote_candidate (
  1203. NiceAgent *agent,
  1204. guint stream_id,
  1205. guint component_id,
  1206. NiceCandidate *candidate);
  1207. /**
  1208. * nice_agent_set_stream_tos:
  1209. * @agent: The #NiceAgent Object
  1210. * @stream_id: The ID of the stream
  1211. * @tos: The ToS to set
  1212. *
  1213. * Sets the IP_TOS and/or IPV6_TCLASS field on the stream's sockets' options
  1214. *
  1215. * Since: 0.0.9
  1216. */
  1217. void nice_agent_set_stream_tos (
  1218. NiceAgent *agent,
  1219. guint stream_id,
  1220. gint tos);
  1221. /**
  1222. * nice_agent_set_software:
  1223. * @agent: The #NiceAgent Object
  1224. * @software: The value of the SOFTWARE attribute to add.
  1225. *
  1226. * This function will set the value of the SOFTWARE attribute to be added to
  1227. * STUN requests, responses and error responses sent during connectivity checks.
  1228. * <para>
  1229. * The SOFTWARE attribute will only be added in the #NICE_COMPATIBILITY_RFC5245
  1230. * and #NICE_COMPATIBILITY_WLM2009 compatibility modes.
  1231. *
  1232. * </para>
  1233. * <note>
  1234. <para>
  1235. The @software argument will be appended with the libnice version before
  1236. being sent.
  1237. </para>
  1238. <para>
  1239. The @software argument must be in UTF-8 encoding and only the first
  1240. 128 characters will be sent.
  1241. </para>
  1242. </note>
  1243. *
  1244. * Since: 0.0.10
  1245. *
  1246. */
  1247. void nice_agent_set_software (
  1248. NiceAgent *agent,
  1249. const gchar *software);
  1250. /**
  1251. * nice_agent_set_stream_name:
  1252. * @agent: The #NiceAgent Object
  1253. * @stream_id: The ID of the stream to change
  1254. * @name: The new name of the stream or %NULL
  1255. *
  1256. * This function will assign a media type to a stream. The only values
  1257. * that can be used to produce a valid SDP are: "audio", "video",
  1258. * "text", "application", "image" and "message".
  1259. *
  1260. * This is only useful when parsing and generating an SDP of the
  1261. * candidates.
  1262. *
  1263. * <para>See also: nice_agent_generate_local_sdp()</para>
  1264. * <para>See also: nice_agent_parse_remote_sdp()</para>
  1265. * <para>See also: nice_agent_get_stream_name()</para>
  1266. *
  1267. * Returns: %TRUE if the name has been set. %FALSE in case of error
  1268. * (invalid stream or duplicate name).
  1269. * Since: 0.1.4
  1270. */
  1271. gboolean nice_agent_set_stream_name (
  1272. NiceAgent *agent,
  1273. guint stream_id,
  1274. const gchar *name);
  1275. /**
  1276. * nice_agent_get_stream_name:
  1277. * @agent: The #NiceAgent Object
  1278. * @stream_id: The ID of the stream to change
  1279. *
  1280. * This function will return the name assigned to a stream.
  1281. * <para>See also: nice_agent_set_stream_name()</para>
  1282. *
  1283. * Returns: The name of the stream. The name is only valid while the stream
  1284. * exists or until it changes through a call to nice_agent_set_stream_name().
  1285. *
  1286. *
  1287. * Since: 0.1.4
  1288. */
  1289. const gchar *nice_agent_get_stream_name (
  1290. NiceAgent *agent,
  1291. guint stream_id);
  1292. /**
  1293. * nice_agent_get_default_local_candidate:
  1294. * @agent: The #NiceAgent Object
  1295. * @stream_id: The ID of the stream
  1296. * @component_id: The ID of the component
  1297. *
  1298. * This helper function will return the recommended default candidate to be
  1299. * used for non-ICE compatible clients. This will usually be the candidate
  1300. * with the lowest priority, since it will be the longest path but the one with
  1301. * the most chances of success.
  1302. * <note>
  1303. <para>
  1304. This function is only useful in order to manually generate the
  1305. local SDP
  1306. </para>
  1307. * </note>
  1308. *
  1309. * Returns: The candidate to be used as the default candidate, or %NULL in case
  1310. * of error. Must be freed with nice_candidate_free() once done.
  1311. *
  1312. */
  1313. NiceCandidate *
  1314. nice_agent_get_default_local_candidate (
  1315. NiceAgent *agent,
  1316. guint stream_id,
  1317. guint component_id);
  1318. /**
  1319. * nice_agent_generate_local_sdp:
  1320. * @agent: The #NiceAgent Object
  1321. *
  1322. * Generate an SDP string containing the local candidates and credentials for
  1323. * all streams and components in the agent.
  1324. *
  1325. <note>
  1326. <para>
  1327. The SDP will not contain any codec lines and the 'm' line will not list
  1328. any payload types.
  1329. </para>
  1330. <para>
  1331. It is highly recommended to set names on the streams prior to calling this
  1332. function. Unnamed streams will show up as '-' in the 'm' line, but the SDP
  1333. will not be parseable with nice_agent_parse_remote_sdp() if a stream is
  1334. unnamed.
  1335. </para>
  1336. <para>
  1337. The default candidate in the SDP will be selected based on the lowest
  1338. priority candidate for the first component.
  1339. </para>
  1340. </note>
  1341. *
  1342. * <para>See also: nice_agent_set_stream_name() </para>
  1343. * <para>See also: nice_agent_parse_remote_sdp() </para>
  1344. * <para>See also: nice_agent_generate_local_stream_sdp() </para>
  1345. * <para>See also: nice_agent_generate_local_candidate_sdp() </para>
  1346. * <para>See also: nice_agent_get_default_local_candidate() </para>
  1347. *
  1348. * Returns: A string representing the local SDP. Must be freed with g_free()
  1349. * once done.
  1350. *
  1351. * Since: 0.1.4
  1352. **/
  1353. gchar *
  1354. nice_agent_generate_local_sdp (
  1355. NiceAgent *agent);
  1356. /**
  1357. * nice_agent_generate_local_stream_sdp:
  1358. * @agent: The #NiceAgent Object
  1359. * @stream_id: The ID of the stream
  1360. * @include_non_ice: Whether or not to include non ICE specific lines
  1361. * (m=, c= and a=rtcp: lines)
  1362. *
  1363. * Generate an SDP string containing the local candidates and credentials
  1364. * for a stream.
  1365. *
  1366. <note>
  1367. <para>
  1368. The SDP will not contain any codec lines and the 'm' line will not list
  1369. any payload types.
  1370. </para>
  1371. <para>
  1372. It is highly recommended to set the name of the stream prior to calling this
  1373. function. Unnamed streams will show up as '-' in the 'm' line.
  1374. </para>
  1375. <para>
  1376. The default candidate in the SDP will be selected based on the lowest
  1377. priority candidate.
  1378. </para>
  1379. </note>
  1380. *
  1381. * <para>See also: nice_agent_set_stream_name() </para>
  1382. * <para>See also: nice_agent_parse_remote_stream_sdp() </para>
  1383. * <para>See also: nice_agent_generate_local_sdp() </para>
  1384. * <para>See also: nice_agent_generate_local_candidate_sdp() </para>
  1385. * <para>See also: nice_agent_get_default_local_candidate() </para>
  1386. *
  1387. * Returns: A string representing the local SDP for the stream. Must be freed
  1388. * with g_free() once done.
  1389. *
  1390. * Since: 0.1.4
  1391. **/
  1392. gchar *
  1393. nice_agent_generate_local_stream_sdp (
  1394. NiceAgent *agent,
  1395. guint stream_id,
  1396. gboolean include_non_ice);
  1397. /**
  1398. * nice_agent_generate_local_candidate_sdp:
  1399. * @agent: The #NiceAgent Object
  1400. * @candidate: The candidate to generate
  1401. *
  1402. * Generate an SDP string representing a local candidate.
  1403. *
  1404. * <para>See also: nice_agent_parse_remote_candidate_sdp() </para>
  1405. * <para>See also: nice_agent_generate_local_sdp() </para>
  1406. * <para>See also: nice_agent_generate_local_stream_sdp() </para>
  1407. *
  1408. * Returns: A string representing the SDP for the candidate. Must be freed
  1409. * with g_free() once done.
  1410. *
  1411. * Since: 0.1.4
  1412. **/
  1413. gchar *
  1414. nice_agent_generate_local_candidate_sdp (
  1415. NiceAgent *agent,
  1416. NiceCandidate *candidate);
  1417. /**
  1418. * nice_agent_parse_remote_sdp:
  1419. * @agent: The #NiceAgent Object
  1420. * @sdp: The remote SDP to parse
  1421. *
  1422. * Parse an SDP string and extracts candidates and credentials from it and sets
  1423. * them on the agent.
  1424. *
  1425. * <para>See also: nice_agent_set_stream_name() </para>
  1426. * <para>See also: nice_agent_generate_local_sdp() </para>
  1427. * <para>See also: nice_agent_parse_remote_stream_sdp() </para>
  1428. * <para>See also: nice_agent_parse_remote_candidate_sdp() </para>
  1429. *
  1430. * Returns: The number of candidates added, negative on errors
  1431. *
  1432. * Since: 0.1.4
  1433. **/
  1434. int
  1435. nice_agent_parse_remote_sdp (
  1436. NiceAgent *agent,
  1437. const gchar *sdp);
  1438. /**
  1439. * nice_agent_parse_remote_stream_sdp:
  1440. * @agent: The #NiceAgent Object
  1441. * @stream_id: The ID of the stream to parse
  1442. * @sdp: The remote SDP to parse
  1443. * @ufrag: Pointer to store the ice ufrag if non %NULL. Must be freed with
  1444. * g_free() after use
  1445. * @pwd: Pointer to store the ice password if non %NULL. Must be freed with
  1446. * g_free() after use
  1447. *
  1448. * Parse an SDP string representing a single stream and extracts candidates
  1449. * and credentials from it.
  1450. *
  1451. * <para>See also: nice_agent_generate_local_stream_sdp() </para>
  1452. * <para>See also: nice_agent_parse_remote_sdp() </para>
  1453. * <para>See also: nice_agent_parse_remote_candidate_sdp() </para>
  1454. *
  1455. * Returns: (element-type NiceCandidate) (transfer full): A #GSList of
  1456. * candidates parsed from the SDP, or %NULL in case of errors
  1457. *
  1458. * Since: 0.1.4
  1459. **/
  1460. GSList *
  1461. nice_agent_parse_remote_stream_sdp (
  1462. NiceAgent *agent,
  1463. guint stream_id,
  1464. const gchar *sdp,
  1465. gchar **ufrag,
  1466. gchar **pwd);
  1467. /**
  1468. * nice_agent_parse_remote_candidate_sdp:
  1469. * @agent: The #NiceAgent Object
  1470. * @stream_id: The ID of the stream the candidate belongs to
  1471. * @sdp: The remote SDP to parse
  1472. *
  1473. * Parse an SDP string and extracts the candidate from it.
  1474. *
  1475. * <para>See also: nice_agent_generate_local_candidate_sdp() </para>
  1476. * <para>See also: nice_agent_parse_remote_sdp() </para>
  1477. * <para>See also: nice_agent_parse_remote_stream_sdp() </para>
  1478. *
  1479. * Returns: The parsed candidate or %NULL if there was an error.
  1480. *
  1481. * Since: 0.1.4
  1482. **/
  1483. NiceCandidate *
  1484. nice_agent_parse_remote_candidate_sdp (
  1485. NiceAgent *agent,
  1486. guint stream_id,
  1487. const gchar *sdp);
  1488. /**
  1489. * nice_agent_get_io_stream:
  1490. * @agent: A #NiceAgent
  1491. * @stream_id: The ID of the stream to wrap
  1492. * @component_id: The ID of the component to wrap
  1493. *
  1494. * Gets a #GIOStream wrapper around the given stream and component in
  1495. * @agent. The I/O stream will be valid for as long as @stream_id is valid.
  1496. * The #GInputStream and #GOutputStream implement #GPollableInputStream and
  1497. * #GPollableOutputStream.
  1498. *
  1499. * This function may only be called on reliable #NiceAgents. It is a
  1500. * programming error to try and create an I/O stream wrapper for an
  1501. * unreliable stream.
  1502. *
  1503. * Returns: (transfer full): A #GIOStream.
  1504. *
  1505. * Since: 0.1.5
  1506. */
  1507. GIOStream *
  1508. nice_agent_get_io_stream (
  1509. NiceAgent *agent,
  1510. guint stream_id,
  1511. guint component_id);
  1512. /**
  1513. * nice_component_state_to_string:
  1514. * @state: a #NiceComponentState
  1515. *
  1516. * Returns a string representation of the state, generally to use in debug
  1517. * messages.
  1518. *
  1519. * Returns: (transfer none): a string representation of @state
  1520. * Since: 0.1.6
  1521. */
  1522. const gchar *
  1523. nice_component_state_to_string (NiceComponentState state);
  1524. /**
  1525. * nice_agent_forget_relays:
  1526. * @agent: The #NiceAgent Object
  1527. * @stream_id: The ID of the stream
  1528. * @component_id: The ID of the component
  1529. *
  1530. * Forget all the relay servers previously added using
  1531. * nice_agent_set_relay_info(). Currently connected streams will keep
  1532. * using the relay as long as they have not been restarted and haven't
  1533. * succesfully negotiated a different path.
  1534. *
  1535. * Returns: %FALSE if the component could not be found, %TRUE otherwise
  1536. *
  1537. * Since: 0.1.6
  1538. */
  1539. gboolean
  1540. nice_agent_forget_relays (NiceAgent *agent,
  1541. guint stream_id,
  1542. guint component_id);
  1543. /**
  1544. * nice_agent_get_component_state:
  1545. * @agent: The #NiceAgent Object
  1546. * @stream_id: The ID of the stream
  1547. * @component_id: The ID of the component
  1548. *
  1549. * Retrieves the current state of a component.
  1550. *
  1551. * Returns: the #NiceComponentState of the component and
  1552. * %NICE_COMPONENT_STATE_FAILED if the component was invalid.
  1553. *
  1554. * Since: 0.1.8
  1555. */
  1556. NiceComponentState
  1557. nice_agent_get_component_state (NiceAgent *agent,
  1558. guint stream_id,
  1559. guint component_id);
  1560. /**
  1561. * nice_agent_peer_candidate_gathering_done:
  1562. * @agent: The #NiceAgent Object
  1563. * @stream_id: The ID of the stream
  1564. *
  1565. * Notifies the agent that the remote peer has concluded candidate gathering and
  1566. * thus no more remote candidates are expected to arrive for @stream_id.
  1567. *
  1568. * This will allow the stream components without a successful connectivity check
  1569. * to stop waiting for more candidates to come and finally transit into
  1570. * %NICE_COMPONENT_STATE_FAILED.
  1571. *
  1572. * Calling the function has an effect only when #NiceAgent:trickle-ice is %TRUE.
  1573. *
  1574. * Returns: %FALSE if the stream could not be found, %TRUE otherwise
  1575. *
  1576. * Since: 0.1.16
  1577. */
  1578. gboolean
  1579. nice_agent_peer_candidate_gathering_done (
  1580. NiceAgent *agent,
  1581. guint stream_id);
  1582. /**
  1583. * nice_agent_consent_lost:
  1584. * @agent: The #NiceAgent Object
  1585. * @stream_id: The ID of the stream
  1586. * @component_id: The ID of the component
  1587. *
  1588. * Notifies the agent that consent to receive has been revoked. This will
  1589. * cause the component to fail with 403 'Forbidden' all incoming STUN binding
  1590. * requests as specified in RFC 7675.
  1591. *
  1592. * A stream with a component in the consent-lost state can be reused by
  1593. * performing an ice restart with nice_agent_restart() or
  1594. * nice_agent_restart_stream().
  1595. *
  1596. * Calling the function only has an effect when @agent has been created with
  1597. * @NICE_AGENT_OPTION_CONSENT_FRESHNESS.
  1598. *
  1599. * Returns: %FALSE if the stream or component could not be found or consent
  1600. * freshness is not enabled, %TRUE otherwise
  1601. *
  1602. * Since: 0.1.19
  1603. */
  1604. gboolean
  1605. nice_agent_consent_lost (
  1606. NiceAgent *agent,
  1607. guint stream_id,
  1608. guint component_id);
  1609. /**
  1610. * nice_agent_close_async:
  1611. * @agent: The #NiceAgent object
  1612. * @callback: (nullable): A callback that will be called when the closing is
  1613. * complete
  1614. * @callback_data: (nullable): A pointer that will be passed to the callback
  1615. *
  1616. * Asynchronously closes resources the agent has allocated on remote servers.
  1617. *
  1618. * The agent will call the callback in the current #GMainContext in
  1619. * which this function is called. The #GAsyncResult in the callback
  1620. * can be ignored as this operation never fails.
  1621. *
  1622. * Calling this function before freeing the agent makes sure the allocated relay
  1623. * ports aren't left behind on TURN server but properly removed.
  1624. *
  1625. * Since: 0.1.16
  1626. */
  1627. void
  1628. nice_agent_close_async (NiceAgent *agent, GAsyncReadyCallback callback,
  1629. gpointer callback_data);
  1630. /**
  1631. * nice_agent_get_sockets:
  1632. * @agent: The #NiceAgent Object
  1633. * @stream_id: The ID of the stream
  1634. * @component_id: The ID of the component
  1635. *
  1636. * Each component can have multiple sockets, this is an API to retrieve them all
  1637. * to be able to set properties. Most of the sockets for a component are created when
  1638. * calling nice_agent_gather_candidates(), so this API should be called right after to
  1639. * able to set properties on the sockets before they are used.
  1640. *
  1641. * These sockets can be a mix of UDP & TCP sockets depending on the compatibility mode
  1642. * and options that have been set.
  1643. *
  1644. * Returns: (element-type GSocket) (transfer full): An array
  1645. * containing all of the sockets for this component. Free with
  1646. * g_ptr_array_unref() when done.
  1647. *
  1648. * Since: 0.1.17
  1649. */
  1650. GPtrArray *
  1651. nice_agent_get_sockets (NiceAgent *agent, guint stream_id, guint component_id);
  1652. G_END_DECLS
  1653. #endif /* __LIBNICE_AGENT_H__ */