blob: cf6e3629f6b9333c4b480bea5d74471022628e1e [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
zhihuangd06adf62017-01-12 15:58:31 -080016#include "webrtc/p2p/base/icetransportinternal.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000017#include "webrtc/p2p/base/transportchannel.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020018#include "webrtc/rtc_base/constructormagic.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000019
Honghai Zhangd93f50c2016-10-05 11:47:22 -070020namespace webrtc {
21class MetricsObserverInterface;
22}
23
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000024namespace cricket {
25
26class Candidate;
27
28// Base class for real implementations of TransportChannel. This includes some
29// methods called only by Transport, which do not need to be exposed to the
30// client.
31class TransportChannelImpl : public TransportChannel {
32 public:
deadbeefcbecd352015-09-23 11:50:27 -070033 explicit TransportChannelImpl(const std::string& transport_name,
34 int component)
35 : TransportChannel(transport_name, component) {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000036
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000037 // For ICE channels.
38 virtual IceRole GetIceRole() const = 0;
39 virtual void SetIceRole(IceRole role) = 0;
Peter Boström0c4e06b2015-10-07 12:23:21 +020040 virtual void SetIceTiebreaker(uint64_t tiebreaker) = 0;
Peter Thatcher7cbd1882015-09-17 18:54:52 -070041 // TODO(pthatcher): Remove this once it's no longer called in
42 // remoting/protocol/libjingle_transport_factory.cc
43 virtual void SetIceProtocolType(IceProtocolType type) {}
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070044 // TODO(honghaiz): Remove this once the call in chromoting is removed.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000045 virtual void SetIceCredentials(const std::string& ice_ufrag,
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070046 const std::string& ice_pwd) {
47 SetIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
48 }
49 // TODO(honghaiz): Remove this once the call in chromoting is removed.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000050 virtual void SetRemoteIceCredentials(const std::string& ice_ufrag,
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070051 const std::string& ice_pwd) {
52 SetRemoteIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
53 }
54
55 // SetIceParameters only needs to be implemented by the ICE transport
56 // channels. Non-ICE transport channels should pass them down to the inner
57 // ICE transport channel. The ufrag and pwd in |ice_params| must be set
58 // before candidate gathering can start.
59 virtual void SetIceParameters(const IceParameters& ice_params) = 0;
60 // SetRemoteIceParameters only needs to be implemented by the ICE transport
61 // channels. Non-ICE transport channels should pass them down to the inner
62 // ICE transport channel.
63 virtual void SetRemoteIceParameters(const IceParameters& ice_params) = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000064
65 // SetRemoteIceMode must be implemented only by the ICE transport channels.
66 virtual void SetRemoteIceMode(IceMode mode) = 0;
67
honghaiz1f429e32015-09-28 07:57:34 -070068 virtual void SetIceConfig(const IceConfig& config) = 0;
honghaiz90099622015-07-13 12:19:33 -070069
deadbeefcbecd352015-09-23 11:50:27 -070070 // Start gathering candidates if not already started, or if an ICE restart
71 // occurred.
72 virtual void MaybeStartGathering() = 0;
73
Honghai Zhangd93f50c2016-10-05 11:47:22 -070074 virtual void SetMetricsObserver(
75 webrtc::MetricsObserverInterface* observer) = 0;
76
deadbeefcbecd352015-09-23 11:50:27 -070077 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_