| 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 | 13 |
| 14 using std::string; | 14 using std::string; |
| 15 using base::StringPiece; | 15 using base::StringPiece; |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 QuicCryptoStream::QuicCryptoStream(QuicSession* session) | 19 QuicCryptoStream::QuicCryptoStream(QuicSession* session) |
| 20 : ReliableQuicStream(kCryptoStreamId, session), | 20 : ReliableQuicStream(kCryptoStreamId, session), |
| 21 handshake_complete_(false) { | 21 encryption_established_(false), |
| 22 handshake_confirmed_(false) { |
| 22 crypto_framer_.set_visitor(this); | 23 crypto_framer_.set_visitor(this); |
| 23 } | 24 } |
| 24 | 25 |
| 25 void QuicCryptoStream::OnError(CryptoFramer* framer) { | 26 void QuicCryptoStream::OnError(CryptoFramer* framer) { |
| 26 session()->ConnectionClose(framer->error(), false); | 27 session()->ConnectionClose(framer->error(), false); |
| 27 } | 28 } |
| 28 | 29 |
| 29 uint32 QuicCryptoStream::ProcessData(const char* data, | 30 uint32 QuicCryptoStream::ProcessData(const char* data, |
| 30 uint32 data_len) { | 31 uint32 data_len) { |
| 31 // Do not process handshake messages after the handshake is complete. | 32 // Do not process handshake messages after the handshake is confirmed. |
| 32 if (handshake_complete()) { | 33 if (handshake_confirmed()) { |
| 33 CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE); | 34 CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE); |
| 34 return 0; | 35 return 0; |
| 35 } | 36 } |
| 36 if (!crypto_framer_.ProcessInput(StringPiece(data, data_len))) { | 37 if (!crypto_framer_.ProcessInput(StringPiece(data, data_len))) { |
| 37 CloseConnection(crypto_framer_.error()); | 38 CloseConnection(crypto_framer_.error()); |
| 38 return 0; | 39 return 0; |
| 39 } | 40 } |
| 40 return data_len; | 41 return data_len; |
| 41 } | 42 } |
| 42 | 43 |
| 43 void QuicCryptoStream::CloseConnection(QuicErrorCode error) { | 44 void QuicCryptoStream::CloseConnection(QuicErrorCode error) { |
| 44 session()->connection()->SendConnectionClose(error); | 45 session()->connection()->SendConnectionClose(error); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void QuicCryptoStream::CloseConnectionWithDetails(QuicErrorCode error, | 48 void QuicCryptoStream::CloseConnectionWithDetails(QuicErrorCode error, |
| 48 const string& details) { | 49 const string& details) { |
| 49 session()->connection()->SendConnectionCloseWithDetails(error, details); | 50 session()->connection()->SendConnectionCloseWithDetails(error, details); |
| 50 } | 51 } |
| 51 | 52 |
| 52 void QuicCryptoStream::SetHandshakeComplete(QuicErrorCode error) { | |
| 53 handshake_complete_ = true; | |
| 54 session()->OnCryptoHandshakeComplete(error); | |
| 55 } | |
| 56 | |
| 57 void QuicCryptoStream::SendHandshakeMessage( | 53 void QuicCryptoStream::SendHandshakeMessage( |
| 58 const CryptoHandshakeMessage& message) { | 54 const CryptoHandshakeMessage& message) { |
| 59 const QuicData& data = message.GetSerialized(); | 55 const QuicData& data = message.GetSerialized(); |
| 60 // TODO(wtc): check the return value. | 56 // TODO(wtc): check the return value. |
| 61 WriteData(string(data.data(), data.length()), false); | 57 WriteData(string(data.data(), data.length()), false); |
| 62 } | 58 } |
| 63 | 59 |
| 64 } // namespace net | 60 } // namespace net |
| OLD | NEW |