Chromium Code Reviews| 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 #include "net/quic/quic_client_session.h" | 5 #include "net/quic/quic_client_session.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 #include "net/quic/quic_connection_helper.h" | 13 #include "net/quic/quic_connection_helper.h" |
| 14 #include "net/quic/quic_stream_factory.h" | 14 #include "net/quic/quic_stream_factory.h" |
| 15 #include "net/udp/datagram_client_socket.h" | 15 #include "net/udp/datagram_client_socket.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 namespace { | |
| 20 | |
| 21 Value* NetLogQuicSessionCallback(const std::string& host, | |
|
eroman
2013/02/05 23:52:40
Delete.
Ryan Hamilton
2013/02/06 16:40:15
Whoops! Done. Sorry.
| |
| 22 NetLog::LogLevel /* log_level */) { | |
| 23 DictionaryValue* dict = new DictionaryValue(); | |
| 24 dict->SetString("host", host); | |
| 25 return dict; | |
| 26 } | |
| 27 | |
| 28 Value* NetLogQuicSessionCloseOnErrorCallback(int error, | |
|
eroman
2013/02/05 23:52:40
Delete.
Ryan Hamilton
2013/02/06 16:40:15
Done.
| |
| 29 NetLog::LogLevel /* log_level */) { | |
| 30 DictionaryValue* dict = new DictionaryValue(); | |
| 31 dict->SetInteger("net_error", error); | |
| 32 return dict; | |
| 33 } | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 19 QuicClientSession::QuicClientSession(QuicConnection* connection, | 37 QuicClientSession::QuicClientSession(QuicConnection* connection, |
| 20 QuicConnectionHelper* helper, | 38 QuicConnectionHelper* helper, |
| 21 QuicStreamFactory* stream_factory, | 39 QuicStreamFactory* stream_factory, |
| 22 const string& server_hostname) | 40 const string& server_hostname, |
| 41 NetLog* net_log) | |
| 23 : QuicSession(connection, false), | 42 : QuicSession(connection, false), |
| 24 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 43 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 25 ALLOW_THIS_IN_INITIALIZER_LIST(crypto_stream_(this, server_hostname)), | 44 ALLOW_THIS_IN_INITIALIZER_LIST(crypto_stream_(this, server_hostname)), |
| 26 helper_(helper), | 45 helper_(helper), |
| 27 stream_factory_(stream_factory), | 46 stream_factory_(stream_factory), |
| 28 read_buffer_(new IOBufferWithSize(kMaxPacketSize)), | 47 read_buffer_(new IOBufferWithSize(kMaxPacketSize)), |
| 29 read_pending_(false) { | 48 read_pending_(false), |
| 49 num_total_streams_(0), | |
| 50 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)) { | |
|
eroman
2013/02/05 23:52:40
the fact that it is QUIC and not QUICK keeps blowi
Ryan Hamilton
2013/02/06 16:40:15
:>
| |
| 51 // TODO(rch): pass in full host port proxy pair | |
| 52 net_log_.BeginEvent( | |
| 53 NetLog::TYPE_QUIC_SESSION, | |
| 54 NetLog::StringCallback("host", &server_hostname)); | |
| 30 } | 55 } |
| 31 | 56 |
| 32 QuicClientSession::~QuicClientSession() { | 57 QuicClientSession::~QuicClientSession() { |
| 58 net_log_.EndEvent(NetLog::TYPE_QUIC_SESSION); | |
| 33 } | 59 } |
| 34 | 60 |
| 35 QuicReliableClientStream* QuicClientSession::CreateOutgoingReliableStream() { | 61 QuicReliableClientStream* QuicClientSession::CreateOutgoingReliableStream() { |
| 36 if (!crypto_stream_.handshake_complete()) { | 62 if (!crypto_stream_.handshake_complete()) { |
| 37 DLOG(INFO) << "Crypto handshake not complete, no outgoing stream created."; | 63 DLOG(INFO) << "Crypto handshake not complete, no outgoing stream created."; |
| 38 return NULL; | 64 return NULL; |
| 39 } | 65 } |
| 40 if (GetNumOpenStreams() >= get_max_open_streams()) { | 66 if (GetNumOpenStreams() >= get_max_open_streams()) { |
| 41 DLOG(INFO) << "Failed to create a new outgoing stream. " | 67 DLOG(INFO) << "Failed to create a new outgoing stream. " |
| 42 << "Already " << GetNumOpenStreams() << " open."; | 68 << "Already " << GetNumOpenStreams() << " open."; |
| 43 return NULL; | 69 return NULL; |
| 44 } | 70 } |
| 45 QuicReliableClientStream* stream = | 71 QuicReliableClientStream* stream = |
| 46 new QuicReliableClientStream(GetNextStreamId(), this); | 72 new QuicReliableClientStream(GetNextStreamId(), this, net_log_); |
| 47 ActivateStream(stream); | 73 ActivateStream(stream); |
| 74 ++num_total_streams_; | |
|
eroman
2013/02/05 23:52:40
Not familiar with this code, but should num_total_
Ryan Hamilton
2013/02/06 16:40:15
No, it should not. It is the total number of stre
| |
| 48 return stream; | 75 return stream; |
| 49 } | 76 } |
| 50 | 77 |
| 51 QuicCryptoClientStream* QuicClientSession::GetCryptoStream() { | 78 QuicCryptoClientStream* QuicClientSession::GetCryptoStream() { |
| 52 return &crypto_stream_; | 79 return &crypto_stream_; |
| 53 }; | 80 }; |
| 54 | 81 |
| 55 int QuicClientSession::CryptoConnect(const CompletionCallback& callback) { | 82 int QuicClientSession::CryptoConnect(const CompletionCallback& callback) { |
| 56 if (!crypto_stream_.CryptoConnect()) { | 83 if (!crypto_stream_.CryptoConnect()) { |
| 57 // TODO(wtc): change crypto_stream_.CryptoConnect() to return a | 84 // TODO(wtc): change crypto_stream_.CryptoConnect() to return a |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 } | 136 } |
| 110 | 137 |
| 111 void QuicClientSession::CloseSessionOnError(int error) { | 138 void QuicClientSession::CloseSessionOnError(int error) { |
| 112 while (!streams()->empty()) { | 139 while (!streams()->empty()) { |
| 113 ReliableQuicStream* stream = streams()->begin()->second; | 140 ReliableQuicStream* stream = streams()->begin()->second; |
| 114 QuicStreamId id = stream->id(); | 141 QuicStreamId id = stream->id(); |
| 115 static_cast<QuicReliableClientStream*>(stream)->OnError(error); | 142 static_cast<QuicReliableClientStream*>(stream)->OnError(error); |
| 116 CloseStream(id); | 143 CloseStream(id); |
| 117 } | 144 } |
| 118 stream_factory_->OnSessionClose(this); | 145 stream_factory_->OnSessionClose(this); |
| 146 net_log_.BeginEvent( | |
| 147 NetLog::TYPE_QUIC_SESSION, | |
| 148 NetLog::IntegerCallback("error", error)); | |
|
eroman
2013/02/05 23:52:40
"error" --> "net_error", per the documentation
Ryan Hamilton
2013/02/06 16:40:15
Argh! I changed it in the callback I wrote, but s
| |
| 119 } | 149 } |
| 120 | 150 |
| 121 Value* QuicClientSession::GetInfoAsValue(const HostPortPair& pair) const { | 151 Value* QuicClientSession::GetInfoAsValue(const HostPortPair& pair) const { |
| 122 DictionaryValue* dict = new DictionaryValue(); | 152 DictionaryValue* dict = new DictionaryValue(); |
| 123 dict->SetString("host_port_pair", pair.ToString()); | 153 dict->SetString("host_port_pair", pair.ToString()); |
| 124 dict->SetInteger("open_streams", GetNumOpenStreams()); | 154 dict->SetInteger("open_streams", GetNumOpenStreams()); |
| 155 dict->SetInteger("total_streams", num_total_streams_); | |
| 125 dict->SetString("peer_address", peer_address().ToString()); | 156 dict->SetString("peer_address", peer_address().ToString()); |
| 126 dict->SetString("guid", base::Uint64ToString(guid())); | 157 dict->SetString("guid", base::Uint64ToString(guid())); |
| 127 return dict; | 158 return dict; |
| 128 } | 159 } |
| 129 | 160 |
| 130 void QuicClientSession::OnReadComplete(int result) { | 161 void QuicClientSession::OnReadComplete(int result) { |
| 131 read_pending_ = false; | 162 read_pending_ = false; |
| 132 // TODO(rch): Inform the connection about the result. | 163 // TODO(rch): Inform the connection about the result. |
| 133 if (result > 0) { | 164 if (result > 0) { |
| 134 scoped_refptr<IOBufferWithSize> buffer(read_buffer_); | 165 scoped_refptr<IOBufferWithSize> buffer(read_buffer_); |
| 135 read_buffer_ = new IOBufferWithSize(kMaxPacketSize); | 166 read_buffer_ = new IOBufferWithSize(kMaxPacketSize); |
| 136 QuicEncryptedPacket packet(buffer->data(), result); | 167 QuicEncryptedPacket packet(buffer->data(), result); |
| 137 IPEndPoint local_address; | 168 IPEndPoint local_address; |
| 138 IPEndPoint peer_address; | 169 IPEndPoint peer_address; |
| 139 helper_->GetLocalAddress(&local_address); | 170 helper_->GetLocalAddress(&local_address); |
| 140 helper_->GetPeerAddress(&peer_address); | 171 helper_->GetPeerAddress(&peer_address); |
| 141 // ProcessUdpPacket might result in |this| being deleted, so we | 172 // ProcessUdpPacket might result in |this| being deleted, so we |
| 142 // use a weak pointer to be safe. | 173 // use a weak pointer to be safe. |
| 143 connection()->ProcessUdpPacket(local_address, peer_address, packet); | 174 connection()->ProcessUdpPacket(local_address, peer_address, packet); |
| 144 if (!connection()->connected()) { | 175 if (!connection()->connected()) { |
| 145 stream_factory_->OnSessionClose(this); | 176 stream_factory_->OnSessionClose(this); |
| 146 return; | 177 return; |
| 147 } | 178 } |
| 148 StartReading(); | 179 StartReading(); |
| 149 } | 180 } |
| 150 } | 181 } |
| 151 | 182 |
| 152 } // namespace net | 183 } // namespace net |
| OLD | NEW |