blob: d42a93ddae9f95cf1558f9d32f3273f5e9a113c3 [file] [log] [blame]
deadbeefcbecd352015-09-23 11:50:27 -07001/*
2 * Copyright 2009 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_FAKETRANSPORTCONTROLLER_H_
12#define WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_
13
14#include <map>
jbauch555604a2016-04-26 03:13:22 -070015#include <memory>
deadbeefcbecd352015-09-23 11:50:27 -070016#include <string>
17#include <vector>
18
kjellanderc37ad492016-12-21 23:52:00 -080019#include "webrtc/p2p/base/candidatepairinterface.h"
20#include "webrtc/p2p/base/transportchannel.h"
21#include "webrtc/p2p/base/transportcontroller.h"
22#include "webrtc/p2p/base/transportchannelimpl.h"
deadbeefcbecd352015-09-23 11:50:27 -070023#include "webrtc/base/bind.h"
24#include "webrtc/base/buffer.h"
25#include "webrtc/base/fakesslidentity.h"
26#include "webrtc/base/messagequeue.h"
27#include "webrtc/base/sigslot.h"
28#include "webrtc/base/sslfingerprint.h"
29#include "webrtc/base/thread.h"
30
zhihuang9763d562016-08-05 11:14:50 -070031#ifdef HAVE_QUIC
32#include "webrtc/p2p/quic/quictransport.h"
33#endif
34
deadbeefcbecd352015-09-23 11:50:27 -070035namespace cricket {
36
stefanc1aeaf02015-10-15 07:26:07 -070037namespace {
deadbeefcbecd352015-09-23 11:50:27 -070038struct PacketMessageData : public rtc::MessageData {
39 PacketMessageData(const char* data, size_t len) : packet(data, len) {}
40 rtc::Buffer packet;
41};
stefanc1aeaf02015-10-15 07:26:07 -070042} // namespace
deadbeefcbecd352015-09-23 11:50:27 -070043
44// Fake transport channel class, which can be passed to anything that needs a
45// transport channel. Can be informed of another FakeTransportChannel via
46// SetDestination.
47// TODO(hbos): Move implementation to .cc file, this and other classes in file.
48class FakeTransportChannel : public TransportChannelImpl,
49 public rtc::MessageHandler {
50 public:
mikescarlettb9dd7c52016-02-19 20:43:45 -080051 explicit FakeTransportChannel(const std::string& name, int component)
deadbeefcbecd352015-09-23 11:50:27 -070052 : TransportChannelImpl(name, component),
deadbeefcbecd352015-09-23 11:50:27 -070053 dtls_fingerprint_("", nullptr, 0) {}
54 ~FakeTransportChannel() { Reset(); }
55
Peter Boström0c4e06b2015-10-07 12:23:21 +020056 uint64_t IceTiebreaker() const { return tiebreaker_; }
deadbeefcbecd352015-09-23 11:50:27 -070057 IceMode remote_ice_mode() const { return remote_ice_mode_; }
58 const std::string& ice_ufrag() const { return ice_ufrag_; }
59 const std::string& ice_pwd() const { return ice_pwd_; }
60 const std::string& remote_ice_ufrag() const { return remote_ice_ufrag_; }
61 const std::string& remote_ice_pwd() const { return remote_ice_pwd_; }
62 const rtc::SSLFingerprint& dtls_fingerprint() const {
63 return dtls_fingerprint_;
64 }
65
66 // If async, will send packets by "Post"-ing to message queue instead of
67 // synchronously "Send"-ing.
68 void SetAsync(bool async) { async_ = async; }
deadbeef89824f62016-09-30 11:55:43 -070069 void SetAsyncDelay(int delay_ms) { async_delay_ms_ = delay_ms; }
deadbeefcbecd352015-09-23 11:50:27 -070070
kjellanderc37ad492016-12-21 23:52:00 -080071 TransportChannelState GetState() const override {
deadbeefcbecd352015-09-23 11:50:27 -070072 if (connection_count_ == 0) {
kjellanderc37ad492016-12-21 23:52:00 -080073 return had_connection_ ? TransportChannelState::STATE_FAILED
74 : TransportChannelState::STATE_INIT;
deadbeefcbecd352015-09-23 11:50:27 -070075 }
76
77 if (connection_count_ == 1) {
kjellanderc37ad492016-12-21 23:52:00 -080078 return TransportChannelState::STATE_COMPLETED;
deadbeefcbecd352015-09-23 11:50:27 -070079 }
80
kjellanderc37ad492016-12-21 23:52:00 -080081 return TransportChannelState::STATE_CONNECTING;
deadbeefcbecd352015-09-23 11:50:27 -070082 }
83
84 void SetIceRole(IceRole role) override { role_ = role; }
85 IceRole GetIceRole() const override { return role_; }
Peter Boström0c4e06b2015-10-07 12:23:21 +020086 void SetIceTiebreaker(uint64_t tiebreaker) override {
deadbeefcbecd352015-09-23 11:50:27 -070087 tiebreaker_ = tiebreaker;
88 }
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070089 void SetIceParameters(const IceParameters& ice_params) override {
90 ice_ufrag_ = ice_params.ufrag;
91 ice_pwd_ = ice_params.pwd;
deadbeefcbecd352015-09-23 11:50:27 -070092 }
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070093 void SetRemoteIceParameters(const IceParameters& params) override {
94 remote_ice_ufrag_ = params.ufrag;
95 remote_ice_pwd_ = params.pwd;
deadbeefcbecd352015-09-23 11:50:27 -070096 }
97
98 void SetRemoteIceMode(IceMode mode) override { remote_ice_mode_ = mode; }
99 bool SetRemoteFingerprint(const std::string& alg,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200100 const uint8_t* digest,
deadbeefcbecd352015-09-23 11:50:27 -0700101 size_t digest_len) override {
102 dtls_fingerprint_ = rtc::SSLFingerprint(alg, digest, digest_len);
103 return true;
104 }
105 bool SetSslRole(rtc::SSLRole role) override {
106 ssl_role_ = role;
107 return true;
108 }
109 bool GetSslRole(rtc::SSLRole* role) const override {
110 *role = ssl_role_;
111 return true;
112 }
113
deadbeefcbecd352015-09-23 11:50:27 -0700114 void MaybeStartGathering() override {
115 if (gathering_state_ == kIceGatheringNew) {
116 gathering_state_ = kIceGatheringGathering;
117 SignalGatheringState(this);
118 }
119 }
120
121 IceGatheringState gathering_state() const override {
122 return gathering_state_;
123 }
124
125 void Reset() {
126 if (state_ != STATE_INIT) {
127 state_ = STATE_INIT;
128 if (dest_) {
129 dest_->state_ = STATE_INIT;
130 dest_->dest_ = nullptr;
131 dest_ = nullptr;
132 }
133 }
134 }
135
136 void SetWritable(bool writable) { set_writable(writable); }
137
deadbeefe84cd2e2016-05-04 17:16:34 -0700138 // Simulates the two transport channels connecting to each other.
139 // If |asymmetric| is true this method only affects this FakeTransportChannel.
140 // If false, it affects |dest| as well.
141 void SetDestination(FakeTransportChannel* dest, bool asymmetric = false) {
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700142 if (state_ == STATE_INIT && dest) {
deadbeefcbecd352015-09-23 11:50:27 -0700143 // This simulates the delivery of candidates.
144 dest_ = dest;
deadbeefcbecd352015-09-23 11:50:27 -0700145 if (local_cert_ && dest_->local_cert_) {
146 do_dtls_ = true;
deadbeefcbecd352015-09-23 11:50:27 -0700147 NegotiateSrtpCiphers();
148 }
149 state_ = STATE_CONNECTED;
deadbeefcbecd352015-09-23 11:50:27 -0700150 set_writable(true);
deadbeefe84cd2e2016-05-04 17:16:34 -0700151 if (!asymmetric) {
152 dest->SetDestination(this, true);
153 }
deadbeefcbecd352015-09-23 11:50:27 -0700154 } else if (state_ == STATE_CONNECTED && !dest) {
155 // Simulates loss of connectivity, by asymmetrically forgetting dest_.
156 dest_ = nullptr;
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700157 state_ = STATE_INIT;
deadbeefcbecd352015-09-23 11:50:27 -0700158 set_writable(false);
159 }
160 }
161
162 void SetConnectionCount(size_t connection_count) {
163 size_t old_connection_count = connection_count_;
164 connection_count_ = connection_count;
165 if (connection_count)
166 had_connection_ = true;
Honghai Zhang1590c392016-05-24 13:15:02 -0700167 // In this fake transport channel, |connection_count_| determines the
168 // transport channel state.
deadbeefcbecd352015-09-23 11:50:27 -0700169 if (connection_count_ < old_connection_count)
Honghai Zhang1590c392016-05-24 13:15:02 -0700170 SignalStateChanged(this);
deadbeefcbecd352015-09-23 11:50:27 -0700171 }
172
173 void SetCandidatesGatheringComplete() {
174 if (gathering_state_ != kIceGatheringComplete) {
175 gathering_state_ = kIceGatheringComplete;
176 SignalGatheringState(this);
177 }
178 }
179
180 void SetReceiving(bool receiving) { set_receiving(receiving); }
181
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700182 void SetIceConfig(const IceConfig& config) override { ice_config_ = config; }
deadbeefcbecd352015-09-23 11:50:27 -0700183
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700184 int receiving_timeout() const { return ice_config_.receiving_timeout; }
185 bool gather_continually() const { return ice_config_.gather_continually(); }
deadbeefcbecd352015-09-23 11:50:27 -0700186
187 int SendPacket(const char* data,
188 size_t len,
189 const rtc::PacketOptions& options,
190 int flags) override {
191 if (state_ != STATE_CONNECTED) {
192 return -1;
193 }
194
195 if (flags != PF_SRTP_BYPASS && flags != 0) {
196 return -1;
197 }
198
199 PacketMessageData* packet = new PacketMessageData(data, len);
200 if (async_) {
deadbeef89824f62016-09-30 11:55:43 -0700201 if (async_delay_ms_) {
202 rtc::Thread::Current()->PostDelayed(RTC_FROM_HERE, async_delay_ms_,
203 this, 0, packet);
204 } else {
205 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, 0, packet);
206 }
deadbeefcbecd352015-09-23 11:50:27 -0700207 } else {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700208 rtc::Thread::Current()->Send(RTC_FROM_HERE, this, 0, packet);
deadbeefcbecd352015-09-23 11:50:27 -0700209 }
nisse1bffc1d2016-05-02 08:18:55 -0700210 rtc::SentPacket sent_packet(options.packet_id, rtc::TimeMillis());
stefanc1aeaf02015-10-15 07:26:07 -0700211 SignalSentPacket(this, sent_packet);
deadbeefcbecd352015-09-23 11:50:27 -0700212 return static_cast<int>(len);
213 }
214 int SetOption(rtc::Socket::Option opt, int value) override { return true; }
215 bool GetOption(rtc::Socket::Option opt, int* value) override { return true; }
216 int GetError() override { return 0; }
217
218 void AddRemoteCandidate(const Candidate& candidate) override {
219 remote_candidates_.push_back(candidate);
220 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700221
222 void RemoveRemoteCandidate(const Candidate& candidate) override {}
223
deadbeefcbecd352015-09-23 11:50:27 -0700224 const Candidates& remote_candidates() const { return remote_candidates_; }
225
226 void OnMessage(rtc::Message* msg) override {
227 PacketMessageData* data = static_cast<PacketMessageData*>(msg->pdata);
228 dest_->SignalReadPacket(dest_, data->packet.data<char>(),
229 data->packet.size(), rtc::CreatePacketTime(0), 0);
230 delete data;
231 }
232
233 bool SetLocalCertificate(
nisseef8b61e2016-04-29 06:09:15 -0700234 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override {
deadbeefcbecd352015-09-23 11:50:27 -0700235 local_cert_ = certificate;
236 return true;
237 }
238
239 void SetRemoteSSLCertificate(rtc::FakeSSLCertificate* cert) {
240 remote_cert_ = cert;
241 }
242
243 bool IsDtlsActive() const override { return do_dtls_; }
244
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800245 bool SetSrtpCryptoSuites(const std::vector<int>& ciphers) override {
deadbeefcbecd352015-09-23 11:50:27 -0700246 srtp_ciphers_ = ciphers;
247 return true;
248 }
249
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800250 bool GetSrtpCryptoSuite(int* crypto_suite) override {
251 if (chosen_crypto_suite_ != rtc::SRTP_INVALID_CRYPTO_SUITE) {
252 *crypto_suite = chosen_crypto_suite_;
deadbeefcbecd352015-09-23 11:50:27 -0700253 return true;
254 }
255 return false;
256 }
257
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800258 bool GetSslCipherSuite(int* cipher_suite) override { return false; }
deadbeefcbecd352015-09-23 11:50:27 -0700259
nisseef8b61e2016-04-29 06:09:15 -0700260 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override {
deadbeefcbecd352015-09-23 11:50:27 -0700261 return local_cert_;
262 }
263
jbauch555604a2016-04-26 03:13:22 -0700264 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate()
kwibergb4d01c42016-04-06 05:15:06 -0700265 const override {
jbauch555604a2016-04-26 03:13:22 -0700266 return remote_cert_ ? std::unique_ptr<rtc::SSLCertificate>(
kwibergb4d01c42016-04-06 05:15:06 -0700267 remote_cert_->GetReference())
268 : nullptr;
deadbeefcbecd352015-09-23 11:50:27 -0700269 }
270
271 bool ExportKeyingMaterial(const std::string& label,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200272 const uint8_t* context,
deadbeefcbecd352015-09-23 11:50:27 -0700273 size_t context_len,
274 bool use_context,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200275 uint8_t* result,
deadbeefcbecd352015-09-23 11:50:27 -0700276 size_t result_len) override {
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800277 if (chosen_crypto_suite_ != rtc::SRTP_INVALID_CRYPTO_SUITE) {
deadbeefcbecd352015-09-23 11:50:27 -0700278 memset(result, 0xff, result_len);
279 return true;
280 }
281
282 return false;
283 }
284
deadbeefcbecd352015-09-23 11:50:27 -0700285 bool GetStats(ConnectionInfos* infos) override {
286 ConnectionInfo info;
287 infos->clear();
288 infos->push_back(info);
289 return true;
290 }
291
292 void set_ssl_max_protocol_version(rtc::SSLProtocolVersion version) {
293 ssl_max_version_ = version;
294 }
295 rtc::SSLProtocolVersion ssl_max_protocol_version() const {
296 return ssl_max_version_;
297 }
298
Honghai Zhangd93f50c2016-10-05 11:47:22 -0700299 void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override {
300 }
301
deadbeefcbecd352015-09-23 11:50:27 -0700302 private:
deadbeefe84cd2e2016-05-04 17:16:34 -0700303 void NegotiateSrtpCiphers() {
304 for (std::vector<int>::const_iterator it1 = srtp_ciphers_.begin();
305 it1 != srtp_ciphers_.end(); ++it1) {
306 for (std::vector<int>::const_iterator it2 = dest_->srtp_ciphers_.begin();
307 it2 != dest_->srtp_ciphers_.end(); ++it2) {
308 if (*it1 == *it2) {
309 chosen_crypto_suite_ = *it1;
310 return;
311 }
312 }
313 }
314 }
315
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700316 enum State { STATE_INIT, STATE_CONNECTED };
deadbeefcbecd352015-09-23 11:50:27 -0700317 FakeTransportChannel* dest_ = nullptr;
318 State state_ = STATE_INIT;
319 bool async_ = false;
deadbeef89824f62016-09-30 11:55:43 -0700320 int async_delay_ms_ = 0;
deadbeefcbecd352015-09-23 11:50:27 -0700321 Candidates remote_candidates_;
322 rtc::scoped_refptr<rtc::RTCCertificate> local_cert_;
323 rtc::FakeSSLCertificate* remote_cert_ = nullptr;
324 bool do_dtls_ = false;
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800325 std::vector<int> srtp_ciphers_;
326 int chosen_crypto_suite_ = rtc::SRTP_INVALID_CRYPTO_SUITE;
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700327 IceConfig ice_config_;
deadbeefcbecd352015-09-23 11:50:27 -0700328 IceRole role_ = ICEROLE_UNKNOWN;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200329 uint64_t tiebreaker_ = 0;
deadbeefcbecd352015-09-23 11:50:27 -0700330 std::string ice_ufrag_;
331 std::string ice_pwd_;
332 std::string remote_ice_ufrag_;
333 std::string remote_ice_pwd_;
334 IceMode remote_ice_mode_ = ICEMODE_FULL;
Guo-wei Shieha7446d22016-01-11 15:27:03 -0800335 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12;
deadbeefcbecd352015-09-23 11:50:27 -0700336 rtc::SSLFingerprint dtls_fingerprint_;
337 rtc::SSLRole ssl_role_ = rtc::SSL_CLIENT;
338 size_t connection_count_ = 0;
339 IceGatheringState gathering_state_ = kIceGatheringNew;
340 bool had_connection_ = false;
341};
342
Honghai Zhangcc411c02016-03-29 17:27:21 -0700343// Fake candidate pair class, which can be passed to BaseChannel for testing
344// purposes.
345class FakeCandidatePair : public CandidatePairInterface {
346 public:
347 FakeCandidatePair(const Candidate& local_candidate,
348 const Candidate& remote_candidate)
349 : local_candidate_(local_candidate),
350 remote_candidate_(remote_candidate) {}
351 const Candidate& local_candidate() const override { return local_candidate_; }
352 const Candidate& remote_candidate() const override {
353 return remote_candidate_;
354 }
355
356 private:
357 Candidate local_candidate_;
358 Candidate remote_candidate_;
359};
360
deadbeefcbecd352015-09-23 11:50:27 -0700361// Fake TransportController class, which can be passed into a BaseChannel object
362// for test purposes. Can be connected to other FakeTransportControllers via
363// Connect().
364//
365// This fake is unusual in that for the most part, it's implemented with the
366// real TransportController code, but with fake TransportChannels underneath.
367class FakeTransportController : public TransportController {
368 public:
369 FakeTransportController()
370 : TransportController(rtc::Thread::Current(),
371 rtc::Thread::Current(),
deadbeef49f34fd2016-12-06 16:22:06 -0800372 nullptr) {}
deadbeefcbecd352015-09-23 11:50:27 -0700373
Taylor Brandstetterf0bb3602016-08-26 20:59:24 -0700374 explicit FakeTransportController(bool redetermine_role_on_ice_restart)
375 : TransportController(rtc::Thread::Current(),
376 rtc::Thread::Current(),
377 nullptr,
deadbeef49f34fd2016-12-06 16:22:06 -0800378 redetermine_role_on_ice_restart) {}
Taylor Brandstetterf0bb3602016-08-26 20:59:24 -0700379
deadbeefcbecd352015-09-23 11:50:27 -0700380 explicit FakeTransportController(IceRole role)
381 : TransportController(rtc::Thread::Current(),
382 rtc::Thread::Current(),
deadbeef49f34fd2016-12-06 16:22:06 -0800383 nullptr) {
deadbeefcbecd352015-09-23 11:50:27 -0700384 SetIceRole(role);
385 }
386
johan27c3d5b2016-10-17 00:54:57 -0700387 explicit FakeTransportController(rtc::Thread* network_thread)
deadbeef49f34fd2016-12-06 16:22:06 -0800388 : TransportController(rtc::Thread::Current(), network_thread, nullptr) {}
deadbeefcbecd352015-09-23 11:50:27 -0700389
johan27c3d5b2016-10-17 00:54:57 -0700390 FakeTransportController(rtc::Thread* network_thread, IceRole role)
deadbeef49f34fd2016-12-06 16:22:06 -0800391 : TransportController(rtc::Thread::Current(), network_thread, nullptr) {
deadbeefcbecd352015-09-23 11:50:27 -0700392 SetIceRole(role);
393 }
394
deadbeef49f34fd2016-12-06 16:22:06 -0800395 FakeTransportChannel* GetFakeTransportChannel_n(
396 const std::string& transport_name,
397 int component) {
398 return static_cast<FakeTransportChannel*>(
399 get_channel_for_testing(transport_name, component));
deadbeefcbecd352015-09-23 11:50:27 -0700400 }
401
deadbeef49f34fd2016-12-06 16:22:06 -0800402 // Simulate the exchange of transport descriptions, and the gathering and
403 // exchange of ICE candidates.
deadbeefcbecd352015-09-23 11:50:27 -0700404 void Connect(FakeTransportController* dest) {
deadbeef49f34fd2016-12-06 16:22:06 -0800405 for (const std::string& transport_name : transport_names_for_testing()) {
406 TransportDescription local_desc(
407 std::vector<std::string>(),
408 rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH),
409 rtc::CreateRandomString(cricket::ICE_PWD_LENGTH),
410 cricket::ICEMODE_FULL, cricket::CONNECTIONROLE_NONE, nullptr);
411 TransportDescription remote_desc(
412 std::vector<std::string>(),
413 rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH),
414 rtc::CreateRandomString(cricket::ICE_PWD_LENGTH),
415 cricket::ICEMODE_FULL, cricket::CONNECTIONROLE_NONE, nullptr);
416 std::string err;
417 SetLocalTransportDescription(transport_name, local_desc,
418 cricket::CA_OFFER, &err);
419 dest->SetRemoteTransportDescription(transport_name, local_desc,
420 cricket::CA_OFFER, &err);
421 dest->SetLocalTransportDescription(transport_name, remote_desc,
422 cricket::CA_ANSWER, &err);
423 SetRemoteTransportDescription(transport_name, remote_desc,
424 cricket::CA_ANSWER, &err);
425 }
426 MaybeStartGathering();
427 dest->MaybeStartGathering();
Danil Chapovalov7f216b72016-05-12 09:20:31 +0200428 network_thread()->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700429 RTC_FROM_HERE,
deadbeef49f34fd2016-12-06 16:22:06 -0800430 rtc::Bind(&FakeTransportController::SetChannelDestinations_n, this,
431 dest));
deadbeefcbecd352015-09-23 11:50:27 -0700432 }
433
Honghai Zhangcc411c02016-03-29 17:27:21 -0700434 FakeCandidatePair* CreateFakeCandidatePair(
435 const rtc::SocketAddress& local_address,
436 int16_t local_network_id,
437 const rtc::SocketAddress& remote_address,
438 int16_t remote_network_id) {
439 Candidate local_candidate(0, "udp", local_address, 0u, "", "", "local", 0,
440 "foundation", local_network_id, 0);
441 Candidate remote_candidate(0, "udp", remote_address, 0u, "", "", "local", 0,
442 "foundation", remote_network_id, 0);
443 return new FakeCandidatePair(local_candidate, remote_candidate);
444 }
445
deadbeef57fd7262016-12-06 15:28:55 -0800446 protected:
deadbeef49f34fd2016-12-06 16:22:06 -0800447 // The ICE channel is never actually used by TransportController directly,
448 // since (currently) the DTLS channel pretends to be both ICE + DTLS. This
449 // will change when we get rid of TransportChannelImpl.
kjellanderc37ad492016-12-21 23:52:00 -0800450 TransportChannelImpl* CreateIceTransportChannel_n(
deadbeef49f34fd2016-12-06 16:22:06 -0800451 const std::string& transport_name,
452 int component) override {
453 return nullptr;
deadbeef57fd7262016-12-06 15:28:55 -0800454 }
455
deadbeef49f34fd2016-12-06 16:22:06 -0800456 TransportChannelImpl* CreateDtlsTransportChannel_n(
457 const std::string& transport_name,
458 int component,
kjellanderc37ad492016-12-21 23:52:00 -0800459 TransportChannelImpl*) override {
deadbeef49f34fd2016-12-06 16:22:06 -0800460 return new FakeTransportChannel(transport_name, component);
deadbeefcbecd352015-09-23 11:50:27 -0700461 }
462
463 private:
deadbeef49f34fd2016-12-06 16:22:06 -0800464 void SetChannelDestinations_n(FakeTransportController* dest) {
465 for (TransportChannelImpl* tc : channels_for_testing()) {
466 FakeTransportChannel* local = static_cast<FakeTransportChannel*>(tc);
467 FakeTransportChannel* remote = dest->GetFakeTransportChannel_n(
468 local->transport_name(), local->component());
469 if (remote) {
470 bool asymmetric = false;
471 local->SetDestination(remote, asymmetric);
472 }
473 }
474 }
deadbeefcbecd352015-09-23 11:50:27 -0700475};
476
477} // namespace cricket
478
479#endif // WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_