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_crypto_stream.h" | 5 #include "net/quic/quic_crypto_stream.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
10 #include "net/quic/crypto/crypto_handshake.h" | 10 #include "net/quic/crypto/crypto_handshake.h" |
11 #include "net/quic/quic_connection.h" | 11 #include "net/quic/quic_connection.h" |
12 #include "net/quic/quic_session.h" | 12 #include "net/quic/quic_session.h" |
13 #include "net/quic/quic_utils.h" | 13 #include "net/quic/quic_utils.h" |
14 | 14 |
15 using std::string; | 15 using std::string; |
16 using base::StringPiece; | 16 using base::StringPiece; |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 | 19 |
| 20 #define ENDPOINT (is_server_ ? "Server: " : " Client: ") |
| 21 |
20 QuicCryptoStream::QuicCryptoStream(QuicSession* session) | 22 QuicCryptoStream::QuicCryptoStream(QuicSession* session) |
21 : ReliableQuicStream(kCryptoStreamId, session), | 23 : ReliableQuicStream(kCryptoStreamId, session), |
22 encryption_established_(false), | 24 encryption_established_(false), |
23 handshake_confirmed_(false) { | 25 handshake_confirmed_(false), |
| 26 is_server_(session->is_server()) { |
24 crypto_framer_.set_visitor(this); | 27 crypto_framer_.set_visitor(this); |
25 if (version() <= QUIC_VERSION_20) { | 28 if (version() <= QUIC_VERSION_20) { |
26 // Prior to QUIC_VERSION_21 the crypto stream is not subject to any flow | 29 // Prior to QUIC_VERSION_21 the crypto stream is not subject to any flow |
27 // control. | 30 // control. |
28 DisableFlowControl(); | 31 DisableFlowControl(); |
29 } | 32 } |
30 // The crypto stream is exempt from connection level flow control. | 33 // The crypto stream is exempt from connection level flow control. |
31 DisableConnectionFlowControlForThisStream(); | 34 DisableConnectionFlowControlForThisStream(); |
32 } | 35 } |
33 | 36 |
34 void QuicCryptoStream::OnError(CryptoFramer* framer) { | 37 void QuicCryptoStream::OnError(CryptoFramer* framer) { |
35 DLOG(WARNING) << "Error processing crypto data: " | 38 DLOG(WARNING) << "Error processing crypto data: " |
36 << QuicUtils::ErrorToString(framer->error()); | 39 << QuicUtils::ErrorToString(framer->error()); |
37 } | 40 } |
38 | 41 |
39 void QuicCryptoStream::OnHandshakeMessage( | 42 void QuicCryptoStream::OnHandshakeMessage( |
40 const CryptoHandshakeMessage& message) { | 43 const CryptoHandshakeMessage& message) { |
| 44 DVLOG(1) << ENDPOINT << "Received " << message.DebugString(); |
41 session()->OnCryptoHandshakeMessageReceived(message); | 45 session()->OnCryptoHandshakeMessageReceived(message); |
42 } | 46 } |
43 | 47 |
44 uint32 QuicCryptoStream::ProcessRawData(const char* data, | 48 uint32 QuicCryptoStream::ProcessRawData(const char* data, |
45 uint32 data_len) { | 49 uint32 data_len) { |
46 if (!crypto_framer_.ProcessInput(StringPiece(data, data_len))) { | 50 if (!crypto_framer_.ProcessInput(StringPiece(data, data_len))) { |
47 CloseConnection(crypto_framer_.error()); | 51 CloseConnection(crypto_framer_.error()); |
48 return 0; | 52 return 0; |
49 } | 53 } |
50 return data_len; | 54 return data_len; |
51 } | 55 } |
52 | 56 |
53 QuicPriority QuicCryptoStream::EffectivePriority() const { | 57 QuicPriority QuicCryptoStream::EffectivePriority() const { |
54 return QuicUtils::HighestPriority(); | 58 return QuicUtils::HighestPriority(); |
55 } | 59 } |
56 | 60 |
57 void QuicCryptoStream::SendHandshakeMessage( | 61 void QuicCryptoStream::SendHandshakeMessage( |
58 const CryptoHandshakeMessage& message) { | 62 const CryptoHandshakeMessage& message) { |
| 63 DVLOG(1) << ENDPOINT << "Sending " << message.DebugString(); |
59 session()->OnCryptoHandshakeMessageSent(message); | 64 session()->OnCryptoHandshakeMessageSent(message); |
60 const QuicData& data = message.GetSerialized(); | 65 const QuicData& data = message.GetSerialized(); |
61 // TODO(wtc): check the return value. | 66 // TODO(wtc): check the return value. |
62 WriteOrBufferData(string(data.data(), data.length()), false, NULL); | 67 WriteOrBufferData(string(data.data(), data.length()), false, NULL); |
63 } | 68 } |
64 | 69 |
65 const QuicCryptoNegotiatedParameters& | 70 const QuicCryptoNegotiatedParameters& |
66 QuicCryptoStream::crypto_negotiated_params() const { | 71 QuicCryptoStream::crypto_negotiated_params() const { |
67 return crypto_negotiated_params_; | 72 return crypto_negotiated_params_; |
68 } | 73 } |
69 | 74 |
70 } // namespace net | 75 } // namespace net |
OLD | NEW |