Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(471)

Side by Side Diff: webrtc/p2p/base/port.h

Issue 2163403002: Prepare for ICE-renomination (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 friend class Connection; 410 friend class Connection;
411 }; 411 };
412 412
413 // Represents a communication link between a port on the local client and a 413 // Represents a communication link between a port on the local client and a
414 // port on the remote client. 414 // port on the remote client.
415 class Connection : public CandidatePairInterface, 415 class Connection : public CandidatePairInterface,
416 public rtc::MessageHandler, 416 public rtc::MessageHandler,
417 public sigslot::has_slots<> { 417 public sigslot::has_slots<> {
418 public: 418 public:
419 struct SentPing { 419 struct SentPing {
420 SentPing(const std::string id, int64_t sent_time) 420 SentPing(const std::string id, int64_t sent_time, int nomination)
421 : id(id), sent_time(sent_time) {} 421 : id(id), sent_time(sent_time), nomination(nomination) {}
422 422
423 std::string id; 423 std::string id;
424 int64_t sent_time; 424 int64_t sent_time;
425 int nomination;
425 }; 426 };
426 427
427 // States are from RFC 5245. http://tools.ietf.org/html/rfc5245#section-5.7.4 428 // States are from RFC 5245. http://tools.ietf.org/html/rfc5245#section-5.7.4
428 enum State { 429 enum State {
429 STATE_WAITING = 0, // Check has not been performed, Waiting pair on CL. 430 STATE_WAITING = 0, // Check has not been performed, Waiting pair on CL.
430 STATE_INPROGRESS, // Check has been sent, transaction is in progress. 431 STATE_INPROGRESS, // Check has been sent, transaction is in progress.
431 STATE_SUCCEEDED, // Check already done, produced a successful result. 432 STATE_SUCCEEDED, // Check already done, produced a successful result.
432 STATE_FAILED // Check for this connection failed. 433 STATE_FAILED // Check for this connection failed.
433 }; 434 };
434 435
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 // Called when a connection is determined to be no longer useful to us. We 505 // Called when a connection is determined to be no longer useful to us. We
505 // still keep it around in case the other side wants to use it. But we can 506 // still keep it around in case the other side wants to use it. But we can
506 // safely stop pinging on it and we can allow it to time out if the other 507 // safely stop pinging on it and we can allow it to time out if the other
507 // side stops using it as well. 508 // side stops using it as well.
508 bool pruned() const { return pruned_; } 509 bool pruned() const { return pruned_; }
509 void Prune(); 510 void Prune();
510 511
511 bool use_candidate_attr() const { return use_candidate_attr_; } 512 bool use_candidate_attr() const { return use_candidate_attr_; }
512 void set_use_candidate_attr(bool enable); 513 void set_use_candidate_attr(bool enable);
513 514
514 bool nominated() const { return nominated_; } 515 void set_nomination(int value) { nomination_ = value; }
515 void set_nominated(bool nominated) { nominated_ = nominated; } 516
517 int remote_nomination() const { return remote_nomination_; }
518 bool nominated() const { return remote_nomination_ > 0; }
519 // Public for unit tests.
520 void set_remote_nomination(int remote_nomination) {
521 // We don't un-nominate a connection, so we will keep the maximum
522 // nominated value.
523 if (remote_nomination > remote_nomination_) {
524 remote_nomination_ = remote_nomination;
525 }
526 }
527 // Public for unit tests.
528 int acked_nomination() const { return acked_nomination_; }
516 529
517 void set_remote_ice_mode(IceMode mode) { 530 void set_remote_ice_mode(IceMode mode) {
518 remote_ice_mode_ = mode; 531 remote_ice_mode_ = mode;
519 } 532 }
520 533
521 void set_receiving_timeout(int64_t receiving_timeout_ms) { 534 void set_receiving_timeout(int64_t receiving_timeout_ms) {
522 receiving_timeout_ = receiving_timeout_ms; 535 receiving_timeout_ = receiving_timeout_ms;
523 } 536 }
524 537
525 // Makes the connection go away. 538 // Makes the connection go away.
526 void Destroy(); 539 void Destroy();
527 540
528 // Makes the connection go away, in a failed state. 541 // Makes the connection go away, in a failed state.
529 void FailAndDestroy(); 542 void FailAndDestroy();
530 543
531 // Prunes the connection and sets its state to STATE_FAILED, 544 // Prunes the connection and sets its state to STATE_FAILED,
532 // 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.
533 void FailAndPrune(); 546 void FailAndPrune();
534 547
535 // 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
536 // the current time, which is compared against various timeouts. 549 // the current time, which is compared against various timeouts.
537 void UpdateState(int64_t now); 550 void UpdateState(int64_t now);
538 551
539 // Called when this connection should try checking writability again. 552 // Called when this connection should try checking writability again.
540 int64_t last_ping_sent() const { return last_ping_sent_; } 553 int64_t last_ping_sent() const { return last_ping_sent_; }
541 void Ping(int64_t now); 554 void Ping(int64_t now);
542 void ReceivedPingResponse(int rtt); 555 void ReceivedPingResponse(int rtt, const std::string& request_id);
543 int64_t last_ping_response_received() const { 556 int64_t last_ping_response_received() const {
544 return last_ping_response_received_; 557 return last_ping_response_received_;
545 } 558 }
546 559
547 // 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
548 // public because the connection intercepts the first ping for us. 561 // public because the connection intercepts the first ping for us.
549 int64_t last_ping_received() const { return last_ping_received_; } 562 int64_t last_ping_received() const { return last_ping_received_; }
550 void ReceivedPing(); 563 void ReceivedPing();
551 // 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.
552 void HandleBindingRequest(IceMessage* msg); 565 void HandleBindingRequest(IceMessage* msg);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 // If the response is not received within 2 * RTT, the response is assumed to 637 // If the response is not received within 2 * RTT, the response is assumed to
625 // be missing. 638 // be missing.
626 bool missing_responses(int64_t now) const; 639 bool missing_responses(int64_t now) const;
627 640
628 // Changes the state and signals if necessary. 641 // Changes the state and signals if necessary.
629 void set_write_state(WriteState value); 642 void set_write_state(WriteState value);
630 void UpdateReceiving(int64_t now); 643 void UpdateReceiving(int64_t now);
631 void set_state(State state); 644 void set_state(State state);
632 void set_connected(bool value); 645 void set_connected(bool value);
633 646
647 int nomination() const { return nomination_; }
648
634 void OnMessage(rtc::Message *pmsg); 649 void OnMessage(rtc::Message *pmsg);
635 650
636 Port* port_; 651 Port* port_;
637 size_t local_candidate_index_; 652 size_t local_candidate_index_;
638 Candidate remote_candidate_; 653 Candidate remote_candidate_;
654
655 ConnectionInfo stats_;
656 rtc::RateTracker recv_rate_tracker_;
657 rtc::RateTracker send_rate_tracker_;
658
659 private:
639 WriteState write_state_; 660 WriteState write_state_;
640 bool receiving_; 661 bool receiving_;
641 bool connected_; 662 bool connected_;
642 bool pruned_; 663 bool pruned_;
643 // By default |use_candidate_attr_| flag will be true, 664 // By default |use_candidate_attr_| flag will be true,
644 // as we will be using aggressive nomination. 665 // as we will be using aggressive nomination.
645 // But when peer is ice-lite, this flag "must" be initialized to false and 666 // But when peer is ice-lite, this flag "must" be initialized to false and
646 // turn on when connection becomes "best connection". 667 // turn on when connection becomes "best connection".
647 bool use_candidate_attr_; 668 bool use_candidate_attr_;
648 // Whether this connection has been nominated by the controlling side via 669 // Used by the controlling side to indicate that this connection will be
649 // the use_candidate attribute. 670 // selected for transmission if the peer supports ICE-renomination when this
650 bool nominated_; 671 // value is positive. A larger-value indicates that a connection is nominated
672 // later and should be selected by the controlled side with higher precedence.
673 // A zero-value indicates not nominating this connection.
674 int nomination_ = 0;
675 // The last nominating value that has been acknowledged.
676 int acked_nomination_ = 0;
677 // Used by the controlled side to remember the nomination value received from
678 // the controlling side. When the peer does not support ICE re-nomination,
679 // its value will be 1 if the connection has been nominated.
680 int remote_nomination_ = 0;
681
651 IceMode remote_ice_mode_; 682 IceMode remote_ice_mode_;
652 StunRequestManager requests_; 683 StunRequestManager requests_;
653 int rtt_; 684 int rtt_;
654 int rtt_samples_ = 0; 685 int rtt_samples_ = 0;
655 int64_t last_ping_sent_; // last time we sent a ping to the other side 686 int64_t last_ping_sent_; // last time we sent a ping to the other side
656 int64_t last_ping_received_; // last time we received a ping from the other 687 int64_t last_ping_received_; // last time we received a ping from the other
657 // side 688 // side
658 int64_t last_data_received_; 689 int64_t last_data_received_;
659 int64_t last_ping_response_received_; 690 int64_t last_ping_response_received_;
660 int64_t receiving_unchanged_since_ = 0; 691 int64_t receiving_unchanged_since_ = 0;
661 std::vector<SentPing> pings_since_last_response_; 692 std::vector<SentPing> pings_since_last_response_;
662 693
663 rtc::RateTracker recv_rate_tracker_;
664 rtc::RateTracker send_rate_tracker_;
665
666 ConnectionInfo stats_;
667
668 private:
669 void MaybeAddPrflxCandidate(ConnectionRequest* request, 694 void MaybeAddPrflxCandidate(ConnectionRequest* request,
670 StunMessage* response); 695 StunMessage* response);
671 696
672 bool reported_; 697 bool reported_;
673 State state_; 698 State state_;
674 // Time duration to switch from receiving to not receiving. 699 // Time duration to switch from receiving to not receiving.
675 int receiving_timeout_; 700 int receiving_timeout_;
676 int64_t time_created_ms_; 701 int64_t time_created_ms_;
677 int num_pings_sent_ = 0; 702 int num_pings_sent_ = 0;
678 703
(...skipping 11 matching lines...) Expand all
690 const rtc::PacketOptions& options) override; 715 const rtc::PacketOptions& options) override;
691 int GetError() override { return error_; } 716 int GetError() override { return error_; }
692 717
693 private: 718 private:
694 int error_ = 0; 719 int error_ = 0;
695 }; 720 };
696 721
697 } // namespace cricket 722 } // namespace cricket
698 723
699 #endif // WEBRTC_P2P_BASE_PORT_H_ 724 #endif // WEBRTC_P2P_BASE_PORT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698