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