2 * Copyright 2012 The WebRTC Project Authors. All rights reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #ifndef WEBRTC_P2P_BASE_TRANSPORTDESCRIPTION_H_
12 #define WEBRTC_P2P_BASE_TRANSPORTDESCRIPTION_H_
18 #include "webrtc/p2p/base/candidate.h"
19 #include "webrtc/p2p/base/constants.h"
20 #include "webrtc/base/scoped_ptr.h"
21 #include "webrtc/base/sslfingerprint.h"
25 // SEC_ENABLED and SEC_REQUIRED should only be used if the session
26 // was negotiated over TLS, to protect the inline crypto material
28 // SEC_DISABLED: No crypto in outgoing offer, ignore any supplied crypto.
29 // SEC_ENABLED: Crypto in outgoing offer and answer (if supplied in offer).
30 // SEC_REQUIRED: Crypto in outgoing offer and answer. Fail any offer with absent
31 // or unsupported crypto.
38 // The transport protocol we've elected to use.
39 enum TransportProtocol {
40 ICEPROTO_GOOGLE, // Google version of ICE protocol.
41 ICEPROTO_HYBRID, // ICE, but can fall back to the Google version.
42 ICEPROTO_RFC5245 // Standard RFC 5245 version of ICE.
44 // The old name for TransportProtocol.
45 // TODO(juberti): remove this.
46 typedef TransportProtocol IceProtocolType;
48 // Whether our side of the call is driving the negotiation, or the other side.
50 ICEROLE_CONTROLLING = 0,
55 // ICE RFC 5245 implementation type.
57 ICEMODE_FULL, // As defined in http://tools.ietf.org/html/rfc5245#section-4.1
58 ICEMODE_LITE // As defined in http://tools.ietf.org/html/rfc5245#section-4.2
61 // RFC 4145 - http://tools.ietf.org/html/rfc4145#section-4
62 // 'active': The endpoint will initiate an outgoing connection.
63 // 'passive': The endpoint will accept an incoming connection.
64 // 'actpass': The endpoint is willing to accept an incoming
65 // connection or to initiate an outgoing connection.
67 CONNECTIONROLE_NONE = 0,
68 CONNECTIONROLE_ACTIVE,
69 CONNECTIONROLE_PASSIVE,
70 CONNECTIONROLE_ACTPASS,
71 CONNECTIONROLE_HOLDCONN,
74 extern const char CONNECTIONROLE_ACTIVE_STR[];
75 extern const char CONNECTIONROLE_PASSIVE_STR[];
76 extern const char CONNECTIONROLE_ACTPASS_STR[];
77 extern const char CONNECTIONROLE_HOLDCONN_STR[];
79 bool StringToConnectionRole(const std::string& role_str, ConnectionRole* role);
80 bool ConnectionRoleToString(const ConnectionRole& role, std::string* role_str);
82 typedef std::vector<Candidate> Candidates;
84 struct TransportDescription {
85 TransportDescription()
86 : ice_mode(ICEMODE_FULL),
87 connection_role(CONNECTIONROLE_NONE) {}
89 TransportDescription(const std::string& transport_type,
90 const std::vector<std::string>& transport_options,
91 const std::string& ice_ufrag,
92 const std::string& ice_pwd,
95 const rtc::SSLFingerprint* identity_fingerprint,
96 const Candidates& candidates)
97 : transport_type(transport_type),
98 transport_options(transport_options),
102 connection_role(role),
103 identity_fingerprint(CopyFingerprint(identity_fingerprint)),
104 candidates(candidates) {}
105 TransportDescription(const std::string& transport_type,
106 const std::string& ice_ufrag,
107 const std::string& ice_pwd)
108 : transport_type(transport_type),
109 ice_ufrag(ice_ufrag),
111 ice_mode(ICEMODE_FULL),
112 connection_role(CONNECTIONROLE_NONE) {}
113 TransportDescription(const TransportDescription& from)
114 : transport_type(from.transport_type),
115 transport_options(from.transport_options),
116 ice_ufrag(from.ice_ufrag),
117 ice_pwd(from.ice_pwd),
118 ice_mode(from.ice_mode),
119 connection_role(from.connection_role),
120 identity_fingerprint(CopyFingerprint(from.identity_fingerprint.get())),
121 candidates(from.candidates) {}
123 TransportDescription& operator=(const TransportDescription& from) {
128 transport_type = from.transport_type;
129 transport_options = from.transport_options;
130 ice_ufrag = from.ice_ufrag;
131 ice_pwd = from.ice_pwd;
132 ice_mode = from.ice_mode;
133 connection_role = from.connection_role;
135 identity_fingerprint.reset(CopyFingerprint(
136 from.identity_fingerprint.get()));
137 candidates = from.candidates;
141 bool HasOption(const std::string& option) const {
142 return (std::find(transport_options.begin(), transport_options.end(),
143 option) != transport_options.end());
145 void AddOption(const std::string& option) {
146 transport_options.push_back(option);
148 bool secure() const { return identity_fingerprint != NULL; }
150 static rtc::SSLFingerprint* CopyFingerprint(
151 const rtc::SSLFingerprint* from) {
155 return new rtc::SSLFingerprint(*from);
158 std::string transport_type; // xmlns of <transport>
159 std::vector<std::string> transport_options;
160 std::string ice_ufrag;
163 ConnectionRole connection_role;
165 rtc::scoped_ptr<rtc::SSLFingerprint> identity_fingerprint;
166 Candidates candidates;
169 } // namespace cricket
171 #endif // WEBRTC_P2P_BASE_TRANSPORTDESCRIPTION_H_