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_candidate_h
36 #define _ice_candidate_h
37 #ifdef __cplusplus
38 using namespace std;
39 extern "C" {
40 #endif /* __cplusplus */
41 
42 typedef enum {HOST=1, SERVER_REFLEXIVE, PEER_REFLEXIVE, RELAYED, CTYPE_MAX} nr_ice_candidate_type;
43 
44 struct nr_ice_candidate_ {
45   char *label;
46   char codeword[5];
47   int state;
48   int trickled;
49 #define NR_ICE_CAND_STATE_CREATED          1
50 #define NR_ICE_CAND_STATE_INITIALIZING     2
51 #define NR_ICE_CAND_STATE_INITIALIZED      3
52 #define NR_ICE_CAND_STATE_FAILED           4
53 #define NR_ICE_CAND_PEER_CANDIDATE_UNPAIRED 9
54 #define NR_ICE_CAND_PEER_CANDIDATE_PAIRED   10
55   struct nr_ice_ctx_ *ctx;
56   nr_ice_socket *isock;               /* The socket to read from
57                                          (it contains all other candidates
58                                          on this socket) */
59   nr_socket *osock;                   /* The socket to write to */
60   nr_ice_media_stream *stream;        /* The media stream this is associated with */
61   nr_ice_component *component;        /* The component this is associated with */
62   nr_ice_candidate_type type;         /* The type of the candidate (S 4.1.1) */
63   nr_socket_tcp_type tcp_type;
64   UCHAR component_id;                 /* The component id (S 4.1.2.1) */
65   nr_transport_addr addr;             /* The advertised address;
66                                          JDR calls this the candidate */
67   nr_transport_addr base;             /* The base address (S 2.1)*/
68   char *foundation;                   /* Foundation for the candidate (S 4) */
69   UINT4 priority;                     /* The priority value (S 5.4 */
70   nr_ice_stun_server *stun_server;
71   nr_transport_addr stun_server_addr; /* Resolved STUN server address */
72   void *delay_timer;
73   void *resolver_handle;
74 
75   /* Holding data for STUN and TURN */
76   union {
77     struct {
78       nr_stun_client_ctx *stun;
79       void *stun_handle;
80       /* If this is a srflx that is piggybacking on a relay candidate, this is
81        * a back pointer to that relay candidate. */
82       nr_ice_candidate *relay_candidate;
83     } srvrflx;
84     struct {
85       nr_turn_client_ctx *turn;
86       nr_ice_turn_server *server;
87       nr_ice_candidate *srvflx_candidate;
88       nr_socket *turn_sock;
89       void *turn_handle;
90     } relayed;
91   } u;
92 
93   NR_async_cb done_cb;
94   void *cb_arg;
95 
96   NR_async_cb ready_cb;
97   void *ready_cb_arg;
98   void *ready_cb_timer;
99 
100   TAILQ_ENTRY(nr_ice_candidate_) entry_sock;
101   TAILQ_ENTRY(nr_ice_candidate_) entry_comp;
102 };
103 
104 extern char *nr_ice_candidate_type_names[];
105 extern char *nr_ice_candidate_tcp_type_names[];
106 
107 
108 int nr_ice_candidate_create(struct nr_ice_ctx_ *ctx,nr_ice_component *component, nr_ice_socket *isock, nr_socket *osock, nr_ice_candidate_type ctype, nr_socket_tcp_type tcp_type, nr_ice_stun_server *stun_server, UCHAR component_id, nr_ice_candidate **candp);
109 int nr_ice_candidate_initialize(nr_ice_candidate *cand, NR_async_cb ready_cb, void *cb_arg);
110 void nr_ice_candidate_compute_codeword(nr_ice_candidate *cand);
111 int nr_ice_candidate_process_stun(nr_ice_candidate *cand, UCHAR *msg, int len, nr_transport_addr *faddr);
112 int nr_ice_candidate_destroy(nr_ice_candidate **candp);
113 int nr_ice_format_candidate_attribute(nr_ice_candidate *cand, char *attr, int maxlen);
114 int nr_ice_peer_candidate_from_attribute(nr_ice_ctx *ctx,char *attr,nr_ice_media_stream *stream,nr_ice_candidate **candp);
115 int nr_ice_peer_peer_rflx_candidate_create(nr_ice_ctx *ctx,char *label, nr_ice_component *comp,nr_transport_addr *addr, nr_ice_candidate **candp);
116 int nr_ice_candidate_compute_priority(nr_ice_candidate *cand);
117 
118 #ifdef __cplusplus
119 }
120 #endif /* __cplusplus */
121 #endif
122 
123