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 typedef std::vector<Candidate> Candidates; 79 80 struct TransportDescription { 81 TransportDescription() : ice_mode(ICEMODE_FULL) {} 82 83 TransportDescription(const std::string& transport_type, 84 const std::vector<std::string>& transport_options, 85 const std::string& ice_ufrag, 86 const std::string& ice_pwd, 87 IceMode ice_mode, 88 const talk_base::SSLFingerprint* identity_fingerprint, 89 const Candidates& candidates) 90 : transport_type(transport_type), 91 transport_options(transport_options), 92 ice_ufrag(ice_ufrag), 93 ice_pwd(ice_pwd), 94 ice_mode(ice_mode), 95 identity_fingerprint(CopyFingerprint(identity_fingerprint)), 96 candidates(candidates) {} 97 TransportDescription(const std::string& transport_type, 98 const Candidates& candidates) 99 : transport_type(transport_type), 100 ice_mode(ICEMODE_FULL), 101 candidates(candidates) {} 102 TransportDescription(const TransportDescription& from) 103 : transport_type(from.transport_type), 104 transport_options(from.transport_options), 105 ice_ufrag(from.ice_ufrag), 106 ice_pwd(from.ice_pwd), 107 ice_mode(from.ice_mode), 108 identity_fingerprint(CopyFingerprint(from.identity_fingerprint.get())), 109 candidates(from.candidates) {} 110 111 TransportDescription& operator=(const TransportDescription& from) { 112 // Self-assignment 113 if (this == &from) 114 return *this; 115 116 transport_type = from.transport_type; 117 transport_options = from.transport_options; 118 ice_ufrag = from.ice_ufrag; 119 ice_pwd = from.ice_pwd; 120 ice_mode = from.ice_mode; 121 122 identity_fingerprint.reset(CopyFingerprint( 123 from.identity_fingerprint.get())); 124 candidates = from.candidates; 125 return *this; 126 } 127 128 bool HasOption(const std::string& option) const { 129 return (std::find(transport_options.begin(), transport_options.end(), 130 option) != transport_options.end()); 131 } 132 void AddOption(const std::string& option) { 133 transport_options.push_back(option); 134 } 135 bool secure() { return identity_fingerprint != NULL; } 136 137 static talk_base::SSLFingerprint* CopyFingerprint( 138 const talk_base::SSLFingerprint* from) { 139 if (!from) 140 return NULL; 141 142 return new talk_base::SSLFingerprint(*from); 143 } 144 145 std::string transport_type; // xmlns of <transport> 146 std::vector<std::string> transport_options; 147 std::string ice_ufrag; 148 std::string ice_pwd; 149 IceMode ice_mode; 150 151 talk_base::scoped_ptr<talk_base::SSLFingerprint> identity_fingerprint; 152 Candidates candidates; 153 }; 154 155 } // namespace cricket 156 157 #endif // TALK_P2P_BASE_TRANSPORTDESCRIPTION_H_ 158