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

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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
pthatcher1 2016/07/28 22:57:26 I'd call this "nomination".
honghaiz3 2016/08/03 04:46:56 Done.
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
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) { nominating_value_ = value; }
512
513 int nominated_value() const { return nominated_value_; }
514 // Public for unit tests.
515 void set_nominated_value(int nominated_value) {
516 // We don't un-nominate a connection, so we will keep the maximum
517 // nominated value.
518 if (nominated_value > nominated_value_) {
519 nominated_value_ = nominated_value;
520 }
pthatcher1 2016/07/28 22:57:26 I think we should go from including the attribute
honghaiz3 2016/08/03 04:46:56 The check protects packet re-ordering. If for som
pthatcher1 2016/08/03 22:13:25 Ah, good point about reordering. Do we have a uni
honghaiz3 2016/08/03 23:39:51 Done. Add a test for ignoring smaller nomination.
521 }
511 522
512 void set_remote_ice_mode(IceMode mode) { 523 void set_remote_ice_mode(IceMode mode) {
513 remote_ice_mode_ = mode; 524 remote_ice_mode_ = mode;
514 } 525 }
515 526
516 void set_receiving_timeout(int64_t receiving_timeout_ms) { 527 void set_receiving_timeout(int64_t receiving_timeout_ms) {
517 receiving_timeout_ = receiving_timeout_ms; 528 receiving_timeout_ = receiving_timeout_ms;
518 } 529 }
519 530
520 // Makes the connection go away. 531 // Makes the connection go away.
521 void Destroy(); 532 void Destroy();
522 533
523 // Makes the connection go away, in a failed state. 534 // Makes the connection go away, in a failed state.
524 void FailAndDestroy(); 535 void FailAndDestroy();
525 536
526 // Prunes the connection and sets its state to STATE_FAILED, 537 // 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. 538 // It will not be used or send pings although it can still receive packets.
528 void FailAndPrune(); 539 void FailAndPrune();
529 540
530 // Checks that the state of this connection is up-to-date. The argument is 541 // Checks that the state of this connection is up-to-date. The argument is
531 // the current time, which is compared against various timeouts. 542 // the current time, which is compared against various timeouts.
532 void UpdateState(int64_t now); 543 void UpdateState(int64_t now);
533 544
534 // Called when this connection should try checking writability again. 545 // Called when this connection should try checking writability again.
535 int64_t last_ping_sent() const { return last_ping_sent_; } 546 int64_t last_ping_sent() const { return last_ping_sent_; }
536 void Ping(int64_t now); 547 void Ping(int64_t now);
537 void ReceivedPingResponse(int rtt); 548 void ReceivedPingResponse(int rtt, const std::string& request_id);
538 int64_t last_ping_response_received() const { 549 int64_t last_ping_response_received() const {
539 return last_ping_response_received_; 550 return last_ping_response_received_;
540 } 551 }
541 552
542 // Called whenever a valid ping is received on this connection. This is 553 // Called whenever a valid ping is received on this connection. This is
543 // public because the connection intercepts the first ping for us. 554 // public because the connection intercepts the first ping for us.
544 int64_t last_ping_received() const { return last_ping_received_; } 555 int64_t last_ping_received() const { return last_ping_received_; }
545 void ReceivedPing(); 556 void ReceivedPing();
546 // Handles the binding request; sends a response if this is a valid request. 557 // Handles the binding request; sends a response if this is a valid request.
547 void HandleBindingRequest(IceMessage* msg); 558 void HandleBindingRequest(IceMessage* msg);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 // If the response is not received within 2 * RTT, the response is assumed to 630 // If the response is not received within 2 * RTT, the response is assumed to
620 // be missing. 631 // be missing.
621 bool missing_responses(int64_t now) const; 632 bool missing_responses(int64_t now) const;
622 633
623 // Changes the state and signals if necessary. 634 // Changes the state and signals if necessary.
624 void set_write_state(WriteState value); 635 void set_write_state(WriteState value);
625 void UpdateReceiving(int64_t now); 636 void UpdateReceiving(int64_t now);
626 void set_state(State state); 637 void set_state(State state);
627 void set_connected(bool value); 638 void set_connected(bool value);
628 639
640 int acknowledged_nominating_value() const {
641 return acknowledged_nominating_value_;
pthatcher1 2016/07/28 22:57:26 acked_nomination would be a better name.
honghaiz3 2016/08/03 04:46:56 Done.
642 }
643
629 void OnMessage(rtc::Message *pmsg); 644 void OnMessage(rtc::Message *pmsg);
630 645
631 Port* port_; 646 Port* port_;
632 size_t local_candidate_index_; 647 size_t local_candidate_index_;
633 Candidate remote_candidate_; 648 Candidate remote_candidate_;
649
650 ConnectionInfo stats_;
651 rtc::RateTracker recv_rate_tracker_;
652 rtc::RateTracker send_rate_tracker_;
653
654 private:
634 WriteState write_state_; 655 WriteState write_state_;
635 bool receiving_; 656 bool receiving_;
636 bool connected_; 657 bool connected_;
637 bool pruned_; 658 bool pruned_;
638 // By default |use_candidate_attr_| flag will be true, 659 // By default |use_candidate_attr_| flag will be true,
639 // as we will be using aggressive nomination. 660 // as we will be using aggressive nomination.
640 // But when peer is ice-lite, this flag "must" be initialized to false and 661 // But when peer is ice-lite, this flag "must" be initialized to false and
641 // turn on when connection becomes "best connection". 662 // turn on when connection becomes "best connection".
642 bool use_candidate_attr_; 663 bool use_candidate_attr_;
643 // Whether this connection has been nominated by the controlling side via 664 // Used by the controlling side to indicate that this connection will be
644 // the use_candidate attribute. 665 // selected for transmission if the peer supports ICE-renomination when this
645 bool nominated_; 666 // value is positive. A larger-value indicates that a connection is nominated
667 // later and should be selected by the controlled side with higher precedence.
668 // A zero-value indicates not nominating this connection.
669 int nominating_value_ = 0;
670 // The last nominating value that has been acknowledged.
671 int acknowledged_nominating_value_ = 0;
672 // Used by the controlled side to remember the nomination value received from
673 // the controlling side. When the peer does not support ICE re-nomination,
674 // its value will be 1 if the connection is nominated.
675 int nominated_value_ = 0;
pthatcher1 2016/07/28 22:57:26 nominating_value/nominated_value is confusing. Pe
honghaiz3 2016/08/03 04:46:56 Done. There might be role switch, so better to hav
676
646 IceMode remote_ice_mode_; 677 IceMode remote_ice_mode_;
647 StunRequestManager requests_; 678 StunRequestManager requests_;
648 int rtt_; 679 int rtt_;
649 int rtt_samples_ = 0; 680 int rtt_samples_ = 0;
650 int64_t last_ping_sent_; // last time we sent a ping to the other side 681 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 682 int64_t last_ping_received_; // last time we received a ping from the other
652 // side 683 // side
653 int64_t last_data_received_; 684 int64_t last_data_received_;
654 int64_t last_ping_response_received_; 685 int64_t last_ping_response_received_;
655 int64_t receiving_unchanged_since_ = 0; 686 int64_t receiving_unchanged_since_ = 0;
656 std::vector<SentPing> pings_since_last_response_; 687 std::vector<SentPing> pings_since_last_response_;
657 688
658 rtc::RateTracker recv_rate_tracker_;
659 rtc::RateTracker send_rate_tracker_;
660
661 ConnectionInfo stats_;
662
663 private:
664 void MaybeAddPrflxCandidate(ConnectionRequest* request, 689 void MaybeAddPrflxCandidate(ConnectionRequest* request,
665 StunMessage* response); 690 StunMessage* response);
666 691
667 bool reported_; 692 bool reported_;
668 State state_; 693 State state_;
669 // Time duration to switch from receiving to not receiving. 694 // Time duration to switch from receiving to not receiving.
670 int receiving_timeout_; 695 int receiving_timeout_;
671 int64_t time_created_ms_; 696 int64_t time_created_ms_;
672 int num_pings_sent_ = 0; 697 int num_pings_sent_ = 0;
673 698
(...skipping 11 matching lines...) Expand all
685 const rtc::PacketOptions& options) override; 710 const rtc::PacketOptions& options) override;
686 int GetError() override { return error_; } 711 int GetError() override { return error_; }
687 712
688 private: 713 private:
689 int error_ = 0; 714 int error_ = 0;
690 }; 715 };
691 716
692 } // namespace cricket 717 } // namespace cricket
693 718
694 #endif // WEBRTC_P2P_BASE_PORT_H_ 719 #endif // WEBRTC_P2P_BASE_PORT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698