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