blob: 0c7fa506b7d6fa1a49b5399ba0631b599523a570 [file] [log] [blame]
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +00001/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
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.
9 */
10
11#ifndef WEBRTC_P2P_BASE_TRANSPORTCHANNELIMPL_H_
12#define WEBRTC_P2P_BASE_TRANSPORTCHANNELIMPL_H_
13
14#include <string>
kwiberg4485ffb2016-04-26 08:14:39 -070015
16#include "webrtc/base/constructormagic.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000017#include "webrtc/p2p/base/transportchannel.h"
18
19namespace buzz { class XmlElement; }
20
21namespace cricket {
22
23class Candidate;
24
Peter Thatcher7cbd1882015-09-17 18:54:52 -070025// TODO(pthatcher): Remove this once it's no longer used in
26// remoting/protocol/libjingle_transport_factory.cc
27enum IceProtocolType {
28 ICEPROTO_RFC5245 // Standard RFC 5245 version of ICE.
29};
30
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000031// Base class for real implementations of TransportChannel. This includes some
32// methods called only by Transport, which do not need to be exposed to the
33// client.
34class TransportChannelImpl : public TransportChannel {
35 public:
deadbeefcbecd352015-09-23 11:50:27 -070036 explicit TransportChannelImpl(const std::string& transport_name,
37 int component)
38 : TransportChannel(transport_name, component) {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000039
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000040 // For ICE channels.
41 virtual IceRole GetIceRole() const = 0;
42 virtual void SetIceRole(IceRole role) = 0;
Peter Boström0c4e06b2015-10-07 12:23:21 +020043 virtual void SetIceTiebreaker(uint64_t tiebreaker) = 0;
Peter Thatcher7cbd1882015-09-17 18:54:52 -070044 // TODO(pthatcher): Remove this once it's no longer called in
45 // remoting/protocol/libjingle_transport_factory.cc
46 virtual void SetIceProtocolType(IceProtocolType type) {}
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070047 // TODO(honghaiz): Remove this once the call in chromoting is removed.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000048 virtual void SetIceCredentials(const std::string& ice_ufrag,
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070049 const std::string& ice_pwd) {
50 SetIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
51 }
52 // TODO(honghaiz): Remove this once the call in chromoting is removed.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000053 virtual void SetRemoteIceCredentials(const std::string& ice_ufrag,
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070054 const std::string& ice_pwd) {
55 SetRemoteIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
56 }
57
58 // SetIceParameters only needs to be implemented by the ICE transport
59 // channels. Non-ICE transport channels should pass them down to the inner
60 // ICE transport channel. The ufrag and pwd in |ice_params| must be set
61 // before candidate gathering can start.
62 virtual void SetIceParameters(const IceParameters& ice_params) = 0;
63 // SetRemoteIceParameters only needs to be implemented by the ICE transport
64 // channels. Non-ICE transport channels should pass them down to the inner
65 // ICE transport channel.
66 virtual void SetRemoteIceParameters(const IceParameters& ice_params) = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000067
68 // SetRemoteIceMode must be implemented only by the ICE transport channels.
69 virtual void SetRemoteIceMode(IceMode mode) = 0;
70
honghaiz1f429e32015-09-28 07:57:34 -070071 virtual void SetIceConfig(const IceConfig& config) = 0;
honghaiz90099622015-07-13 12:19:33 -070072
deadbeefcbecd352015-09-23 11:50:27 -070073 // Start gathering candidates if not already started, or if an ICE restart
74 // occurred.
75 virtual void MaybeStartGathering() = 0;
76
77 sigslot::signal1<TransportChannelImpl*> SignalGatheringState;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000078
79 // Handles sending and receiving of candidates. The Transport
80 // receives the candidates and may forward them to the relevant
81 // channel.
82 //
83 // Note: Since candidates are delivered asynchronously to the
84 // channel, they cannot return an error if the message is invalid.
85 // It is assumed that the Transport will have checked validity
86 // before forwarding.
deadbeefcbecd352015-09-23 11:50:27 -070087 sigslot::signal2<TransportChannelImpl*, const Candidate&>
88 SignalCandidateGathered;
Honghai Zhang7fb69db2016-03-14 11:59:18 -070089 sigslot::signal2<TransportChannelImpl*, const Candidates&>
90 SignalCandidatesRemoved;
deadbeefcbecd352015-09-23 11:50:27 -070091 virtual void AddRemoteCandidate(const Candidate& candidate) = 0;
Honghai Zhang7fb69db2016-03-14 11:59:18 -070092 virtual void RemoveRemoteCandidate(const Candidate& candidate) = 0;
deadbeefcbecd352015-09-23 11:50:27 -070093
94 virtual IceGatheringState gathering_state() const = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000095
96 // DTLS methods
Henrik Boströmf3ecdb92015-09-08 12:11:54 +020097 virtual bool SetLocalCertificate(
98 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000099
100 // Set DTLS Remote fingerprint. Must be after local identity set.
101 virtual bool SetRemoteFingerprint(const std::string& digest_alg,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200102 const uint8_t* digest,
103 size_t digest_len) = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000104
105 virtual bool SetSslRole(rtc::SSLRole role) = 0;
106
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000107 // Invoked when there is conflict in the ICE role between local and remote
108 // agents.
109 sigslot::signal1<TransportChannelImpl*> SignalRoleConflict;
110
Honghai Zhang1590c392016-05-24 13:15:02 -0700111 // Emitted whenever the transport channel state changed.
112 sigslot::signal1<TransportChannelImpl*> SignalStateChanged;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000113
zhihuangd82eee02016-08-26 11:25:05 -0700114 // Emitted whenever the Dtls handshake failed on some transport channel.
115 sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError;
116
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000117 private:
henrikg3c089d72015-09-16 05:37:44 -0700118 RTC_DISALLOW_COPY_AND_ASSIGN(TransportChannelImpl);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000119};
120
121} // namespace cricket
122
123#endif // WEBRTC_P2P_BASE_TRANSPORTCHANNELIMPL_H_