1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/mtransport/third_party/nICEr/src/ice/ice_ctx.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,186 @@ 1.4 +/* 1.5 +Copyright (c) 2007, Adobe Systems, Incorporated 1.6 +All rights reserved. 1.7 + 1.8 +Redistribution and use in source and binary forms, with or without 1.9 +modification, are permitted provided that the following conditions are 1.10 +met: 1.11 + 1.12 +* Redistributions of source code must retain the above copyright 1.13 + notice, this list of conditions and the following disclaimer. 1.14 + 1.15 +* Redistributions in binary form must reproduce the above copyright 1.16 + notice, this list of conditions and the following disclaimer in the 1.17 + documentation and/or other materials provided with the distribution. 1.18 + 1.19 +* Neither the name of Adobe Systems, Network Resonance nor the names of its 1.20 + contributors may be used to endorse or promote products derived from 1.21 + this software without specific prior written permission. 1.22 + 1.23 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.24 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.25 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.26 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.27 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.28 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.29 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.30 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.31 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.32 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.33 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.34 +*/ 1.35 + 1.36 + 1.37 + 1.38 +#ifndef _ice_ctx_h 1.39 +#define _ice_ctx_h 1.40 +#ifdef __cplusplus 1.41 +using namespace std; 1.42 +extern "C" { 1.43 +#endif /* __cplusplus */ 1.44 + 1.45 +/* Not good practice but making includes simpler */ 1.46 +#include "transport_addr.h" 1.47 +#include "nr_socket.h" 1.48 +#include "nr_resolver.h" 1.49 +#include "nr_interface_prioritizer.h" 1.50 +#include "stun_client_ctx.h" 1.51 +#include "stun_server_ctx.h" 1.52 +#include "turn_client_ctx.h" 1.53 + 1.54 +#define NR_ICE_STUN_SERVER_TYPE_ADDR 1 1.55 +#define NR_ICE_STUN_SERVER_TYPE_DNSNAME 2 1.56 + 1.57 +typedef struct nr_ice_stun_server_ { 1.58 + int type; 1.59 + union { 1.60 + nr_transport_addr addr; 1.61 + struct { 1.62 + char host[256]; /* Limit from RFC 1034, plus a 0 byte */ 1.63 + UINT2 port; 1.64 + } dnsname; 1.65 + } u; 1.66 + int index; 1.67 +} nr_ice_stun_server; 1.68 + 1.69 +typedef struct nr_ice_turn_server_ { 1.70 + nr_ice_stun_server turn_server; 1.71 + int transport; 1.72 + char *username; 1.73 + Data *password; 1.74 +} nr_ice_turn_server; 1.75 + 1.76 +typedef struct nr_ice_foundation_ { 1.77 + int index; 1.78 + 1.79 + nr_transport_addr addr; 1.80 + int type; 1.81 + nr_ice_stun_server *stun_server; 1.82 + 1.83 + STAILQ_ENTRY(nr_ice_foundation_) entry; 1.84 +} nr_ice_foundation; 1.85 + 1.86 +typedef STAILQ_HEAD(nr_ice_foundation_head_,nr_ice_foundation_) nr_ice_foundation_head; 1.87 + 1.88 +typedef TAILQ_HEAD(nr_ice_candidate_head_,nr_ice_candidate_) nr_ice_candidate_head; 1.89 +typedef TAILQ_HEAD(nr_ice_cand_pair_head_,nr_ice_cand_pair_) nr_ice_cand_pair_head; 1.90 +typedef struct nr_ice_component_ nr_ice_component; 1.91 +typedef struct nr_ice_media_stream_ nr_ice_media_stream; 1.92 +typedef struct nr_ice_ctx_ nr_ice_ctx; 1.93 +typedef struct nr_ice_peer_ctx_ nr_ice_peer_ctx; 1.94 +typedef struct nr_ice_candidate_ nr_ice_candidate; 1.95 +typedef struct nr_ice_cand_pair_ nr_ice_cand_pair; 1.96 +typedef void (*nr_ice_trickle_candidate_cb) (void *cb_arg, 1.97 + nr_ice_ctx *ctx, nr_ice_media_stream *stream, int component_id, 1.98 + nr_ice_candidate *candidate); 1.99 + 1.100 +#include "ice_socket.h" 1.101 +#include "ice_component.h" 1.102 +#include "ice_media_stream.h" 1.103 +#include "ice_candidate.h" 1.104 +#include "ice_candidate_pair.h" 1.105 +#include "ice_handler.h" 1.106 +#include "ice_peer_ctx.h" 1.107 + 1.108 +typedef struct nr_ice_stun_id_ { 1.109 + UCHAR id[12]; 1.110 + 1.111 + STAILQ_ENTRY(nr_ice_stun_id_) entry; 1.112 +} nr_ice_stun_id; 1.113 + 1.114 +typedef STAILQ_HEAD(nr_ice_stun_id_head_,nr_ice_stun_id_) nr_ice_stun_id_head; 1.115 + 1.116 +struct nr_ice_ctx_ { 1.117 + UINT4 flags; 1.118 + int state; 1.119 +#define NR_ICE_STATE_CREATED 1 1.120 +#define NR_ICE_STATE_INITIALIZING 2 1.121 +#define NR_ICE_STATE_INITIALIZED 3 1.122 + char *label; 1.123 + 1.124 + char *ufrag; 1.125 + char *pwd; 1.126 + 1.127 + UINT4 Ta; 1.128 + 1.129 + nr_ice_stun_server *stun_servers; /* The list of stun servers */ 1.130 + int stun_server_ct; 1.131 + nr_ice_turn_server *turn_servers; /* The list of turn servers */ 1.132 + int turn_server_ct; 1.133 + nr_local_addr *local_addrs; /* The list of available local addresses and corresponding interface information */ 1.134 + int local_addr_ct; 1.135 + 1.136 + nr_resolver *resolver; /* The resolver to use */ 1.137 + nr_interface_prioritizer *interface_prioritizer; /* Priority decision logic */ 1.138 + 1.139 + nr_ice_foundation_head foundations; 1.140 + 1.141 + nr_ice_media_stream_head streams; /* Media streams */ 1.142 + int stream_ct; 1.143 + nr_ice_socket_head sockets; /* The sockets we're using */ 1.144 + int uninitialized_candidates; 1.145 + 1.146 + UINT4 gather_rto; 1.147 + UINT4 stun_delay; 1.148 + 1.149 + nr_ice_peer_ctx_head peers; 1.150 + nr_ice_stun_id_head ids; 1.151 + 1.152 + NR_async_cb done_cb; 1.153 + void *cb_arg; 1.154 + 1.155 + nr_ice_trickle_candidate_cb trickle_cb; 1.156 + void *trickle_cb_arg; 1.157 +}; 1.158 + 1.159 +int nr_ice_ctx_create(char *label, UINT4 flags, nr_ice_ctx **ctxp); 1.160 +#define NR_ICE_CTX_FLAGS_OFFERER 1 1.161 +#define NR_ICE_CTX_FLAGS_ANSWERER (1<<1) 1.162 +#define NR_ICE_CTX_FLAGS_AGGRESSIVE_NOMINATION (1<<2) 1.163 +#define NR_ICE_CTX_FLAGS_LITE (1<<3) 1.164 + 1.165 +int nr_ice_ctx_destroy(nr_ice_ctx **ctxp); 1.166 +int nr_ice_initialize(nr_ice_ctx *ctx, NR_async_cb done_cb, void *cb_arg); 1.167 +int nr_ice_add_candidate(nr_ice_ctx *ctx, nr_ice_candidate *cand); 1.168 +void nr_ice_initialize_finished_cb(NR_SOCKET s, int h, void *cb_arg); 1.169 +int nr_ice_add_media_stream(nr_ice_ctx *ctx,char *label,int components, nr_ice_media_stream **streamp); 1.170 +int nr_ice_get_global_attributes(nr_ice_ctx *ctx,char ***attrsp, int *attrctp); 1.171 +int nr_ice_ctx_deliver_packet(nr_ice_ctx *ctx, nr_ice_component *comp, nr_transport_addr *source_addr, UCHAR *data, int len); 1.172 +int nr_ice_ctx_is_known_id(nr_ice_ctx *ctx, UCHAR id[12]); 1.173 +int nr_ice_ctx_remember_id(nr_ice_ctx *ctx, nr_stun_message *msg); 1.174 +int nr_ice_ctx_finalize(nr_ice_ctx *ctx, nr_ice_peer_ctx *pctx); 1.175 +int nr_ice_ctx_set_stun_servers(nr_ice_ctx *ctx,nr_ice_stun_server *servers, int ct); 1.176 +int nr_ice_ctx_set_turn_servers(nr_ice_ctx *ctx,nr_ice_turn_server *servers, int ct); 1.177 +int nr_ice_ctx_set_resolver(nr_ice_ctx *ctx, nr_resolver *resolver); 1.178 +int nr_ice_ctx_set_interface_prioritizer(nr_ice_ctx *ctx, nr_interface_prioritizer *prioritizer); 1.179 +int nr_ice_ctx_set_trickle_cb(nr_ice_ctx *ctx, nr_ice_trickle_candidate_cb cb, void *cb_arg); 1.180 + 1.181 +#define NR_ICE_MAX_ATTRIBUTE_SIZE 256 1.182 + 1.183 +extern int LOG_ICE; 1.184 + 1.185 +#ifdef __cplusplus 1.186 +} 1.187 +#endif /* __cplusplus */ 1.188 +#endif 1.189 +