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   int obfuscate_addrs;                /* True if addresses should be obfuscated */
69   char *mdns_addr;                    /* MDNS address, if any */
70   char *foundation;                   /* Foundation for the candidate (S 4) */
71   UINT4 priority;                     /* The priority value (S 5.4 */
72   nr_ice_stun_server *stun_server;
73   nr_transport_addr stun_server_addr; /* Resolved STUN server address */
74   void *delay_timer;
75   void *resolver_handle;
76 
77   /* Holding data for STUN and TURN */
78   union {
79     struct {
80       nr_stun_client_ctx *stun;
81       void *stun_handle;
82       /* If this is a srflx that is piggybacking on a relay candidate, this is
83        * a back pointer to that relay candidate. */
84       nr_ice_candidate *relay_candidate;
85     } srvrflx;
86     struct {
87       nr_turn_client_ctx *turn;
88       nr_ice_turn_server *server;
89       nr_ice_candidate *srvflx_candidate;
90       nr_socket *turn_sock;
91       void *turn_handle;
92     } relayed;
93   } u;
94 
95   NR_async_cb done_cb;
96   void *cb_arg;
97 
98   NR_async_cb ready_cb;
99   void *ready_cb_arg;
100   void *ready_cb_timer;
101 
102   TAILQ_ENTRY(nr_ice_candidate_) entry_sock;
103   TAILQ_ENTRY(nr_ice_candidate_) entry_comp;
104 };
105 
106 extern char *nr_ice_candidate_type_names[];
107 extern char *nr_ice_candidate_tcp_type_names[];
108 
109 
110 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);
111 int nr_ice_candidate_initialize(nr_ice_candidate *cand, NR_async_cb ready_cb, void *cb_arg);
112 void nr_ice_candidate_compute_codeword(nr_ice_candidate *cand);
113 int nr_ice_candidate_process_stun(nr_ice_candidate *cand, UCHAR *msg, int len, nr_transport_addr *faddr);
114 int nr_ice_candidate_destroy(nr_ice_candidate **candp);
115 void nr_ice_candidate_stop_gathering(nr_ice_candidate *cand);
116 int nr_ice_format_candidate_attribute(nr_ice_candidate *cand, char *attr, int maxlen, int obfuscate_srflx_addr);
117 int nr_ice_peer_candidate_from_attribute(nr_ice_ctx *ctx,char *attr,nr_ice_media_stream *stream,nr_ice_candidate **candp);
118 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);
119 int nr_ice_candidate_compute_priority(nr_ice_candidate *cand);
120 
121 #ifdef __cplusplus
122 }
123 #endif /* __cplusplus */
124 #endif
125 
126