| 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 explicit FakeDtlsTransport(const std::string& name, int component) |
| 279 IceMode remote_ice_mode() const { return remote_ice_mode_; } | 278 : ice_transport_(new FakeIceTransport(name, component)), |
| 280 const std::string& ice_ufrag() const { return ice_ufrag_; } | 279 transport_name_(ice_transport_->transport_name()), |
| 281 const std::string& ice_pwd() const { return ice_pwd_; } | 280 component_(ice_transport_->component()), |
| 282 const std::string& remote_ice_ufrag() const { return remote_ice_ufrag_; } | 281 dtls_fingerprint_("", nullptr, 0) { |
| 283 const std::string& remote_ice_pwd() const { return remote_ice_pwd_; } | 282 ice_transport_->SignalReadPacket.connect( |
| 283 this, &FakeDtlsTransport::OnIceTransportReadPacket); |
| 284 } |
| 285 |
| 286 ~FakeDtlsTransport() override { Reset(); } |
| 287 |
| 288 uint64_t IceTiebreaker() const { return ice_transport_->IceTiebreaker(); } |
| 289 IceMode remote_ice_mode() const { return ice_transport_->remote_ice_mode(); } |
| 290 const std::string& ice_ufrag() const { return ice_transport_->ice_ufrag(); } |
| 291 const std::string& ice_pwd() const { return ice_transport_->ice_pwd(); } |
| 292 const std::string& remote_ice_ufrag() const { |
| 293 return ice_transport_->remote_ice_ufrag(); |
| 294 } |
| 295 const std::string& remote_ice_pwd() const { |
| 296 return ice_transport_->remote_ice_pwd(); |
| 297 } |
| 298 |
| 299 DtlsTransportState dtls_state() const override { return dtls_state_; } |
| 300 |
| 301 const std::string& transport_name() const override { return transport_name_; } |
| 302 |
| 303 int component() const override { return component_; } |
| 304 |
| 284 const rtc::SSLFingerprint& dtls_fingerprint() const { | 305 const rtc::SSLFingerprint& dtls_fingerprint() const { |
| 285 return dtls_fingerprint_; | 306 return dtls_fingerprint_; |
| 286 } | 307 } |
| 287 | 308 |
| 288 // If async, will send packets by "Post"-ing to message queue instead of | 309 // If async, will send packets by "Post"-ing to message queue instead of |
| 289 // synchronously "Send"-ing. | 310 // synchronously "Send"-ing. |
| 290 void SetAsync(bool async) { async_ = async; } | 311 void SetAsync(bool async) { ice_transport_->SetAsync(async); } |
| 291 void SetAsyncDelay(int delay_ms) { async_delay_ms_ = delay_ms; } | 312 void SetAsyncDelay(int delay_ms) { ice_transport_->SetAsyncDelay(delay_ms); } |
| 292 | 313 |
| 293 IceTransportState GetState() const override { | 314 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 | 315 |
| 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, | 316 bool SetRemoteFingerprint(const std::string& alg, |
| 322 const uint8_t* digest, | 317 const uint8_t* digest, |
| 323 size_t digest_len) override { | 318 size_t digest_len) override { |
| 324 dtls_fingerprint_ = rtc::SSLFingerprint(alg, digest, digest_len); | 319 dtls_fingerprint_ = rtc::SSLFingerprint(alg, digest, digest_len); |
| 325 return true; | 320 return true; |
| 326 } | 321 } |
| 322 |
| 327 bool SetSslRole(rtc::SSLRole role) override { | 323 bool SetSslRole(rtc::SSLRole role) override { |
| 328 ssl_role_ = role; | 324 ssl_role_ = role; |
| 329 return true; | 325 return true; |
| 330 } | 326 } |
| 327 |
| 331 bool GetSslRole(rtc::SSLRole* role) const override { | 328 bool GetSslRole(rtc::SSLRole* role) const override { |
| 332 *role = ssl_role_; | 329 *role = ssl_role_; |
| 333 return true; | 330 return true; |
| 334 } | 331 } |
| 335 | 332 |
| 336 void MaybeStartGathering() override { | 333 IceGatheringState gathering_state() const { |
| 337 if (gathering_state_ == kIceGatheringNew) { | 334 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 } | 335 } |
| 346 | 336 |
| 347 void Reset() { | 337 void Reset() { |
| 348 if (state_ != STATE_INIT) { | 338 if (state_ != STATE_INIT) { |
| 349 state_ = STATE_INIT; | 339 state_ = STATE_INIT; |
| 350 if (dest_) { | 340 if (dest_) { |
| 351 dest_->state_ = STATE_INIT; | 341 dest_->state_ = STATE_INIT; |
| 352 dest_->dest_ = nullptr; | 342 dest_->dest_ = nullptr; |
| 353 dest_ = nullptr; | 343 dest_ = nullptr; |
| 354 } | 344 } |
| 355 } | 345 } |
| 356 } | 346 } |
| 357 | 347 |
| 358 void SetWritable(bool writable) { set_writable(writable); } | 348 void SetWritable(bool writable) { set_writable(writable); } |
| 359 | 349 |
| 360 // Simulates the two transport channels connecting to each other. | 350 // Simulates the two transport channels connecting to each other. |
| 361 // If |asymmetric| is true this method only affects this FakeTransportChannel. | 351 // If |asymmetric| is true this method only affects this FakeDtlsTransport. |
| 362 // If false, it affects |dest| as well. | 352 // If false, it affects |dest| as well. |
| 363 void SetDestination(FakeTransportChannel* dest, bool asymmetric = false) { | 353 void SetDestination(FakeDtlsTransport* dest, bool asymmetric = false) { |
| 364 if (state_ == STATE_INIT && dest) { | 354 if (state_ == STATE_INIT && dest) { |
| 365 // This simulates the delivery of candidates. | 355 // This simulates the delivery of candidates. |
| 366 dest_ = dest; | 356 dest_ = dest; |
| 367 if (local_cert_ && dest_->local_cert_) { | 357 if (local_cert_ && dest_->local_cert_) { |
| 368 do_dtls_ = true; | 358 do_dtls_ = true; |
| 369 NegotiateSrtpCiphers(); | 359 NegotiateSrtpCiphers(); |
| 370 } | 360 } |
| 371 state_ = STATE_CONNECTED; | 361 state_ = STATE_CONNECTED; |
| 372 set_writable(true); | 362 SetWritable(true); |
| 373 if (!asymmetric) { | 363 if (!asymmetric) { |
| 374 dest->SetDestination(this, true); | 364 dest->SetDestination(this, true); |
| 375 } | 365 } |
| 366 ice_transport_->SetDestination( |
| 367 static_cast<FakeIceTransport*>(dest->ice_transport()), asymmetric); |
| 376 } else if (state_ == STATE_CONNECTED && !dest) { | 368 } else if (state_ == STATE_CONNECTED && !dest) { |
| 377 // Simulates loss of connectivity, by asymmetrically forgetting dest_. | 369 // Simulates loss of connectivity, by asymmetrically forgetting dest_. |
| 378 dest_ = nullptr; | 370 dest_ = nullptr; |
| 379 state_ = STATE_INIT; | 371 state_ = STATE_INIT; |
| 380 set_writable(false); | 372 SetWritable(false); |
| 373 ice_transport_->SetDestination(nullptr, asymmetric); |
| 381 } | 374 } |
| 382 } | 375 } |
| 383 | 376 |
| 384 void SetConnectionCount(size_t connection_count) { | 377 void SetConnectionCount(size_t connection_count) { |
| 385 size_t old_connection_count = connection_count_; | 378 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 } | 379 } |
| 394 | 380 |
| 395 void SetCandidatesGatheringComplete() { | 381 void SetCandidatesGatheringComplete() { |
| 396 if (gathering_state_ != kIceGatheringComplete) { | 382 ice_transport_->SetCandidatesGatheringComplete(); |
| 397 gathering_state_ = kIceGatheringComplete; | |
| 398 SignalGatheringState(this); | |
| 399 } | |
| 400 } | 383 } |
| 401 | 384 |
| 402 void SetReceiving(bool receiving) { set_receiving(receiving); } | 385 void SetReceiving(bool receiving) { |
| 386 ice_transport_->SetReceiving(receiving); |
| 387 set_receiving(receiving); |
| 388 } |
| 403 | 389 |
| 404 void SetIceConfig(const IceConfig& config) override { ice_config_ = config; } | 390 int receiving_timeout() const { return ice_transport_->receiving_timeout(); } |
| 405 | 391 bool gather_continually() const { |
| 406 int receiving_timeout() const { return ice_config_.receiving_timeout; } | 392 return ice_transport_->gather_continually(); |
| 407 bool gather_continually() const { return ice_config_.gather_continually(); } | 393 } |
| 408 | 394 |
| 409 int SendPacket(const char* data, | 395 int SendPacket(const char* data, |
| 410 size_t len, | 396 size_t len, |
| 411 const rtc::PacketOptions& options, | 397 const rtc::PacketOptions& options, |
| 412 int flags) override { | 398 int flags) override { |
| 413 if (state_ != STATE_CONNECTED) { | 399 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 } | 400 } |
| 443 | 401 |
| 444 void RemoveRemoteCandidate(const Candidate& candidate) override {} | 402 bool GetOption(rtc::Socket::Option opt, int* value) override { return true; } |
| 445 | 403 |
| 446 const Candidates& remote_candidates() const { return remote_candidates_; } | 404 const Candidates& remote_candidates() const { |
| 405 return ice_transport_->remote_candidates(); |
| 406 } |
| 447 | 407 |
| 448 void OnMessage(rtc::Message* msg) override { | 408 void OnIceTransportReadPacket(PacketTransportInterface* ice_, |
| 449 PacketMessageData* data = static_cast<PacketMessageData*>(msg->pdata); | 409 const char* data, |
| 450 dest_->SignalReadPacket(dest_, data->packet.data<char>(), | 410 size_t len, |
| 451 data->packet.size(), rtc::CreatePacketTime(0), 0); | 411 const rtc::PacketTime& time, |
| 452 delete data; | 412 int flags) { |
| 413 SignalReadPacket(this, data, len, time, flags); |
| 453 } | 414 } |
| 454 | 415 |
| 455 bool SetLocalCertificate( | 416 bool SetLocalCertificate( |
| 456 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override { | 417 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override { |
| 457 local_cert_ = certificate; | 418 local_cert_ = certificate; |
| 458 return true; | 419 return true; |
| 459 } | 420 } |
| 460 | 421 |
| 461 void SetRemoteSSLCertificate(rtc::FakeSSLCertificate* cert) { | 422 void SetRemoteSSLCertificate(rtc::FakeSSLCertificate* cert) { |
| 462 remote_cert_ = cert; | 423 remote_cert_ = cert; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 uint8_t* result, | 458 uint8_t* result, |
| 498 size_t result_len) override { | 459 size_t result_len) override { |
| 499 if (chosen_crypto_suite_ != rtc::SRTP_INVALID_CRYPTO_SUITE) { | 460 if (chosen_crypto_suite_ != rtc::SRTP_INVALID_CRYPTO_SUITE) { |
| 500 memset(result, 0xff, result_len); | 461 memset(result, 0xff, result_len); |
| 501 return true; | 462 return true; |
| 502 } | 463 } |
| 503 | 464 |
| 504 return false; | 465 return false; |
| 505 } | 466 } |
| 506 | 467 |
| 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) { | 468 void set_ssl_max_protocol_version(rtc::SSLProtocolVersion version) { |
| 515 ssl_max_version_ = version; | 469 ssl_max_version_ = version; |
| 516 } | 470 } |
| 517 rtc::SSLProtocolVersion ssl_max_protocol_version() const { | 471 rtc::SSLProtocolVersion ssl_max_protocol_version() const { |
| 518 return ssl_max_version_; | 472 return ssl_max_version_; |
| 519 } | 473 } |
| 520 | 474 |
| 521 void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override { | 475 IceTransportInternal* ice_transport() override { return ice_transport_; } |
| 476 |
| 477 bool writable() const override { return writable_; } |
| 478 |
| 479 bool receiving() const override { return receiving_; } |
| 480 |
| 481 int GetError() override { return ice_transport_->GetError(); } |
| 482 |
| 483 int SetOption(rtc::Socket::Option opt, int value) override { |
| 484 return ice_transport_->SetOption(opt, value); |
| 485 } |
| 486 |
| 487 bool SetSrtpCiphers(const std::vector<std::string>& ciphers) override { |
| 488 std::vector<int> crypto_suites; |
| 489 for (const auto cipher : ciphers) { |
| 490 crypto_suites.push_back(rtc::SrtpCryptoSuiteFromName(cipher)); |
| 491 } |
| 492 return SetSrtpCryptoSuites(crypto_suites); |
| 522 } | 493 } |
| 523 | 494 |
| 524 private: | 495 private: |
| 525 void NegotiateSrtpCiphers() { | 496 void NegotiateSrtpCiphers() { |
| 526 for (std::vector<int>::const_iterator it1 = srtp_ciphers_.begin(); | 497 for (std::vector<int>::const_iterator it1 = srtp_ciphers_.begin(); |
| 527 it1 != srtp_ciphers_.end(); ++it1) { | 498 it1 != srtp_ciphers_.end(); ++it1) { |
| 528 for (std::vector<int>::const_iterator it2 = dest_->srtp_ciphers_.begin(); | 499 for (std::vector<int>::const_iterator it2 = dest_->srtp_ciphers_.begin(); |
| 529 it2 != dest_->srtp_ciphers_.end(); ++it2) { | 500 it2 != dest_->srtp_ciphers_.end(); ++it2) { |
| 530 if (*it1 == *it2) { | 501 if (*it1 == *it2) { |
| 531 chosen_crypto_suite_ = *it1; | 502 chosen_crypto_suite_ = *it1; |
| 532 return; | 503 return; |
| 533 } | 504 } |
| 534 } | 505 } |
| 535 } | 506 } |
| 536 } | 507 } |
| 537 | 508 |
| 509 void set_receiving(bool receiving) { |
| 510 if (receiving_ == receiving) { |
| 511 return; |
| 512 } |
| 513 receiving_ = receiving; |
| 514 SignalReceivingState(this); |
| 515 } |
| 516 |
| 517 void set_writable(bool writable) { |
| 518 if (writable_ == writable) { |
| 519 return; |
| 520 } |
| 521 writable_ = writable; |
| 522 if (writable_) { |
| 523 SignalReadyToSend(this); |
| 524 } |
| 525 SignalWritableState(this); |
| 526 } |
| 527 |
| 538 enum State { STATE_INIT, STATE_CONNECTED }; | 528 enum State { STATE_INIT, STATE_CONNECTED }; |
| 539 FakeTransportChannel* dest_ = nullptr; | 529 FakeIceTransport* ice_transport_; |
| 530 std::string transport_name_; |
| 531 int component_; |
| 532 FakeDtlsTransport* dest_ = nullptr; |
| 540 State state_ = STATE_INIT; | 533 State state_ = STATE_INIT; |
| 541 bool async_ = false; | |
| 542 int async_delay_ms_ = 0; | |
| 543 Candidates remote_candidates_; | 534 Candidates remote_candidates_; |
| 544 rtc::scoped_refptr<rtc::RTCCertificate> local_cert_; | 535 rtc::scoped_refptr<rtc::RTCCertificate> local_cert_; |
| 545 rtc::FakeSSLCertificate* remote_cert_ = nullptr; | 536 rtc::FakeSSLCertificate* remote_cert_ = nullptr; |
| 546 bool do_dtls_ = false; | 537 bool do_dtls_ = false; |
| 547 std::vector<int> srtp_ciphers_; | 538 std::vector<int> srtp_ciphers_; |
| 548 int chosen_crypto_suite_ = rtc::SRTP_INVALID_CRYPTO_SUITE; | 539 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; | 540 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; |
| 558 rtc::SSLFingerprint dtls_fingerprint_; | 541 rtc::SSLFingerprint dtls_fingerprint_; |
| 559 rtc::SSLRole ssl_role_ = rtc::SSL_CLIENT; | 542 rtc::SSLRole ssl_role_ = rtc::SSL_CLIENT; |
| 560 size_t connection_count_ = 0; | 543 |
| 561 IceGatheringState gathering_state_ = kIceGatheringNew; | 544 DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW; |
| 562 bool had_connection_ = false; | 545 |
| 546 bool receiving_ = false; |
| 547 bool writable_ = false; |
| 563 }; | 548 }; |
| 564 | 549 |
| 565 // Fake candidate pair class, which can be passed to BaseChannel for testing | 550 // Fake candidate pair class, which can be passed to BaseChannel for testing |
| 566 // purposes. | 551 // purposes. |
| 567 class FakeCandidatePair : public CandidatePairInterface { | 552 class FakeCandidatePair : public CandidatePairInterface { |
| 568 public: | 553 public: |
| 569 FakeCandidatePair(const Candidate& local_candidate, | 554 FakeCandidatePair(const Candidate& local_candidate, |
| 570 const Candidate& remote_candidate) | 555 const Candidate& remote_candidate) |
| 571 : local_candidate_(local_candidate), | 556 : local_candidate_(local_candidate), |
| 572 remote_candidate_(remote_candidate) {} | 557 remote_candidate_(remote_candidate) {} |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 } | 592 } |
| 608 | 593 |
| 609 explicit FakeTransportController(rtc::Thread* network_thread) | 594 explicit FakeTransportController(rtc::Thread* network_thread) |
| 610 : TransportController(rtc::Thread::Current(), network_thread, nullptr) {} | 595 : TransportController(rtc::Thread::Current(), network_thread, nullptr) {} |
| 611 | 596 |
| 612 FakeTransportController(rtc::Thread* network_thread, IceRole role) | 597 FakeTransportController(rtc::Thread* network_thread, IceRole role) |
| 613 : TransportController(rtc::Thread::Current(), network_thread, nullptr) { | 598 : TransportController(rtc::Thread::Current(), network_thread, nullptr) { |
| 614 SetIceRole(role); | 599 SetIceRole(role); |
| 615 } | 600 } |
| 616 | 601 |
| 617 FakeTransportChannel* GetFakeTransportChannel_n( | 602 FakeDtlsTransport* GetFakeDtlsTransport_n(const std::string& transport_name, |
| 618 const std::string& transport_name, | 603 int component) { |
| 619 int component) { | 604 return static_cast<FakeDtlsTransport*>( |
| 620 return static_cast<FakeTransportChannel*>( | |
| 621 get_channel_for_testing(transport_name, component)); | 605 get_channel_for_testing(transport_name, component)); |
| 622 } | 606 } |
| 623 | 607 |
| 624 // Simulate the exchange of transport descriptions, and the gathering and | 608 // Simulate the exchange of transport descriptions, and the gathering and |
| 625 // exchange of ICE candidates. | 609 // exchange of ICE candidates. |
| 626 void Connect(FakeTransportController* dest) { | 610 void Connect(FakeTransportController* dest) { |
| 627 for (const std::string& transport_name : transport_names_for_testing()) { | 611 for (const std::string& transport_name : transport_names_for_testing()) { |
| 628 TransportDescription local_desc( | 612 TransportDescription local_desc( |
| 629 std::vector<std::string>(), | 613 std::vector<std::string>(), |
| 630 rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH), | 614 rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 659 const rtc::SocketAddress& remote_address, | 643 const rtc::SocketAddress& remote_address, |
| 660 int16_t remote_network_id) { | 644 int16_t remote_network_id) { |
| 661 Candidate local_candidate(0, "udp", local_address, 0u, "", "", "local", 0, | 645 Candidate local_candidate(0, "udp", local_address, 0u, "", "", "local", 0, |
| 662 "foundation", local_network_id, 0); | 646 "foundation", local_network_id, 0); |
| 663 Candidate remote_candidate(0, "udp", remote_address, 0u, "", "", "local", 0, | 647 Candidate remote_candidate(0, "udp", remote_address, 0u, "", "", "local", 0, |
| 664 "foundation", remote_network_id, 0); | 648 "foundation", remote_network_id, 0); |
| 665 return new FakeCandidatePair(local_candidate, remote_candidate); | 649 return new FakeCandidatePair(local_candidate, remote_candidate); |
| 666 } | 650 } |
| 667 | 651 |
| 668 void DestroyRtcpTransport(const std::string& transport_name) { | 652 void DestroyRtcpTransport(const std::string& transport_name) { |
| 669 DestroyTransportChannel_n(transport_name, | 653 DestroyDtlsTransport_n(transport_name, |
| 670 cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 654 cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
| 671 } | 655 } |
| 672 | 656 |
| 673 protected: | 657 protected: |
| 674 // The ICE channel is never actually used by TransportController directly, | 658 // The ICE channel is never actually used by TransportController directly, |
| 675 // since (currently) the DTLS channel pretends to be both ICE + DTLS. This | 659 // since (currently) the DTLS channel pretends to be both ICE + DTLS. This |
| 676 // will change when we get rid of TransportChannelImpl. | 660 // will change when we get rid of TransportChannelImpl. |
| 677 IceTransportInternal* CreateIceTransportChannel_n( | 661 IceTransportInternal* CreateIceTransportChannel_n( |
| 678 const std::string& transport_name, | 662 const std::string& transport_name, |
| 679 int component) override { | 663 int component) override { |
| 680 return nullptr; | 664 return new FakeIceTransport(transport_name, component); |
| 681 } | 665 } |
| 682 | 666 |
| 683 TransportChannelImpl* CreateDtlsTransportChannel_n( | 667 DtlsTransportInternal* CreateDtlsTransportChannel_n( |
| 684 const std::string& transport_name, | 668 const std::string& transport_name, |
| 685 int component, | 669 int component, |
| 686 IceTransportInternal*) override { | 670 IceTransportInternal* ice) override { |
| 687 return new FakeTransportChannel(transport_name, component); | 671 return new FakeDtlsTransport(static_cast<FakeIceTransport*>(ice)); |
| 688 } | 672 } |
| 689 | 673 |
| 690 private: | 674 private: |
| 691 void SetChannelDestinations_n(FakeTransportController* dest) { | 675 void SetChannelDestinations_n(FakeTransportController* dest) { |
| 692 for (TransportChannelImpl* tc : channels_for_testing()) { | 676 for (DtlsTransportInternal* tc : channels_for_testing()) { |
| 693 FakeTransportChannel* local = static_cast<FakeTransportChannel*>(tc); | 677 FakeDtlsTransport* local = static_cast<FakeDtlsTransport*>(tc); |
| 694 FakeTransportChannel* remote = dest->GetFakeTransportChannel_n( | 678 FakeDtlsTransport* remote = dest->GetFakeDtlsTransport_n( |
| 695 local->transport_name(), local->component()); | 679 local->transport_name(), local->component()); |
| 696 if (remote) { | 680 if (remote) { |
| 697 bool asymmetric = false; | 681 bool asymmetric = false; |
| 698 local->SetDestination(remote, asymmetric); | 682 local->SetDestination(remote, asymmetric); |
| 699 } | 683 } |
| 700 } | 684 } |
| 701 } | 685 } |
| 702 }; | 686 }; |
| 703 | 687 |
| 704 } // namespace cricket | 688 } // namespace cricket |
| 705 | 689 |
| 706 #endif // WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ | 690 #endif // WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ |
| OLD | NEW |