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

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

Issue 1345913004: Replace readable with receiving where receiving means receiving anything (stun ping, response or da… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Address comments Created 5 years, 3 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // The length of time we wait before timing out readability on a connection. 53 // If a connection does not receive anything for this long, it is considered
54 const uint32 CONNECTION_READ_TIMEOUT = 30 * 1000; // 30 seconds 54 // dead.
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
55 59
56 // The length of time we wait before timing out writability on a connection. 60 // The length of time we wait before timing out writability on a connection.
57 const uint32 CONNECTION_WRITE_TIMEOUT = 15 * 1000; // 15 seconds 61 const uint32 CONNECTION_WRITE_TIMEOUT = 15 * 1000; // 15 seconds
58 62
59 // The length of time we wait before we become unwritable. 63 // The length of time we wait before we become unwritable.
60 const uint32 CONNECTION_WRITE_CONNECT_TIMEOUT = 5 * 1000; // 5 seconds 64 const uint32 CONNECTION_WRITE_CONNECT_TIMEOUT = 5 * 1000; // 5 seconds
61 65
62 // The number of pings that must fail to respond before we become unwritable. 66 // The number of pings that must fail to respond before we become unwritable.
63 const uint32 CONNECTION_WRITE_CONNECT_FAILURES = 5; 67 const uint32 CONNECTION_WRITE_CONNECT_FAILURES = 5;
64 68
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 414
411 // Returns the description of the local port 415 // Returns the description of the local port
412 virtual const Candidate& local_candidate() const; 416 virtual const Candidate& local_candidate() const;
413 417
414 // Returns the description of the remote port to which we communicate. 418 // Returns the description of the remote port to which we communicate.
415 const Candidate& remote_candidate() const { return remote_candidate_; } 419 const Candidate& remote_candidate() const { return remote_candidate_; }
416 420
417 // Returns the pair priority. 421 // Returns the pair priority.
418 uint64 priority() const; 422 uint64 priority() const;
419 423
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
429 enum WriteState { 424 enum WriteState {
430 STATE_WRITABLE = 0, // we have received ping responses recently 425 STATE_WRITABLE = 0, // we have received ping responses recently
431 STATE_WRITE_UNRELIABLE = 1, // we have had a few ping failures 426 STATE_WRITE_UNRELIABLE = 1, // we have had a few ping failures
432 STATE_WRITE_INIT = 2, // we have yet to receive a ping response 427 STATE_WRITE_INIT = 2, // we have yet to receive a ping response
433 STATE_WRITE_TIMEOUT = 3, // we have had a large number of ping failures 428 STATE_WRITE_TIMEOUT = 3, // we have had a large number of ping failures
434 }; 429 };
435 430
436 WriteState write_state() const { return write_state_; } 431 WriteState write_state() const { return write_state_; }
437 bool writable() const { return write_state_ == STATE_WRITABLE; } 432 bool writable() const { return write_state_ == STATE_WRITABLE; }
433 bool receiving() const { return receiving_; }
438 434
439 // Determines whether the connection has finished connecting. This can only 435 // Determines whether the connection has finished connecting. This can only
440 // be false for TCP connections. 436 // be false for TCP connections.
441 bool connected() const { return connected_; } 437 bool connected() const { return connected_; }
442 438
443 // Estimate of the round-trip time over this connection. 439 // Estimate of the round-trip time over this connection.
444 uint32 rtt() const { return rtt_; } 440 uint32 rtt() const { return rtt_; }
445 441
446 size_t sent_total_bytes(); 442 size_t sent_total_bytes();
447 size_t sent_bytes_second(); 443 size_t sent_bytes_second();
(...skipping 11 matching lines...) Expand all
459 455
460 // The connection can send and receive packets asynchronously. This matches 456 // The connection can send and receive packets asynchronously. This matches
461 // the interface of AsyncPacketSocket, which may use UDP or TCP under the 457 // the interface of AsyncPacketSocket, which may use UDP or TCP under the
462 // covers. 458 // covers.
463 virtual int Send(const void* data, size_t size, 459 virtual int Send(const void* data, size_t size,
464 const rtc::PacketOptions& options) = 0; 460 const rtc::PacketOptions& options) = 0;
465 461
466 // Error if Send() returns < 0 462 // Error if Send() returns < 0
467 virtual int GetError() = 0; 463 virtual int GetError() = 0;
468 464
469 sigslot::signal4<Connection*, const char*, size_t, 465 sigslot::signal4<Connection*, const char*, size_t, const rtc::PacketTime&>
470 const rtc::PacketTime&> SignalReadPacket; 466 SignalReadPacket;
471 467
472 sigslot::signal1<Connection*> SignalReadyToSend; 468 sigslot::signal1<Connection*> SignalReadyToSend;
473 469
474 // Called when a packet is received on this connection. 470 // Called when a packet is received on this connection.
475 void OnReadPacket(const char* data, size_t size, 471 void OnReadPacket(const char* data, size_t size,
476 const rtc::PacketTime& packet_time); 472 const rtc::PacketTime& packet_time);
477 473
478 // Called when the socket is currently able to send. 474 // Called when the socket is currently able to send.
479 void OnReadyToSend(); 475 void OnReadyToSend();
480 476
481 // Called when a connection is determined to be no longer useful to us. We 477 // Called when a connection is determined to be no longer useful to us. We
482 // still keep it around in case the other side wants to use it. But we can 478 // still keep it around in case the other side wants to use it. But we can
483 // safely stop pinging on it and we can allow it to time out if the other 479 // safely stop pinging on it and we can allow it to time out if the other
484 // side stops using it as well. 480 // side stops using it as well.
485 bool pruned() const { return pruned_; } 481 bool pruned() const { return pruned_; }
486 void Prune(); 482 void Prune();
487 483
488 bool use_candidate_attr() const { return use_candidate_attr_; } 484 bool use_candidate_attr() const { return use_candidate_attr_; }
489 void set_use_candidate_attr(bool enable); 485 void set_use_candidate_attr(bool enable);
490 486
491 bool nominated() const { return nominated_; } 487 bool nominated() const { return nominated_; }
492 void set_nominated(bool nominated) { nominated_ = nominated; } 488 void set_nominated(bool nominated) { nominated_ = nominated; }
493 489
494 void set_remote_ice_mode(IceMode mode) { 490 void set_remote_ice_mode(IceMode mode) {
495 remote_ice_mode_ = mode; 491 remote_ice_mode_ = mode;
496 } 492 }
497 493
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
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);
569 void set_write_state(WriteState value); 568 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_;
582 WriteState write_state_; 581 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
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_;
614 616
615 friend class Port; 617 friend class Port;
616 friend class ConnectionRequest; 618 friend class ConnectionRequest;
617 }; 619 };
618 620
619 // ProxyConnection defers all the interesting work to the port 621 // ProxyConnection defers all the interesting work to the port
620 class ProxyConnection : public Connection { 622 class ProxyConnection : public Connection {
621 public: 623 public:
622 ProxyConnection(Port* port, size_t index, const Candidate& candidate); 624 ProxyConnection(Port* port, size_t index, const Candidate& candidate);
623 625
624 virtual int Send(const void* data, size_t size, 626 virtual int Send(const void* data, size_t size,
625 const rtc::PacketOptions& options); 627 const rtc::PacketOptions& options);
626 virtual int GetError() { return error_; } 628 virtual int GetError() { return error_; }
627 629
628 private: 630 private:
629 int error_; 631 int error_;
630 }; 632 };
631 633
632 } // namespace cricket 634 } // namespace cricket
633 635
634 #endif // WEBRTC_P2P_BASE_PORT_H_ 636 #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