candidate.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. * This file is part of the Nice GLib ICE library.
  3. *
  4. * (C) 2006-2009 Collabora Ltd.
  5. * Contact: Youness Alaoui
  6. * (C) 2006-2009 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_CANDIDATE_H__
  40. #define __LIBNICE_CANDIDATE_H__
  41. #include "address.h"
  42. #include <glib.h>
  43. #include <glib-object.h>
  44. /**
  45. * SECTION:candidate
  46. * @short_description: ICE candidate representation
  47. * @see_also: #NiceAddress
  48. * @stability: Stable
  49. *
  50. * A representation of an ICE candidate. Make sure you read the ICE drafts[1] to
  51. * understand correctly the concept of ICE candidates.
  52. *
  53. * [1] http://tools.ietf.org/wg/mmusic/draft-ietf-mmusic-ice/
  54. */
  55. G_BEGIN_DECLS
  56. /* Max foundation size '1*32ice-char' plus terminating NULL, ICE ID-19 */
  57. /**
  58. * NICE_CANDIDATE_MAX_FOUNDATION:
  59. *
  60. * The maximum size a candidate foundation can have.
  61. */
  62. #define NICE_CANDIDATE_MAX_FOUNDATION (32+1)
  63. /**
  64. * NICE_CANDIDATE_MAX_TURN_SERVERS
  65. *
  66. * The maximum number of turns servers.
  67. */
  68. #define NICE_CANDIDATE_MAX_TURN_SERVERS 8
  69. /**
  70. * NICE_CANDIDATE_MAX_LOCAL_ADDRESSES
  71. *
  72. * The maximum number of local addresses. The constraint is that the
  73. * maximum number of local addresses and number of turn servers must
  74. * fit on 9 bits, to ensure candidate priority uniqueness. See also
  75. * @NICE_CANDIDATE_MAX_TURN_SERVERS. We choose 6 bits for the number of
  76. * local addresses, and 3 bits for the number of turn servers.
  77. */
  78. #define NICE_CANDIDATE_MAX_LOCAL_ADDRESSES 64
  79. /**
  80. * NiceCandidateType:
  81. * @NICE_CANDIDATE_TYPE_HOST: A host candidate
  82. * @NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE: A server reflexive candidate
  83. * @NICE_CANDIDATE_TYPE_PEER_REFLEXIVE: A peer reflexive candidate
  84. * @NICE_CANDIDATE_TYPE_RELAYED: A relay candidate
  85. *
  86. * An enum represneting the type of a candidate
  87. */
  88. typedef enum
  89. {
  90. NICE_CANDIDATE_TYPE_HOST,
  91. NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE,
  92. NICE_CANDIDATE_TYPE_PEER_REFLEXIVE,
  93. NICE_CANDIDATE_TYPE_RELAYED,
  94. } NiceCandidateType;
  95. /**
  96. * NiceCandidateTransport:
  97. * @NICE_CANDIDATE_TRANSPORT_UDP: UDP transport
  98. * @NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE: TCP Active transport
  99. * @NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE: TCP Passive transport
  100. * @NICE_CANDIDATE_TRANSPORT_TCP_SO: TCP Simultaneous-Open transport
  101. *
  102. * An enum representing the type of transport to use
  103. */
  104. typedef enum
  105. {
  106. NICE_CANDIDATE_TRANSPORT_UDP,
  107. NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE,
  108. NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE,
  109. NICE_CANDIDATE_TRANSPORT_TCP_SO,
  110. } NiceCandidateTransport;
  111. /**
  112. * NiceRelayType:
  113. * @NICE_RELAY_TYPE_TURN_UDP: A TURN relay using UDP
  114. * @NICE_RELAY_TYPE_TURN_TCP: A TURN relay using TCP
  115. * @NICE_RELAY_TYPE_TURN_TLS: A TURN relay using TLS over TCP
  116. *
  117. * An enum representing the type of relay to use
  118. */
  119. typedef enum {
  120. NICE_RELAY_TYPE_TURN_UDP,
  121. NICE_RELAY_TYPE_TURN_TCP,
  122. NICE_RELAY_TYPE_TURN_TLS
  123. } NiceRelayType;
  124. typedef struct _NiceCandidate NiceCandidate;
  125. /**
  126. * NiceCandidate:
  127. * @type: The type of candidate
  128. * @transport: The transport being used for the candidate
  129. * @addr: The #NiceAddress of the candidate
  130. * @base_addr: The #NiceAddress of the base address used by the candidate
  131. * @priority: The priority of the candidate <emphasis> see note </emphasis>
  132. * @stream_id: The ID of the stream to which belongs the candidate
  133. * @component_id: The ID of the component to which belongs the candidate
  134. * @foundation: The foundation of the candidate
  135. * @username: The candidate-specific username to use (overrides the one set
  136. * by nice_agent_set_local_credentials() or nice_agent_set_remote_credentials())
  137. * @password: The candidate-specific password to use (overrides the one set
  138. * by nice_agent_set_local_credentials() or nice_agent_set_remote_credentials())
  139. *
  140. * A structure to represent an ICE candidate
  141. <note>
  142. <para>
  143. The @priority is an integer as specified in the ICE draft 19. If you are
  144. using the MSN or the GOOGLE compatibility mode (which are based on ICE
  145. draft 6, which uses a floating point qvalue as priority), then the @priority
  146. value will represent the qvalue multiplied by 1000.
  147. </para>
  148. </note>
  149. */
  150. struct _NiceCandidate
  151. {
  152. NiceCandidateType type;
  153. NiceCandidateTransport transport;
  154. NiceAddress addr;
  155. NiceAddress base_addr;
  156. guint32 priority;
  157. guint stream_id;
  158. guint component_id;
  159. gchar foundation[NICE_CANDIDATE_MAX_FOUNDATION];
  160. gchar *username; /* pointer to a nul-terminated username string */
  161. gchar *password; /* pointer to a nul-terminated password string */
  162. };
  163. /**
  164. * nice_candidate_new:
  165. * @type: The #NiceCandidateType of the candidate to create
  166. *
  167. * Creates a new candidate. Must be freed with nice_candidate_free()
  168. *
  169. * Returns: A new #NiceCandidate
  170. */
  171. NiceCandidate *
  172. nice_candidate_new (NiceCandidateType type);
  173. /**
  174. * nice_candidate_free:
  175. * @candidate: The candidate to free
  176. *
  177. * Frees a #NiceCandidate
  178. */
  179. void
  180. nice_candidate_free (NiceCandidate *candidate);
  181. /**
  182. * nice_candidate_copy:
  183. * @candidate: The candidate to copy
  184. *
  185. * Makes a copy of a #NiceCandidate
  186. *
  187. * Returns: A new #NiceCandidate, a copy of @candidate
  188. */
  189. NiceCandidate *
  190. nice_candidate_copy (const NiceCandidate *candidate);
  191. /**
  192. * nice_candidate_equal_target:
  193. * @candidate1: A candidate
  194. * @candidate2: A candidate
  195. *
  196. * Verifies that the candidates point to the same place, meaning they have
  197. * the same transport and the same address. It ignores all other aspects.
  198. *
  199. * Returns: %TRUE if the candidates point to the same place
  200. *
  201. * Since: 0.1.15
  202. */
  203. gboolean
  204. nice_candidate_equal_target (const NiceCandidate *candidate1,
  205. const NiceCandidate *candidate2);
  206. GType nice_candidate_get_type (void);
  207. /**
  208. * nice_candidate_type_to_string:
  209. * @type: a #NiceCandidateType
  210. *
  211. * Useful for debugging functions, just returns a static string with the
  212. * candidate type.
  213. *
  214. * Returns: a static string with the candidate type
  215. *
  216. * Since: 0.1.19
  217. */
  218. const gchar *
  219. nice_candidate_type_to_string (NiceCandidateType type);
  220. /**
  221. * nice_candidate_transport_to_string:
  222. * @transport: a #NiceCandidateTransport
  223. *
  224. * Useful for debugging functions, just returns a static string with the
  225. * candidate transport.
  226. *
  227. * Returns: a static string with the candidate transport
  228. *
  229. * Since: 0.1.19
  230. */
  231. const gchar *
  232. nice_candidate_transport_to_string (NiceCandidateTransport transport);
  233. /**
  234. * nice_candidate_relay_address:
  235. * @candidate: A relay candidate
  236. * @addr: The #NiceAddress to fill
  237. *
  238. * In case the given candidate is relayed through a TURN server, use this utility function to get
  239. * its address.
  240. *
  241. * Since: 0.1.19
  242. */
  243. void
  244. nice_candidate_relay_address (const NiceCandidate *candidate, NiceAddress *addr);
  245. /**
  246. * NICE_TYPE_CANDIDATE:
  247. *
  248. * A boxed type for a #NiceCandidate.
  249. */
  250. #define NICE_TYPE_CANDIDATE nice_candidate_get_type ()
  251. G_END_DECLS
  252. #endif /* __LIBNICE_CANDIDATE_H__ */