| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 if (dest_) { | 134 if (dest_) { |
| 135 dest_->state_ = STATE_INIT; | 135 dest_->state_ = STATE_INIT; |
| 136 dest_->dest_ = nullptr; | 136 dest_->dest_ = nullptr; |
| 137 dest_ = nullptr; | 137 dest_ = nullptr; |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 void SetWritable(bool writable) { set_writable(writable); } | 142 void SetWritable(bool writable) { set_writable(writable); } |
| 143 | 143 |
| 144 void SetDestination(FakeTransportChannel* dest) { | 144 // Simulates the two transport channels connecting to each other. |
| 145 // If |asymmetric| is true this method only affects this FakeTransportChannel. |
| 146 // If false, it affects |dest| as well. |
| 147 void SetDestination(FakeTransportChannel* dest, bool asymmetric = false) { |
| 145 if (state_ == STATE_CONNECTING && dest) { | 148 if (state_ == STATE_CONNECTING && dest) { |
| 146 // This simulates the delivery of candidates. | 149 // This simulates the delivery of candidates. |
| 147 dest_ = dest; | 150 dest_ = dest; |
| 148 dest_->dest_ = this; | |
| 149 if (local_cert_ && dest_->local_cert_) { | 151 if (local_cert_ && dest_->local_cert_) { |
| 150 do_dtls_ = true; | 152 do_dtls_ = true; |
| 151 dest_->do_dtls_ = true; | |
| 152 NegotiateSrtpCiphers(); | 153 NegotiateSrtpCiphers(); |
| 153 } | 154 } |
| 154 state_ = STATE_CONNECTED; | 155 state_ = STATE_CONNECTED; |
| 155 dest_->state_ = STATE_CONNECTED; | |
| 156 set_writable(true); | 156 set_writable(true); |
| 157 dest_->set_writable(true); | 157 if (!asymmetric) { |
| 158 dest->SetDestination(this, true); |
| 159 } |
| 158 } else if (state_ == STATE_CONNECTED && !dest) { | 160 } else if (state_ == STATE_CONNECTED && !dest) { |
| 159 // Simulates loss of connectivity, by asymmetrically forgetting dest_. | 161 // Simulates loss of connectivity, by asymmetrically forgetting dest_. |
| 160 dest_ = nullptr; | 162 dest_ = nullptr; |
| 161 state_ = STATE_CONNECTING; | 163 state_ = STATE_CONNECTING; |
| 162 set_writable(false); | 164 set_writable(false); |
| 163 } | 165 } |
| 164 } | 166 } |
| 165 | 167 |
| 166 void SetConnectionCount(size_t connection_count) { | 168 void SetConnectionCount(size_t connection_count) { |
| 167 size_t old_connection_count = connection_count_; | 169 size_t old_connection_count = connection_count_; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 uint8_t* result, | 277 uint8_t* result, |
| 276 size_t result_len) override { | 278 size_t result_len) override { |
| 277 if (chosen_crypto_suite_ != rtc::SRTP_INVALID_CRYPTO_SUITE) { | 279 if (chosen_crypto_suite_ != rtc::SRTP_INVALID_CRYPTO_SUITE) { |
| 278 memset(result, 0xff, result_len); | 280 memset(result, 0xff, result_len); |
| 279 return true; | 281 return true; |
| 280 } | 282 } |
| 281 | 283 |
| 282 return false; | 284 return false; |
| 283 } | 285 } |
| 284 | 286 |
| 285 void NegotiateSrtpCiphers() { | |
| 286 for (std::vector<int>::const_iterator it1 = srtp_ciphers_.begin(); | |
| 287 it1 != srtp_ciphers_.end(); ++it1) { | |
| 288 for (std::vector<int>::const_iterator it2 = dest_->srtp_ciphers_.begin(); | |
| 289 it2 != dest_->srtp_ciphers_.end(); ++it2) { | |
| 290 if (*it1 == *it2) { | |
| 291 chosen_crypto_suite_ = *it1; | |
| 292 dest_->chosen_crypto_suite_ = *it2; | |
| 293 return; | |
| 294 } | |
| 295 } | |
| 296 } | |
| 297 } | |
| 298 | |
| 299 bool GetStats(ConnectionInfos* infos) override { | 287 bool GetStats(ConnectionInfos* infos) override { |
| 300 ConnectionInfo info; | 288 ConnectionInfo info; |
| 301 infos->clear(); | 289 infos->clear(); |
| 302 infos->push_back(info); | 290 infos->push_back(info); |
| 303 return true; | 291 return true; |
| 304 } | 292 } |
| 305 | 293 |
| 306 void set_ssl_max_protocol_version(rtc::SSLProtocolVersion version) { | 294 void set_ssl_max_protocol_version(rtc::SSLProtocolVersion version) { |
| 307 ssl_max_version_ = version; | 295 ssl_max_version_ = version; |
| 308 } | 296 } |
| 309 rtc::SSLProtocolVersion ssl_max_protocol_version() const { | 297 rtc::SSLProtocolVersion ssl_max_protocol_version() const { |
| 310 return ssl_max_version_; | 298 return ssl_max_version_; |
| 311 } | 299 } |
| 312 | 300 |
| 313 private: | 301 private: |
| 302 void NegotiateSrtpCiphers() { |
| 303 for (std::vector<int>::const_iterator it1 = srtp_ciphers_.begin(); |
| 304 it1 != srtp_ciphers_.end(); ++it1) { |
| 305 for (std::vector<int>::const_iterator it2 = dest_->srtp_ciphers_.begin(); |
| 306 it2 != dest_->srtp_ciphers_.end(); ++it2) { |
| 307 if (*it1 == *it2) { |
| 308 chosen_crypto_suite_ = *it1; |
| 309 return; |
| 310 } |
| 311 } |
| 312 } |
| 313 } |
| 314 |
| 314 enum State { STATE_INIT, STATE_CONNECTING, STATE_CONNECTED }; | 315 enum State { STATE_INIT, STATE_CONNECTING, STATE_CONNECTED }; |
| 315 FakeTransportChannel* dest_ = nullptr; | 316 FakeTransportChannel* dest_ = nullptr; |
| 316 State state_ = STATE_INIT; | 317 State state_ = STATE_INIT; |
| 317 bool async_ = false; | 318 bool async_ = false; |
| 318 Candidates remote_candidates_; | 319 Candidates remote_candidates_; |
| 319 rtc::scoped_refptr<rtc::RTCCertificate> local_cert_; | 320 rtc::scoped_refptr<rtc::RTCCertificate> local_cert_; |
| 320 rtc::FakeSSLCertificate* remote_cert_ = nullptr; | 321 rtc::FakeSSLCertificate* remote_cert_ = nullptr; |
| 321 bool do_dtls_ = false; | 322 bool do_dtls_ = false; |
| 322 std::vector<int> srtp_ciphers_; | 323 std::vector<int> srtp_ciphers_; |
| 323 int chosen_crypto_suite_ = rtc::SRTP_INVALID_CRYPTO_SUITE; | 324 int chosen_crypto_suite_ = rtc::SRTP_INVALID_CRYPTO_SUITE; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 352 FakeTransport(const std::string& name, PortAllocator* allocator) | 353 FakeTransport(const std::string& name, PortAllocator* allocator) |
| 353 : Transport(name, nullptr) {} | 354 : Transport(name, nullptr) {} |
| 354 | 355 |
| 355 ~FakeTransport() { DestroyAllChannels(); } | 356 ~FakeTransport() { DestroyAllChannels(); } |
| 356 | 357 |
| 357 const ChannelMap& channels() const { return channels_; } | 358 const ChannelMap& channels() const { return channels_; } |
| 358 | 359 |
| 359 // If async, will send packets by "Post"-ing to message queue instead of | 360 // If async, will send packets by "Post"-ing to message queue instead of |
| 360 // synchronously "Send"-ing. | 361 // synchronously "Send"-ing. |
| 361 void SetAsync(bool async) { async_ = async; } | 362 void SetAsync(bool async) { async_ = async; } |
| 362 void SetDestination(FakeTransport* dest) { | 363 |
| 364 // If |asymmetric| is true, only set the destination for this transport, and |
| 365 // not |dest|. |
| 366 void SetDestination(FakeTransport* dest, bool asymmetric = false) { |
| 363 dest_ = dest; | 367 dest_ = dest; |
| 364 for (const auto& kv : channels_) { | 368 for (const auto& kv : channels_) { |
| 365 kv.second->SetLocalCertificate(certificate_); | 369 kv.second->SetLocalCertificate(certificate_); |
| 366 SetChannelDestination(kv.first, kv.second); | 370 SetChannelDestination(kv.first, kv.second, asymmetric); |
| 367 } | 371 } |
| 368 } | 372 } |
| 369 | 373 |
| 370 void SetWritable(bool writable) { | 374 void SetWritable(bool writable) { |
| 371 for (const auto& kv : channels_) { | 375 for (const auto& kv : channels_) { |
| 372 kv.second->SetWritable(writable); | 376 kv.second->SetWritable(writable); |
| 373 } | 377 } |
| 374 } | 378 } |
| 375 | 379 |
| 376 void SetLocalCertificate( | 380 void SetLocalCertificate( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 using Transport::remote_description; | 412 using Transport::remote_description; |
| 409 | 413 |
| 410 protected: | 414 protected: |
| 411 TransportChannelImpl* CreateTransportChannel(int component) override { | 415 TransportChannelImpl* CreateTransportChannel(int component) override { |
| 412 if (channels_.find(component) != channels_.end()) { | 416 if (channels_.find(component) != channels_.end()) { |
| 413 return nullptr; | 417 return nullptr; |
| 414 } | 418 } |
| 415 FakeTransportChannel* channel = new FakeTransportChannel(name(), component); | 419 FakeTransportChannel* channel = new FakeTransportChannel(name(), component); |
| 416 channel->set_ssl_max_protocol_version(ssl_max_version_); | 420 channel->set_ssl_max_protocol_version(ssl_max_version_); |
| 417 channel->SetAsync(async_); | 421 channel->SetAsync(async_); |
| 418 SetChannelDestination(component, channel); | 422 SetChannelDestination(component, channel, false); |
| 419 channels_[component] = channel; | 423 channels_[component] = channel; |
| 420 return channel; | 424 return channel; |
| 421 } | 425 } |
| 422 | 426 |
| 423 void DestroyTransportChannel(TransportChannelImpl* channel) override { | 427 void DestroyTransportChannel(TransportChannelImpl* channel) override { |
| 424 channels_.erase(channel->component()); | 428 channels_.erase(channel->component()); |
| 425 delete channel; | 429 delete channel; |
| 426 } | 430 } |
| 427 | 431 |
| 428 private: | 432 private: |
| 429 FakeTransportChannel* GetFakeChannel(int component) { | 433 FakeTransportChannel* GetFakeChannel(int component) { |
| 430 auto it = channels_.find(component); | 434 auto it = channels_.find(component); |
| 431 return (it != channels_.end()) ? it->second : nullptr; | 435 return (it != channels_.end()) ? it->second : nullptr; |
| 432 } | 436 } |
| 433 | 437 |
| 434 void SetChannelDestination(int component, FakeTransportChannel* channel) { | 438 void SetChannelDestination(int component, |
| 439 FakeTransportChannel* channel, |
| 440 bool asymmetric) { |
| 435 FakeTransportChannel* dest_channel = nullptr; | 441 FakeTransportChannel* dest_channel = nullptr; |
| 436 if (dest_) { | 442 if (dest_) { |
| 437 dest_channel = dest_->GetFakeChannel(component); | 443 dest_channel = dest_->GetFakeChannel(component); |
| 438 if (dest_channel) { | 444 if (dest_channel && !asymmetric) { |
| 439 dest_channel->SetLocalCertificate(dest_->certificate_); | 445 dest_channel->SetLocalCertificate(dest_->certificate_); |
| 440 } | 446 } |
| 441 } | 447 } |
| 442 channel->SetDestination(dest_channel); | 448 channel->SetDestination(dest_channel, asymmetric); |
| 443 } | 449 } |
| 444 | 450 |
| 445 // Note, this is distinct from the Channel map owned by Transport. | 451 // Note, this is distinct from the Channel map owned by Transport. |
| 446 // This map just tracks the FakeTransportChannels created by this class. | 452 // This map just tracks the FakeTransportChannels created by this class. |
| 447 // It's mainly needed so that we can access a FakeTransportChannel directly, | 453 // It's mainly needed so that we can access a FakeTransportChannel directly, |
| 448 // even if wrapped by a DtlsTransportChannelWrapper. | 454 // even if wrapped by a DtlsTransportChannelWrapper. |
| 449 ChannelMap channels_; | 455 ChannelMap channels_; |
| 450 FakeTransport* dest_ = nullptr; | 456 FakeTransport* dest_ = nullptr; |
| 451 bool async_ = false; | 457 bool async_ = false; |
| 452 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; | 458 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 } | 578 } |
| 573 } | 579 } |
| 574 | 580 |
| 575 private: | 581 private: |
| 576 bool fail_create_channel_; | 582 bool fail_create_channel_; |
| 577 }; | 583 }; |
| 578 | 584 |
| 579 } // namespace cricket | 585 } // namespace cricket |
| 580 | 586 |
| 581 #endif // WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ | 587 #endif // WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ |
| OLD | NEW |