michael@0: /* michael@0: Copyright (c) 2007, Adobe Systems, Incorporated michael@0: All rights reserved. michael@0: michael@0: Redistribution and use in source and binary forms, with or without michael@0: modification, are permitted provided that the following conditions are michael@0: met: michael@0: michael@0: * Redistributions of source code must retain the above copyright michael@0: notice, this list of conditions and the following disclaimer. michael@0: michael@0: * Redistributions in binary form must reproduce the above copyright michael@0: notice, this list of conditions and the following disclaimer in the michael@0: documentation and/or other materials provided with the distribution. michael@0: michael@0: * Neither the name of Adobe Systems, Network Resonance nor the names of its michael@0: contributors may be used to endorse or promote products derived from michael@0: this software without specific prior written permission. michael@0: michael@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT michael@0: OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@0: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@0: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, michael@0: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY michael@0: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT michael@0: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE michael@0: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: michael@0: michael@0: michael@0: #ifndef _ice_candidate_h michael@0: #define _ice_candidate_h michael@0: #ifdef __cplusplus michael@0: using namespace std; michael@0: extern "C" { michael@0: #endif /* __cplusplus */ michael@0: michael@0: typedef enum {HOST=1, SERVER_REFLEXIVE, PEER_REFLEXIVE, RELAYED, CTYPE_MAX} nr_ice_candidate_type; michael@0: michael@0: struct nr_ice_candidate_ { michael@0: char *label; michael@0: char codeword[5]; michael@0: int state; michael@0: #define NR_ICE_CAND_STATE_CREATED 1 michael@0: #define NR_ICE_CAND_STATE_INITIALIZING 2 michael@0: #define NR_ICE_CAND_STATE_INITIALIZED 3 michael@0: #define NR_ICE_CAND_STATE_FAILED 4 michael@0: #define NR_ICE_CAND_PEER_CANDIDATE_UNPAIRED 9 michael@0: #define NR_ICE_CAND_PEER_CANDIDATE_PAIRED 10 michael@0: struct nr_ice_ctx_ *ctx; michael@0: nr_ice_socket *isock; /* The socket to read from michael@0: (it contains all other candidates michael@0: on this socket) */ michael@0: nr_socket *osock; /* The socket to write to */ michael@0: nr_ice_media_stream *stream; /* The media stream this is associated with */ michael@0: nr_ice_component *component; /* The component this is associated with */ michael@0: nr_ice_candidate_type type; /* The type of the candidate (S 4.1.1) */ michael@0: UCHAR component_id; /* The component id (S 4.1.2.1) */ michael@0: nr_transport_addr addr; /* The advertised address; michael@0: JDR calls this the candidate */ michael@0: nr_transport_addr base; /* The base address (S 2.1)*/ michael@0: char *foundation; /* Foundation for the candidate (S 4) */ michael@0: UINT4 priority; /* The priority value (S 5.4 */ michael@0: nr_ice_stun_server *stun_server; michael@0: nr_transport_addr stun_server_addr; /* Resolved STUN server address */ michael@0: void *delay_timer; michael@0: void *resolver_handle; michael@0: michael@0: /* Holding data for STUN and TURN */ michael@0: union { michael@0: struct { michael@0: nr_stun_client_ctx *stun; michael@0: void *stun_handle; michael@0: } srvrflx; michael@0: struct { michael@0: nr_turn_client_ctx *turn; michael@0: nr_ice_turn_server *server; michael@0: nr_ice_candidate *srvflx_candidate; michael@0: nr_socket *turn_sock; michael@0: void *turn_handle; michael@0: } relayed; michael@0: } u; michael@0: michael@0: NR_async_cb done_cb; michael@0: void *cb_arg; michael@0: michael@0: NR_async_cb ready_cb; michael@0: void *ready_cb_arg; michael@0: void *ready_cb_timer; michael@0: michael@0: TAILQ_ENTRY(nr_ice_candidate_) entry_sock; michael@0: TAILQ_ENTRY(nr_ice_candidate_) entry_comp; michael@0: }; michael@0: michael@0: extern char *nr_ice_candidate_type_names[]; michael@0: michael@0: michael@0: 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_ice_stun_server *stun_server, UCHAR component_id, nr_ice_candidate **candp); michael@0: int nr_ice_candidate_initialize(nr_ice_candidate *cand, NR_async_cb ready_cb, void *cb_arg); michael@0: void nr_ice_candidate_compute_codeword(nr_ice_candidate *cand); michael@0: int nr_ice_candidate_process_stun(nr_ice_candidate *cand, UCHAR *msg, int len, nr_transport_addr *faddr); michael@0: int nr_ice_candidate_destroy(nr_ice_candidate **candp); michael@0: void nr_ice_candidate_destroy_cb(NR_SOCKET s, int h, void *cb_arg); michael@0: int nr_ice_format_candidate_attribute(nr_ice_candidate *cand, char *attr, int maxlen); michael@0: int nr_ice_peer_candidate_from_attribute(nr_ice_ctx *ctx,char *attr,nr_ice_media_stream *stream,nr_ice_candidate **candp); michael@0: 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); michael@0: int nr_ice_candidate_compute_priority(nr_ice_candidate *cand); michael@0: michael@0: #ifdef __cplusplus michael@0: } michael@0: #endif /* __cplusplus */ michael@0: #endif michael@0: