| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_config.h" |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/strings/string_piece.h" | |
| 10 #include "net/quic/crypto/crypto_handshake.h" | |
| 11 #include "net/quic/quic_connection.h" | |
| 12 #include "net/quic/quic_session.h" | |
| 13 | 6 |
| 14 using std::string; | 7 using std::string; |
| 15 using base::StringPiece; | |
| 16 | 8 |
| 17 namespace net { | 9 namespace net { |
| 18 | 10 |
| 19 QuicCryptoStream::QuicCryptoStream(QuicSession* session) | |
| 20 : ReliableQuicStream(kCryptoStreamId, session), | |
| 21 handshake_complete_(false) { | |
| 22 crypto_framer_.set_visitor(this); | |
| 23 } | |
| 24 | |
| 25 void QuicCryptoStream::OnError(CryptoFramer* framer) { | |
| 26 session()->ConnectionClose(framer->error(), false); | |
| 27 } | |
| 28 | |
| 29 uint32 QuicCryptoStream::ProcessData(const char* data, | |
| 30 uint32 data_len) { | |
| 31 // Do not process handshake messages after the handshake is complete. | |
| 32 if (handshake_complete()) { | |
| 33 CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE); | |
| 34 return 0; | |
| 35 } | |
| 36 if (!crypto_framer_.ProcessInput(StringPiece(data, data_len))) { | |
| 37 CloseConnection(crypto_framer_.error()); | |
| 38 return 0; | |
| 39 } | |
| 40 return data_len; | |
| 41 } | |
| 42 | |
| 43 void QuicCryptoStream::CloseConnection(QuicErrorCode error) { | |
| 44 session()->connection()->SendConnectionClose(error); | |
| 45 } | |
| 46 | |
| 47 void QuicCryptoStream::CloseConnectionWithDetails(QuicErrorCode error, | |
| 48 const string& details) { | |
| 49 session()->connection()->SendConnectionCloseWithDetails(error, details); | |
| 50 } | |
| 51 | |
| 52 void QuicCryptoStream::SetHandshakeComplete(QuicErrorCode error) { | |
| 53 handshake_complete_ = true; | |
| 54 session()->OnCryptoHandshakeComplete(error); | |
| 55 } | |
| 56 | |
| 57 void QuicCryptoStream::SendHandshakeMessage( | |
| 58 const CryptoHandshakeMessage& message) { | |
| 59 const QuicData& data = message.GetSerialized(); | |
| 60 // TODO(wtc): check the return value. | |
| 61 WriteData(string(data.data(), data.length()), false); | |
| 62 } | |
| 63 | |
| 64 QuicNegotiatedParameters::QuicNegotiatedParameters() | 11 QuicNegotiatedParameters::QuicNegotiatedParameters() |
| 65 : idle_connection_state_lifetime(QuicTime::Delta::Zero()), | 12 : idle_connection_state_lifetime(QuicTime::Delta::Zero()), |
| 66 keepalive_timeout(QuicTime::Delta::Zero()) { | 13 keepalive_timeout(QuicTime::Delta::Zero()) { |
| 67 } | 14 } |
| 68 | 15 |
| 69 QuicConfig::QuicConfig() | 16 QuicConfig::QuicConfig() |
| 70 : idle_connection_state_lifetime_(QuicTime::Delta::Zero()), | 17 : idle_connection_state_lifetime_(QuicTime::Delta::Zero()), |
| 71 keepalive_timeout_(QuicTime::Delta::Zero()) { | 18 keepalive_timeout_(QuicTime::Delta::Zero()) { |
| 72 } | 19 } |
| 73 | 20 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 91 return false; | 38 return false; |
| 92 } | 39 } |
| 93 | 40 |
| 94 congestion_control_.assign(cgst, cgst + num_cgst); | 41 congestion_control_.assign(cgst, cgst + num_cgst); |
| 95 | 42 |
| 96 uint32 idle; | 43 uint32 idle; |
| 97 error = scfg.GetUint32(kICSL, &idle); | 44 error = scfg.GetUint32(kICSL, &idle); |
| 98 if (error != QUIC_NO_ERROR) { | 45 if (error != QUIC_NO_ERROR) { |
| 99 return false; | 46 return false; |
| 100 } | 47 } |
| 101 | |
| 102 idle_connection_state_lifetime_ = QuicTime::Delta::FromSeconds(idle); | 48 idle_connection_state_lifetime_ = QuicTime::Delta::FromSeconds(idle); |
| 103 | 49 |
| 104 keepalive_timeout_ = QuicTime::Delta::Zero(); | 50 keepalive_timeout_ = QuicTime::Delta::Zero(); |
| 105 | 51 |
| 106 uint32 keepalive; | 52 uint32 keepalive; |
| 107 error = scfg.GetUint32(kKATO, &keepalive); | 53 error = scfg.GetUint32(kKATO, &keepalive); |
| 108 // KATO is optional. | 54 // KATO is optional. |
| 109 if (error == QUIC_NO_ERROR) { | 55 if (error == QUIC_NO_ERROR) { |
| 110 keepalive_timeout_ = QuicTime::Delta::FromSeconds(keepalive); | 56 keepalive_timeout_ = QuicTime::Delta::FromSeconds(keepalive); |
| 111 } | 57 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 if (error_details) { | 125 if (error_details) { |
| 180 *error_details = "Bad KATO"; | 126 *error_details = "Bad KATO"; |
| 181 } | 127 } |
| 182 return error; | 128 return error; |
| 183 } | 129 } |
| 184 | 130 |
| 185 return QUIC_NO_ERROR; | 131 return QUIC_NO_ERROR; |
| 186 } | 132 } |
| 187 | 133 |
| 188 } // namespace net | 134 } // namespace net |
| 135 |
| OLD | NEW |