1 /* 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 40 namespace 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. 49 enum SecurePolicy { 50 SEC_DISABLED, 51 SEC_ENABLED, 52 SEC_REQUIRED 53 }; 54 55 // The transport protocol we've elected to use. 56 enum 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. 63 typedef TransportProtocol IceProtocolType; 64 65 // Whether our side of the call is driving the negotiation, or the other side. 66 enum IceRole { 67 ICEROLE_CONTROLLING = 0, 68 ICEROLE_CONTROLLED, 69 ICEROLE_UNKNOWN 70 }; 71 72 // ICE RFC 5245 implementation type. 73 enum 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 78 // 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. 83 enum ConnectionRole { 84 CONNECTIONROLE_NONE = 0, 85 CONNECTIONROLE_ACTIVE, 86 CONNECTIONROLE_PASSIVE, 87 CONNECTIONROLE_ACTPASS, 88 CONNECTIONROLE_HOLDCONN, 89 }; 90 91 extern const char CONNECTIONROLE_ACTIVE_STR[]; 92 extern const char CONNECTIONROLE_PASSIVE_STR[]; 93 extern const char CONNECTIONROLE_ACTPASS_STR[]; 94 extern const char CONNECTIONROLE_HOLDCONN_STR[]; 95 96 bool StringToConnectionRole(const std::string& role_str, ConnectionRole* role); 97 bool ConnectionRoleToString(const ConnectionRole& role, std::string* role_str); 98 99 typedef std::vector<Candidate> Candidates; 100 101 struct TransportDescription { TransportDescriptionTransportDescription102 TransportDescription() : ice_mode(ICEMODE_FULL) {} 103 TransportDescriptionTransportDescription104 TransportDescription(const std::string& transport_type, 105 const std::vector<std::string>& transport_options, 106 const std::string& ice_ufrag, 107 const std::string& ice_pwd, 108 IceMode ice_mode, 109 ConnectionRole role, 110 const talk_base::SSLFingerprint* identity_fingerprint, 111 const Candidates& candidates) 112 : transport_type(transport_type), 113 transport_options(transport_options), 114 ice_ufrag(ice_ufrag), 115 ice_pwd(ice_pwd), 116 ice_mode(ice_mode), 117 connection_role(role), 118 identity_fingerprint(CopyFingerprint(identity_fingerprint)), 119 candidates(candidates) {} TransportDescriptionTransportDescription120 TransportDescription(const std::string& transport_type, 121 const std::string& ice_ufrag, 122 const std::string& ice_pwd) 123 : transport_type(transport_type), 124 ice_ufrag(ice_ufrag), 125 ice_pwd(ice_pwd), 126 ice_mode(ICEMODE_FULL), 127 connection_role(CONNECTIONROLE_NONE) {} TransportDescriptionTransportDescription128 TransportDescription(const TransportDescription& from) 129 : transport_type(from.transport_type), 130 transport_options(from.transport_options), 131 ice_ufrag(from.ice_ufrag), 132 ice_pwd(from.ice_pwd), 133 ice_mode(from.ice_mode), 134 connection_role(from.connection_role), 135 identity_fingerprint(CopyFingerprint(from.identity_fingerprint.get())), 136 candidates(from.candidates) {} 137 138 TransportDescription& operator=(const TransportDescription& from) { 139 // Self-assignment 140 if (this == &from) 141 return *this; 142 143 transport_type = from.transport_type; 144 transport_options = from.transport_options; 145 ice_ufrag = from.ice_ufrag; 146 ice_pwd = from.ice_pwd; 147 ice_mode = from.ice_mode; 148 connection_role = from.connection_role; 149 150 identity_fingerprint.reset(CopyFingerprint( 151 from.identity_fingerprint.get())); 152 candidates = from.candidates; 153 return *this; 154 } 155 HasOptionTransportDescription156 bool HasOption(const std::string& option) const { 157 return (std::find(transport_options.begin(), transport_options.end(), 158 option) != transport_options.end()); 159 } AddOptionTransportDescription160 void AddOption(const std::string& option) { 161 transport_options.push_back(option); 162 } secureTransportDescription163 bool secure() const { return identity_fingerprint != NULL; } 164 CopyFingerprintTransportDescription165 static talk_base::SSLFingerprint* CopyFingerprint( 166 const talk_base::SSLFingerprint* from) { 167 if (!from) 168 return NULL; 169 170 return new talk_base::SSLFingerprint(*from); 171 } 172 173 std::string transport_type; // xmlns of <transport> 174 std::vector<std::string> transport_options; 175 std::string ice_ufrag; 176 std::string ice_pwd; 177 IceMode ice_mode; 178 ConnectionRole connection_role; 179 180 talk_base::scoped_ptr<talk_base::SSLFingerprint> identity_fingerprint; 181 Candidates candidates; 182 }; 183 184 } // namespace cricket 185 186 #endif // TALK_P2P_BASE_TRANSPORTDESCRIPTION_H_ 187