OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // The entity that handles framing writes for a Quic client or server. | 5 // The entity that handles framing writes for a Quic client or server. |
6 // Each QuicSession will have a connection associated with it. | 6 // Each QuicSession will have a connection associated with it. |
7 // | 7 // |
8 // On the server side, the Dispatcher handles the raw reads, and hands off | 8 // On the server side, the Dispatcher handles the raw reads, and hands off |
9 // packets via ProcessUdpPacket for framing and processing. | 9 // packets via ProcessUdpPacket for framing and processing. |
10 // | 10 // |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "base/logging.h" | 29 #include "base/logging.h" |
30 #include "base/macros.h" | 30 #include "base/macros.h" |
31 #include "base/memory/scoped_ptr.h" | 31 #include "base/memory/scoped_ptr.h" |
32 #include "base/strings/string_piece.h" | 32 #include "base/strings/string_piece.h" |
33 #include "net/base/ip_endpoint.h" | 33 #include "net/base/ip_endpoint.h" |
34 #include "net/quic/crypto/quic_decrypter.h" | 34 #include "net/quic/crypto/quic_decrypter.h" |
35 #include "net/quic/quic_alarm.h" | 35 #include "net/quic/quic_alarm.h" |
36 #include "net/quic/quic_blocked_writer_interface.h" | 36 #include "net/quic/quic_blocked_writer_interface.h" |
37 #include "net/quic/quic_fec_group.h" | 37 #include "net/quic/quic_fec_group.h" |
38 #include "net/quic/quic_framer.h" | 38 #include "net/quic/quic_framer.h" |
| 39 #include "net/quic/quic_one_block_arena.h" |
39 #include "net/quic/quic_packet_creator.h" | 40 #include "net/quic/quic_packet_creator.h" |
40 #include "net/quic/quic_packet_generator.h" | 41 #include "net/quic/quic_packet_generator.h" |
41 #include "net/quic/quic_packet_writer.h" | 42 #include "net/quic/quic_packet_writer.h" |
42 #include "net/quic/quic_protocol.h" | 43 #include "net/quic/quic_protocol.h" |
43 #include "net/quic/quic_received_packet_manager.h" | 44 #include "net/quic/quic_received_packet_manager.h" |
44 #include "net/quic/quic_sent_entropy_manager.h" | 45 #include "net/quic/quic_sent_entropy_manager.h" |
45 #include "net/quic/quic_sent_packet_manager.h" | 46 #include "net/quic/quic_sent_packet_manager.h" |
46 #include "net/quic/quic_time.h" | 47 #include "net/quic/quic_time.h" |
47 #include "net/quic/quic_types.h" | 48 #include "net/quic/quic_types.h" |
48 | 49 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 244 |
244 // Called when the connection parameters are set from the supplied | 245 // Called when the connection parameters are set from the supplied |
245 // |config|. | 246 // |config|. |
246 virtual void OnSetFromConfig(const QuicConfig& config) {} | 247 virtual void OnSetFromConfig(const QuicConfig& config) {} |
247 | 248 |
248 // Called when RTT may have changed, including when an RTT is read from | 249 // Called when RTT may have changed, including when an RTT is read from |
249 // the config. | 250 // the config. |
250 virtual void OnRttChanged(QuicTime::Delta rtt) const {} | 251 virtual void OnRttChanged(QuicTime::Delta rtt) const {} |
251 }; | 252 }; |
252 | 253 |
| 254 // QuicConnections currently use around 1KB of polymorphic types which would |
| 255 // ordinarily be on the heap. Instead, store them inline in an arena. |
| 256 using QuicConnectionArena = QuicOneBlockArena<1024>; |
| 257 |
253 class NET_EXPORT_PRIVATE QuicConnectionHelperInterface { | 258 class NET_EXPORT_PRIVATE QuicConnectionHelperInterface { |
254 public: | 259 public: |
255 virtual ~QuicConnectionHelperInterface() {} | 260 virtual ~QuicConnectionHelperInterface() {} |
256 | 261 |
257 // Returns a QuicClock to be used for all time related functions. | 262 // Returns a QuicClock to be used for all time related functions. |
258 virtual const QuicClock* GetClock() const = 0; | 263 virtual const QuicClock* GetClock() const = 0; |
259 | 264 |
260 // Returns a QuicRandom to be used for all random number related functions. | 265 // Returns a QuicRandom to be used for all random number related functions. |
261 virtual QuicRandom* GetRandomGenerator() = 0; | 266 virtual QuicRandom* GetRandomGenerator() = 0; |
262 | 267 |
263 // Creates a new platform-specific alarm which will be configured to | 268 // Creates a new platform-specific alarm which will be configured to notify |
264 // notify |delegate| when the alarm fires. Caller takes ownership | 269 // |delegate| when the alarm fires. Returns an alarm allocated on the heap. |
265 // of the new alarm, which will not yet be "set" to fire. | 270 // Caller takes ownership of the new alarm, which will not yet be "set" to |
| 271 // fire. |
266 virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) = 0; | 272 virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) = 0; |
267 | 273 |
| 274 // Creates a new platform-specific alarm which will be configured to notify |
| 275 // |delegate| when the alarm fires. Caller takes ownership of the new alarm, |
| 276 // which will not yet be "set" to fire. If |arena| is null, then the alarm |
| 277 // will be created on the heap. Otherwise, it will be created in |arena|. |
| 278 virtual QuicArenaScopedPtr<QuicAlarm> CreateAlarm( |
| 279 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate, |
| 280 QuicConnectionArena* arena) = 0; |
| 281 |
268 // Returns a QuicBufferAllocator to be used for all stream frame buffers. | 282 // Returns a QuicBufferAllocator to be used for all stream frame buffers. |
269 virtual QuicBufferAllocator* GetBufferAllocator() = 0; | 283 virtual QuicBufferAllocator* GetBufferAllocator() = 0; |
270 }; | 284 }; |
271 | 285 |
272 class NET_EXPORT_PRIVATE QuicConnection | 286 class NET_EXPORT_PRIVATE QuicConnection |
273 : public QuicFramerVisitorInterface, | 287 : public QuicFramerVisitorInterface, |
274 public QuicBlockedWriterInterface, | 288 public QuicBlockedWriterInterface, |
275 public QuicPacketGenerator::DelegateInterface, | 289 public QuicPacketGenerator::DelegateInterface, |
276 public QuicSentPacketManager::NetworkChangeVisitor { | 290 public QuicSentPacketManager::NetworkChangeVisitor { |
277 public: | 291 public: |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 int stop_waiting_count_; | 877 int stop_waiting_count_; |
864 // When true, ack only every 10 packets as long as they arrive close together. | 878 // When true, ack only every 10 packets as long as they arrive close together. |
865 bool ack_decimation_enabled_; | 879 bool ack_decimation_enabled_; |
866 | 880 |
867 // Indicates the retransmit alarm is going to be set by the | 881 // Indicates the retransmit alarm is going to be set by the |
868 // ScopedRetransmitAlarmDelayer | 882 // ScopedRetransmitAlarmDelayer |
869 bool delay_setting_retransmission_alarm_; | 883 bool delay_setting_retransmission_alarm_; |
870 // Indicates the retransmission alarm needs to be set. | 884 // Indicates the retransmission alarm needs to be set. |
871 bool pending_retransmission_alarm_; | 885 bool pending_retransmission_alarm_; |
872 | 886 |
| 887 // Arena to store class implementations within the QuicConnection. |
| 888 QuicConnectionArena arena_; |
| 889 |
873 // An alarm that fires when an ACK should be sent to the peer. | 890 // An alarm that fires when an ACK should be sent to the peer. |
874 scoped_ptr<QuicAlarm> ack_alarm_; | 891 QuicArenaScopedPtr<QuicAlarm> ack_alarm_; |
875 // An alarm that fires when a packet needs to be retransmitted. | 892 // An alarm that fires when a packet needs to be retransmitted. |
876 scoped_ptr<QuicAlarm> retransmission_alarm_; | 893 QuicArenaScopedPtr<QuicAlarm> retransmission_alarm_; |
877 // An alarm that is scheduled when the SentPacketManager requires a delay | 894 // An alarm that is scheduled when the SentPacketManager requires a delay |
878 // before sending packets and fires when the packet may be sent. | 895 // before sending packets and fires when the packet may be sent. |
879 scoped_ptr<QuicAlarm> send_alarm_; | 896 QuicArenaScopedPtr<QuicAlarm> send_alarm_; |
880 // An alarm that is scheduled when the connection can still write and there | 897 // An alarm that is scheduled when the connection can still write and there |
881 // may be more data to send. | 898 // may be more data to send. |
882 scoped_ptr<QuicAlarm> resume_writes_alarm_; | 899 QuicArenaScopedPtr<QuicAlarm> resume_writes_alarm_; |
883 // An alarm that fires when the connection may have timed out. | 900 // An alarm that fires when the connection may have timed out. |
884 scoped_ptr<QuicAlarm> timeout_alarm_; | 901 QuicArenaScopedPtr<QuicAlarm> timeout_alarm_; |
885 // An alarm that fires when a ping should be sent. | 902 // An alarm that fires when a ping should be sent. |
886 scoped_ptr<QuicAlarm> ping_alarm_; | 903 QuicArenaScopedPtr<QuicAlarm> ping_alarm_; |
887 // An alarm that fires when an MTU probe should be sent. | 904 // An alarm that fires when an MTU probe should be sent. |
888 scoped_ptr<QuicAlarm> mtu_discovery_alarm_; | 905 QuicArenaScopedPtr<QuicAlarm> mtu_discovery_alarm_; |
889 | 906 |
890 // Neither visitor is owned by this class. | 907 // Neither visitor is owned by this class. |
891 QuicConnectionVisitorInterface* visitor_; | 908 QuicConnectionVisitorInterface* visitor_; |
892 QuicConnectionDebugVisitor* debug_visitor_; | 909 QuicConnectionDebugVisitor* debug_visitor_; |
893 | 910 |
894 QuicPacketGenerator packet_generator_; | 911 QuicPacketGenerator packet_generator_; |
895 | 912 |
896 // An alarm that fires when an FEC packet should be sent. | 913 // An alarm that fires when an FEC packet should be sent. |
897 scoped_ptr<QuicAlarm> fec_alarm_; | 914 QuicArenaScopedPtr<QuicAlarm> fec_alarm_; |
898 | 915 |
899 // Network idle time before we kill of this connection. | 916 // Network idle time before we kill of this connection. |
900 QuicTime::Delta idle_network_timeout_; | 917 QuicTime::Delta idle_network_timeout_; |
901 // Overall connection timeout. | 918 // Overall connection timeout. |
902 QuicTime::Delta overall_connection_timeout_; | 919 QuicTime::Delta overall_connection_timeout_; |
903 | 920 |
904 // Statistics for this session. | 921 // Statistics for this session. |
905 QuicConnectionStats stats_; | 922 QuicConnectionStats stats_; |
906 | 923 |
907 // The time that we got a packet for this connection. | 924 // The time that we got a packet for this connection. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 | 998 |
982 // If true, multipath is enabled for this connection. | 999 // If true, multipath is enabled for this connection. |
983 bool multipath_enabled_; | 1000 bool multipath_enabled_; |
984 | 1001 |
985 DISALLOW_COPY_AND_ASSIGN(QuicConnection); | 1002 DISALLOW_COPY_AND_ASSIGN(QuicConnection); |
986 }; | 1003 }; |
987 | 1004 |
988 } // namespace net | 1005 } // namespace net |
989 | 1006 |
990 #endif // NET_QUIC_QUIC_CONNECTION_H_ | 1007 #endif // NET_QUIC_QUIC_CONNECTION_H_ |
OLD | NEW |