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

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

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

Powered by Google App Engine
This is Rietveld 408576698