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