| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 ICE_TYPE_PREFERENCE_RELAY_TLS = 0, | 85 ICE_TYPE_PREFERENCE_RELAY_TLS = 0, |
| 86 ICE_TYPE_PREFERENCE_RELAY_TCP = 1, | 86 ICE_TYPE_PREFERENCE_RELAY_TCP = 1, |
| 87 ICE_TYPE_PREFERENCE_RELAY_UDP = 2, | 87 ICE_TYPE_PREFERENCE_RELAY_UDP = 2, |
| 88 ICE_TYPE_PREFERENCE_PRFLX_TCP = 80, | 88 ICE_TYPE_PREFERENCE_PRFLX_TCP = 80, |
| 89 ICE_TYPE_PREFERENCE_HOST_TCP = 90, | 89 ICE_TYPE_PREFERENCE_HOST_TCP = 90, |
| 90 ICE_TYPE_PREFERENCE_SRFLX = 100, | 90 ICE_TYPE_PREFERENCE_SRFLX = 100, |
| 91 ICE_TYPE_PREFERENCE_PRFLX = 110, | 91 ICE_TYPE_PREFERENCE_PRFLX = 110, |
| 92 ICE_TYPE_PREFERENCE_HOST = 126 | 92 ICE_TYPE_PREFERENCE_HOST = 126 |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 // States are from RFC 5245. http://tools.ietf.org/html/rfc5245#section-5.7.4 |
| 96 enum class IceCandidatePairState { |
| 97 WAITING = 0, // Check has not been performed, Waiting pair on CL. |
| 98 IN_PROGRESS, // Check has been sent, transaction is in progress. |
| 99 SUCCEEDED, // Check already done, produced a successful result. |
| 100 FAILED, // Check for this connection failed. |
| 101 // According to spec there should also be a frozen state, but nothing is ever |
| 102 // frozen because we have not implemented ICE freezing logic. |
| 103 }; |
| 104 |
| 95 const char* ProtoToString(ProtocolType proto); | 105 const char* ProtoToString(ProtocolType proto); |
| 96 bool StringToProto(const char* value, ProtocolType* proto); | 106 bool StringToProto(const char* value, ProtocolType* proto); |
| 97 | 107 |
| 98 struct ProtocolAddress { | 108 struct ProtocolAddress { |
| 99 rtc::SocketAddress address; | 109 rtc::SocketAddress address; |
| 100 ProtocolType proto; | 110 ProtocolType proto; |
| 101 | 111 |
| 102 ProtocolAddress(const rtc::SocketAddress& a, ProtocolType p) | 112 ProtocolAddress(const rtc::SocketAddress& a, ProtocolType p) |
| 103 : address(a), proto(p) {} | 113 : address(a), proto(p) {} |
| 104 | 114 |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 public: | 422 public: |
| 413 struct SentPing { | 423 struct SentPing { |
| 414 SentPing(const std::string id, int64_t sent_time, uint32_t nomination) | 424 SentPing(const std::string id, int64_t sent_time, uint32_t nomination) |
| 415 : id(id), sent_time(sent_time), nomination(nomination) {} | 425 : id(id), sent_time(sent_time), nomination(nomination) {} |
| 416 | 426 |
| 417 std::string id; | 427 std::string id; |
| 418 int64_t sent_time; | 428 int64_t sent_time; |
| 419 uint32_t nomination; | 429 uint32_t nomination; |
| 420 }; | 430 }; |
| 421 | 431 |
| 422 // States are from RFC 5245. http://tools.ietf.org/html/rfc5245#section-5.7.4 | |
| 423 enum State { | |
| 424 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_SUCCEEDED, // Check already done, produced a successful result. | |
| 427 STATE_FAILED // Check for this connection failed. | |
| 428 }; | |
| 429 | |
| 430 virtual ~Connection(); | 432 virtual ~Connection(); |
| 431 | 433 |
| 432 // The local port where this connection sends and receives packets. | 434 // The local port where this connection sends and receives packets. |
| 433 Port* port() { return port_; } | 435 Port* port() { return port_; } |
| 434 const Port* port() const { return port_; } | 436 const Port* port() const { return port_; } |
| 435 | 437 |
| 436 // Implementation of virtual methods in CandidatePairInterface. | 438 // Implementation of virtual methods in CandidatePairInterface. |
| 437 // Returns the description of the local port | 439 // Returns the description of the local port |
| 438 virtual const Candidate& local_candidate() const; | 440 virtual const Candidate& local_candidate() const; |
| 439 // Returns the description of the remote port to which we communicate. | 441 // Returns the description of the remote port to which we communicate. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 460 bool active() const { | 462 bool active() const { |
| 461 return write_state_ != STATE_WRITE_TIMEOUT; | 463 return write_state_ != STATE_WRITE_TIMEOUT; |
| 462 } | 464 } |
| 463 | 465 |
| 464 // A connection is dead if it can be safely deleted. | 466 // A connection is dead if it can be safely deleted. |
| 465 bool dead(int64_t now) const; | 467 bool dead(int64_t now) const; |
| 466 | 468 |
| 467 // Estimate of the round-trip time over this connection. | 469 // Estimate of the round-trip time over this connection. |
| 468 int rtt() const { return rtt_; } | 470 int rtt() const { return rtt_; } |
| 469 | 471 |
| 472 // Gets the |ConnectionInfo| stats, where |best_connection| has not been |
| 473 // populated (default value false). |
| 470 ConnectionInfo stats(); | 474 ConnectionInfo stats(); |
| 471 | 475 |
| 472 sigslot::signal1<Connection*> SignalStateChange; | 476 sigslot::signal1<Connection*> SignalStateChange; |
| 473 | 477 |
| 474 // Sent when the connection has decided that it is no longer of value. It | 478 // Sent when the connection has decided that it is no longer of value. It |
| 475 // will delete itself immediately after this call. | 479 // will delete itself immediately after this call. |
| 476 sigslot::signal1<Connection*> SignalDestroyed; | 480 sigslot::signal1<Connection*> SignalDestroyed; |
| 477 | 481 |
| 478 // The connection can send and receive packets asynchronously. This matches | 482 // The connection can send and receive packets asynchronously. This matches |
| 479 // the interface of AsyncPacketSocket, which may use UDP or TCP under the | 483 // the interface of AsyncPacketSocket, which may use UDP or TCP under the |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 bool reported() const { return reported_; } | 572 bool reported() const { return reported_; } |
| 569 void set_reported(bool reported) { reported_ = reported;} | 573 void set_reported(bool reported) { reported_ = reported;} |
| 570 | 574 |
| 571 // This signal will be fired if this connection is nominated by the | 575 // This signal will be fired if this connection is nominated by the |
| 572 // controlling side. | 576 // controlling side. |
| 573 sigslot::signal1<Connection*> SignalNominated; | 577 sigslot::signal1<Connection*> SignalNominated; |
| 574 | 578 |
| 575 // Invoked when Connection receives STUN error response with 487 code. | 579 // Invoked when Connection receives STUN error response with 487 code. |
| 576 void HandleRoleConflictFromPeer(); | 580 void HandleRoleConflictFromPeer(); |
| 577 | 581 |
| 578 State state() const { return state_; } | 582 IceCandidatePairState state() const { return state_; } |
| 579 | 583 |
| 580 int num_pings_sent() const { return num_pings_sent_; } | 584 int num_pings_sent() const { return num_pings_sent_; } |
| 581 | 585 |
| 582 IceMode remote_ice_mode() const { return remote_ice_mode_; } | 586 IceMode remote_ice_mode() const { return remote_ice_mode_; } |
| 583 | 587 |
| 584 uint32_t ComputeNetworkCost() const; | 588 uint32_t ComputeNetworkCost() const; |
| 585 | 589 |
| 586 // Update the ICE password and/or generation of the remote candidate if the | 590 // Update the ICE password and/or generation of the remote candidate if the |
| 587 // ufrag in |params| matches the candidate's ufrag, and the | 591 // ufrag in |params| matches the candidate's ufrag, and the |
| 588 // candidate's password and/or ufrag has not been set. | 592 // candidate's password and/or ufrag has not been set. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 | 627 |
| 624 bool rtt_converged() const; | 628 bool rtt_converged() const; |
| 625 | 629 |
| 626 // 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 |
| 627 // be missing. | 631 // be missing. |
| 628 bool missing_responses(int64_t now) const; | 632 bool missing_responses(int64_t now) const; |
| 629 | 633 |
| 630 // Changes the state and signals if necessary. | 634 // Changes the state and signals if necessary. |
| 631 void set_write_state(WriteState value); | 635 void set_write_state(WriteState value); |
| 632 void UpdateReceiving(int64_t now); | 636 void UpdateReceiving(int64_t now); |
| 633 void set_state(State state); | 637 void set_state(IceCandidatePairState state); |
| 634 void set_connected(bool value); | 638 void set_connected(bool value); |
| 635 | 639 |
| 636 uint32_t nomination() const { return nomination_; } | 640 uint32_t nomination() const { return nomination_; } |
| 637 | 641 |
| 638 void OnMessage(rtc::Message *pmsg); | 642 void OnMessage(rtc::Message *pmsg); |
| 639 | 643 |
| 640 Port* port_; | 644 Port* port_; |
| 641 size_t local_candidate_index_; | 645 size_t local_candidate_index_; |
| 642 Candidate remote_candidate_; | 646 Candidate remote_candidate_; |
| 643 | 647 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 int rtt_samples_ = 0; | 683 int rtt_samples_ = 0; |
| 680 int64_t last_ping_sent_; // last time we sent a ping to the other side | 684 int64_t last_ping_sent_; // last time we sent a ping to the other side |
| 681 int64_t last_ping_received_; // last time we received a ping from the other | 685 int64_t last_ping_received_; // last time we received a ping from the other |
| 682 // side | 686 // side |
| 683 int64_t last_data_received_; | 687 int64_t last_data_received_; |
| 684 int64_t last_ping_response_received_; | 688 int64_t last_ping_response_received_; |
| 685 int64_t receiving_unchanged_since_ = 0; | 689 int64_t receiving_unchanged_since_ = 0; |
| 686 std::vector<SentPing> pings_since_last_response_; | 690 std::vector<SentPing> pings_since_last_response_; |
| 687 | 691 |
| 688 bool reported_; | 692 bool reported_; |
| 689 State state_; | 693 IceCandidatePairState state_; |
| 690 // Time duration to switch from receiving to not receiving. | 694 // Time duration to switch from receiving to not receiving. |
| 691 int receiving_timeout_; | 695 int receiving_timeout_; |
| 692 int64_t time_created_ms_; | 696 int64_t time_created_ms_; |
| 693 int num_pings_sent_ = 0; | 697 int num_pings_sent_ = 0; |
| 694 | 698 |
| 695 friend class Port; | 699 friend class Port; |
| 696 friend class ConnectionRequest; | 700 friend class ConnectionRequest; |
| 697 }; | 701 }; |
| 698 | 702 |
| 699 // ProxyConnection defers all the interesting work to the port. | 703 // ProxyConnection defers all the interesting work to the port. |
| 700 class ProxyConnection : public Connection { | 704 class ProxyConnection : public Connection { |
| 701 public: | 705 public: |
| 702 ProxyConnection(Port* port, size_t index, const Candidate& remote_candidate); | 706 ProxyConnection(Port* port, size_t index, const Candidate& remote_candidate); |
| 703 | 707 |
| 704 int Send(const void* data, | 708 int Send(const void* data, |
| 705 size_t size, | 709 size_t size, |
| 706 const rtc::PacketOptions& options) override; | 710 const rtc::PacketOptions& options) override; |
| 707 int GetError() override { return error_; } | 711 int GetError() override { return error_; } |
| 708 | 712 |
| 709 private: | 713 private: |
| 710 int error_ = 0; | 714 int error_ = 0; |
| 711 }; | 715 }; |
| 712 | 716 |
| 713 } // namespace cricket | 717 } // namespace cricket |
| 714 | 718 |
| 715 #endif // WEBRTC_P2P_BASE_PORT_H_ | 719 #endif // WEBRTC_P2P_BASE_PORT_H_ |
| OLD | NEW |