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_pair_h
36 #define _ice_candidate_pair_h
37 #ifdef __cplusplus
38 using namespace std;
39 extern "C" {
40 #endif /* __cplusplus */
41 
42 
43 struct nr_ice_cand_pair_ {
44   nr_ice_peer_ctx *pctx;
45   char codeword[5];
46   char *as_string;
47   int state;                          /* The current state (S 5.7.3) */
48 #define NR_ICE_PAIR_STATE_FROZEN           1
49 #define NR_ICE_PAIR_STATE_WAITING          2
50 #define NR_ICE_PAIR_STATE_IN_PROGRESS      3
51 #define NR_ICE_PAIR_STATE_FAILED           4
52 #define NR_ICE_PAIR_STATE_SUCCEEDED        5
53 #define NR_ICE_PAIR_STATE_CANCELLED        6
54 
55   UCHAR peer_nominated;               /* The peer sent USE-CANDIDATE
56                                          on this check */
57   UCHAR nominated;                    /* Is this nominated or not */
58 
59   UCHAR triggered;            /* Ignore further trigger check requests */
60 
61   UINT8 priority;                  /* The priority for this pair */
62   nr_ice_candidate *local;            /* The local candidate */
63   nr_ice_candidate *remote;           /* The remote candidate */
64   char *foundation;                   /* The combined foundations */
65 
66   // for RTCIceCandidatePairStats
67   UINT8 bytes_sent;
68   UINT8 bytes_recvd;
69   struct timeval last_sent;
70   struct timeval last_recvd;
71 
72   nr_stun_client_ctx *stun_client;    /* STUN context when acting as a client */
73   void *stun_client_handle;
74 
75   void *stun_cb_timer;
76   void *restart_role_change_cb_timer;
77   void *restart_nominated_cb_timer;
78 
79   TAILQ_ENTRY(nr_ice_cand_pair_) check_queue_entry;   /* the check list */
80   TAILQ_ENTRY(nr_ice_cand_pair_) triggered_check_queue_entry;  /* the trigger check queue */
81 };
82 
83 int nr_ice_candidate_pair_create(nr_ice_peer_ctx *pctx, nr_ice_candidate *lcand,nr_ice_candidate *rcand,nr_ice_cand_pair **pairp);
84 int nr_ice_candidate_pair_unfreeze(nr_ice_peer_ctx *pctx, nr_ice_cand_pair *pair);
85 int nr_ice_candidate_pair_start(nr_ice_peer_ctx *pctx, nr_ice_cand_pair *pair);
86 void nr_ice_candidate_pair_set_state(nr_ice_peer_ctx *pctx, nr_ice_cand_pair *pair, int state);
87 void nr_ice_candidate_pair_dump_state(nr_ice_cand_pair *pair, int log_level);
88 void nr_ice_candidate_pair_cancel(nr_ice_peer_ctx *pctx,nr_ice_cand_pair *pair, int move_to_wait_state);
89 int nr_ice_candidate_pair_select(nr_ice_cand_pair *pair);
90 int nr_ice_candidate_pair_do_triggered_check(nr_ice_peer_ctx *pctx, nr_ice_cand_pair *pair);
91 void nr_ice_candidate_pair_insert(nr_ice_cand_pair_head *head,nr_ice_cand_pair *pair);
92 int nr_ice_candidate_pair_trigger_check_append(nr_ice_cand_pair_head *head,nr_ice_cand_pair *pair);
93 void nr_ice_candidate_pair_restart_stun_nominated_cb(NR_SOCKET s, int how, void *cb_arg);
94 int nr_ice_candidate_pair_destroy(nr_ice_cand_pair **pairp);
95 void nr_ice_candidate_pair_role_change(nr_ice_cand_pair *pair);
96 
97 #ifdef __cplusplus
98 }
99 #endif /* __cplusplus */
100 #endif
101 
102