10e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org/*
20e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * libjingle
30e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * Copyright 2012, The Libjingle Authors.
40e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *
50e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * Redistribution and use in source and binary forms, with or without
60e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * modification, are permitted provided that the following conditions are met:
70e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *
80e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *  1. Redistributions of source code must retain the above copyright notice,
90e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *     this list of conditions and the following disclaimer.
100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *  2. Redistributions in binary form must reproduce the above copyright notice,
110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *     this list of conditions and the following disclaimer in the documentation
120e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *     and/or other materials provided with the distribution.
130e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *  3. The name of the author may not be used to endorse or promote products
140e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *     derived from this software without specific prior written permission.
150e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *
160e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
170e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
190e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
220e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
230e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
240e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
250e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
260e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org */
270e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
280e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#ifndef TALK_P2P_BASE_TRANSPORTDESCRIPTION_H_
290e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#define TALK_P2P_BASE_TRANSPORTDESCRIPTION_H_
300e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include <algorithm>
320e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include <string>
330e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include <vector>
340e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
350e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "talk/p2p/base/candidate.h"
360e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "talk/p2p/base/constants.h"
37cf81adffe15fa8ea0f333432e41f6d504148f18abuildbot@webrtc.org#include "webrtc/base/scoped_ptr.h"
38cf81adffe15fa8ea0f333432e41f6d504148f18abuildbot@webrtc.org#include "webrtc/base/sslfingerprint.h"
390e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
400e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgnamespace cricket {
410e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
420e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// SEC_ENABLED and SEC_REQUIRED should only be used if the session
430e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// was negotiated over TLS, to protect the inline crypto material
440e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// exchange.
450e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// SEC_DISABLED: No crypto in outgoing offer, ignore any supplied crypto.
460e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// SEC_ENABLED:  Crypto in outgoing offer and answer (if supplied in offer).
470e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// SEC_REQUIRED: Crypto in outgoing offer and answer. Fail any offer with absent
480e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org//               or unsupported crypto.
490e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgenum SecurePolicy {
500e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  SEC_DISABLED,
510e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  SEC_ENABLED,
520e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  SEC_REQUIRED
530e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org};
540e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
550e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// The transport protocol we've elected to use.
560e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgenum TransportProtocol {
570e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  ICEPROTO_GOOGLE,  // Google version of ICE protocol.
580e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  ICEPROTO_HYBRID,  // ICE, but can fall back to the Google version.
590e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  ICEPROTO_RFC5245  // Standard RFC 5245 version of ICE.
600e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org};
610e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// The old name for TransportProtocol.
620e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// TODO(juberti): remove this.
630e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgtypedef TransportProtocol IceProtocolType;
640e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
65e560834da4ee5a5f38a96a8cb9290c5ce1096989mallinath@webrtc.org// Whether our side of the call is driving the negotiation, or the other side.
66e560834da4ee5a5f38a96a8cb9290c5ce1096989mallinath@webrtc.orgenum IceRole {
67e560834da4ee5a5f38a96a8cb9290c5ce1096989mallinath@webrtc.org  ICEROLE_CONTROLLING = 0,
68e560834da4ee5a5f38a96a8cb9290c5ce1096989mallinath@webrtc.org  ICEROLE_CONTROLLED,
69e560834da4ee5a5f38a96a8cb9290c5ce1096989mallinath@webrtc.org  ICEROLE_UNKNOWN
70e560834da4ee5a5f38a96a8cb9290c5ce1096989mallinath@webrtc.org};
71e560834da4ee5a5f38a96a8cb9290c5ce1096989mallinath@webrtc.org
720e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// ICE RFC 5245 implementation type.
730e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgenum IceMode {
740e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  ICEMODE_FULL,  // As defined in http://tools.ietf.org/html/rfc5245#section-4.1
750e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  ICEMODE_LITE   // As defined in http://tools.ietf.org/html/rfc5245#section-4.2
760e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org};
770e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
78a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org// RFC 4145 - http://tools.ietf.org/html/rfc4145#section-4
79a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org// 'active':  The endpoint will initiate an outgoing connection.
80a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org// 'passive': The endpoint will accept an incoming connection.
81a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org// 'actpass': The endpoint is willing to accept an incoming
82a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org//            connection or to initiate an outgoing connection.
83a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.orgenum ConnectionRole {
84a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org  CONNECTIONROLE_NONE = 0,
85a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org  CONNECTIONROLE_ACTIVE,
86a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org  CONNECTIONROLE_PASSIVE,
87a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org  CONNECTIONROLE_ACTPASS,
88a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org  CONNECTIONROLE_HOLDCONN,
89a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org};
90a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org
91a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.orgextern const char CONNECTIONROLE_ACTIVE_STR[];
92a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.orgextern const char CONNECTIONROLE_PASSIVE_STR[];
93a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.orgextern const char CONNECTIONROLE_ACTPASS_STR[];
94a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.orgextern const char CONNECTIONROLE_HOLDCONN_STR[];
95a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org
96a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.orgbool StringToConnectionRole(const std::string& role_str, ConnectionRole* role);
978841d7bf4010478a4b3978ff2d181d9504b2bbe3mallinath@webrtc.orgbool ConnectionRoleToString(const ConnectionRole& role, std::string* role_str);
98a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org
990e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgtypedef std::vector<Candidate> Candidates;
1000e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1010e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgstruct TransportDescription {
1023e32030ec396a850c18e817b611f092fdd08e102jiayl@webrtc.org  TransportDescription()
1033e32030ec396a850c18e817b611f092fdd08e102jiayl@webrtc.org      : ice_mode(ICEMODE_FULL),
1043e32030ec396a850c18e817b611f092fdd08e102jiayl@webrtc.org        connection_role(CONNECTIONROLE_NONE) {}
1050e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1060e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  TransportDescription(const std::string& transport_type,
1070e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                       const std::vector<std::string>& transport_options,
1080e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                       const std::string& ice_ufrag,
1090e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                       const std::string& ice_pwd,
1100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                       IceMode ice_mode,
111a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org                       ConnectionRole role,
1122a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org                       const rtc::SSLFingerprint* identity_fingerprint,
1130e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                       const Candidates& candidates)
1140e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      : transport_type(transport_type),
1150e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        transport_options(transport_options),
1160e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        ice_ufrag(ice_ufrag),
1170e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        ice_pwd(ice_pwd),
1180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        ice_mode(ice_mode),
119a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org        connection_role(role),
1200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        identity_fingerprint(CopyFingerprint(identity_fingerprint)),
1210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        candidates(candidates) {}
1220e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  TransportDescription(const std::string& transport_type,
123a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org                       const std::string& ice_ufrag,
124a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org                       const std::string& ice_pwd)
1250e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      : transport_type(transport_type),
126a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org        ice_ufrag(ice_ufrag),
127a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org        ice_pwd(ice_pwd),
1280e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        ice_mode(ICEMODE_FULL),
129a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org        connection_role(CONNECTIONROLE_NONE) {}
1300e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  TransportDescription(const TransportDescription& from)
1310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      : transport_type(from.transport_type),
1320e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        transport_options(from.transport_options),
1330e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        ice_ufrag(from.ice_ufrag),
1340e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        ice_pwd(from.ice_pwd),
1350e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        ice_mode(from.ice_mode),
136a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org        connection_role(from.connection_role),
1370e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        identity_fingerprint(CopyFingerprint(from.identity_fingerprint.get())),
1380e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        candidates(from.candidates) {}
1390e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1400e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  TransportDescription& operator=(const TransportDescription& from) {
1410e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    // Self-assignment
1420e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    if (this == &from)
1430e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      return *this;
1440e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1450e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    transport_type = from.transport_type;
1460e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    transport_options = from.transport_options;
1470e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    ice_ufrag = from.ice_ufrag;
1480e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    ice_pwd = from.ice_pwd;
1490e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    ice_mode = from.ice_mode;
150a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org    connection_role = from.connection_role;
1510e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1520e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    identity_fingerprint.reset(CopyFingerprint(
1530e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        from.identity_fingerprint.get()));
1540e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    candidates = from.candidates;
1550e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    return *this;
1560e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
1570e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1580e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool HasOption(const std::string& option) const {
1590e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    return (std::find(transport_options.begin(), transport_options.end(),
1600e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                      option) != transport_options.end());
1610e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
1620e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void AddOption(const std::string& option) {
1630e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    transport_options.push_back(option);
1640e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
1658841d7bf4010478a4b3978ff2d181d9504b2bbe3mallinath@webrtc.org  bool secure() const { return identity_fingerprint != NULL; }
1660e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1672a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  static rtc::SSLFingerprint* CopyFingerprint(
1682a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org      const rtc::SSLFingerprint* from) {
1690e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    if (!from)
1700e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      return NULL;
1710e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1722a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org    return new rtc::SSLFingerprint(*from);
1730e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
1740e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1750e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  std::string transport_type;  // xmlns of <transport>
1760e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  std::vector<std::string> transport_options;
1770e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  std::string ice_ufrag;
1780e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  std::string ice_pwd;
1790e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  IceMode ice_mode;
180a487db2aeda23ade81f0b2e5fd4d50f874d06a9csergeyu@chromium.org  ConnectionRole connection_role;
1810e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1822a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::scoped_ptr<rtc::SSLFingerprint> identity_fingerprint;
1830e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  Candidates candidates;
1840e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org};
1850e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1860e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org}  // namespace cricket
1870e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1880e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#endif  // TALK_P2P_BASE_TRANSPORTDESCRIPTION_H_
189