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 #include "net/quic/quic_utils.h"
     14 
     15 using std::string;
     16 using base::StringPiece;
     17 
     18 namespace net {
     19 
     20 QuicCryptoStream::QuicCryptoStream(QuicSession* session)
     21     : ReliableQuicStream(kCryptoStreamId, session),
     22       encryption_established_(false),
     23       handshake_confirmed_(false) {
     24   crypto_framer_.set_visitor(this);
     25   DisableFlowControl();
     26 }
     27 
     28 void QuicCryptoStream::OnError(CryptoFramer* framer) {
     29   DLOG(WARNING) << "Error processing crypto data: "
     30                 << QuicUtils::ErrorToString(framer->error());
     31 }
     32 
     33 void QuicCryptoStream::OnHandshakeMessage(
     34     const CryptoHandshakeMessage& message) {
     35   session()->OnCryptoHandshakeMessageReceived(message);
     36 }
     37 
     38 uint32 QuicCryptoStream::ProcessRawData(const char* data,
     39                                         uint32 data_len) {
     40   // Do not process handshake messages after the handshake is confirmed.
     41   if (handshake_confirmed()) {
     42     CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE);
     43     return 0;
     44   }
     45   if (!crypto_framer_.ProcessInput(StringPiece(data, data_len))) {
     46     CloseConnection(crypto_framer_.error());
     47     return 0;
     48   }
     49   return data_len;
     50 }
     51 
     52 QuicPriority QuicCryptoStream::EffectivePriority() const {
     53   return QuicUtils::HighestPriority();
     54 }
     55 
     56 void QuicCryptoStream::SendHandshakeMessage(
     57     const CryptoHandshakeMessage& message) {
     58   session()->OnCryptoHandshakeMessageSent(message);
     59   const QuicData& data = message.GetSerialized();
     60   // TODO(wtc): check the return value.
     61   WriteOrBufferData(string(data.data(), data.length()), false, NULL);
     62 }
     63 
     64 const QuicCryptoNegotiatedParameters&
     65 QuicCryptoStream::crypto_negotiated_params() const {
     66   return crypto_negotiated_params_;
     67 }
     68 
     69 }  // namespace net
     70