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

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

Issue 1793553002: Using 64-bit timestamp in webrtc/p2p (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel_unittest.cc ('k') | webrtc/p2p/base/port.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 extern const char SSLTCP_PROTOCOL_NAME[]; 45 extern const char SSLTCP_PROTOCOL_NAME[];
46 46
47 // RFC 6544, TCP candidate encoding rules. 47 // RFC 6544, TCP candidate encoding rules.
48 extern const int DISCARD_PORT; 48 extern const int DISCARD_PORT;
49 extern const char TCPTYPE_ACTIVE_STR[]; 49 extern const char TCPTYPE_ACTIVE_STR[];
50 extern const char TCPTYPE_PASSIVE_STR[]; 50 extern const char TCPTYPE_PASSIVE_STR[];
51 extern const char TCPTYPE_SIMOPEN_STR[]; 51 extern const char TCPTYPE_SIMOPEN_STR[];
52 52
53 // The minimum time we will wait before destroying a connection after creating 53 // The minimum time we will wait before destroying a connection after creating
54 // it. 54 // it.
55 const uint32_t MIN_CONNECTION_LIFETIME = 10 * 1000; // 10 seconds. 55 static const int MIN_CONNECTION_LIFETIME = 10 * 1000; // 10 seconds.
56 56
57 // A connection will be declared dead if it has not received anything for this 57 // A connection will be declared dead if it has not received anything for this
58 // long. 58 // long.
59 const uint32_t DEAD_CONNECTION_RECEIVE_TIMEOUT = 30 * 1000; // 30 seconds. 59 static const int DEAD_CONNECTION_RECEIVE_TIMEOUT = 30 * 1000; // 30 seconds.
60 60
61 // The timeout duration when a connection does not receive anything. 61 // The timeout duration when a connection does not receive anything.
62 const uint32_t WEAK_CONNECTION_RECEIVE_TIMEOUT = 2500; // 2.5 seconds 62 static const int WEAK_CONNECTION_RECEIVE_TIMEOUT = 2500; // 2.5 seconds
63 63
64 // The length of time we wait before timing out writability on a connection. 64 // The length of time we wait before timing out writability on a connection.
65 const uint32_t CONNECTION_WRITE_TIMEOUT = 15 * 1000; // 15 seconds 65 static const int CONNECTION_WRITE_TIMEOUT = 15 * 1000; // 15 seconds
66 66
67 // The length of time we wait before we become unwritable. 67 // The length of time we wait before we become unwritable.
68 const uint32_t CONNECTION_WRITE_CONNECT_TIMEOUT = 5 * 1000; // 5 seconds 68 static const int CONNECTION_WRITE_CONNECT_TIMEOUT = 5 * 1000; // 5 seconds
69
70 // This is the length of time that we wait for a ping response to come back.
71 static const int CONNECTION_RESPONSE_TIMEOUT = 5 * 1000; // 5 seconds
69 72
70 // The number of pings that must fail to respond before we become unwritable. 73 // The number of pings that must fail to respond before we become unwritable.
71 const uint32_t CONNECTION_WRITE_CONNECT_FAILURES = 5; 74 static const uint32_t CONNECTION_WRITE_CONNECT_FAILURES = 5;
72
73 // This is the length of time that we wait for a ping response to come back.
74 const int CONNECTION_RESPONSE_TIMEOUT = 5 * 1000; // 5 seconds
75 75
76 enum RelayType { 76 enum RelayType {
77 RELAY_GTURN, // Legacy google relay service. 77 RELAY_GTURN, // Legacy google relay service.
78 RELAY_TURN // Standard (TURN) relay service. 78 RELAY_TURN // Standard (TURN) relay service.
79 }; 79 };
80 80
81 enum IcePriorityValue { 81 enum IcePriorityValue {
82 // The reason we are choosing Relay preference 2 is because, we can run 82 // The reason we are choosing Relay preference 2 is because, we can run
83 // Relay from client to server on UDP/TCP/TLS. To distinguish the transport 83 // Relay from client to server on UDP/TCP/TLS. To distinguish the transport
84 // protocol, we prefer UDP over TCP over TLS. 84 // protocol, we prefer UDP over TCP over TLS.
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 405
406 friend class Connection; 406 friend class Connection;
407 }; 407 };
408 408
409 // Represents a communication link between a port on the local client and a 409 // Represents a communication link between a port on the local client and a
410 // port on the remote client. 410 // port on the remote client.
411 class Connection : public rtc::MessageHandler, 411 class Connection : 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, uint32_t sent_time) 415 SentPing(const std::string id, int64_t sent_time)
416 : id(id), sent_time(sent_time) {} 416 : id(id), sent_time(sent_time) {}
417 417
418 std::string id; 418 std::string id;
419 uint32_t sent_time; 419 int64_t sent_time;
420 }; 420 };
421 421
422 // States are from RFC 5245. http://tools.ietf.org/html/rfc5245#section-5.7.4 422 // States are from RFC 5245. http://tools.ietf.org/html/rfc5245#section-5.7.4
423 enum State { 423 enum State {
424 STATE_WAITING = 0, // Check has not been performed, Waiting pair on CL. 424 STATE_WAITING = 0, // Check has not been performed, Waiting pair on CL.
425 STATE_INPROGRESS, // Check has been sent, transaction is in progress. 425 STATE_INPROGRESS, // Check has been sent, transaction is in progress.
426 STATE_SUCCEEDED, // Check already done, produced a successful result. 426 STATE_SUCCEEDED, // Check already done, produced a successful result.
427 STATE_FAILED // Check for this connection failed. 427 STATE_FAILED // Check for this connection failed.
428 }; 428 };
429 429
(...skipping 24 matching lines...) Expand all
454 bool receiving() const { return receiving_; } 454 bool receiving() const { return receiving_; }
455 455
456 // Determines whether the connection has finished connecting. This can only 456 // Determines whether the connection has finished connecting. This can only
457 // be false for TCP connections. 457 // be false for TCP connections.
458 bool connected() const { return connected_; } 458 bool connected() const { return connected_; }
459 bool weak() const { return !(writable() && receiving() && connected()); } 459 bool weak() const { return !(writable() && receiving() && connected()); }
460 bool active() const { 460 bool active() const {
461 return write_state_ != STATE_WRITE_TIMEOUT; 461 return write_state_ != STATE_WRITE_TIMEOUT;
462 } 462 }
463 // A connection is dead if it can be safely deleted. 463 // A connection is dead if it can be safely deleted.
464 bool dead(uint32_t now) const; 464 bool dead(int64_t now) const;
465 465
466 // Estimate of the round-trip time over this connection. 466 // Estimate of the round-trip time over this connection.
467 uint32_t rtt() const { return rtt_; } 467 int rtt() const { return rtt_; }
468 468
469 size_t sent_total_bytes(); 469 size_t sent_total_bytes();
470 size_t sent_bytes_second(); 470 size_t sent_bytes_second();
471 // Used to track how many packets are discarded in the application socket due 471 // Used to track how many packets are discarded in the application socket due
472 // to errors. 472 // to errors.
473 size_t sent_discarded_packets(); 473 size_t sent_discarded_packets();
474 size_t sent_total_packets(); 474 size_t sent_total_packets();
475 size_t recv_total_bytes(); 475 size_t recv_total_bytes();
476 size_t recv_bytes_second(); 476 size_t recv_bytes_second();
477 sigslot::signal1<Connection*> SignalStateChange; 477 sigslot::signal1<Connection*> SignalStateChange;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 bool use_candidate_attr() const { return use_candidate_attr_; } 511 bool use_candidate_attr() const { return use_candidate_attr_; }
512 void set_use_candidate_attr(bool enable); 512 void set_use_candidate_attr(bool enable);
513 513
514 bool nominated() const { return nominated_; } 514 bool nominated() const { return nominated_; }
515 void set_nominated(bool nominated) { nominated_ = nominated; } 515 void set_nominated(bool nominated) { nominated_ = nominated; }
516 516
517 void set_remote_ice_mode(IceMode mode) { 517 void set_remote_ice_mode(IceMode mode) {
518 remote_ice_mode_ = mode; 518 remote_ice_mode_ = mode;
519 } 519 }
520 520
521 void set_receiving_timeout(uint32_t receiving_timeout_ms) { 521 void set_receiving_timeout(int64_t receiving_timeout_ms) {
522 receiving_timeout_ = receiving_timeout_ms; 522 receiving_timeout_ = receiving_timeout_ms;
523 } 523 }
524 524
525 // Makes the connection go away. 525 // Makes the connection go away.
526 void Destroy(); 526 void Destroy();
527 527
528 // Makes the connection go away, in a failed state. 528 // Makes the connection go away, in a failed state.
529 void FailAndDestroy(); 529 void FailAndDestroy();
530 530
531 // Checks that the state of this connection is up-to-date. The argument is 531 // Checks that the state of this connection is up-to-date. The argument is
532 // the current time, which is compared against various timeouts. 532 // the current time, which is compared against various timeouts.
533 void UpdateState(uint32_t now); 533 void UpdateState(int64_t now);
534 534
535 // Called when this connection should try checking writability again. 535 // Called when this connection should try checking writability again.
536 uint32_t last_ping_sent() const { return last_ping_sent_; } 536 int64_t last_ping_sent() const { return last_ping_sent_; }
537 void Ping(uint32_t now); 537 void Ping(int64_t now);
538 void ReceivedPingResponse(); 538 void ReceivedPingResponse();
539 uint32_t last_ping_response_received() const { 539 int64_t last_ping_response_received() const {
540 return last_ping_response_received_; 540 return last_ping_response_received_;
541 } 541 }
542 542
543 // Called whenever a valid ping is received on this connection. This is 543 // Called whenever a valid ping is received on this connection. This is
544 // public because the connection intercepts the first ping for us. 544 // public because the connection intercepts the first ping for us.
545 uint32_t last_ping_received() const { return last_ping_received_; } 545 int64_t last_ping_received() const { return last_ping_received_; }
546 void ReceivedPing(); 546 void ReceivedPing();
547 // Handles the binding request; sends a response if this is a valid request. 547 // Handles the binding request; sends a response if this is a valid request.
548 void HandleBindingRequest(IceMessage* msg); 548 void HandleBindingRequest(IceMessage* msg);
549 549
550 // Debugging description of this connection 550 // Debugging description of this connection
551 std::string ToDebugId() const; 551 std::string ToDebugId() const;
552 std::string ToString() const; 552 std::string ToString() const;
553 std::string ToSensitiveString() const; 553 std::string ToSensitiveString() const;
554 // Prints pings_since_last_response_ into a string. 554 // Prints pings_since_last_response_ into a string.
555 void PrintPingsSinceLastResponse(std::string* pings, size_t max); 555 void PrintPingsSinceLastResponse(std::string* pings, size_t max);
(...skipping 19 matching lines...) Expand all
575 void MaybeSetRemoteIceCredentials(const std::string& ice_ufrag, 575 void MaybeSetRemoteIceCredentials(const std::string& ice_ufrag,
576 const std::string& ice_pwd); 576 const std::string& ice_pwd);
577 577
578 // If |remote_candidate_| is peer reflexive and is equivalent to 578 // If |remote_candidate_| is peer reflexive and is equivalent to
579 // |new_candidate| except the type, update |remote_candidate_| to 579 // |new_candidate| except the type, update |remote_candidate_| to
580 // |new_candidate|. 580 // |new_candidate|.
581 void MaybeUpdatePeerReflexiveCandidate(const Candidate& new_candidate); 581 void MaybeUpdatePeerReflexiveCandidate(const Candidate& new_candidate);
582 582
583 // Returns the last received time of any data, stun request, or stun 583 // Returns the last received time of any data, stun request, or stun
584 // response in milliseconds 584 // response in milliseconds
585 uint32_t last_received() const; 585 int64_t last_received() const;
586 586
587 protected: 587 protected:
588 enum { MSG_DELETE = 0, MSG_FIRST_AVAILABLE }; 588 enum { MSG_DELETE = 0, MSG_FIRST_AVAILABLE };
589 589
590 // Constructs a new connection to the given remote port. 590 // Constructs a new connection to the given remote port.
591 Connection(Port* port, size_t index, const Candidate& candidate); 591 Connection(Port* port, size_t index, const Candidate& candidate);
592 592
593 // Called back when StunRequestManager has a stun packet to send 593 // Called back when StunRequestManager has a stun packet to send
594 void OnSendStunPacket(const void* data, size_t size, StunRequest* req); 594 void OnSendStunPacket(const void* data, size_t size, StunRequest* req);
595 595
(...skipping 23 matching lines...) Expand all
619 // By default |use_candidate_attr_| flag will be true, 619 // By default |use_candidate_attr_| flag will be true,
620 // as we will be using aggressive nomination. 620 // as we will be using aggressive nomination.
621 // But when peer is ice-lite, this flag "must" be initialized to false and 621 // But when peer is ice-lite, this flag "must" be initialized to false and
622 // turn on when connection becomes "best connection". 622 // turn on when connection becomes "best connection".
623 bool use_candidate_attr_; 623 bool use_candidate_attr_;
624 // Whether this connection has been nominated by the controlling side via 624 // Whether this connection has been nominated by the controlling side via
625 // the use_candidate attribute. 625 // the use_candidate attribute.
626 bool nominated_; 626 bool nominated_;
627 IceMode remote_ice_mode_; 627 IceMode remote_ice_mode_;
628 StunRequestManager requests_; 628 StunRequestManager requests_;
629 uint32_t rtt_; 629 int rtt_;
630 uint32_t last_ping_sent_; // last time we sent a ping to the other side 630 int64_t last_ping_sent_; // last time we sent a ping to the other side
631 uint32_t last_ping_received_; // last time we received a ping from the other 631 int64_t last_ping_received_; // last time we received a ping from the other
632 // side 632 // side
633 uint32_t last_data_received_; 633 int64_t last_data_received_;
634 uint32_t last_ping_response_received_; 634 int64_t last_ping_response_received_;
635 std::vector<SentPing> pings_since_last_response_; 635 std::vector<SentPing> pings_since_last_response_;
636 636
637 rtc::RateTracker recv_rate_tracker_; 637 rtc::RateTracker recv_rate_tracker_;
638 rtc::RateTracker send_rate_tracker_; 638 rtc::RateTracker send_rate_tracker_;
639 uint32_t sent_packets_discarded_; 639 uint32_t sent_packets_discarded_;
640 uint32_t sent_packets_total_; 640 uint32_t sent_packets_total_;
641 641
642 private: 642 private:
643 void MaybeAddPrflxCandidate(ConnectionRequest* request, 643 void MaybeAddPrflxCandidate(ConnectionRequest* request,
644 StunMessage* response); 644 StunMessage* response);
645 645
646 bool reported_; 646 bool reported_;
647 State state_; 647 State state_;
648 // Time duration to switch from receiving to not receiving. 648 // Time duration to switch from receiving to not receiving.
649 uint32_t receiving_timeout_; 649 int receiving_timeout_;
650 uint32_t time_created_ms_; 650 int64_t time_created_ms_;
651 651
652 friend class Port; 652 friend class Port;
653 friend class ConnectionRequest; 653 friend class ConnectionRequest;
654 }; 654 };
655 655
656 // ProxyConnection defers all the interesting work to the port. 656 // ProxyConnection defers all the interesting work to the port.
657 class ProxyConnection : public Connection { 657 class ProxyConnection : public Connection {
658 public: 658 public:
659 ProxyConnection(Port* port, size_t index, const Candidate& remote_candidate); 659 ProxyConnection(Port* port, size_t index, const Candidate& remote_candidate);
660 660
661 int Send(const void* data, 661 int Send(const void* data,
662 size_t size, 662 size_t size,
663 const rtc::PacketOptions& options) override; 663 const rtc::PacketOptions& options) override;
664 int GetError() override { return error_; } 664 int GetError() override { return error_; }
665 665
666 private: 666 private:
667 int error_ = 0; 667 int error_ = 0;
668 }; 668 };
669 669
670 } // namespace cricket 670 } // namespace cricket
671 671
672 #endif // WEBRTC_P2P_BASE_PORT_H_ 672 #endif // WEBRTC_P2P_BASE_PORT_H_
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel_unittest.cc ('k') | webrtc/p2p/base/port.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698