blob: a8233a61f3a97e415beeb7a4a7ac3d086b5d083b [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2012, The Libjingle Authors.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef TALK_P2P_BASE_TRANSPORTDESCRIPTION_H_
29#define TALK_P2P_BASE_TRANSPORTDESCRIPTION_H_
30
31#include <algorithm>
32#include <string>
33#include <vector>
34
35#include "talk/base/scoped_ptr.h"
36#include "talk/base/sslfingerprint.h"
37#include "talk/p2p/base/candidate.h"
38#include "talk/p2p/base/constants.h"
39
40namespace cricket {
41
42// SEC_ENABLED and SEC_REQUIRED should only be used if the session
43// was negotiated over TLS, to protect the inline crypto material
44// exchange.
45// SEC_DISABLED: No crypto in outgoing offer, ignore any supplied crypto.
46// SEC_ENABLED: Crypto in outgoing offer and answer (if supplied in offer).
47// SEC_REQUIRED: Crypto in outgoing offer and answer. Fail any offer with absent
48// or unsupported crypto.
49enum SecurePolicy {
50 SEC_DISABLED,
51 SEC_ENABLED,
52 SEC_REQUIRED
53};
54
55// The transport protocol we've elected to use.
56enum TransportProtocol {
57 ICEPROTO_GOOGLE, // Google version of ICE protocol.
58 ICEPROTO_HYBRID, // ICE, but can fall back to the Google version.
59 ICEPROTO_RFC5245 // Standard RFC 5245 version of ICE.
60};
61// The old name for TransportProtocol.
62// TODO(juberti): remove this.
63typedef TransportProtocol IceProtocolType;
64
mallinath@webrtc.orga5506692013-08-12 21:18:15 +000065// Whether our side of the call is driving the negotiation, or the other side.
66enum IceRole {
67 ICEROLE_CONTROLLING = 0,
68 ICEROLE_CONTROLLED,
69 ICEROLE_UNKNOWN
70};
71
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072// ICE RFC 5245 implementation type.
73enum IceMode {
74 ICEMODE_FULL, // As defined in http://tools.ietf.org/html/rfc5245#section-4.1
75 ICEMODE_LITE // As defined in http://tools.ietf.org/html/rfc5245#section-4.2
76};
77
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +000078// RFC 4145 - http://tools.ietf.org/html/rfc4145#section-4
79// 'active': The endpoint will initiate an outgoing connection.
80// 'passive': The endpoint will accept an incoming connection.
81// 'actpass': The endpoint is willing to accept an incoming
82// connection or to initiate an outgoing connection.
83enum ConnectionRole {
84 CONNECTIONROLE_NONE = 0,
85 CONNECTIONROLE_ACTIVE,
86 CONNECTIONROLE_PASSIVE,
87 CONNECTIONROLE_ACTPASS,
88 CONNECTIONROLE_HOLDCONN,
89};
90
91extern const char CONNECTIONROLE_ACTIVE_STR[];
92extern const char CONNECTIONROLE_PASSIVE_STR[];
93extern const char CONNECTIONROLE_ACTPASS_STR[];
94extern const char CONNECTIONROLE_HOLDCONN_STR[];
95
96bool StringToConnectionRole(const std::string& role_str, ConnectionRole* role);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000097bool ConnectionRoleToString(const ConnectionRole& role, std::string* role_str);
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +000098
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099typedef std::vector<Candidate> Candidates;
100
101struct TransportDescription {
jiayl@webrtc.org974bbbb2014-07-01 18:33:07 +0000102 TransportDescription()
103 : ice_mode(ICEMODE_FULL),
104 connection_role(CONNECTIONROLE_NONE) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105
106 TransportDescription(const std::string& transport_type,
107 const std::vector<std::string>& transport_options,
108 const std::string& ice_ufrag,
109 const std::string& ice_pwd,
110 IceMode ice_mode,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000111 ConnectionRole role,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112 const talk_base::SSLFingerprint* identity_fingerprint,
113 const Candidates& candidates)
114 : transport_type(transport_type),
115 transport_options(transport_options),
116 ice_ufrag(ice_ufrag),
117 ice_pwd(ice_pwd),
118 ice_mode(ice_mode),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000119 connection_role(role),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120 identity_fingerprint(CopyFingerprint(identity_fingerprint)),
121 candidates(candidates) {}
122 TransportDescription(const std::string& transport_type,
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000123 const std::string& ice_ufrag,
124 const std::string& ice_pwd)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125 : transport_type(transport_type),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000126 ice_ufrag(ice_ufrag),
127 ice_pwd(ice_pwd),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000128 ice_mode(ICEMODE_FULL),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000129 connection_role(CONNECTIONROLE_NONE) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130 TransportDescription(const TransportDescription& from)
131 : transport_type(from.transport_type),
132 transport_options(from.transport_options),
133 ice_ufrag(from.ice_ufrag),
134 ice_pwd(from.ice_pwd),
135 ice_mode(from.ice_mode),
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000136 connection_role(from.connection_role),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137 identity_fingerprint(CopyFingerprint(from.identity_fingerprint.get())),
138 candidates(from.candidates) {}
139
140 TransportDescription& operator=(const TransportDescription& from) {
141 // Self-assignment
142 if (this == &from)
143 return *this;
144
145 transport_type = from.transport_type;
146 transport_options = from.transport_options;
147 ice_ufrag = from.ice_ufrag;
148 ice_pwd = from.ice_pwd;
149 ice_mode = from.ice_mode;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000150 connection_role = from.connection_role;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151
152 identity_fingerprint.reset(CopyFingerprint(
153 from.identity_fingerprint.get()));
154 candidates = from.candidates;
155 return *this;
156 }
157
158 bool HasOption(const std::string& option) const {
159 return (std::find(transport_options.begin(), transport_options.end(),
160 option) != transport_options.end());
161 }
162 void AddOption(const std::string& option) {
163 transport_options.push_back(option);
164 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000165 bool secure() const { return identity_fingerprint != NULL; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166
167 static talk_base::SSLFingerprint* CopyFingerprint(
168 const talk_base::SSLFingerprint* from) {
169 if (!from)
170 return NULL;
171
172 return new talk_base::SSLFingerprint(*from);
173 }
174
175 std::string transport_type; // xmlns of <transport>
176 std::vector<std::string> transport_options;
177 std::string ice_ufrag;
178 std::string ice_pwd;
179 IceMode ice_mode;
sergeyu@chromium.org0be6aa02013-08-23 23:21:25 +0000180 ConnectionRole connection_role;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181
182 talk_base::scoped_ptr<talk_base::SSLFingerprint> identity_fingerprint;
183 Candidates candidates;
184};
185
186} // namespace cricket
187
188#endif // TALK_P2P_BASE_TRANSPORTDESCRIPTION_H_