blob: 1d43e54d0a8fd477e4e0ca700e20f1bcb4f7c67a [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
Honghai Zhangd93f50c2016-10-05 11:47:22 -070021namespace webrtc {
22class MetricsObserverInterface;
23}
24
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000025namespace cricket {
26
27class Candidate;
28
Peter Thatcher7cbd1882015-09-17 18:54:52 -070029// TODO(pthatcher): Remove this once it's no longer used in
30// remoting/protocol/libjingle_transport_factory.cc
31enum IceProtocolType {
32 ICEPROTO_RFC5245 // Standard RFC 5245 version of ICE.
33};
34
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000035// Base class for real implementations of TransportChannel. This includes some
36// methods called only by Transport, which do not need to be exposed to the
37// client.
38class TransportChannelImpl : public TransportChannel {
39 public:
deadbeefcbecd352015-09-23 11:50:27 -070040 explicit TransportChannelImpl(const std::string& transport_name,
41 int component)
42 : TransportChannel(transport_name, component) {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000043
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000044 // For ICE channels.
45 virtual IceRole GetIceRole() const = 0;
46 virtual void SetIceRole(IceRole role) = 0;
Peter Boström0c4e06b2015-10-07 12:23:21 +020047 virtual void SetIceTiebreaker(uint64_t tiebreaker) = 0;
Peter Thatcher7cbd1882015-09-17 18:54:52 -070048 // TODO(pthatcher): Remove this once it's no longer called in
49 // remoting/protocol/libjingle_transport_factory.cc
50 virtual void SetIceProtocolType(IceProtocolType type) {}
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070051 // TODO(honghaiz): Remove this once the call in chromoting is removed.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000052 virtual void SetIceCredentials(const std::string& ice_ufrag,
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070053 const std::string& ice_pwd) {
54 SetIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
55 }
56 // TODO(honghaiz): Remove this once the call in chromoting is removed.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000057 virtual void SetRemoteIceCredentials(const std::string& ice_ufrag,
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070058 const std::string& ice_pwd) {
59 SetRemoteIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
60 }
61
62 // SetIceParameters only needs to be implemented by the ICE transport
63 // channels. Non-ICE transport channels should pass them down to the inner
64 // ICE transport channel. The ufrag and pwd in |ice_params| must be set
65 // before candidate gathering can start.
66 virtual void SetIceParameters(const IceParameters& ice_params) = 0;
67 // SetRemoteIceParameters only needs to be implemented by the ICE transport
68 // channels. Non-ICE transport channels should pass them down to the inner
69 // ICE transport channel.
70 virtual void SetRemoteIceParameters(const IceParameters& ice_params) = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000071
72 // SetRemoteIceMode must be implemented only by the ICE transport channels.
73 virtual void SetRemoteIceMode(IceMode mode) = 0;
74
honghaiz1f429e32015-09-28 07:57:34 -070075 virtual void SetIceConfig(const IceConfig& config) = 0;
honghaiz90099622015-07-13 12:19:33 -070076
deadbeefcbecd352015-09-23 11:50:27 -070077 // Start gathering candidates if not already started, or if an ICE restart
78 // occurred.
79 virtual void MaybeStartGathering() = 0;
80
Honghai Zhangd93f50c2016-10-05 11:47:22 -070081 virtual void SetMetricsObserver(
82 webrtc::MetricsObserverInterface* observer) = 0;
83
deadbeefcbecd352015-09-23 11:50:27 -070084 sigslot::signal1<TransportChannelImpl*> SignalGatheringState;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000085
86 // Handles sending and receiving of candidates. The Transport
87 // receives the candidates and may forward them to the relevant
88 // channel.
89 //
90 // Note: Since candidates are delivered asynchronously to the
91 // channel, they cannot return an error if the message is invalid.
92 // It is assumed that the Transport will have checked validity
93 // before forwarding.
deadbeefcbecd352015-09-23 11:50:27 -070094 sigslot::signal2<TransportChannelImpl*, const Candidate&>
95 SignalCandidateGathered;
Honghai Zhang7fb69db2016-03-14 11:59:18 -070096 sigslot::signal2<TransportChannelImpl*, const Candidates&>
97 SignalCandidatesRemoved;
deadbeefcbecd352015-09-23 11:50:27 -070098 virtual void AddRemoteCandidate(const Candidate& candidate) = 0;
Honghai Zhang7fb69db2016-03-14 11:59:18 -070099 virtual void RemoveRemoteCandidate(const Candidate& candidate) = 0;
deadbeefcbecd352015-09-23 11:50:27 -0700100
101 virtual IceGatheringState gathering_state() const = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000102
103 // DTLS methods
Henrik Boströmf3ecdb92015-09-08 12:11:54 +0200104 virtual bool SetLocalCertificate(
105 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000106
107 // Set DTLS Remote fingerprint. Must be after local identity set.
108 virtual bool SetRemoteFingerprint(const std::string& digest_alg,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200109 const uint8_t* digest,
110 size_t digest_len) = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000111
112 virtual bool SetSslRole(rtc::SSLRole role) = 0;
113
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000114 // Invoked when there is conflict in the ICE role between local and remote
115 // agents.
116 sigslot::signal1<TransportChannelImpl*> SignalRoleConflict;
117
Honghai Zhang1590c392016-05-24 13:15:02 -0700118 // Emitted whenever the transport channel state changed.
119 sigslot::signal1<TransportChannelImpl*> SignalStateChanged;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000120
zhihuangd82eee02016-08-26 11:25:05 -0700121 // Emitted whenever the Dtls handshake failed on some transport channel.
122 sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError;
123
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000124 private:
henrikg3c089d72015-09-16 05:37:44 -0700125 RTC_DISALLOW_COPY_AND_ASSIGN(TransportChannelImpl);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000126};
127
128} // namespace cricket
129
130#endif // WEBRTC_P2P_BASE_TRANSPORTCHANNELIMPL_H_