quic_server_session.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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
19namespace net {
20
21class QuicConfig;
22class QuicConnection;
23class QuicCryptoServerConfig;
24class ReliableQuicStream;
25
26namespace 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.
31class QuicSessionOwner {
32 public:
33  virtual ~QuicSessionOwner() {}
34
35  virtual void OnConnectionClose(QuicGuid guid, QuicErrorCode error) = 0;
36};
37
38class 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 protected:
52  // QuicSession methods:
53  virtual ReliableQuicStream* CreateIncomingReliableStream(
54      QuicStreamId id) OVERRIDE;
55  virtual ReliableQuicStream* CreateOutgoingReliableStream() OVERRIDE;
56  virtual QuicCryptoServerStream* GetCryptoStream() OVERRIDE;
57
58  // If we should create an incoming stream, returns true. Otherwise
59  // does error handling, including communicating the error to the client and
60  // possibly closing the connection, and returns false.
61  virtual bool ShouldCreateIncomingReliableStream(QuicStreamId id);
62
63  virtual QuicCryptoServerStream* CreateQuicCryptoServerStream(
64    const QuicCryptoServerConfig& crypto_config);
65
66 private:
67  scoped_ptr<QuicCryptoServerStream> crypto_stream_;
68  QuicSessionOwner* owner_;
69
70  DISALLOW_COPY_AND_ASSIGN(QuicServerSession);
71};
72
73}  // namespace tools
74}  // namespace net
75
76#endif  // NET_TOOLS_QUIC_QUIC_SERVER_SESSION_H_
77