Don't pass the agent to the socket layer
[sipe-libnice.git] / agent / component.h
blob577dbfe6b25817619976d1076f7622ca8c6dce7e
1 /*
2 * This file is part of the Nice GLib ICE library.
4 * (C) 2006-2010 Collabora Ltd.
5 * Contact: Youness Alaoui
6 * (C) 2006-2010 Nokia Corporation. All rights reserved.
7 * Contact: Kai Vehmanen
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/
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.
19 * The Original Code is the Nice GLib ICE library.
21 * The Initial Developers of the Original Code are Collabora Ltd and Nokia
22 * Corporation. All Rights Reserved.
24 * Contributors:
25 * Dafydd Harries, Collabora Ltd.
26 * Youness Alaoui, Collabora Ltd.
27 * Kai Vehmanen, Nokia
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.
40 #ifndef _NICE_COMPONENT_H
41 #define _NICE_COMPONENT_H
43 #include <glib.h>
45 typedef struct _Component Component;
47 #include "agent.h"
48 #include "candidate.h"
49 #include "stun/stunagent.h"
50 #include "stun/usages/timer.h"
51 #include "pseudotcp.h"
52 #include "stream.h"
53 #include "socket.h"
55 G_BEGIN_DECLS
58 /* (ICE ยง4.1.1.1, ID-19)
59 * ""For RTP-based media streams, the RTP itself has a component
60 * ID of 1, and RTCP a component ID of 2. If an agent is using RTCP it MUST
61 * obtain a candidate for it. If an agent is using both RTP and RTCP, it
62 * would end up with 2*K host candidates if an agent has K interfaces.""
65 typedef struct _CandidatePair CandidatePair;
66 typedef struct _CandidatePairKeepalive CandidatePairKeepalive;
67 typedef struct _IncomingCheck IncomingCheck;
69 struct _CandidatePairKeepalive
71 NiceAgent *agent;
72 GSource *tick_source;
73 guint stream_id;
74 guint component_id;
75 StunTimer timer;
76 uint8_t stun_buffer[STUN_MAX_MESSAGE_SIZE];
77 StunMessage stun_message;
80 struct _CandidatePair
82 NiceCandidate *local;
83 NiceCandidate *remote;
84 guint64 priority; /**< candidate pair priority */
85 CandidatePairKeepalive keepalive;
88 struct _IncomingCheck
90 NiceAddress from;
91 NiceSocket *local_socket;
92 guint32 priority;
93 gboolean use_candidate;
94 uint8_t *username;
95 uint16_t username_len;
98 typedef struct {
99 NiceAgent *agent;
100 Stream *stream;
101 Component *component;
102 } TcpUserData;
104 struct _Component
106 NiceComponentType type;
107 guint id; /**< component id */
108 NiceComponentState state;
109 GSList *local_candidates; /**< list of Candidate objs */
110 GSList *remote_candidates; /**< list of Candidate objs */
111 GSList *sockets; /**< list of NiceSocket objs */
112 GSList *gsources; /**< list of GSource objs */
113 GSList *incoming_checks; /**< list of IncomingCheck objs */
114 GList *turn_servers; /**< List of TURN servers */
115 CandidatePair selected_pair; /**< independent from checklists,
116 see ICE 11.1. "Sending Media" (ID-19) */
117 NiceCandidate *restart_candidate; /**< for storing active remote candidate during a restart */
118 NiceAgentRecvFunc g_source_io_cb; /**< function called on io cb */
119 gpointer data; /**< data passed to the io function */
120 GMainContext *ctx; /**< context for data callbacks for this
121 component */
122 PseudoTcpSocket *tcp;
123 GSource* tcp_clock;
124 TcpUserData *tcp_data;
125 gboolean tcp_readable;
126 guint min_port;
127 guint max_port;
130 Component *
131 component_new (guint component_id);
133 void
134 component_free (Component *cmp);
136 gboolean
137 component_find_pair (Component *cmp, NiceAgent *agent, const gchar *lfoundation, const gchar *rfoundation, CandidatePair *pair);
139 gboolean
140 component_restart (Component *cmp);
142 void
143 component_update_selected_pair (Component *component, const CandidatePair *pair);
145 NiceCandidate *
146 component_find_remote_candidate (const Component *component, const NiceAddress *addr, NiceCandidateTransport transport);
148 NiceCandidate *
149 component_set_selected_remote_candidate (NiceAgent *agent, Component *component,
150 NiceCandidate *candidate);
152 G_END_DECLS
154 #endif /* _NICE_COMPONENT_H */