|
1 /* |
|
2 Copyright (c) 2007, Adobe Systems, Incorporated |
|
3 All rights reserved. |
|
4 |
|
5 Redistribution and use in source and binary forms, with or without |
|
6 modification, are permitted provided that the following conditions are |
|
7 met: |
|
8 |
|
9 * Redistributions of source code must retain the above copyright |
|
10 notice, this list of conditions and the following disclaimer. |
|
11 |
|
12 * Redistributions in binary form must reproduce the above copyright |
|
13 notice, this list of conditions and the following disclaimer in the |
|
14 documentation and/or other materials provided with the distribution. |
|
15 |
|
16 * Neither the name of Adobe Systems, Network Resonance nor the names of its |
|
17 contributors may be used to endorse or promote products derived from |
|
18 this software without specific prior written permission. |
|
19 |
|
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
21 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
23 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
24 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
31 */ |
|
32 |
|
33 |
|
34 |
|
35 #ifndef _ice_ctx_h |
|
36 #define _ice_ctx_h |
|
37 #ifdef __cplusplus |
|
38 using namespace std; |
|
39 extern "C" { |
|
40 #endif /* __cplusplus */ |
|
41 |
|
42 /* Not good practice but making includes simpler */ |
|
43 #include "transport_addr.h" |
|
44 #include "nr_socket.h" |
|
45 #include "nr_resolver.h" |
|
46 #include "nr_interface_prioritizer.h" |
|
47 #include "stun_client_ctx.h" |
|
48 #include "stun_server_ctx.h" |
|
49 #include "turn_client_ctx.h" |
|
50 |
|
51 #define NR_ICE_STUN_SERVER_TYPE_ADDR 1 |
|
52 #define NR_ICE_STUN_SERVER_TYPE_DNSNAME 2 |
|
53 |
|
54 typedef struct nr_ice_stun_server_ { |
|
55 int type; |
|
56 union { |
|
57 nr_transport_addr addr; |
|
58 struct { |
|
59 char host[256]; /* Limit from RFC 1034, plus a 0 byte */ |
|
60 UINT2 port; |
|
61 } dnsname; |
|
62 } u; |
|
63 int index; |
|
64 } nr_ice_stun_server; |
|
65 |
|
66 typedef struct nr_ice_turn_server_ { |
|
67 nr_ice_stun_server turn_server; |
|
68 int transport; |
|
69 char *username; |
|
70 Data *password; |
|
71 } nr_ice_turn_server; |
|
72 |
|
73 typedef struct nr_ice_foundation_ { |
|
74 int index; |
|
75 |
|
76 nr_transport_addr addr; |
|
77 int type; |
|
78 nr_ice_stun_server *stun_server; |
|
79 |
|
80 STAILQ_ENTRY(nr_ice_foundation_) entry; |
|
81 } nr_ice_foundation; |
|
82 |
|
83 typedef STAILQ_HEAD(nr_ice_foundation_head_,nr_ice_foundation_) nr_ice_foundation_head; |
|
84 |
|
85 typedef TAILQ_HEAD(nr_ice_candidate_head_,nr_ice_candidate_) nr_ice_candidate_head; |
|
86 typedef TAILQ_HEAD(nr_ice_cand_pair_head_,nr_ice_cand_pair_) nr_ice_cand_pair_head; |
|
87 typedef struct nr_ice_component_ nr_ice_component; |
|
88 typedef struct nr_ice_media_stream_ nr_ice_media_stream; |
|
89 typedef struct nr_ice_ctx_ nr_ice_ctx; |
|
90 typedef struct nr_ice_peer_ctx_ nr_ice_peer_ctx; |
|
91 typedef struct nr_ice_candidate_ nr_ice_candidate; |
|
92 typedef struct nr_ice_cand_pair_ nr_ice_cand_pair; |
|
93 typedef void (*nr_ice_trickle_candidate_cb) (void *cb_arg, |
|
94 nr_ice_ctx *ctx, nr_ice_media_stream *stream, int component_id, |
|
95 nr_ice_candidate *candidate); |
|
96 |
|
97 #include "ice_socket.h" |
|
98 #include "ice_component.h" |
|
99 #include "ice_media_stream.h" |
|
100 #include "ice_candidate.h" |
|
101 #include "ice_candidate_pair.h" |
|
102 #include "ice_handler.h" |
|
103 #include "ice_peer_ctx.h" |
|
104 |
|
105 typedef struct nr_ice_stun_id_ { |
|
106 UCHAR id[12]; |
|
107 |
|
108 STAILQ_ENTRY(nr_ice_stun_id_) entry; |
|
109 } nr_ice_stun_id; |
|
110 |
|
111 typedef STAILQ_HEAD(nr_ice_stun_id_head_,nr_ice_stun_id_) nr_ice_stun_id_head; |
|
112 |
|
113 struct nr_ice_ctx_ { |
|
114 UINT4 flags; |
|
115 int state; |
|
116 #define NR_ICE_STATE_CREATED 1 |
|
117 #define NR_ICE_STATE_INITIALIZING 2 |
|
118 #define NR_ICE_STATE_INITIALIZED 3 |
|
119 char *label; |
|
120 |
|
121 char *ufrag; |
|
122 char *pwd; |
|
123 |
|
124 UINT4 Ta; |
|
125 |
|
126 nr_ice_stun_server *stun_servers; /* The list of stun servers */ |
|
127 int stun_server_ct; |
|
128 nr_ice_turn_server *turn_servers; /* The list of turn servers */ |
|
129 int turn_server_ct; |
|
130 nr_local_addr *local_addrs; /* The list of available local addresses and corresponding interface information */ |
|
131 int local_addr_ct; |
|
132 |
|
133 nr_resolver *resolver; /* The resolver to use */ |
|
134 nr_interface_prioritizer *interface_prioritizer; /* Priority decision logic */ |
|
135 |
|
136 nr_ice_foundation_head foundations; |
|
137 |
|
138 nr_ice_media_stream_head streams; /* Media streams */ |
|
139 int stream_ct; |
|
140 nr_ice_socket_head sockets; /* The sockets we're using */ |
|
141 int uninitialized_candidates; |
|
142 |
|
143 UINT4 gather_rto; |
|
144 UINT4 stun_delay; |
|
145 |
|
146 nr_ice_peer_ctx_head peers; |
|
147 nr_ice_stun_id_head ids; |
|
148 |
|
149 NR_async_cb done_cb; |
|
150 void *cb_arg; |
|
151 |
|
152 nr_ice_trickle_candidate_cb trickle_cb; |
|
153 void *trickle_cb_arg; |
|
154 }; |
|
155 |
|
156 int nr_ice_ctx_create(char *label, UINT4 flags, nr_ice_ctx **ctxp); |
|
157 #define NR_ICE_CTX_FLAGS_OFFERER 1 |
|
158 #define NR_ICE_CTX_FLAGS_ANSWERER (1<<1) |
|
159 #define NR_ICE_CTX_FLAGS_AGGRESSIVE_NOMINATION (1<<2) |
|
160 #define NR_ICE_CTX_FLAGS_LITE (1<<3) |
|
161 |
|
162 int nr_ice_ctx_destroy(nr_ice_ctx **ctxp); |
|
163 int nr_ice_initialize(nr_ice_ctx *ctx, NR_async_cb done_cb, void *cb_arg); |
|
164 int nr_ice_add_candidate(nr_ice_ctx *ctx, nr_ice_candidate *cand); |
|
165 void nr_ice_initialize_finished_cb(NR_SOCKET s, int h, void *cb_arg); |
|
166 int nr_ice_add_media_stream(nr_ice_ctx *ctx,char *label,int components, nr_ice_media_stream **streamp); |
|
167 int nr_ice_get_global_attributes(nr_ice_ctx *ctx,char ***attrsp, int *attrctp); |
|
168 int nr_ice_ctx_deliver_packet(nr_ice_ctx *ctx, nr_ice_component *comp, nr_transport_addr *source_addr, UCHAR *data, int len); |
|
169 int nr_ice_ctx_is_known_id(nr_ice_ctx *ctx, UCHAR id[12]); |
|
170 int nr_ice_ctx_remember_id(nr_ice_ctx *ctx, nr_stun_message *msg); |
|
171 int nr_ice_ctx_finalize(nr_ice_ctx *ctx, nr_ice_peer_ctx *pctx); |
|
172 int nr_ice_ctx_set_stun_servers(nr_ice_ctx *ctx,nr_ice_stun_server *servers, int ct); |
|
173 int nr_ice_ctx_set_turn_servers(nr_ice_ctx *ctx,nr_ice_turn_server *servers, int ct); |
|
174 int nr_ice_ctx_set_resolver(nr_ice_ctx *ctx, nr_resolver *resolver); |
|
175 int nr_ice_ctx_set_interface_prioritizer(nr_ice_ctx *ctx, nr_interface_prioritizer *prioritizer); |
|
176 int nr_ice_ctx_set_trickle_cb(nr_ice_ctx *ctx, nr_ice_trickle_candidate_cb cb, void *cb_arg); |
|
177 |
|
178 #define NR_ICE_MAX_ATTRIBUTE_SIZE 256 |
|
179 |
|
180 extern int LOG_ICE; |
|
181 |
|
182 #ifdef __cplusplus |
|
183 } |
|
184 #endif /* __cplusplus */ |
|
185 #endif |
|
186 |