| 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 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 const std::string& ice_pwd() const { return ice_pwd_; } | 58 const std::string& ice_pwd() const { return ice_pwd_; } |
| 59 const std::string& remote_ice_ufrag() const { return remote_ice_ufrag_; } | 59 const std::string& remote_ice_ufrag() const { return remote_ice_ufrag_; } |
| 60 const std::string& remote_ice_pwd() const { return remote_ice_pwd_; } | 60 const std::string& remote_ice_pwd() const { return remote_ice_pwd_; } |
| 61 const rtc::SSLFingerprint& dtls_fingerprint() const { | 61 const rtc::SSLFingerprint& dtls_fingerprint() const { |
| 62 return dtls_fingerprint_; | 62 return dtls_fingerprint_; |
| 63 } | 63 } |
| 64 | 64 |
| 65 // If async, will send packets by "Post"-ing to message queue instead of | 65 // If async, will send packets by "Post"-ing to message queue instead of |
| 66 // synchronously "Send"-ing. | 66 // synchronously "Send"-ing. |
| 67 void SetAsync(bool async) { async_ = async; } | 67 void SetAsync(bool async) { async_ = async; } |
| 68 void SetAsyncDelay(int delay_ms) { async_delay_ms_ = delay_ms; } |
| 68 | 69 |
| 69 TransportChannelState GetState() const override { | 70 TransportChannelState GetState() const override { |
| 70 if (connection_count_ == 0) { | 71 if (connection_count_ == 0) { |
| 71 return had_connection_ ? TransportChannelState::STATE_FAILED | 72 return had_connection_ ? TransportChannelState::STATE_FAILED |
| 72 : TransportChannelState::STATE_INIT; | 73 : TransportChannelState::STATE_INIT; |
| 73 } | 74 } |
| 74 | 75 |
| 75 if (connection_count_ == 1) { | 76 if (connection_count_ == 1) { |
| 76 return TransportChannelState::STATE_COMPLETED; | 77 return TransportChannelState::STATE_COMPLETED; |
| 77 } | 78 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 if (state_ != STATE_CONNECTED) { | 192 if (state_ != STATE_CONNECTED) { |
| 192 return -1; | 193 return -1; |
| 193 } | 194 } |
| 194 | 195 |
| 195 if (flags != PF_SRTP_BYPASS && flags != 0) { | 196 if (flags != PF_SRTP_BYPASS && flags != 0) { |
| 196 return -1; | 197 return -1; |
| 197 } | 198 } |
| 198 | 199 |
| 199 PacketMessageData* packet = new PacketMessageData(data, len); | 200 PacketMessageData* packet = new PacketMessageData(data, len); |
| 200 if (async_) { | 201 if (async_) { |
| 201 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, 0, packet); | 202 if (async_delay_ms_) { |
| 203 rtc::Thread::Current()->PostDelayed(RTC_FROM_HERE, async_delay_ms_, |
| 204 this, 0, packet); |
| 205 } else { |
| 206 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, 0, packet); |
| 207 } |
| 202 } else { | 208 } else { |
| 203 rtc::Thread::Current()->Send(RTC_FROM_HERE, this, 0, packet); | 209 rtc::Thread::Current()->Send(RTC_FROM_HERE, this, 0, packet); |
| 204 } | 210 } |
| 205 rtc::SentPacket sent_packet(options.packet_id, rtc::TimeMillis()); | 211 rtc::SentPacket sent_packet(options.packet_id, rtc::TimeMillis()); |
| 206 SignalSentPacket(this, sent_packet); | 212 SignalSentPacket(this, sent_packet); |
| 207 return static_cast<int>(len); | 213 return static_cast<int>(len); |
| 208 } | 214 } |
| 209 int SetOption(rtc::Socket::Option opt, int value) override { return true; } | 215 int SetOption(rtc::Socket::Option opt, int value) override { return true; } |
| 210 bool GetOption(rtc::Socket::Option opt, int* value) override { return true; } | 216 bool GetOption(rtc::Socket::Option opt, int* value) override { return true; } |
| 211 int GetError() override { return 0; } | 217 int GetError() override { return 0; } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 return; | 308 return; |
| 303 } | 309 } |
| 304 } | 310 } |
| 305 } | 311 } |
| 306 } | 312 } |
| 307 | 313 |
| 308 enum State { STATE_INIT, STATE_CONNECTED }; | 314 enum State { STATE_INIT, STATE_CONNECTED }; |
| 309 FakeTransportChannel* dest_ = nullptr; | 315 FakeTransportChannel* dest_ = nullptr; |
| 310 State state_ = STATE_INIT; | 316 State state_ = STATE_INIT; |
| 311 bool async_ = false; | 317 bool async_ = false; |
| 318 int async_delay_ms_ = 0; |
| 312 Candidates remote_candidates_; | 319 Candidates remote_candidates_; |
| 313 rtc::scoped_refptr<rtc::RTCCertificate> local_cert_; | 320 rtc::scoped_refptr<rtc::RTCCertificate> local_cert_; |
| 314 rtc::FakeSSLCertificate* remote_cert_ = nullptr; | 321 rtc::FakeSSLCertificate* remote_cert_ = nullptr; |
| 315 bool do_dtls_ = false; | 322 bool do_dtls_ = false; |
| 316 std::vector<int> srtp_ciphers_; | 323 std::vector<int> srtp_ciphers_; |
| 317 int chosen_crypto_suite_ = rtc::SRTP_INVALID_CRYPTO_SUITE; | 324 int chosen_crypto_suite_ = rtc::SRTP_INVALID_CRYPTO_SUITE; |
| 318 IceConfig ice_config_; | 325 IceConfig ice_config_; |
| 319 IceRole role_ = ICEROLE_UNKNOWN; | 326 IceRole role_ = ICEROLE_UNKNOWN; |
| 320 uint64_t tiebreaker_ = 0; | 327 uint64_t tiebreaker_ = 0; |
| 321 std::string ice_ufrag_; | 328 std::string ice_ufrag_; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 345 FakeTransport(const std::string& name, PortAllocator* allocator) | 352 FakeTransport(const std::string& name, PortAllocator* allocator) |
| 346 : Transport(name, nullptr) {} | 353 : Transport(name, nullptr) {} |
| 347 | 354 |
| 348 ~FakeTransport() { DestroyAllChannels(); } | 355 ~FakeTransport() { DestroyAllChannels(); } |
| 349 | 356 |
| 350 const ChannelMap& channels() const { return channels_; } | 357 const ChannelMap& channels() const { return channels_; } |
| 351 | 358 |
| 352 // If async, will send packets by "Post"-ing to message queue instead of | 359 // If async, will send packets by "Post"-ing to message queue instead of |
| 353 // synchronously "Send"-ing. | 360 // synchronously "Send"-ing. |
| 354 void SetAsync(bool async) { async_ = async; } | 361 void SetAsync(bool async) { async_ = async; } |
| 362 void SetAsyncDelay(int delay_ms) { async_delay_ms_ = delay_ms; } |
| 355 | 363 |
| 356 // If |asymmetric| is true, only set the destination for this transport, and | 364 // If |asymmetric| is true, only set the destination for this transport, and |
| 357 // not |dest|. | 365 // not |dest|. |
| 358 void SetDestination(FakeTransport* dest, bool asymmetric = false) { | 366 void SetDestination(FakeTransport* dest, bool asymmetric = false) { |
| 359 dest_ = dest; | 367 dest_ = dest; |
| 360 for (const auto& kv : channels_) { | 368 for (const auto& kv : channels_) { |
| 361 kv.second->SetLocalCertificate(certificate_); | 369 kv.second->SetLocalCertificate(certificate_); |
| 362 SetChannelDestination(kv.first, kv.second, asymmetric); | 370 SetChannelDestination(kv.first, kv.second, asymmetric); |
| 363 } | 371 } |
| 364 } | 372 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 using Transport::NegotiateRole; | 414 using Transport::NegotiateRole; |
| 407 | 415 |
| 408 protected: | 416 protected: |
| 409 TransportChannelImpl* CreateTransportChannel(int component) override { | 417 TransportChannelImpl* CreateTransportChannel(int component) override { |
| 410 if (channels_.find(component) != channels_.end()) { | 418 if (channels_.find(component) != channels_.end()) { |
| 411 return nullptr; | 419 return nullptr; |
| 412 } | 420 } |
| 413 FakeTransportChannel* channel = new FakeTransportChannel(name(), component); | 421 FakeTransportChannel* channel = new FakeTransportChannel(name(), component); |
| 414 channel->set_ssl_max_protocol_version(ssl_max_version_); | 422 channel->set_ssl_max_protocol_version(ssl_max_version_); |
| 415 channel->SetAsync(async_); | 423 channel->SetAsync(async_); |
| 424 channel->SetAsyncDelay(async_delay_ms_); |
| 416 SetChannelDestination(component, channel, false); | 425 SetChannelDestination(component, channel, false); |
| 417 channels_[component] = channel; | 426 channels_[component] = channel; |
| 418 return channel; | 427 return channel; |
| 419 } | 428 } |
| 420 | 429 |
| 421 void DestroyTransportChannel(TransportChannelImpl* channel) override { | 430 void DestroyTransportChannel(TransportChannelImpl* channel) override { |
| 422 channels_.erase(channel->component()); | 431 channels_.erase(channel->component()); |
| 423 delete channel; | 432 delete channel; |
| 424 } | 433 } |
| 425 | 434 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 442 channel->SetDestination(dest_channel, asymmetric); | 451 channel->SetDestination(dest_channel, asymmetric); |
| 443 } | 452 } |
| 444 | 453 |
| 445 // Note, this is distinct from the Channel map owned by Transport. | 454 // Note, this is distinct from the Channel map owned by Transport. |
| 446 // This map just tracks the FakeTransportChannels created by this class. | 455 // This map just tracks the FakeTransportChannels created by this class. |
| 447 // It's mainly needed so that we can access a FakeTransportChannel directly, | 456 // It's mainly needed so that we can access a FakeTransportChannel directly, |
| 448 // even if wrapped by a DtlsTransportChannelWrapper. | 457 // even if wrapped by a DtlsTransportChannelWrapper. |
| 449 ChannelMap channels_; | 458 ChannelMap channels_; |
| 450 FakeTransport* dest_ = nullptr; | 459 FakeTransport* dest_ = nullptr; |
| 451 bool async_ = false; | 460 bool async_ = false; |
| 461 int async_delay_ms_ = 0; |
| 452 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; | 462 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; |
| 453 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; | 463 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; |
| 454 }; | 464 }; |
| 455 | 465 |
| 456 // Fake candidate pair class, which can be passed to BaseChannel for testing | 466 // Fake candidate pair class, which can be passed to BaseChannel for testing |
| 457 // purposes. | 467 // purposes. |
| 458 class FakeCandidatePair : public CandidatePairInterface { | 468 class FakeCandidatePair : public CandidatePairInterface { |
| 459 public: | 469 public: |
| 460 FakeCandidatePair(const Candidate& local_candidate, | 470 FakeCandidatePair(const Candidate& local_candidate, |
| 461 const Candidate& remote_candidate) | 471 const Candidate& remote_candidate) |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 } | 582 } |
| 573 } | 583 } |
| 574 | 584 |
| 575 private: | 585 private: |
| 576 bool fail_create_channel_; | 586 bool fail_create_channel_; |
| 577 }; | 587 }; |
| 578 | 588 |
| 579 } // namespace cricket | 589 } // namespace cricket |
| 580 | 590 |
| 581 #endif // WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ | 591 #endif // WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ |
| OLD | NEW |