blob: 7592a3cbc85fe8ea0190ba64538300e202b245ae [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
Honghai Zhangd93f50c2016-10-05 11:47:22 -070019namespace webrtc {
20class MetricsObserverInterface;
21}
22
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000023namespace cricket {
24
25class Candidate;
26
kjellanderc37ad492016-12-21 23:52:00 -080027// TODO(pthatcher): Remove this once it's no longer used in
28// remoting/protocol/libjingle_transport_factory.cc
29enum IceProtocolType {
30 ICEPROTO_RFC5245 // Standard RFC 5245 version of ICE.
31};
32
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000033// Base class for real implementations of TransportChannel. This includes some
34// methods called only by Transport, which do not need to be exposed to the
35// client.
36class TransportChannelImpl : public TransportChannel {
37 public:
deadbeefcbecd352015-09-23 11:50:27 -070038 explicit TransportChannelImpl(const std::string& transport_name,
39 int component)
40 : TransportChannel(transport_name, component) {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000041
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000042 // For ICE channels.
43 virtual IceRole GetIceRole() const = 0;
44 virtual void SetIceRole(IceRole role) = 0;
Peter Boström0c4e06b2015-10-07 12:23:21 +020045 virtual void SetIceTiebreaker(uint64_t tiebreaker) = 0;
Peter Thatcher7cbd1882015-09-17 18:54:52 -070046 // TODO(pthatcher): Remove this once it's no longer called in
47 // remoting/protocol/libjingle_transport_factory.cc
48 virtual void SetIceProtocolType(IceProtocolType type) {}
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070049 // TODO(honghaiz): Remove this once the call in chromoting is removed.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000050 virtual void SetIceCredentials(const std::string& ice_ufrag,
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070051 const std::string& ice_pwd) {
52 SetIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
53 }
54 // TODO(honghaiz): Remove this once the call in chromoting is removed.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000055 virtual void SetRemoteIceCredentials(const std::string& ice_ufrag,
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070056 const std::string& ice_pwd) {
57 SetRemoteIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
58 }
59
60 // SetIceParameters 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. The ufrag and pwd in |ice_params| must be set
63 // before candidate gathering can start.
64 virtual void SetIceParameters(const IceParameters& ice_params) = 0;
65 // SetRemoteIceParameters only needs to be implemented by the ICE transport
66 // channels. Non-ICE transport channels should pass them down to the inner
67 // ICE transport channel.
68 virtual void SetRemoteIceParameters(const IceParameters& ice_params) = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000069
70 // SetRemoteIceMode must be implemented only by the ICE transport channels.
71 virtual void SetRemoteIceMode(IceMode mode) = 0;
72
honghaiz1f429e32015-09-28 07:57:34 -070073 virtual void SetIceConfig(const IceConfig& config) = 0;
honghaiz90099622015-07-13 12:19:33 -070074
deadbeefcbecd352015-09-23 11:50:27 -070075 // Start gathering candidates if not already started, or if an ICE restart
76 // occurred.
77 virtual void MaybeStartGathering() = 0;
78
Honghai Zhangd93f50c2016-10-05 11:47:22 -070079 virtual void SetMetricsObserver(
80 webrtc::MetricsObserverInterface* observer) = 0;
81
deadbeefcbecd352015-09-23 11:50:27 -070082 sigslot::signal1<TransportChannelImpl*> SignalGatheringState;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000083
84 // Handles sending and receiving of candidates. The Transport
85 // receives the candidates and may forward them to the relevant
86 // channel.
87 //
88 // Note: Since candidates are delivered asynchronously to the
89 // channel, they cannot return an error if the message is invalid.
90 // It is assumed that the Transport will have checked validity
91 // before forwarding.
deadbeefcbecd352015-09-23 11:50:27 -070092 sigslot::signal2<TransportChannelImpl*, const Candidate&>
93 SignalCandidateGathered;
Honghai Zhang7fb69db2016-03-14 11:59:18 -070094 sigslot::signal2<TransportChannelImpl*, const Candidates&>
95 SignalCandidatesRemoved;
deadbeefcbecd352015-09-23 11:50:27 -070096 virtual void AddRemoteCandidate(const Candidate& candidate) = 0;
Honghai Zhang7fb69db2016-03-14 11:59:18 -070097 virtual void RemoveRemoteCandidate(const Candidate& candidate) = 0;
deadbeefcbecd352015-09-23 11:50:27 -070098
99 virtual IceGatheringState gathering_state() const = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000100
101 // DTLS methods
Henrik Boströmf3ecdb92015-09-08 12:11:54 +0200102 virtual bool SetLocalCertificate(
103 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000104
105 // Set DTLS Remote fingerprint. Must be after local identity set.
106 virtual bool SetRemoteFingerprint(const std::string& digest_alg,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200107 const uint8_t* digest,
108 size_t digest_len) = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000109
110 virtual bool SetSslRole(rtc::SSLRole role) = 0;
111
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000112 // Invoked when there is conflict in the ICE role between local and remote
113 // agents.
114 sigslot::signal1<TransportChannelImpl*> SignalRoleConflict;
115
Honghai Zhang1590c392016-05-24 13:15:02 -0700116 // Emitted whenever the transport channel state changed.
117 sigslot::signal1<TransportChannelImpl*> SignalStateChanged;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000118
zhihuangd82eee02016-08-26 11:25:05 -0700119 // Emitted whenever the Dtls handshake failed on some transport channel.
120 sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError;
121
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000122 private:
henrikg3c089d72015-09-16 05:37:44 -0700123 RTC_DISALLOW_COPY_AND_ASSIGN(TransportChannelImpl);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000124};
125
126} // namespace cricket
127
128#endif // WEBRTC_P2P_BASE_TRANSPORTCHANNELIMPL_H_