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