| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 extern const char UDP_PROTOCOL_NAME[]; | 43 extern const char UDP_PROTOCOL_NAME[]; |
| 44 extern const char TCP_PROTOCOL_NAME[]; | 44 extern const char TCP_PROTOCOL_NAME[]; |
| 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 // If a connection does not receive anything for this long, it is considered | 53 // The length of time we wait before timing out readability on a connection. |
| 54 // dead. | 54 const uint32 CONNECTION_READ_TIMEOUT = 30 * 1000; // 30 seconds |
| 55 const uint32 DEAD_CONNECTION_RECEIVE_TIMEOUT = 30 * 1000; // 30 seconds. | |
| 56 | |
| 57 // The timeout duration when a connection does not receive anything. | |
| 58 const uint32 WEAK_CONNECTION_RECEIVE_TIMEOUT = 2500; // 2.5 seconds | |
| 59 | 55 |
| 60 // The length of time we wait before timing out writability on a connection. | 56 // The length of time we wait before timing out writability on a connection. |
| 61 const uint32 CONNECTION_WRITE_TIMEOUT = 15 * 1000; // 15 seconds | 57 const uint32 CONNECTION_WRITE_TIMEOUT = 15 * 1000; // 15 seconds |
| 62 | 58 |
| 63 // The length of time we wait before we become unwritable. | 59 // The length of time we wait before we become unwritable. |
| 64 const uint32 CONNECTION_WRITE_CONNECT_TIMEOUT = 5 * 1000; // 5 seconds | 60 const uint32 CONNECTION_WRITE_CONNECT_TIMEOUT = 5 * 1000; // 5 seconds |
| 65 | 61 |
| 66 // The number of pings that must fail to respond before we become unwritable. | 62 // The number of pings that must fail to respond before we become unwritable. |
| 67 const uint32 CONNECTION_WRITE_CONNECT_FAILURES = 5; | 63 const uint32 CONNECTION_WRITE_CONNECT_FAILURES = 5; |
| 68 | 64 |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 | 410 |
| 415 // Returns the description of the local port | 411 // Returns the description of the local port |
| 416 virtual const Candidate& local_candidate() const; | 412 virtual const Candidate& local_candidate() const; |
| 417 | 413 |
| 418 // Returns the description of the remote port to which we communicate. | 414 // Returns the description of the remote port to which we communicate. |
| 419 const Candidate& remote_candidate() const { return remote_candidate_; } | 415 const Candidate& remote_candidate() const { return remote_candidate_; } |
| 420 | 416 |
| 421 // Returns the pair priority. | 417 // Returns the pair priority. |
| 422 uint64 priority() const; | 418 uint64 priority() const; |
| 423 | 419 |
| 420 enum ReadState { |
| 421 STATE_READ_INIT = 0, // we have yet to receive a ping |
| 422 STATE_READABLE = 1, // we have received pings recently |
| 423 STATE_READ_TIMEOUT = 2, // we haven't received pings in a while |
| 424 }; |
| 425 |
| 426 ReadState read_state() const { return read_state_; } |
| 427 bool readable() const { return read_state_ == STATE_READABLE; } |
| 428 |
| 424 enum WriteState { | 429 enum WriteState { |
| 425 STATE_WRITABLE = 0, // we have received ping responses recently | 430 STATE_WRITABLE = 0, // we have received ping responses recently |
| 426 STATE_WRITE_UNRELIABLE = 1, // we have had a few ping failures | 431 STATE_WRITE_UNRELIABLE = 1, // we have had a few ping failures |
| 427 STATE_WRITE_INIT = 2, // we have yet to receive a ping response | 432 STATE_WRITE_INIT = 2, // we have yet to receive a ping response |
| 428 STATE_WRITE_TIMEOUT = 3, // we have had a large number of ping failures | 433 STATE_WRITE_TIMEOUT = 3, // we have had a large number of ping failures |
| 429 }; | 434 }; |
| 430 | 435 |
| 431 WriteState write_state() const { return write_state_; } | 436 WriteState write_state() const { return write_state_; } |
| 432 bool writable() const { return write_state_ == STATE_WRITABLE; } | 437 bool writable() const { return write_state_ == STATE_WRITABLE; } |
| 433 bool receiving() const { return receiving_; } | |
| 434 | 438 |
| 435 // Determines whether the connection has finished connecting. This can only | 439 // Determines whether the connection has finished connecting. This can only |
| 436 // be false for TCP connections. | 440 // be false for TCP connections. |
| 437 bool connected() const { return connected_; } | 441 bool connected() const { return connected_; } |
| 438 | 442 |
| 439 // Estimate of the round-trip time over this connection. | 443 // Estimate of the round-trip time over this connection. |
| 440 uint32 rtt() const { return rtt_; } | 444 uint32 rtt() const { return rtt_; } |
| 441 | 445 |
| 442 size_t sent_total_bytes(); | 446 size_t sent_total_bytes(); |
| 443 size_t sent_bytes_second(); | 447 size_t sent_bytes_second(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 455 | 459 |
| 456 // The connection can send and receive packets asynchronously. This matches | 460 // The connection can send and receive packets asynchronously. This matches |
| 457 // the interface of AsyncPacketSocket, which may use UDP or TCP under the | 461 // the interface of AsyncPacketSocket, which may use UDP or TCP under the |
| 458 // covers. | 462 // covers. |
| 459 virtual int Send(const void* data, size_t size, | 463 virtual int Send(const void* data, size_t size, |
| 460 const rtc::PacketOptions& options) = 0; | 464 const rtc::PacketOptions& options) = 0; |
| 461 | 465 |
| 462 // Error if Send() returns < 0 | 466 // Error if Send() returns < 0 |
| 463 virtual int GetError() = 0; | 467 virtual int GetError() = 0; |
| 464 | 468 |
| 465 sigslot::signal4<Connection*, const char*, size_t, const rtc::PacketTime&> | 469 sigslot::signal4<Connection*, const char*, size_t, |
| 466 SignalReadPacket; | 470 const rtc::PacketTime&> SignalReadPacket; |
| 467 | 471 |
| 468 sigslot::signal1<Connection*> SignalReadyToSend; | 472 sigslot::signal1<Connection*> SignalReadyToSend; |
| 469 | 473 |
| 470 // Called when a packet is received on this connection. | 474 // Called when a packet is received on this connection. |
| 471 void OnReadPacket(const char* data, size_t size, | 475 void OnReadPacket(const char* data, size_t size, |
| 472 const rtc::PacketTime& packet_time); | 476 const rtc::PacketTime& packet_time); |
| 473 | 477 |
| 474 // Called when the socket is currently able to send. | 478 // Called when the socket is currently able to send. |
| 475 void OnReadyToSend(); | 479 void OnReadyToSend(); |
| 476 | 480 |
| 477 // Called when a connection is determined to be no longer useful to us. We | 481 // Called when a connection is determined to be no longer useful to us. We |
| 478 // still keep it around in case the other side wants to use it. But we can | 482 // still keep it around in case the other side wants to use it. But we can |
| 479 // safely stop pinging on it and we can allow it to time out if the other | 483 // safely stop pinging on it and we can allow it to time out if the other |
| 480 // side stops using it as well. | 484 // side stops using it as well. |
| 481 bool pruned() const { return pruned_; } | 485 bool pruned() const { return pruned_; } |
| 482 void Prune(); | 486 void Prune(); |
| 483 | 487 |
| 484 bool use_candidate_attr() const { return use_candidate_attr_; } | 488 bool use_candidate_attr() const { return use_candidate_attr_; } |
| 485 void set_use_candidate_attr(bool enable); | 489 void set_use_candidate_attr(bool enable); |
| 486 | 490 |
| 487 bool nominated() const { return nominated_; } | 491 bool nominated() const { return nominated_; } |
| 488 void set_nominated(bool nominated) { nominated_ = nominated; } | 492 void set_nominated(bool nominated) { nominated_ = nominated; } |
| 489 | 493 |
| 490 void set_remote_ice_mode(IceMode mode) { | 494 void set_remote_ice_mode(IceMode mode) { |
| 491 remote_ice_mode_ = mode; | 495 remote_ice_mode_ = mode; |
| 492 } | 496 } |
| 493 | 497 |
| 494 void set_receiving_timeout(uint32 receiving_timeout_ms) { | |
| 495 receiving_timeout_ = receiving_timeout_ms; | |
| 496 } | |
| 497 | |
| 498 // Makes the connection go away. | 498 // Makes the connection go away. |
| 499 void Destroy(); | 499 void Destroy(); |
| 500 | 500 |
| 501 // Checks that the state of this connection is up-to-date. The argument is | 501 // Checks that the state of this connection is up-to-date. The argument is |
| 502 // the current time, which is compared against various timeouts. | 502 // the current time, which is compared against various timeouts. |
| 503 void UpdateState(uint32 now); | 503 void UpdateState(uint32 now); |
| 504 | 504 |
| 505 // Called when this connection should try checking writability again. | 505 // Called when this connection should try checking writability again. |
| 506 uint32 last_ping_sent() const { return last_ping_sent_; } | 506 uint32 last_ping_sent() const { return last_ping_sent_; } |
| 507 void Ping(uint32 now); | 507 void Ping(uint32 now); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 | 558 |
| 559 // Callbacks from ConnectionRequest | 559 // Callbacks from ConnectionRequest |
| 560 virtual void OnConnectionRequestResponse(ConnectionRequest* req, | 560 virtual void OnConnectionRequestResponse(ConnectionRequest* req, |
| 561 StunMessage* response); | 561 StunMessage* response); |
| 562 void OnConnectionRequestErrorResponse(ConnectionRequest* req, | 562 void OnConnectionRequestErrorResponse(ConnectionRequest* req, |
| 563 StunMessage* response); | 563 StunMessage* response); |
| 564 void OnConnectionRequestTimeout(ConnectionRequest* req); | 564 void OnConnectionRequestTimeout(ConnectionRequest* req); |
| 565 void OnConnectionRequestSent(ConnectionRequest* req); | 565 void OnConnectionRequestSent(ConnectionRequest* req); |
| 566 | 566 |
| 567 // Changes the state and signals if necessary. | 567 // Changes the state and signals if necessary. |
| 568 void set_read_state(ReadState value); |
| 568 void set_write_state(WriteState value); | 569 void set_write_state(WriteState value); |
| 569 void set_receiving(bool value); | |
| 570 void set_state(State state); | 570 void set_state(State state); |
| 571 void set_connected(bool value); | 571 void set_connected(bool value); |
| 572 | 572 |
| 573 // Checks if this connection is useless, and hence, should be destroyed. | 573 // Checks if this connection is useless, and hence, should be destroyed. |
| 574 void CheckTimeout(); | 574 void CheckTimeout(); |
| 575 | 575 |
| 576 void OnMessage(rtc::Message *pmsg); | 576 void OnMessage(rtc::Message *pmsg); |
| 577 | 577 |
| 578 Port* port_; | 578 Port* port_; |
| 579 size_t local_candidate_index_; | 579 size_t local_candidate_index_; |
| 580 Candidate remote_candidate_; | 580 Candidate remote_candidate_; |
| 581 ReadState read_state_; |
| 581 WriteState write_state_; | 582 WriteState write_state_; |
| 582 bool receiving_; | |
| 583 bool connected_; | 583 bool connected_; |
| 584 bool pruned_; | 584 bool pruned_; |
| 585 // By default |use_candidate_attr_| flag will be true, | 585 // By default |use_candidate_attr_| flag will be true, |
| 586 // as we will be using aggressive nomination. | 586 // as we will be using aggressive nomination. |
| 587 // But when peer is ice-lite, this flag "must" be initialized to false and | 587 // But when peer is ice-lite, this flag "must" be initialized to false and |
| 588 // turn on when connection becomes "best connection". | 588 // turn on when connection becomes "best connection". |
| 589 bool use_candidate_attr_; | 589 bool use_candidate_attr_; |
| 590 // Whether this connection has been nominated by the controlling side via | 590 // Whether this connection has been nominated by the controlling side via |
| 591 // the use_candidate attribute. | 591 // the use_candidate attribute. |
| 592 bool nominated_; | 592 bool nominated_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 604 rtc::RateTracker send_rate_tracker_; | 604 rtc::RateTracker send_rate_tracker_; |
| 605 uint32 sent_packets_discarded_; | 605 uint32 sent_packets_discarded_; |
| 606 uint32 sent_packets_total_; | 606 uint32 sent_packets_total_; |
| 607 | 607 |
| 608 private: | 608 private: |
| 609 void MaybeAddPrflxCandidate(ConnectionRequest* request, | 609 void MaybeAddPrflxCandidate(ConnectionRequest* request, |
| 610 StunMessage* response); | 610 StunMessage* response); |
| 611 | 611 |
| 612 bool reported_; | 612 bool reported_; |
| 613 State state_; | 613 State state_; |
| 614 // Time duration to switch from receiving to not receiving. | |
| 615 uint32 receiving_timeout_; | |
| 616 | 614 |
| 617 friend class Port; | 615 friend class Port; |
| 618 friend class ConnectionRequest; | 616 friend class ConnectionRequest; |
| 619 }; | 617 }; |
| 620 | 618 |
| 621 // ProxyConnection defers all the interesting work to the port | 619 // ProxyConnection defers all the interesting work to the port |
| 622 class ProxyConnection : public Connection { | 620 class ProxyConnection : public Connection { |
| 623 public: | 621 public: |
| 624 ProxyConnection(Port* port, size_t index, const Candidate& candidate); | 622 ProxyConnection(Port* port, size_t index, const Candidate& candidate); |
| 625 | 623 |
| 626 virtual int Send(const void* data, size_t size, | 624 virtual int Send(const void* data, size_t size, |
| 627 const rtc::PacketOptions& options); | 625 const rtc::PacketOptions& options); |
| 628 virtual int GetError() { return error_; } | 626 virtual int GetError() { return error_; } |
| 629 | 627 |
| 630 private: | 628 private: |
| 631 int error_; | 629 int error_; |
| 632 }; | 630 }; |
| 633 | 631 |
| 634 } // namespace cricket | 632 } // namespace cricket |
| 635 | 633 |
| 636 #endif // WEBRTC_P2P_BASE_PORT_H_ | 634 #endif // WEBRTC_P2P_BASE_PORT_H_ |
| OLD | NEW |