Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / quic / p2p / quic_p2p_session.h
blob992e7b59c6c3eecc034c9519e335f35a492f579e
1 // Copyright 2015 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.
5 #ifndef NET_QUIC_P2P_QUIC_P2P_SESSION_H_
6 #define NET_QUIC_P2P_QUIC_P2P_SESSION_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_piece.h"
11 #include "net/quic/p2p/quic_p2p_stream.h"
12 #include "net/quic/quic_client_session_base.h"
13 #include "net/quic/quic_protocol.h"
15 namespace net {
17 class QuicConfig;
18 class QuicConnection;
19 class QuicP2PCryptoStream;
20 class QuicP2PCryptoConfig;
21 class Socket;
22 class IOBuffer;
24 // QuicP2PSession represents a QUIC session over peer-to-peer transport
25 // specified by |socket|. There is no handshake performed by this class, i.e.
26 // the handshake is expected to happen out-of-bound before QuicP2PSession is
27 // created. The out-of-bound handshake should generate the following parameters
28 // passed to the constructor:
29 // 1. Negotiated QuicConfig.
30 // 2. Secret key exchanged with the peer on the other end of the |socket|.
31 // This key is passed to the constructor as part of the |crypto_config|.
32 class NET_EXPORT QuicP2PSession : public QuicSession {
33 public:
34 class Delegate {
35 public:
36 virtual void OnIncomingStream(QuicP2PStream* stream) = 0;
38 virtual void OnConnectionClosed(QuicErrorCode error) = 0;
41 // |config| must be already negotiated. |crypto_config| contains a secret key
42 // shared with the peer.
43 QuicP2PSession(const QuicConfig& config,
44 const QuicP2PCryptoConfig& crypto_config,
45 scoped_ptr<QuicConnection> connection,
46 scoped_ptr<Socket> socket);
47 ~QuicP2PSession() override;
49 // QuicSession overrides.
50 void Initialize() override;
51 QuicP2PStream* CreateOutgoingDynamicStream() override;
53 // QuicConnectionVisitorInterface overrides.
54 void OnConnectionClosed(QuicErrorCode error, bool from_peer) override;
56 void SetDelegate(Delegate* delegate);
58 protected:
59 // QuicSession overrides.
60 QuicCryptoStream* GetCryptoStream() override;
61 QuicP2PStream* CreateIncomingDynamicStream(QuicStreamId id) override;
63 QuicP2PSession* CreateDataStream(QuicStreamId id);
65 private:
66 enum ReadState {
67 READ_STATE_DO_READ,
68 READ_STATE_DO_READ_COMPLETE,
71 void DoReadLoop(int result);
72 int DoRead();
73 int DoReadComplete(int result);
75 scoped_ptr<Socket> socket_;
76 scoped_ptr<QuicP2PCryptoStream> crypto_stream_;
78 Delegate* delegate_ = nullptr;
80 ReadState read_state_ = READ_STATE_DO_READ;
81 scoped_refptr<IOBuffer> read_buffer_;
83 DISALLOW_COPY_AND_ASSIGN(QuicP2PSession);
86 } // namespace net
88 #endif // NET_QUIC_P2P_QUIC_P2P_SESSION_H_