Home | History | Annotate | Download | only in base
      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/p2p/base/candidate.h"
     36 #include "talk/p2p/base/constants.h"
     37 #include "webrtc/base/scoped_ptr.h"
     38 #include "webrtc/base/sslfingerprint.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 {
    102   TransportDescription()
    103       : ice_mode(ICEMODE_FULL),
    104         connection_role(CONNECTIONROLE_NONE) {}
    105 
    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,
    111                        ConnectionRole role,
    112                        const rtc::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),
    119         connection_role(role),
    120         identity_fingerprint(CopyFingerprint(identity_fingerprint)),
    121         candidates(candidates) {}
    122   TransportDescription(const std::string& transport_type,
    123                        const std::string& ice_ufrag,
    124                        const std::string& ice_pwd)
    125       : transport_type(transport_type),
    126         ice_ufrag(ice_ufrag),
    127         ice_pwd(ice_pwd),
    128         ice_mode(ICEMODE_FULL),
    129         connection_role(CONNECTIONROLE_NONE) {}
    130   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),
    136         connection_role(from.connection_role),
    137         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;
    150     connection_role = from.connection_role;
    151 
    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   }
    165   bool secure() const { return identity_fingerprint != NULL; }
    166 
    167   static rtc::SSLFingerprint* CopyFingerprint(
    168       const rtc::SSLFingerprint* from) {
    169     if (!from)
    170       return NULL;
    171 
    172     return new rtc::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;
    180   ConnectionRole connection_role;
    181 
    182   rtc::scoped_ptr<rtc::SSLFingerprint> identity_fingerprint;
    183   Candidates candidates;
    184 };
    185 
    186 }  // namespace cricket
    187 
    188 #endif  // TALK_P2P_BASE_TRANSPORTDESCRIPTION_H_
    189