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/api/quicdatachannel.h" | 11 #include "webrtc/api/quicdatachannel.h" |
12 | 12 |
13 #include <map> | 13 #include <map> |
| 14 #include <memory> |
14 #include <sstream> | 15 #include <sstream> |
15 #include <string> | 16 #include <string> |
16 #include <vector> | 17 #include <vector> |
17 | 18 |
18 #include "webrtc/base/bind.h" | 19 #include "webrtc/base/bind.h" |
19 #include "webrtc/base/gunit.h" | 20 #include "webrtc/base/gunit.h" |
20 #include "webrtc/base/scoped_ptr.h" | |
21 #include "webrtc/base/scoped_ref_ptr.h" | 21 #include "webrtc/base/scoped_ref_ptr.h" |
22 #include "webrtc/p2p/base/faketransportcontroller.h" | 22 #include "webrtc/p2p/base/faketransportcontroller.h" |
23 #include "webrtc/p2p/quic/quictransportchannel.h" | 23 #include "webrtc/p2p/quic/quictransportchannel.h" |
24 #include "webrtc/p2p/quic/reliablequicstream.h" | 24 #include "webrtc/p2p/quic/reliablequicstream.h" |
25 | 25 |
26 using cricket::FakeTransportChannel; | 26 using cricket::FakeTransportChannel; |
27 using cricket::QuicTransportChannel; | 27 using cricket::QuicTransportChannel; |
28 using cricket::ReliableQuicStream; | 28 using cricket::ReliableQuicStream; |
29 | 29 |
30 using webrtc::DataBuffer; | 30 using webrtc::DataBuffer; |
(...skipping 28 matching lines...) Expand all Loading... |
59 static const DataBuffer kLargeBuffer4(kLargeMessage4); | 59 static const DataBuffer kLargeBuffer4(kLargeMessage4); |
60 | 60 |
61 // Oversized message (> 16 KB) that violates the QUIC stream flow control limit. | 61 // Oversized message (> 16 KB) that violates the QUIC stream flow control limit. |
62 static const std::string kOversizedMessage = std::string("a", 20000); | 62 static const std::string kOversizedMessage = std::string("a", 20000); |
63 static const DataBuffer kOversizedBuffer(kOversizedMessage); | 63 static const DataBuffer kOversizedBuffer(kOversizedMessage); |
64 | 64 |
65 // Creates a fingerprint from a certificate. | 65 // Creates a fingerprint from a certificate. |
66 static rtc::SSLFingerprint* CreateFingerprint(rtc::RTCCertificate* cert) { | 66 static rtc::SSLFingerprint* CreateFingerprint(rtc::RTCCertificate* cert) { |
67 std::string digest_algorithm; | 67 std::string digest_algorithm; |
68 cert->ssl_certificate().GetSignatureDigestAlgorithm(&digest_algorithm); | 68 cert->ssl_certificate().GetSignatureDigestAlgorithm(&digest_algorithm); |
69 rtc::scoped_ptr<rtc::SSLFingerprint> fingerprint( | 69 std::unique_ptr<rtc::SSLFingerprint> fingerprint( |
70 rtc::SSLFingerprint::Create(digest_algorithm, cert->identity())); | 70 rtc::SSLFingerprint::Create(digest_algorithm, cert->identity())); |
71 return fingerprint.release(); | 71 return fingerprint.release(); |
72 } | 72 } |
73 | 73 |
74 // FakeObserver receives messages from the QuicDataChannel. | 74 // FakeObserver receives messages from the QuicDataChannel. |
75 class FakeObserver : public DataChannelObserver { | 75 class FakeObserver : public DataChannelObserver { |
76 public: | 76 public: |
77 FakeObserver() | 77 FakeObserver() |
78 : on_state_change_count_(0), on_buffered_amount_change_count_(0) {} | 78 : on_state_change_count_(0), on_buffered_amount_change_count_(0) {} |
79 | 79 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 QuicDataChannelPeer() | 169 QuicDataChannelPeer() |
170 : ice_transport_channel_(new FakeTransportChannel("data", 0)), | 170 : ice_transport_channel_(new FakeTransportChannel("data", 0)), |
171 quic_transport_channel_(ice_transport_channel_) { | 171 quic_transport_channel_(ice_transport_channel_) { |
172 ice_transport_channel_->SetAsync(true); | 172 ice_transport_channel_->SetAsync(true); |
173 fake_quic_data_transport_.ConnectToTransportChannel( | 173 fake_quic_data_transport_.ConnectToTransportChannel( |
174 &quic_transport_channel_); | 174 &quic_transport_channel_); |
175 } | 175 } |
176 | 176 |
177 void GenerateCertificateAndFingerprint() { | 177 void GenerateCertificateAndFingerprint() { |
178 rtc::scoped_refptr<rtc::RTCCertificate> local_cert = | 178 rtc::scoped_refptr<rtc::RTCCertificate> local_cert = |
179 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>( | 179 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( |
180 rtc::SSLIdentity::Generate("cert_name", rtc::KT_DEFAULT))); | 180 rtc::SSLIdentity::Generate("cert_name", rtc::KT_DEFAULT))); |
181 quic_transport_channel_.SetLocalCertificate(local_cert); | 181 quic_transport_channel_.SetLocalCertificate(local_cert); |
182 local_fingerprint_.reset(CreateFingerprint(local_cert.get())); | 182 local_fingerprint_.reset(CreateFingerprint(local_cert.get())); |
183 } | 183 } |
184 | 184 |
185 rtc::scoped_refptr<QuicDataChannel> CreateDataChannelWithTransportChannel( | 185 rtc::scoped_refptr<QuicDataChannel> CreateDataChannelWithTransportChannel( |
186 int id, | 186 int id, |
187 const std::string& label, | 187 const std::string& label, |
188 const std::string& protocol) { | 188 const std::string& protocol) { |
189 rtc::scoped_refptr<QuicDataChannel> data_channel = | 189 rtc::scoped_refptr<QuicDataChannel> data_channel = |
190 fake_quic_data_transport_.CreateDataChannel(id, label, protocol); | 190 fake_quic_data_transport_.CreateDataChannel(id, label, protocol); |
191 data_channel->SetTransportChannel(&quic_transport_channel_); | 191 data_channel->SetTransportChannel(&quic_transport_channel_); |
192 return data_channel; | 192 return data_channel; |
193 } | 193 } |
194 | 194 |
195 rtc::scoped_refptr<QuicDataChannel> CreateDataChannelWithoutTransportChannel( | 195 rtc::scoped_refptr<QuicDataChannel> CreateDataChannelWithoutTransportChannel( |
196 int id, | 196 int id, |
197 const std::string& label, | 197 const std::string& label, |
198 const std::string& protocol) { | 198 const std::string& protocol) { |
199 return fake_quic_data_transport_.CreateDataChannel(id, label, protocol); | 199 return fake_quic_data_transport_.CreateDataChannel(id, label, protocol); |
200 } | 200 } |
201 | 201 |
202 // Connects |ice_transport_channel_| to that of the other peer. | 202 // Connects |ice_transport_channel_| to that of the other peer. |
203 void Connect(QuicDataChannelPeer* other_peer) { | 203 void Connect(QuicDataChannelPeer* other_peer) { |
204 ice_transport_channel_->Connect(); | 204 ice_transport_channel_->Connect(); |
205 other_peer->ice_transport_channel_->Connect(); | 205 other_peer->ice_transport_channel_->Connect(); |
206 ice_transport_channel_->SetDestination(other_peer->ice_transport_channel_); | 206 ice_transport_channel_->SetDestination(other_peer->ice_transport_channel_); |
207 } | 207 } |
208 | 208 |
209 rtc::scoped_ptr<rtc::SSLFingerprint>& local_fingerprint() { | 209 std::unique_ptr<rtc::SSLFingerprint>& local_fingerprint() { |
210 return local_fingerprint_; | 210 return local_fingerprint_; |
211 } | 211 } |
212 | 212 |
213 QuicTransportChannel* quic_transport_channel() { | 213 QuicTransportChannel* quic_transport_channel() { |
214 return &quic_transport_channel_; | 214 return &quic_transport_channel_; |
215 } | 215 } |
216 | 216 |
217 FakeTransportChannel* ice_transport_channel() { | 217 FakeTransportChannel* ice_transport_channel() { |
218 return ice_transport_channel_; | 218 return ice_transport_channel_; |
219 } | 219 } |
220 | 220 |
221 private: | 221 private: |
222 FakeTransportChannel* ice_transport_channel_; | 222 FakeTransportChannel* ice_transport_channel_; |
223 QuicTransportChannel quic_transport_channel_; | 223 QuicTransportChannel quic_transport_channel_; |
224 | 224 |
225 rtc::scoped_ptr<rtc::SSLFingerprint> local_fingerprint_; | 225 std::unique_ptr<rtc::SSLFingerprint> local_fingerprint_; |
226 | 226 |
227 FakeQuicDataTransport fake_quic_data_transport_; | 227 FakeQuicDataTransport fake_quic_data_transport_; |
228 }; | 228 }; |
229 | 229 |
230 class QuicDataChannelTest : public testing::Test { | 230 class QuicDataChannelTest : public testing::Test { |
231 public: | 231 public: |
232 QuicDataChannelTest() {} | 232 QuicDataChannelTest() {} |
233 | 233 |
234 // Connect the QuicTransportChannels and complete the crypto handshake. | 234 // Connect the QuicTransportChannels and complete the crypto handshake. |
235 void ConnectTransportChannels() { | 235 void ConnectTransportChannels() { |
236 SetCryptoParameters(); | 236 SetCryptoParameters(); |
237 peer1_.Connect(&peer2_); | 237 peer1_.Connect(&peer2_); |
238 ASSERT_TRUE_WAIT(peer1_.quic_transport_channel()->writable() && | 238 ASSERT_TRUE_WAIT(peer1_.quic_transport_channel()->writable() && |
239 peer2_.quic_transport_channel()->writable(), | 239 peer2_.quic_transport_channel()->writable(), |
240 kTimeoutMs); | 240 kTimeoutMs); |
241 } | 241 } |
242 | 242 |
243 // Sets crypto parameters required for the QUIC handshake. | 243 // Sets crypto parameters required for the QUIC handshake. |
244 void SetCryptoParameters() { | 244 void SetCryptoParameters() { |
245 peer1_.GenerateCertificateAndFingerprint(); | 245 peer1_.GenerateCertificateAndFingerprint(); |
246 peer2_.GenerateCertificateAndFingerprint(); | 246 peer2_.GenerateCertificateAndFingerprint(); |
247 | 247 |
248 peer1_.quic_transport_channel()->SetSslRole(rtc::SSL_CLIENT); | 248 peer1_.quic_transport_channel()->SetSslRole(rtc::SSL_CLIENT); |
249 peer2_.quic_transport_channel()->SetSslRole(rtc::SSL_SERVER); | 249 peer2_.quic_transport_channel()->SetSslRole(rtc::SSL_SERVER); |
250 | 250 |
251 rtc::scoped_ptr<rtc::SSLFingerprint>& peer1_fingerprint = | 251 std::unique_ptr<rtc::SSLFingerprint>& peer1_fingerprint = |
252 peer1_.local_fingerprint(); | 252 peer1_.local_fingerprint(); |
253 rtc::scoped_ptr<rtc::SSLFingerprint>& peer2_fingerprint = | 253 std::unique_ptr<rtc::SSLFingerprint>& peer2_fingerprint = |
254 peer2_.local_fingerprint(); | 254 peer2_.local_fingerprint(); |
255 | 255 |
256 peer1_.quic_transport_channel()->SetRemoteFingerprint( | 256 peer1_.quic_transport_channel()->SetRemoteFingerprint( |
257 peer2_fingerprint->algorithm, | 257 peer2_fingerprint->algorithm, |
258 reinterpret_cast<const uint8_t*>(peer2_fingerprint->digest.data()), | 258 reinterpret_cast<const uint8_t*>(peer2_fingerprint->digest.data()), |
259 peer2_fingerprint->digest.size()); | 259 peer2_fingerprint->digest.size()); |
260 peer2_.quic_transport_channel()->SetRemoteFingerprint( | 260 peer2_.quic_transport_channel()->SetRemoteFingerprint( |
261 peer1_fingerprint->algorithm, | 261 peer1_fingerprint->algorithm, |
262 reinterpret_cast<const uint8_t*>(peer1_fingerprint->digest.data()), | 262 reinterpret_cast<const uint8_t*>(peer1_fingerprint->digest.data()), |
263 peer1_fingerprint->digest.size()); | 263 peer1_fingerprint->digest.size()); |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 size_t bytes_read2; | 650 size_t bytes_read2; |
651 ASSERT_TRUE(webrtc::ParseQuicDataMessageHeader( | 651 ASSERT_TRUE(webrtc::ParseQuicDataMessageHeader( |
652 header2.data<char>(), header2.size(), &decoded_data_channel_id2, | 652 header2.data<char>(), header2.size(), &decoded_data_channel_id2, |
653 &decoded_message_id2, &bytes_read2)); | 653 &decoded_message_id2, &bytes_read2)); |
654 EXPECT_EQ(data_channel_id2, decoded_data_channel_id2); | 654 EXPECT_EQ(data_channel_id2, decoded_data_channel_id2); |
655 EXPECT_EQ(message_id2, decoded_message_id2); | 655 EXPECT_EQ(message_id2, decoded_message_id2); |
656 EXPECT_EQ(8u, bytes_read2); | 656 EXPECT_EQ(8u, bytes_read2); |
657 } | 657 } |
658 | 658 |
659 } // namespace | 659 } // namespace |
OLD | NEW |