OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/p2p/quic/quicsession.h" | 11 #include "webrtc/p2p/quic/quicsession.h" |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
18 #include "webrtc/base/messagehandler.h" | 18 #include "webrtc/base/messagehandler.h" |
19 #include "webrtc/base/messagequeue.h" | 19 #include "webrtc/base/messagequeue.h" |
20 | 20 |
21 namespace cricket { | 21 namespace cricket { |
22 | 22 |
| 23 // Default priority for incoming QUIC streams. |
| 24 // TODO(mikescarlett): Determine if this value is correct. |
| 25 static const net::SpdyPriority kDefaultPriority = 3; |
| 26 |
23 QuicSession::QuicSession(std::unique_ptr<net::QuicConnection> connection, | 27 QuicSession::QuicSession(std::unique_ptr<net::QuicConnection> connection, |
24 const net::QuicConfig& config) | 28 const net::QuicConfig& config) |
25 : net::QuicSession(connection.release(), config) {} | 29 : net::QuicSession(connection.release(), config) {} |
26 | 30 |
27 QuicSession::~QuicSession() {} | 31 QuicSession::~QuicSession() {} |
28 | 32 |
29 void QuicSession::StartClientHandshake( | 33 void QuicSession::StartClientHandshake( |
30 net::QuicCryptoClientStream* crypto_stream) { | 34 net::QuicCryptoClientStream* crypto_stream) { |
31 SetCryptoStream(crypto_stream); | 35 SetCryptoStream(crypto_stream); |
32 net::QuicSession::Initialize(); | 36 net::QuicSession::Initialize(); |
(...skipping 22 matching lines...) Expand all Loading... |
55 net::QuicSession::OnCryptoHandshakeEvent(event); | 59 net::QuicSession::OnCryptoHandshakeEvent(event); |
56 if (event == HANDSHAKE_CONFIRMED) { | 60 if (event == HANDSHAKE_CONFIRMED) { |
57 LOG(LS_INFO) << "QuicSession handshake complete"; | 61 LOG(LS_INFO) << "QuicSession handshake complete"; |
58 RTC_DCHECK(IsEncryptionEstablished()); | 62 RTC_DCHECK(IsEncryptionEstablished()); |
59 RTC_DCHECK(IsCryptoHandshakeConfirmed()); | 63 RTC_DCHECK(IsCryptoHandshakeConfirmed()); |
60 | 64 |
61 SignalHandshakeComplete(); | 65 SignalHandshakeComplete(); |
62 } | 66 } |
63 } | 67 } |
64 | 68 |
| 69 void QuicSession::CloseStream(net::QuicStreamId stream_id) { |
| 70 if (IsClosedStream(stream_id)) { |
| 71 // When CloseStream has been called recursively (via |
| 72 // ReliableQuicStream::OnClose), the stream is already closed so return. |
| 73 return; |
| 74 } |
| 75 write_blocked_streams()->UnregisterStream(stream_id); |
| 76 net::QuicSession::CloseStream(stream_id); |
| 77 } |
| 78 |
65 ReliableQuicStream* QuicSession::CreateIncomingDynamicStream( | 79 ReliableQuicStream* QuicSession::CreateIncomingDynamicStream( |
66 net::QuicStreamId id) { | 80 net::QuicStreamId id) { |
67 ReliableQuicStream* stream = CreateDataStream(id); | 81 ReliableQuicStream* stream = CreateDataStream(id, kDefaultPriority); |
68 if (stream) { | 82 if (stream) { |
69 SignalIncomingStream(stream); | 83 SignalIncomingStream(stream); |
70 } | 84 } |
71 return stream; | 85 return stream; |
72 } | 86 } |
73 | 87 |
74 ReliableQuicStream* QuicSession::CreateOutgoingDynamicStream( | 88 ReliableQuicStream* QuicSession::CreateOutgoingDynamicStream( |
75 net::SpdyPriority priority) { | 89 net::SpdyPriority priority) { |
76 return CreateDataStream(GetNextOutgoingStreamId()); | 90 return CreateDataStream(GetNextOutgoingStreamId(), priority); |
77 } | 91 } |
78 | 92 |
79 ReliableQuicStream* QuicSession::CreateDataStream(net::QuicStreamId id) { | 93 ReliableQuicStream* QuicSession::CreateDataStream(net::QuicStreamId id, |
| 94 net::SpdyPriority priority) { |
80 if (crypto_stream_ == nullptr || !crypto_stream_->encryption_established()) { | 95 if (crypto_stream_ == nullptr || !crypto_stream_->encryption_established()) { |
81 // Encryption not active so no stream created | 96 // Encryption not active so no stream created |
82 return nullptr; | 97 return nullptr; |
83 } | 98 } |
84 ReliableQuicStream* stream = new ReliableQuicStream(id, this); | 99 ReliableQuicStream* stream = new ReliableQuicStream(id, this); |
85 if (stream) { | 100 if (stream) { |
86 ActivateStream(stream); // QuicSession owns the stream. | 101 // Make QuicSession take ownership of the stream. |
| 102 ActivateStream(stream); |
| 103 // Register the stream to the QuicWriteBlockedList. |priority| is clamped |
| 104 // between 0 and 7, with 0 being the highest priority and 7 the lowest |
| 105 // priority. |
| 106 write_blocked_streams()->RegisterStream(stream->id(), priority); |
87 } | 107 } |
88 return stream; | 108 return stream; |
89 } | 109 } |
90 | 110 |
91 void QuicSession::OnConnectionClosed(net::QuicErrorCode error, | 111 void QuicSession::OnConnectionClosed(net::QuicErrorCode error, |
92 const std::string& error_details, | 112 const std::string& error_details, |
93 net::ConnectionCloseSource source) { | 113 net::ConnectionCloseSource source) { |
94 net::QuicSession::OnConnectionClosed(error, error_details, source); | 114 net::QuicSession::OnConnectionClosed(error, error_details, source); |
95 SignalConnectionClosed(error, | 115 SignalConnectionClosed(error, |
96 source == net::ConnectionCloseSource::FROM_PEER); | 116 source == net::ConnectionCloseSource::FROM_PEER); |
97 } | 117 } |
98 | 118 |
99 bool QuicSession::OnReadPacket(const char* data, size_t data_len) { | 119 bool QuicSession::OnReadPacket(const char* data, size_t data_len) { |
100 net::QuicReceivedPacket packet(data, data_len, clock_.Now()); | 120 net::QuicReceivedPacket packet(data, data_len, clock_.Now()); |
101 ProcessUdpPacket(connection()->self_address(), connection()->peer_address(), | 121 ProcessUdpPacket(connection()->self_address(), connection()->peer_address(), |
102 packet); | 122 packet); |
103 return true; | 123 return true; |
104 } | 124 } |
105 | 125 |
106 } // namespace cricket | 126 } // namespace cricket |
OLD | NEW |