50fa0b1b162999190aa199b6980994c85bcf63d8
[platform/upstream/libnice.git] / agent / conncheck.h
1 /*
2  * This file is part of the Nice GLib ICE library.
3  *
4  * (C) 2006-2009 Collabora Ltd.
5  *  Contact: Youness Alaoui
6  * (C) 2006-2009 Nokia Corporation. All rights reserved.
7  *  Contact: Kai Vehmanen
8  *
9  * The contents of this file are subject to the Mozilla Public License Version
10  * 1.1 (the "License"); you may not use this file except in compliance with
11  * the License. You may obtain a copy of the License at
12  * http://www.mozilla.org/MPL/
13  *
14  * Software distributed under the License is distributed on an "AS IS" basis,
15  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
16  * for the specific language governing rights and limitations under the
17  * License.
18  *
19  * The Original Code is the Nice GLib ICE library.
20  *
21  * The Initial Developers of the Original Code are Collabora Ltd and Nokia
22  * Corporation. All Rights Reserved.
23  *
24  * Contributors:
25  *   Dafydd Harries, Collabora Ltd.
26  *   Youness Alaoui, Collabora Ltd.
27  *   Kai Vehmanen, Nokia
28  *
29  * Alternatively, the contents of this file may be used under the terms of the
30  * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
31  * case the provisions of LGPL are applicable instead of those above. If you
32  * wish to allow use of your version of this file only under the terms of the
33  * LGPL and not to allow others to use your version of this file under the
34  * MPL, indicate your decision by deleting the provisions above and replace
35  * them with the notice and other provisions required by the LGPL. If you do
36  * not delete the provisions above, a recipient may use your version of this
37  * file under either the MPL or the LGPL.
38  */
39
40 #ifndef _NICE_CONNCHECK_H
41 #define _NICE_CONNCHECK_H
42
43 /* note: this is a private header to libnice */
44
45 #include "agent.h"
46 #include "stream.h"
47 #include "stun/stunagent.h"
48 #include "stun/usages/timer.h"
49
50 #define NICE_CANDIDATE_PAIR_MAX_FOUNDATION        NICE_CANDIDATE_MAX_FOUNDATION*2
51
52 /**
53  * NiceCheckState:
54  * @NICE_CHECK_WAITING: Waiting to be scheduled.
55  * @NICE_CHECK_IN_PROGRESS: Connection checks started.
56  * @NICE_CHECK_SUCCEEDED: Connection successfully checked.
57  * @NICE_CHECK_FAILED: No connectivity; retransmissions ceased.
58  * @NICE_CHECK_FROZEN: Waiting to be scheduled to %NICE_CHECK_WAITING.
59  * @NICE_CHECK_DISCOVERED: A valid candidate pair not on the check list.
60  *
61  * States for checking a candidate pair.
62  */
63 typedef enum
64 {
65   NICE_CHECK_WAITING = 1,
66   NICE_CHECK_IN_PROGRESS,
67   NICE_CHECK_SUCCEEDED,
68   NICE_CHECK_FAILED,
69   NICE_CHECK_FROZEN,
70   NICE_CHECK_DISCOVERED,
71 } NiceCheckState;
72
73 typedef struct _CandidateCheckPair CandidateCheckPair;
74 typedef struct _StunTransaction StunTransaction;
75
76 struct _StunTransaction
77 {
78   gint64 next_tick;       /* next tick timestamp */
79   StunTimer timer;
80   uint8_t buffer[STUN_MAX_MESSAGE_SIZE_IPV6];
81   StunMessage message;
82 };
83
84 struct _CandidateCheckPair
85 {
86   guint stream_id;
87   guint component_id;
88   NiceCandidate *local;
89   NiceCandidate *remote;
90   NiceSocket *sockptr;
91   gchar foundation[NICE_CANDIDATE_PAIR_MAX_FOUNDATION];
92   NiceCheckState state;
93   gboolean nominated;
94   gboolean valid;
95   gboolean use_candidate_on_next_check;
96   gboolean mark_nominated_on_response_arrival;
97   gboolean retransmit;  /* if the first stun request must be retransmitted */
98   CandidateCheckPair *discovered_pair;
99   CandidateCheckPair *succeeded_pair;
100   guint64 priority;
101   guint32 stun_priority;
102   GSList *stun_transactions; /* a list of ongoing stun requests */
103 };
104
105 int conn_check_add_for_candidate (NiceAgent *agent, guint stream_id, NiceComponent *component, NiceCandidate *remote);
106 int conn_check_add_for_local_candidate (NiceAgent *agent, guint stream_id, NiceComponent *component, NiceCandidate *local);
107 gboolean conn_check_add_for_candidate_pair (NiceAgent *agent, guint stream_id, NiceComponent *component, NiceCandidate *local, NiceCandidate *remote);
108 void conn_check_free (NiceAgent *agent);
109 void conn_check_schedule_next (NiceAgent *agent);
110 int conn_check_send (NiceAgent *agent, CandidateCheckPair *pair);
111 void conn_check_prune_stream (NiceAgent *agent, NiceStream *stream);
112 gboolean conn_check_handle_inbound_stun (NiceAgent *agent, NiceStream *stream, NiceComponent *component, NiceSocket *udp_socket, const NiceAddress *from, gchar *buf, guint len);
113 gint conn_check_compare (const CandidateCheckPair *a, const CandidateCheckPair *b);
114 void conn_check_remote_candidates_set(NiceAgent *agent, NiceStream *stream, NiceComponent *component);
115 void conn_check_remote_credentials_set(NiceAgent *agent, NiceStream *stream);
116 NiceCandidateTransport conn_check_match_transport (NiceCandidateTransport transport);
117 void
118 conn_check_prune_socket (NiceAgent *agent, NiceStream *stream, NiceComponent *component,
119     NiceSocket *sock);
120
121 void recalculate_pair_priorities (NiceAgent *agent);
122 void conn_check_update_selected_pair (NiceAgent *agent,
123     NiceComponent *component, CandidateCheckPair *pair);
124 void conn_check_update_check_list_state_for_ready (NiceAgent *agent,
125     NiceStream *stream, NiceComponent *component);
126 void conn_check_unfreeze_related (NiceAgent *agent, CandidateCheckPair *pair);
127 guint conn_check_stun_transactions_count (NiceAgent *agent);
128
129
130 #endif /*_NICE_CONNCHECK_H */