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 // A server specific QuicSession subclass.
      6 
      7 #ifndef NET_TOOLS_QUIC_QUIC_SERVER_SESSION_H_
      8 #define NET_TOOLS_QUIC_QUIC_SERVER_SESSION_H_
      9 
     10 #include <set>
     11 #include <vector>
     12 
     13 #include "base/containers/hash_tables.h"
     14 #include "base/memory/scoped_ptr.h"
     15 #include "net/quic/quic_crypto_server_stream.h"
     16 #include "net/quic/quic_protocol.h"
     17 #include "net/quic/quic_session.h"
     18 
     19 namespace net {
     20 
     21 class QuicConfig;
     22 class QuicConnection;
     23 class QuicCryptoServerConfig;
     24 class ReliableQuicStream;
     25 
     26 namespace tools {
     27 
     28 // An interface from the session to the entity owning the session.
     29 // This lets the session notify its owner (the Dispatcher) when the connection
     30 // is closed.
     31 class QuicSessionOwner {
     32  public:
     33   virtual ~QuicSessionOwner() {}
     34 
     35   virtual void OnConnectionClose(QuicGuid guid, QuicErrorCode error) = 0;
     36 };
     37 
     38 class QuicServerSession : public QuicSession {
     39  public:
     40   QuicServerSession(const QuicConfig& config,
     41                     QuicConnection *connection,
     42                     QuicSessionOwner* owner);
     43 
     44   // Override the base class to notify the owner of the connection close.
     45   virtual void ConnectionClose(QuicErrorCode error, bool from_peer) OVERRIDE;
     46 
     47   virtual ~QuicServerSession();
     48 
     49   virtual void InitializeSession(const QuicCryptoServerConfig& crypto_config);
     50 
     51   const QuicCryptoServerStream* crypto_stream() { return crypto_stream_.get(); }
     52 
     53  protected:
     54   // QuicSession methods:
     55   virtual ReliableQuicStream* CreateIncomingReliableStream(
     56       QuicStreamId id) OVERRIDE;
     57   virtual ReliableQuicStream* CreateOutgoingReliableStream() OVERRIDE;
     58   virtual QuicCryptoServerStream* GetCryptoStream() OVERRIDE;
     59 
     60   // If we should create an incoming stream, returns true. Otherwise
     61   // does error handling, including communicating the error to the client and
     62   // possibly closing the connection, and returns false.
     63   virtual bool ShouldCreateIncomingReliableStream(QuicStreamId id);
     64 
     65   virtual QuicCryptoServerStream* CreateQuicCryptoServerStream(
     66     const QuicCryptoServerConfig& crypto_config);
     67 
     68  private:
     69   scoped_ptr<QuicCryptoServerStream> crypto_stream_;
     70   QuicSessionOwner* owner_;
     71 
     72   DISALLOW_COPY_AND_ASSIGN(QuicServerSession);
     73 };
     74 
     75 }  // namespace tools
     76 }  // namespace net
     77 
     78 #endif  // NET_TOOLS_QUIC_QUIC_SERVER_SESSION_H_
     79