fd1dfe43154fc76e583821943ce2fcac6288e230
[platform/upstream/libnice.git] / agent / discovery.h
1 /*
2  * This file is part of the Nice GLib ICE library.
3  *
4  * (C) 2008-2009 Collabora Ltd.
5  *  Contact: Youness Alaoui
6  * (C) 2007-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  *   Youness Alaoui, Collabora Ltd.
26  *   Kai Vehmanen, Nokia
27  *
28  * Alternatively, the contents of this file may be used under the terms of the
29  * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
30  * case the provisions of LGPL are applicable instead of those above. If you
31  * wish to allow use of your version of this file only under the terms of the
32  * LGPL and not to allow others to use your version of this file under the
33  * MPL, indicate your decision by deleting the provisions above and replace
34  * them with the notice and other provisions required by the LGPL. If you do
35  * not delete the provisions above, a recipient may use your version of this
36  * file under either the MPL or the LGPL.
37  */
38
39 #ifndef _NICE_DISCOVERY_H
40 #define _NICE_DISCOVERY_H
41
42 /* note: this is a private header to libnice */
43
44 #include "stream.h"
45 #include "agent.h"
46
47 typedef struct
48 {
49   NiceCandidateType type;   /* candidate type STUN or TURN */
50   NiceSocket *nicesock;  /* XXX: should be taken from local cand: existing socket to use */
51   NiceAddress server;       /* STUN/TURN server address */
52   gint64 next_tick;       /* next tick timestamp */
53   gboolean pending;         /* is discovery in progress? */
54   gboolean done;            /* is discovery complete? */
55   guint stream_id;
56   guint component_id;
57   TurnServer *turn;
58   StunAgent stun_agent;
59   StunTimer timer;
60   uint8_t stun_buffer[STUN_MAX_MESSAGE_SIZE_IPV6];
61   StunMessage stun_message;
62   uint8_t stun_resp_buffer[STUN_MAX_MESSAGE_SIZE];
63   StunMessage stun_resp_msg;
64 } CandidateDiscovery;
65
66 typedef struct
67 {
68   NiceSocket *nicesock;     /* existing socket to use */
69   NiceAddress server;       /* STUN/TURN server address */
70   NiceCandidate *candidate; /* candidate to refresh */
71   guint stream_id;
72   guint component_id;
73   StunAgent stun_agent;
74   GSource *timer_source;
75   GSource *tick_source;
76   StunTimer timer;
77   uint8_t stun_buffer[STUN_MAX_MESSAGE_SIZE_IPV6];
78   StunMessage stun_message;
79   uint8_t stun_resp_buffer[STUN_MAX_MESSAGE_SIZE];
80   StunMessage stun_resp_msg;
81
82   gboolean disposing;
83   GDestroyNotify destroy_cb;
84   gpointer destroy_cb_data;
85   GSource *destroy_source;
86 } CandidateRefresh;
87
88 void refresh_free (NiceAgent *agent, CandidateRefresh *refresh);
89 void refresh_prune_agent_async (NiceAgent *agent,
90   NiceTimeoutLockedCallback function, gpointer user_data);
91 void refresh_prune_stream_async (NiceAgent *agent, NiceStream *stream,
92   NiceTimeoutLockedCallback function);
93 void refresh_prune_candidate (NiceAgent *agent, NiceCandidate *candidate);
94 void refresh_prune_candidate_async (NiceAgent *agent, NiceCandidate *candidate,
95   NiceTimeoutLockedCallback function);
96
97
98 void discovery_free (NiceAgent *agent);
99 void discovery_prune_stream (NiceAgent *agent, guint stream_id);
100 void discovery_prune_socket (NiceAgent *agent, NiceSocket *sock);
101 void discovery_schedule (NiceAgent *agent);
102
103 typedef enum {
104   HOST_CANDIDATE_SUCCESS,
105   HOST_CANDIDATE_FAILED,
106   HOST_CANDIDATE_CANT_CREATE_SOCKET,
107   HOST_CANDIDATE_REDUNDANT,
108   HOST_CANDIDATE_DUPLICATE_PORT
109 } HostCandidateResult;
110
111 HostCandidateResult
112 discovery_add_local_host_candidate (
113   NiceAgent *agent,
114   guint stream_id,
115   guint component_id,
116   NiceAddress *address,
117   NiceCandidateTransport transport,
118   NiceCandidate **candidate);
119
120 NiceCandidate*
121 discovery_add_relay_candidate (
122   NiceAgent *agent,
123   guint stream_id,
124   guint component_id,
125   NiceAddress *address,
126   NiceCandidateTransport transport,
127   NiceSocket *base_socket,
128   TurnServer *turn);
129
130 NiceCandidate*
131 discovery_add_server_reflexive_candidate (
132   NiceAgent *agent,
133   guint stream_id,
134   guint component_id,
135   NiceAddress *address,
136   NiceCandidateTransport transport,
137   NiceSocket *base_socket,
138   gboolean nat_assisted);
139
140 void
141 discovery_discover_tcp_server_reflexive_candidates (
142   NiceAgent *agent,
143   guint stream_id,
144   guint component_id,
145   NiceAddress *address,
146   NiceSocket *base_socket);
147
148 NiceCandidate*
149 discovery_add_peer_reflexive_candidate (
150   NiceAgent *agent,
151   guint stream_id,
152   guint component_id,
153   guint32 priority,
154   NiceAddress *address,
155   NiceSocket *base_socket,
156   NiceCandidate *local,
157   NiceCandidate *remote);
158
159 NiceCandidate *
160 discovery_learn_remote_peer_reflexive_candidate (
161   NiceAgent *agent,
162   NiceStream *stream,
163   NiceComponent *component,
164   guint32 priority, 
165   const NiceAddress *remote_address,
166   NiceSocket *udp_socket,
167   NiceCandidate *local,
168   NiceCandidate *remote);
169
170 #endif /*_NICE_CONNCHECK_H */