OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ | 11 #ifndef WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ |
12 #define WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ | 12 #define WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ |
13 | 13 |
14 #include <map> | 14 #include <map> |
15 #include <memory> | 15 #include <memory> |
16 #include <string> | 16 #include <string> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "webrtc/base/bind.h" | 19 #include "webrtc/base/bind.h" |
20 #include "webrtc/base/buffer.h" | 20 #include "webrtc/base/buffer.h" |
21 #include "webrtc/base/fakesslidentity.h" | 21 #include "webrtc/base/fakesslidentity.h" |
22 #include "webrtc/base/messagequeue.h" | 22 #include "webrtc/base/messagequeue.h" |
23 #include "webrtc/base/sigslot.h" | 23 #include "webrtc/base/sigslot.h" |
24 #include "webrtc/base/sslfingerprint.h" | 24 #include "webrtc/base/sslfingerprint.h" |
25 #include "webrtc/base/thread.h" | 25 #include "webrtc/base/thread.h" |
26 #include "webrtc/p2p/base/candidatepairinterface.h" | 26 #include "webrtc/p2p/base/candidatepairinterface.h" |
| 27 #include "webrtc/p2p/base/dtlstransportinternal.h" |
27 #include "webrtc/p2p/base/icetransportinternal.h" | 28 #include "webrtc/p2p/base/icetransportinternal.h" |
28 #include "webrtc/p2p/base/transportchannel.h" | 29 |
29 #include "webrtc/p2p/base/transportchannelimpl.h" | |
30 #include "webrtc/p2p/base/transportcontroller.h" | 30 #include "webrtc/p2p/base/transportcontroller.h" |
31 | 31 |
32 #ifdef HAVE_QUIC | 32 #ifdef HAVE_QUIC |
33 #include "webrtc/p2p/quic/quictransport.h" | 33 #include "webrtc/p2p/quic/quictransport.h" |
34 #endif | 34 #endif |
35 | 35 |
36 namespace cricket { | 36 namespace cricket { |
37 | 37 |
38 namespace { | 38 namespace { |
39 struct PacketMessageData : public rtc::MessageData { | 39 struct PacketMessageData : public rtc::MessageData { |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 std::string remote_ice_ufrag_; | 256 std::string remote_ice_ufrag_; |
257 std::string remote_ice_pwd_; | 257 std::string remote_ice_pwd_; |
258 IceMode remote_ice_mode_ = ICEMODE_FULL; | 258 IceMode remote_ice_mode_ = ICEMODE_FULL; |
259 size_t connection_count_ = 0; | 259 size_t connection_count_ = 0; |
260 IceGatheringState gathering_state_ = kIceGatheringNew; | 260 IceGatheringState gathering_state_ = kIceGatheringNew; |
261 bool had_connection_ = false; | 261 bool had_connection_ = false; |
262 bool writable_ = false; | 262 bool writable_ = false; |
263 bool receiving_ = false; | 263 bool receiving_ = false; |
264 }; | 264 }; |
265 | 265 |
266 // Fake transport channel class, which can be passed to anything that needs a | 266 class FakeDtlsTransport : public DtlsTransportInternal { |
267 // transport channel. Can be informed of another FakeTransportChannel via | |
268 // SetDestination. | |
269 // TODO(hbos): Move implementation to .cc file, this and other classes in file. | |
270 class FakeTransportChannel : public TransportChannelImpl, | |
271 public rtc::MessageHandler { | |
272 public: | 267 public: |
273 explicit FakeTransportChannel(const std::string& name, int component) | 268 explicit FakeDtlsTransport(FakeIceTransport* ice_transport) |
274 : TransportChannelImpl(name, component), | 269 : ice_transport_(ice_transport), |
275 dtls_fingerprint_("", nullptr, 0) {} | 270 transport_name_(ice_transport->transport_name()), |
276 ~FakeTransportChannel() { Reset(); } | 271 component_(ice_transport->component()), |
| 272 dtls_fingerprint_("", nullptr, 0) { |
| 273 ice_transport_->SignalReadPacket.connect( |
| 274 this, &FakeDtlsTransport::OnIceTransportReadPacket); |
| 275 } |
277 | 276 |
278 uint64_t IceTiebreaker() const { return tiebreaker_; } | 277 // If this constructor is called, a new fake ice transport will be created, |
279 IceMode remote_ice_mode() const { return remote_ice_mode_; } | 278 // and this FakeDtlsTransport will take the ownership. |
280 const std::string& ice_ufrag() const { return ice_ufrag_; } | 279 explicit FakeDtlsTransport(const std::string& name, int component) |
281 const std::string& ice_pwd() const { return ice_pwd_; } | 280 : owned_ice_transport_(new FakeIceTransport(name, component)), |
282 const std::string& remote_ice_ufrag() const { return remote_ice_ufrag_; } | 281 transport_name_(owned_ice_transport_->transport_name()), |
283 const std::string& remote_ice_pwd() const { return remote_ice_pwd_; } | 282 component_(owned_ice_transport_->component()), |
| 283 dtls_fingerprint_("", nullptr, 0) { |
| 284 ice_transport_ = owned_ice_transport_.get(); |
| 285 ice_transport_->SignalReadPacket.connect( |
| 286 this, &FakeDtlsTransport::OnIceTransportReadPacket); |
| 287 } |
| 288 |
| 289 ~FakeDtlsTransport() override { Reset(); } |
| 290 |
| 291 uint64_t IceTiebreaker() const { return ice_transport_->IceTiebreaker(); } |
| 292 IceMode remote_ice_mode() const { return ice_transport_->remote_ice_mode(); } |
| 293 const std::string& ice_ufrag() const { return ice_transport_->ice_ufrag(); } |
| 294 const std::string& ice_pwd() const { return ice_transport_->ice_pwd(); } |
| 295 const std::string& remote_ice_ufrag() const { |
| 296 return ice_transport_->remote_ice_ufrag(); |
| 297 } |
| 298 const std::string& remote_ice_pwd() const { |
| 299 return ice_transport_->remote_ice_pwd(); |
| 300 } |
| 301 |
| 302 DtlsTransportState dtls_state() const override { return dtls_state_; } |
| 303 |
| 304 const std::string& transport_name() const override { return transport_name_; } |
| 305 |
| 306 int component() const override { return component_; } |
| 307 |
284 const rtc::SSLFingerprint& dtls_fingerprint() const { | 308 const rtc::SSLFingerprint& dtls_fingerprint() const { |
285 return dtls_fingerprint_; | 309 return dtls_fingerprint_; |
286 } | 310 } |
287 | 311 |
288 // If async, will send packets by "Post"-ing to message queue instead of | 312 // If async, will send packets by "Post"-ing to message queue instead of |
289 // synchronously "Send"-ing. | 313 // synchronously "Send"-ing. |
290 void SetAsync(bool async) { async_ = async; } | 314 void SetAsync(bool async) { ice_transport_->SetAsync(async); } |
291 void SetAsyncDelay(int delay_ms) { async_delay_ms_ = delay_ms; } | 315 void SetAsyncDelay(int delay_ms) { ice_transport_->SetAsyncDelay(delay_ms); } |
292 | 316 |
293 IceTransportState GetState() const override { | 317 IceRole GetIceRole() const { return ice_transport_->GetIceRole(); } |
294 if (connection_count_ == 0) { | |
295 return had_connection_ ? IceTransportState::STATE_FAILED | |
296 : IceTransportState::STATE_INIT; | |
297 } | |
298 | 318 |
299 if (connection_count_ == 1) { | |
300 return IceTransportState::STATE_COMPLETED; | |
301 } | |
302 | |
303 return IceTransportState::STATE_CONNECTING; | |
304 } | |
305 | |
306 void SetIceRole(IceRole role) override { role_ = role; } | |
307 IceRole GetIceRole() const override { return role_; } | |
308 void SetIceTiebreaker(uint64_t tiebreaker) override { | |
309 tiebreaker_ = tiebreaker; | |
310 } | |
311 void SetIceParameters(const IceParameters& ice_params) override { | |
312 ice_ufrag_ = ice_params.ufrag; | |
313 ice_pwd_ = ice_params.pwd; | |
314 } | |
315 void SetRemoteIceParameters(const IceParameters& params) override { | |
316 remote_ice_ufrag_ = params.ufrag; | |
317 remote_ice_pwd_ = params.pwd; | |
318 } | |
319 | |
320 void SetRemoteIceMode(IceMode mode) override { remote_ice_mode_ = mode; } | |
321 bool SetRemoteFingerprint(const std::string& alg, | 319 bool SetRemoteFingerprint(const std::string& alg, |
322 const uint8_t* digest, | 320 const uint8_t* digest, |
323 size_t digest_len) override { | 321 size_t digest_len) override { |
324 dtls_fingerprint_ = rtc::SSLFingerprint(alg, digest, digest_len); | 322 dtls_fingerprint_ = rtc::SSLFingerprint(alg, digest, digest_len); |
325 return true; | 323 return true; |
326 } | 324 } |
| 325 |
327 bool SetSslRole(rtc::SSLRole role) override { | 326 bool SetSslRole(rtc::SSLRole role) override { |
328 ssl_role_ = role; | 327 ssl_role_ = role; |
329 return true; | 328 return true; |
330 } | 329 } |
| 330 |
331 bool GetSslRole(rtc::SSLRole* role) const override { | 331 bool GetSslRole(rtc::SSLRole* role) const override { |
332 *role = ssl_role_; | 332 *role = ssl_role_; |
333 return true; | 333 return true; |
334 } | 334 } |
335 | 335 |
336 void MaybeStartGathering() override { | 336 IceGatheringState gathering_state() const { |
337 if (gathering_state_ == kIceGatheringNew) { | 337 return ice_transport_->gathering_state(); |
338 gathering_state_ = kIceGatheringGathering; | |
339 SignalGatheringState(this); | |
340 } | |
341 } | |
342 | |
343 IceGatheringState gathering_state() const override { | |
344 return gathering_state_; | |
345 } | 338 } |
346 | 339 |
347 void Reset() { | 340 void Reset() { |
348 if (state_ != STATE_INIT) { | 341 if (state_ != STATE_INIT) { |
349 state_ = STATE_INIT; | 342 state_ = STATE_INIT; |
350 if (dest_) { | 343 if (dest_) { |
351 dest_->state_ = STATE_INIT; | 344 dest_->state_ = STATE_INIT; |
352 dest_->dest_ = nullptr; | 345 dest_->dest_ = nullptr; |
353 dest_ = nullptr; | 346 dest_ = nullptr; |
354 } | 347 } |
355 } | 348 } |
356 } | 349 } |
357 | 350 |
358 void SetWritable(bool writable) { set_writable(writable); } | 351 void SetWritable(bool writable) { set_writable(writable); } |
359 | 352 |
360 // Simulates the two transport channels connecting to each other. | 353 // Simulates the two transport channels connecting to each other. |
361 // If |asymmetric| is true this method only affects this FakeTransportChannel. | 354 // If |asymmetric| is true this method only affects this FakeDtlsTransport. |
362 // If false, it affects |dest| as well. | 355 // If false, it affects |dest| as well. |
363 void SetDestination(FakeTransportChannel* dest, bool asymmetric = false) { | 356 void SetDestination(FakeDtlsTransport* dest, bool asymmetric = false) { |
364 if (state_ == STATE_INIT && dest) { | 357 if (state_ == STATE_INIT && dest) { |
365 // This simulates the delivery of candidates. | 358 // This simulates the delivery of candidates. |
366 dest_ = dest; | 359 dest_ = dest; |
367 if (local_cert_ && dest_->local_cert_) { | 360 if (local_cert_ && dest_->local_cert_) { |
368 do_dtls_ = true; | 361 do_dtls_ = true; |
369 NegotiateSrtpCiphers(); | 362 NegotiateSrtpCiphers(); |
370 } | 363 } |
371 state_ = STATE_CONNECTED; | 364 state_ = STATE_CONNECTED; |
372 set_writable(true); | 365 SetWritable(true); |
373 if (!asymmetric) { | 366 if (!asymmetric) { |
374 dest->SetDestination(this, true); | 367 dest->SetDestination(this, true); |
375 } | 368 } |
| 369 ice_transport_->SetDestination( |
| 370 static_cast<FakeIceTransport*>(dest->ice_transport()), asymmetric); |
376 } else if (state_ == STATE_CONNECTED && !dest) { | 371 } else if (state_ == STATE_CONNECTED && !dest) { |
377 // Simulates loss of connectivity, by asymmetrically forgetting dest_. | 372 // Simulates loss of connectivity, by asymmetrically forgetting dest_. |
378 dest_ = nullptr; | 373 dest_ = nullptr; |
379 state_ = STATE_INIT; | 374 state_ = STATE_INIT; |
380 set_writable(false); | 375 SetWritable(false); |
| 376 ice_transport_->SetDestination(nullptr, asymmetric); |
381 } | 377 } |
382 } | 378 } |
383 | 379 |
384 void SetConnectionCount(size_t connection_count) { | 380 void SetConnectionCount(size_t connection_count) { |
385 size_t old_connection_count = connection_count_; | 381 ice_transport_->SetConnectionCount(connection_count); |
386 connection_count_ = connection_count; | |
387 if (connection_count) | |
388 had_connection_ = true; | |
389 // In this fake transport channel, |connection_count_| determines the | |
390 // transport channel state. | |
391 if (connection_count_ < old_connection_count) | |
392 SignalStateChanged(this); | |
393 } | 382 } |
394 | 383 |
395 void SetCandidatesGatheringComplete() { | 384 void SetCandidatesGatheringComplete() { |
396 if (gathering_state_ != kIceGatheringComplete) { | 385 ice_transport_->SetCandidatesGatheringComplete(); |
397 gathering_state_ = kIceGatheringComplete; | |
398 SignalGatheringState(this); | |
399 } | |
400 } | 386 } |
401 | 387 |
402 void SetReceiving(bool receiving) { set_receiving(receiving); } | 388 void SetReceiving(bool receiving) { |
| 389 ice_transport_->SetReceiving(receiving); |
| 390 set_receiving(receiving); |
| 391 } |
403 | 392 |
404 void SetIceConfig(const IceConfig& config) override { ice_config_ = config; } | 393 int receiving_timeout() const { return ice_transport_->receiving_timeout(); } |
405 | 394 bool gather_continually() const { |
406 int receiving_timeout() const { return ice_config_.receiving_timeout; } | 395 return ice_transport_->gather_continually(); |
407 bool gather_continually() const { return ice_config_.gather_continually(); } | 396 } |
408 | 397 |
409 int SendPacket(const char* data, | 398 int SendPacket(const char* data, |
410 size_t len, | 399 size_t len, |
411 const rtc::PacketOptions& options, | 400 const rtc::PacketOptions& options, |
412 int flags) override { | 401 int flags) override { |
413 if (state_ != STATE_CONNECTED) { | 402 return ice_transport_->SendPacket(data, len, options, flags); |
414 return -1; | |
415 } | |
416 | |
417 if (flags != PF_SRTP_BYPASS && flags != 0) { | |
418 return -1; | |
419 } | |
420 | |
421 PacketMessageData* packet = new PacketMessageData(data, len); | |
422 if (async_) { | |
423 if (async_delay_ms_) { | |
424 rtc::Thread::Current()->PostDelayed(RTC_FROM_HERE, async_delay_ms_, | |
425 this, 0, packet); | |
426 } else { | |
427 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, 0, packet); | |
428 } | |
429 } else { | |
430 rtc::Thread::Current()->Send(RTC_FROM_HERE, this, 0, packet); | |
431 } | |
432 rtc::SentPacket sent_packet(options.packet_id, rtc::TimeMillis()); | |
433 SignalSentPacket(this, sent_packet); | |
434 return static_cast<int>(len); | |
435 } | |
436 int SetOption(rtc::Socket::Option opt, int value) override { return true; } | |
437 bool GetOption(rtc::Socket::Option opt, int* value) override { return true; } | |
438 int GetError() override { return 0; } | |
439 | |
440 void AddRemoteCandidate(const Candidate& candidate) override { | |
441 remote_candidates_.push_back(candidate); | |
442 } | 403 } |
443 | 404 |
444 void RemoveRemoteCandidate(const Candidate& candidate) override {} | 405 bool GetOption(rtc::Socket::Option opt, int* value) override { return true; } |
445 | 406 |
446 const Candidates& remote_candidates() const { return remote_candidates_; } | 407 const Candidates& remote_candidates() const { |
| 408 return ice_transport_->remote_candidates(); |
| 409 } |
447 | 410 |
448 void OnMessage(rtc::Message* msg) override { | 411 void OnIceTransportReadPacket(PacketTransportInterface* ice_, |
449 PacketMessageData* data = static_cast<PacketMessageData*>(msg->pdata); | 412 const char* data, |
450 dest_->SignalReadPacket(dest_, data->packet.data<char>(), | 413 size_t len, |
451 data->packet.size(), rtc::CreatePacketTime(0), 0); | 414 const rtc::PacketTime& time, |
452 delete data; | 415 int flags) { |
| 416 SignalReadPacket(this, data, len, time, flags); |
453 } | 417 } |
454 | 418 |
455 bool SetLocalCertificate( | 419 bool SetLocalCertificate( |
456 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override { | 420 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override { |
457 local_cert_ = certificate; | 421 local_cert_ = certificate; |
458 return true; | 422 return true; |
459 } | 423 } |
460 | 424 |
461 void SetRemoteSSLCertificate(rtc::FakeSSLCertificate* cert) { | 425 void SetRemoteSSLCertificate(rtc::FakeSSLCertificate* cert) { |
462 remote_cert_ = cert; | 426 remote_cert_ = cert; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 uint8_t* result, | 461 uint8_t* result, |
498 size_t result_len) override { | 462 size_t result_len) override { |
499 if (chosen_crypto_suite_ != rtc::SRTP_INVALID_CRYPTO_SUITE) { | 463 if (chosen_crypto_suite_ != rtc::SRTP_INVALID_CRYPTO_SUITE) { |
500 memset(result, 0xff, result_len); | 464 memset(result, 0xff, result_len); |
501 return true; | 465 return true; |
502 } | 466 } |
503 | 467 |
504 return false; | 468 return false; |
505 } | 469 } |
506 | 470 |
507 bool GetStats(ConnectionInfos* infos) override { | |
508 ConnectionInfo info; | |
509 infos->clear(); | |
510 infos->push_back(info); | |
511 return true; | |
512 } | |
513 | |
514 void set_ssl_max_protocol_version(rtc::SSLProtocolVersion version) { | 471 void set_ssl_max_protocol_version(rtc::SSLProtocolVersion version) { |
515 ssl_max_version_ = version; | 472 ssl_max_version_ = version; |
516 } | 473 } |
517 rtc::SSLProtocolVersion ssl_max_protocol_version() const { | 474 rtc::SSLProtocolVersion ssl_max_protocol_version() const { |
518 return ssl_max_version_; | 475 return ssl_max_version_; |
519 } | 476 } |
520 | 477 |
521 void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override { | 478 IceTransportInternal* ice_transport() override { return ice_transport_; } |
| 479 |
| 480 bool writable() const override { return writable_; } |
| 481 |
| 482 bool receiving() const override { return receiving_; } |
| 483 |
| 484 int GetError() override { return ice_transport_->GetError(); } |
| 485 |
| 486 int SetOption(rtc::Socket::Option opt, int value) override { |
| 487 return ice_transport_->SetOption(opt, value); |
| 488 } |
| 489 |
| 490 bool SetSrtpCiphers(const std::vector<std::string>& ciphers) override { |
| 491 std::vector<int> crypto_suites; |
| 492 for (const auto cipher : ciphers) { |
| 493 crypto_suites.push_back(rtc::SrtpCryptoSuiteFromName(cipher)); |
| 494 } |
| 495 return SetSrtpCryptoSuites(crypto_suites); |
522 } | 496 } |
523 | 497 |
524 private: | 498 private: |
525 void NegotiateSrtpCiphers() { | 499 void NegotiateSrtpCiphers() { |
526 for (std::vector<int>::const_iterator it1 = srtp_ciphers_.begin(); | 500 for (std::vector<int>::const_iterator it1 = srtp_ciphers_.begin(); |
527 it1 != srtp_ciphers_.end(); ++it1) { | 501 it1 != srtp_ciphers_.end(); ++it1) { |
528 for (std::vector<int>::const_iterator it2 = dest_->srtp_ciphers_.begin(); | 502 for (std::vector<int>::const_iterator it2 = dest_->srtp_ciphers_.begin(); |
529 it2 != dest_->srtp_ciphers_.end(); ++it2) { | 503 it2 != dest_->srtp_ciphers_.end(); ++it2) { |
530 if (*it1 == *it2) { | 504 if (*it1 == *it2) { |
531 chosen_crypto_suite_ = *it1; | 505 chosen_crypto_suite_ = *it1; |
532 return; | 506 return; |
533 } | 507 } |
534 } | 508 } |
535 } | 509 } |
536 } | 510 } |
537 | 511 |
| 512 void set_receiving(bool receiving) { |
| 513 if (receiving_ == receiving) { |
| 514 return; |
| 515 } |
| 516 receiving_ = receiving; |
| 517 SignalReceivingState(this); |
| 518 } |
| 519 |
| 520 void set_writable(bool writable) { |
| 521 if (writable_ == writable) { |
| 522 return; |
| 523 } |
| 524 writable_ = writable; |
| 525 if (writable_) { |
| 526 SignalReadyToSend(this); |
| 527 } |
| 528 SignalWritableState(this); |
| 529 } |
| 530 |
538 enum State { STATE_INIT, STATE_CONNECTED }; | 531 enum State { STATE_INIT, STATE_CONNECTED }; |
539 FakeTransportChannel* dest_ = nullptr; | 532 FakeIceTransport* ice_transport_; |
| 533 std::unique_ptr<FakeIceTransport> owned_ice_transport_; |
| 534 std::string transport_name_; |
| 535 int component_; |
| 536 FakeDtlsTransport* dest_ = nullptr; |
540 State state_ = STATE_INIT; | 537 State state_ = STATE_INIT; |
541 bool async_ = false; | |
542 int async_delay_ms_ = 0; | |
543 Candidates remote_candidates_; | 538 Candidates remote_candidates_; |
544 rtc::scoped_refptr<rtc::RTCCertificate> local_cert_; | 539 rtc::scoped_refptr<rtc::RTCCertificate> local_cert_; |
545 rtc::FakeSSLCertificate* remote_cert_ = nullptr; | 540 rtc::FakeSSLCertificate* remote_cert_ = nullptr; |
546 bool do_dtls_ = false; | 541 bool do_dtls_ = false; |
547 std::vector<int> srtp_ciphers_; | 542 std::vector<int> srtp_ciphers_; |
548 int chosen_crypto_suite_ = rtc::SRTP_INVALID_CRYPTO_SUITE; | 543 int chosen_crypto_suite_ = rtc::SRTP_INVALID_CRYPTO_SUITE; |
549 IceConfig ice_config_; | |
550 IceRole role_ = ICEROLE_UNKNOWN; | |
551 uint64_t tiebreaker_ = 0; | |
552 std::string ice_ufrag_; | |
553 std::string ice_pwd_; | |
554 std::string remote_ice_ufrag_; | |
555 std::string remote_ice_pwd_; | |
556 IceMode remote_ice_mode_ = ICEMODE_FULL; | |
557 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; | 544 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; |
558 rtc::SSLFingerprint dtls_fingerprint_; | 545 rtc::SSLFingerprint dtls_fingerprint_; |
559 rtc::SSLRole ssl_role_ = rtc::SSL_CLIENT; | 546 rtc::SSLRole ssl_role_ = rtc::SSL_CLIENT; |
560 size_t connection_count_ = 0; | 547 |
561 IceGatheringState gathering_state_ = kIceGatheringNew; | 548 DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW; |
562 bool had_connection_ = false; | 549 |
| 550 bool receiving_ = false; |
| 551 bool writable_ = false; |
563 }; | 552 }; |
564 | 553 |
565 // Fake candidate pair class, which can be passed to BaseChannel for testing | 554 // Fake candidate pair class, which can be passed to BaseChannel for testing |
566 // purposes. | 555 // purposes. |
567 class FakeCandidatePair : public CandidatePairInterface { | 556 class FakeCandidatePair : public CandidatePairInterface { |
568 public: | 557 public: |
569 FakeCandidatePair(const Candidate& local_candidate, | 558 FakeCandidatePair(const Candidate& local_candidate, |
570 const Candidate& remote_candidate) | 559 const Candidate& remote_candidate) |
571 : local_candidate_(local_candidate), | 560 : local_candidate_(local_candidate), |
572 remote_candidate_(remote_candidate) {} | 561 remote_candidate_(remote_candidate) {} |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 } | 596 } |
608 | 597 |
609 explicit FakeTransportController(rtc::Thread* network_thread) | 598 explicit FakeTransportController(rtc::Thread* network_thread) |
610 : TransportController(rtc::Thread::Current(), network_thread, nullptr) {} | 599 : TransportController(rtc::Thread::Current(), network_thread, nullptr) {} |
611 | 600 |
612 FakeTransportController(rtc::Thread* network_thread, IceRole role) | 601 FakeTransportController(rtc::Thread* network_thread, IceRole role) |
613 : TransportController(rtc::Thread::Current(), network_thread, nullptr) { | 602 : TransportController(rtc::Thread::Current(), network_thread, nullptr) { |
614 SetIceRole(role); | 603 SetIceRole(role); |
615 } | 604 } |
616 | 605 |
617 FakeTransportChannel* GetFakeTransportChannel_n( | 606 FakeDtlsTransport* GetFakeDtlsTransport_n(const std::string& transport_name, |
618 const std::string& transport_name, | 607 int component) { |
619 int component) { | 608 return static_cast<FakeDtlsTransport*>( |
620 return static_cast<FakeTransportChannel*>( | |
621 get_channel_for_testing(transport_name, component)); | 609 get_channel_for_testing(transport_name, component)); |
622 } | 610 } |
623 | 611 |
624 // Simulate the exchange of transport descriptions, and the gathering and | 612 // Simulate the exchange of transport descriptions, and the gathering and |
625 // exchange of ICE candidates. | 613 // exchange of ICE candidates. |
626 void Connect(FakeTransportController* dest) { | 614 void Connect(FakeTransportController* dest) { |
627 for (const std::string& transport_name : transport_names_for_testing()) { | 615 for (const std::string& transport_name : transport_names_for_testing()) { |
628 TransportDescription local_desc( | 616 TransportDescription local_desc( |
629 std::vector<std::string>(), | 617 std::vector<std::string>(), |
630 rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH), | 618 rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH), |
(...skipping 28 matching lines...) Expand all Loading... |
659 const rtc::SocketAddress& remote_address, | 647 const rtc::SocketAddress& remote_address, |
660 int16_t remote_network_id) { | 648 int16_t remote_network_id) { |
661 Candidate local_candidate(0, "udp", local_address, 0u, "", "", "local", 0, | 649 Candidate local_candidate(0, "udp", local_address, 0u, "", "", "local", 0, |
662 "foundation", local_network_id, 0); | 650 "foundation", local_network_id, 0); |
663 Candidate remote_candidate(0, "udp", remote_address, 0u, "", "", "local", 0, | 651 Candidate remote_candidate(0, "udp", remote_address, 0u, "", "", "local", 0, |
664 "foundation", remote_network_id, 0); | 652 "foundation", remote_network_id, 0); |
665 return new FakeCandidatePair(local_candidate, remote_candidate); | 653 return new FakeCandidatePair(local_candidate, remote_candidate); |
666 } | 654 } |
667 | 655 |
668 void DestroyRtcpTransport(const std::string& transport_name) { | 656 void DestroyRtcpTransport(const std::string& transport_name) { |
669 DestroyTransportChannel_n(transport_name, | 657 DestroyDtlsTransport_n(transport_name, |
670 cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 658 cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
671 } | 659 } |
672 | 660 |
673 protected: | 661 protected: |
674 // The ICE channel is never actually used by TransportController directly, | 662 // The ICE channel is never actually used by TransportController directly, |
675 // since (currently) the DTLS channel pretends to be both ICE + DTLS. This | 663 // since (currently) the DTLS channel pretends to be both ICE + DTLS. This |
676 // will change when we get rid of TransportChannelImpl. | 664 // will change when we get rid of TransportChannelImpl. |
677 IceTransportInternal* CreateIceTransportChannel_n( | 665 IceTransportInternal* CreateIceTransportChannel_n( |
678 const std::string& transport_name, | 666 const std::string& transport_name, |
679 int component) override { | 667 int component) override { |
680 return nullptr; | 668 return new FakeIceTransport(transport_name, component); |
681 } | 669 } |
682 | 670 |
683 TransportChannelImpl* CreateDtlsTransportChannel_n( | 671 DtlsTransportInternal* CreateDtlsTransportChannel_n( |
684 const std::string& transport_name, | 672 const std::string& transport_name, |
685 int component, | 673 int component, |
686 IceTransportInternal*) override { | 674 IceTransportInternal* ice) override { |
687 return new FakeTransportChannel(transport_name, component); | 675 return new FakeDtlsTransport(static_cast<FakeIceTransport*>(ice)); |
688 } | 676 } |
689 | 677 |
690 private: | 678 private: |
691 void SetChannelDestinations_n(FakeTransportController* dest) { | 679 void SetChannelDestinations_n(FakeTransportController* dest) { |
692 for (TransportChannelImpl* tc : channels_for_testing()) { | 680 for (DtlsTransportInternal* tc : channels_for_testing()) { |
693 FakeTransportChannel* local = static_cast<FakeTransportChannel*>(tc); | 681 FakeDtlsTransport* local = static_cast<FakeDtlsTransport*>(tc); |
694 FakeTransportChannel* remote = dest->GetFakeTransportChannel_n( | 682 FakeDtlsTransport* remote = dest->GetFakeDtlsTransport_n( |
695 local->transport_name(), local->component()); | 683 local->transport_name(), local->component()); |
696 if (remote) { | 684 if (remote) { |
697 bool asymmetric = false; | 685 bool asymmetric = false; |
698 local->SetDestination(remote, asymmetric); | 686 local->SetDestination(remote, asymmetric); |
699 } | 687 } |
700 } | 688 } |
701 } | 689 } |
702 }; | 690 }; |
703 | 691 |
704 } // namespace cricket | 692 } // namespace cricket |
705 | 693 |
706 #endif // WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ | 694 #endif // WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ |
OLD | NEW |