OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 friend class Connection; | 405 friend class Connection; |
406 }; | 406 }; |
407 | 407 |
408 // Represents a communication link between a port on the local client and a | 408 // Represents a communication link between a port on the local client and a |
409 // port on the remote client. | 409 // port on the remote client. |
410 class Connection : public CandidatePairInterface, | 410 class Connection : public CandidatePairInterface, |
411 public rtc::MessageHandler, | 411 public rtc::MessageHandler, |
412 public sigslot::has_slots<> { | 412 public sigslot::has_slots<> { |
413 public: | 413 public: |
414 struct SentPing { | 414 struct SentPing { |
415 SentPing(const std::string id, int64_t sent_time) | 415 SentPing(const std::string id, int64_t sent_time, int nomination_value) |
416 : id(id), sent_time(sent_time) {} | 416 : id(id), sent_time(sent_time), nomination_value(nomination_value) {} |
417 | 417 |
418 std::string id; | 418 std::string id; |
419 int64_t sent_time; | 419 int64_t sent_time; |
| 420 int nomination_value; |
420 }; | 421 }; |
421 | 422 |
422 // States are from RFC 5245. http://tools.ietf.org/html/rfc5245#section-5.7.4 | 423 // States are from RFC 5245. http://tools.ietf.org/html/rfc5245#section-5.7.4 |
423 enum State { | 424 enum State { |
424 STATE_WAITING = 0, // Check has not been performed, Waiting pair on CL. | 425 STATE_WAITING = 0, // Check has not been performed, Waiting pair on CL. |
425 STATE_INPROGRESS, // Check has been sent, transaction is in progress. | 426 STATE_INPROGRESS, // Check has been sent, transaction is in progress. |
426 STATE_SUCCEEDED, // Check already done, produced a successful result. | 427 STATE_SUCCEEDED, // Check already done, produced a successful result. |
427 STATE_FAILED // Check for this connection failed. | 428 STATE_FAILED // Check for this connection failed. |
428 }; | 429 }; |
429 | 430 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 // Called when a connection is determined to be no longer useful to us. We | 500 // Called when a connection is determined to be no longer useful to us. We |
500 // still keep it around in case the other side wants to use it. But we can | 501 // still keep it around in case the other side wants to use it. But we can |
501 // safely stop pinging on it and we can allow it to time out if the other | 502 // safely stop pinging on it and we can allow it to time out if the other |
502 // side stops using it as well. | 503 // side stops using it as well. |
503 bool pruned() const { return pruned_; } | 504 bool pruned() const { return pruned_; } |
504 void Prune(); | 505 void Prune(); |
505 | 506 |
506 bool use_candidate_attr() const { return use_candidate_attr_; } | 507 bool use_candidate_attr() const { return use_candidate_attr_; } |
507 void set_use_candidate_attr(bool enable); | 508 void set_use_candidate_attr(bool enable); |
508 | 509 |
509 bool nominated() const { return nominated_; } | 510 int nominating_value() const { return nominating_value_; } |
510 void set_nominated(bool nominated) { nominated_ = nominated; } | 511 void set_nominating_value(int value) { |
| 512 if (value > nominating_value_) { |
| 513 nomination_acknowledged_ = false; |
| 514 } |
| 515 // A connection may be the selected one earlier, but be switched later, |
| 516 // so its |nominating_value_| may go to 0. |
| 517 nominating_value_ = value; |
| 518 } |
| 519 bool nomination_acknowledged() const { return nomination_acknowledged_; } |
| 520 |
| 521 int nominated_value() const { return nominated_value_; } |
| 522 void set_nominated_value(int nominated_value) { |
| 523 // We don't un-nominate a connection, so we will keep the maximum |
| 524 // nominated value. |
| 525 if (nominated_value > nominated_value_) { |
| 526 nominated_value_ = nominated_value; |
| 527 } |
| 528 } |
511 | 529 |
512 void set_remote_ice_mode(IceMode mode) { | 530 void set_remote_ice_mode(IceMode mode) { |
513 remote_ice_mode_ = mode; | 531 remote_ice_mode_ = mode; |
514 } | 532 } |
515 | 533 |
516 void set_receiving_timeout(int64_t receiving_timeout_ms) { | 534 void set_receiving_timeout(int64_t receiving_timeout_ms) { |
517 receiving_timeout_ = receiving_timeout_ms; | 535 receiving_timeout_ = receiving_timeout_ms; |
518 } | 536 } |
519 | 537 |
520 // Makes the connection go away. | 538 // Makes the connection go away. |
521 void Destroy(); | 539 void Destroy(); |
522 | 540 |
523 // Makes the connection go away, in a failed state. | 541 // Makes the connection go away, in a failed state. |
524 void FailAndDestroy(); | 542 void FailAndDestroy(); |
525 | 543 |
526 // Prunes the connection and sets its state to STATE_FAILED, | 544 // Prunes the connection and sets its state to STATE_FAILED, |
527 // It will not be used or send pings although it can still receive packets. | 545 // It will not be used or send pings although it can still receive packets. |
528 void FailAndPrune(); | 546 void FailAndPrune(); |
529 | 547 |
530 // Checks that the state of this connection is up-to-date. The argument is | 548 // Checks that the state of this connection is up-to-date. The argument is |
531 // the current time, which is compared against various timeouts. | 549 // the current time, which is compared against various timeouts. |
532 void UpdateState(int64_t now); | 550 void UpdateState(int64_t now); |
533 | 551 |
534 // Called when this connection should try checking writability again. | 552 // Called when this connection should try checking writability again. |
535 int64_t last_ping_sent() const { return last_ping_sent_; } | 553 int64_t last_ping_sent() const { return last_ping_sent_; } |
536 void Ping(int64_t now); | 554 void Ping(int64_t now); |
537 void ReceivedPingResponse(int rtt); | 555 void ReceivedPingResponse(int rtt, const std::string& request_id); |
538 int64_t last_ping_response_received() const { | 556 int64_t last_ping_response_received() const { |
539 return last_ping_response_received_; | 557 return last_ping_response_received_; |
540 } | 558 } |
541 | 559 |
542 // Called whenever a valid ping is received on this connection. This is | 560 // Called whenever a valid ping is received on this connection. This is |
543 // public because the connection intercepts the first ping for us. | 561 // public because the connection intercepts the first ping for us. |
544 int64_t last_ping_received() const { return last_ping_received_; } | 562 int64_t last_ping_received() const { return last_ping_received_; } |
545 void ReceivedPing(); | 563 void ReceivedPing(); |
546 // Handles the binding request; sends a response if this is a valid request. | 564 // Handles the binding request; sends a response if this is a valid request. |
547 void HandleBindingRequest(IceMessage* msg); | 565 void HandleBindingRequest(IceMessage* msg); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 Candidate remote_candidate_; | 651 Candidate remote_candidate_; |
634 WriteState write_state_; | 652 WriteState write_state_; |
635 bool receiving_; | 653 bool receiving_; |
636 bool connected_; | 654 bool connected_; |
637 bool pruned_; | 655 bool pruned_; |
638 // By default |use_candidate_attr_| flag will be true, | 656 // By default |use_candidate_attr_| flag will be true, |
639 // as we will be using aggressive nomination. | 657 // as we will be using aggressive nomination. |
640 // But when peer is ice-lite, this flag "must" be initialized to false and | 658 // But when peer is ice-lite, this flag "must" be initialized to false and |
641 // turn on when connection becomes "best connection". | 659 // turn on when connection becomes "best connection". |
642 bool use_candidate_attr_; | 660 bool use_candidate_attr_; |
643 // Whether this connection has been nominated by the controlling side via | 661 // Used by the controlling side to indicate that this connection will be |
644 // the use_candidate attribute. | 662 // selected for transmission if the peer supports ICE-renomination if this |
645 bool nominated_; | 663 // value is positive. A larger-value indicates that a connection is nominated |
| 664 // later and should be selected by the controlled side with higher precedence. |
| 665 // It should start from zero to indicate not nominating this connection yet. |
| 666 int nominating_value_ = 0; |
| 667 // Whether the current nominating_value has been acknowledged by the peer. |
| 668 // If yes, no nomination-value attribute is needed in the ping request on the |
| 669 // same connection. |
| 670 bool nomination_acknowledged_; |
| 671 // Used by the controlled side to remember the nomination value received from |
| 672 // the controlling side. When the peer does not support ICE re-nomination, |
| 673 // its value will be 1 if the connection is nominated. |
| 674 int nominated_value_ = 0; |
| 675 |
646 IceMode remote_ice_mode_; | 676 IceMode remote_ice_mode_; |
647 StunRequestManager requests_; | 677 StunRequestManager requests_; |
648 int rtt_; | 678 int rtt_; |
649 int rtt_samples_ = 0; | 679 int rtt_samples_ = 0; |
650 int64_t last_ping_sent_; // last time we sent a ping to the other side | 680 int64_t last_ping_sent_; // last time we sent a ping to the other side |
651 int64_t last_ping_received_; // last time we received a ping from the other | 681 int64_t last_ping_received_; // last time we received a ping from the other |
652 // side | 682 // side |
653 int64_t last_data_received_; | 683 int64_t last_data_received_; |
654 int64_t last_ping_response_received_; | 684 int64_t last_ping_response_received_; |
655 int64_t receiving_unchanged_since_ = 0; | 685 int64_t receiving_unchanged_since_ = 0; |
(...skipping 29 matching lines...) Expand all Loading... |
685 const rtc::PacketOptions& options) override; | 715 const rtc::PacketOptions& options) override; |
686 int GetError() override { return error_; } | 716 int GetError() override { return error_; } |
687 | 717 |
688 private: | 718 private: |
689 int error_ = 0; | 719 int error_ = 0; |
690 }; | 720 }; |
691 | 721 |
692 } // namespace cricket | 722 } // namespace cricket |
693 | 723 |
694 #endif // WEBRTC_P2P_BASE_PORT_H_ | 724 #endif // WEBRTC_P2P_BASE_PORT_H_ |
OLD | NEW |