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/quicdatatransport.h" | 11 #include "webrtc/api/quicdatatransport.h" |
12 | 12 |
| 13 #include <memory> |
13 #include <set> | 14 #include <set> |
14 #include <string> | 15 #include <string> |
15 #include <unordered_map> | 16 #include <unordered_map> |
16 #include <vector> | 17 #include <vector> |
17 | 18 |
18 #include "webrtc/api/quicdatachannel.h" | 19 #include "webrtc/api/quicdatachannel.h" |
19 #include "webrtc/base/bytebuffer.h" | 20 #include "webrtc/base/bytebuffer.h" |
20 #include "webrtc/base/gunit.h" | 21 #include "webrtc/base/gunit.h" |
21 #include "webrtc/p2p/base/faketransportcontroller.h" | 22 #include "webrtc/p2p/base/faketransportcontroller.h" |
22 #include "webrtc/p2p/quic/quictransportchannel.h" | 23 #include "webrtc/p2p/quic/quictransportchannel.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 public: | 65 public: |
65 QuicDataTransportPeer() | 66 QuicDataTransportPeer() |
66 : quic_data_transport_(rtc::Thread::Current(), rtc::Thread::Current()), | 67 : quic_data_transport_(rtc::Thread::Current(), rtc::Thread::Current()), |
67 ice_transport_channel_(new FakeTransportChannel("data", 0)), | 68 ice_transport_channel_(new FakeTransportChannel("data", 0)), |
68 quic_transport_channel_(ice_transport_channel_) { | 69 quic_transport_channel_(ice_transport_channel_) { |
69 ice_transport_channel_->SetAsync(true); | 70 ice_transport_channel_->SetAsync(true); |
70 } | 71 } |
71 | 72 |
72 void GenerateCertificateAndFingerprint() { | 73 void GenerateCertificateAndFingerprint() { |
73 rtc::scoped_refptr<rtc::RTCCertificate> local_cert = | 74 rtc::scoped_refptr<rtc::RTCCertificate> local_cert = |
74 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>( | 75 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( |
75 rtc::SSLIdentity::Generate("cert_name", rtc::KT_DEFAULT))); | 76 rtc::SSLIdentity::Generate("cert_name", rtc::KT_DEFAULT))); |
76 quic_transport_channel_.SetLocalCertificate(local_cert); | 77 quic_transport_channel_.SetLocalCertificate(local_cert); |
77 local_fingerprint_.reset(CreateFingerprint(local_cert.get())); | 78 local_fingerprint_.reset(CreateFingerprint(local_cert.get())); |
78 } | 79 } |
79 | 80 |
80 // Connects |ice_transport_channel_| to that of the other peer. | 81 // Connects |ice_transport_channel_| to that of the other peer. |
81 void Connect(QuicDataTransportPeer* other_peer) { | 82 void Connect(QuicDataTransportPeer* other_peer) { |
82 ice_transport_channel_->Connect(); | 83 ice_transport_channel_->Connect(); |
83 other_peer->ice_transport_channel_->Connect(); | 84 other_peer->ice_transport_channel_->Connect(); |
84 ice_transport_channel_->SetDestination(other_peer->ice_transport_channel_); | 85 ice_transport_channel_->SetDestination(other_peer->ice_transport_channel_); |
85 } | 86 } |
86 | 87 |
87 rtc::scoped_ptr<rtc::SSLFingerprint>& local_fingerprint() { | 88 std::unique_ptr<rtc::SSLFingerprint>& local_fingerprint() { |
88 return local_fingerprint_; | 89 return local_fingerprint_; |
89 } | 90 } |
90 | 91 |
91 QuicTransportChannel* quic_transport_channel() { | 92 QuicTransportChannel* quic_transport_channel() { |
92 return &quic_transport_channel_; | 93 return &quic_transport_channel_; |
93 } | 94 } |
94 | 95 |
95 // Write a messge directly to the ReliableQuicStream. | 96 // Write a messge directly to the ReliableQuicStream. |
96 void WriteMessage(int data_channel_id, | 97 void WriteMessage(int data_channel_id, |
97 uint64_t message_id, | 98 uint64_t message_id, |
(...skipping 11 matching lines...) Expand all Loading... |
109 return quic_data_transport_.CreateDataChannel("testing", config); | 110 return quic_data_transport_.CreateDataChannel("testing", config); |
110 } | 111 } |
111 | 112 |
112 QuicDataTransport* quic_data_transport() { return &quic_data_transport_; } | 113 QuicDataTransport* quic_data_transport() { return &quic_data_transport_; } |
113 | 114 |
114 private: | 115 private: |
115 // Creates a fingerprint from a certificate. | 116 // Creates a fingerprint from a certificate. |
116 rtc::SSLFingerprint* CreateFingerprint(rtc::RTCCertificate* cert) { | 117 rtc::SSLFingerprint* CreateFingerprint(rtc::RTCCertificate* cert) { |
117 std::string digest_algorithm; | 118 std::string digest_algorithm; |
118 cert->ssl_certificate().GetSignatureDigestAlgorithm(&digest_algorithm); | 119 cert->ssl_certificate().GetSignatureDigestAlgorithm(&digest_algorithm); |
119 rtc::scoped_ptr<rtc::SSLFingerprint> fingerprint( | 120 std::unique_ptr<rtc::SSLFingerprint> fingerprint( |
120 rtc::SSLFingerprint::Create(digest_algorithm, cert->identity())); | 121 rtc::SSLFingerprint::Create(digest_algorithm, cert->identity())); |
121 return fingerprint.release(); | 122 return fingerprint.release(); |
122 } | 123 } |
123 | 124 |
124 QuicDataTransport quic_data_transport_; | 125 QuicDataTransport quic_data_transport_; |
125 FakeTransportChannel* ice_transport_channel_; | 126 FakeTransportChannel* ice_transport_channel_; |
126 QuicTransportChannel quic_transport_channel_; | 127 QuicTransportChannel quic_transport_channel_; |
127 rtc::scoped_ptr<rtc::SSLFingerprint> local_fingerprint_; | 128 std::unique_ptr<rtc::SSLFingerprint> local_fingerprint_; |
128 }; | 129 }; |
129 | 130 |
130 class QuicDataTransportTest : public testing::Test { | 131 class QuicDataTransportTest : public testing::Test { |
131 public: | 132 public: |
132 QuicDataTransportTest() {} | 133 QuicDataTransportTest() {} |
133 | 134 |
134 void ConnectTransportChannels() { | 135 void ConnectTransportChannels() { |
135 SetCryptoParameters(); | 136 SetCryptoParameters(); |
136 peer1_.Connect(&peer2_); | 137 peer1_.Connect(&peer2_); |
137 ASSERT_TRUE_WAIT(peer1_.quic_transport_channel()->writable() && | 138 ASSERT_TRUE_WAIT(peer1_.quic_transport_channel()->writable() && |
138 peer2_.quic_transport_channel()->writable(), | 139 peer2_.quic_transport_channel()->writable(), |
139 kTimeoutMs); | 140 kTimeoutMs); |
140 } | 141 } |
141 | 142 |
142 void SetTransportChannels() { | 143 void SetTransportChannels() { |
143 ASSERT_TRUE(peer1_.quic_data_transport()->SetTransportChannel( | 144 ASSERT_TRUE(peer1_.quic_data_transport()->SetTransportChannel( |
144 peer1_.quic_transport_channel())); | 145 peer1_.quic_transport_channel())); |
145 ASSERT_TRUE(peer2_.quic_data_transport()->SetTransportChannel( | 146 ASSERT_TRUE(peer2_.quic_data_transport()->SetTransportChannel( |
146 peer2_.quic_transport_channel())); | 147 peer2_.quic_transport_channel())); |
147 } | 148 } |
148 | 149 |
149 // Sets crypto parameters required for the QUIC handshake. | 150 // Sets crypto parameters required for the QUIC handshake. |
150 void SetCryptoParameters() { | 151 void SetCryptoParameters() { |
151 peer1_.GenerateCertificateAndFingerprint(); | 152 peer1_.GenerateCertificateAndFingerprint(); |
152 peer2_.GenerateCertificateAndFingerprint(); | 153 peer2_.GenerateCertificateAndFingerprint(); |
153 | 154 |
154 peer1_.quic_transport_channel()->SetSslRole(rtc::SSL_CLIENT); | 155 peer1_.quic_transport_channel()->SetSslRole(rtc::SSL_CLIENT); |
155 peer2_.quic_transport_channel()->SetSslRole(rtc::SSL_SERVER); | 156 peer2_.quic_transport_channel()->SetSslRole(rtc::SSL_SERVER); |
156 | 157 |
157 rtc::scoped_ptr<rtc::SSLFingerprint>& peer1_fingerprint = | 158 std::unique_ptr<rtc::SSLFingerprint>& peer1_fingerprint = |
158 peer1_.local_fingerprint(); | 159 peer1_.local_fingerprint(); |
159 rtc::scoped_ptr<rtc::SSLFingerprint>& peer2_fingerprint = | 160 std::unique_ptr<rtc::SSLFingerprint>& peer2_fingerprint = |
160 peer2_.local_fingerprint(); | 161 peer2_.local_fingerprint(); |
161 | 162 |
162 peer1_.quic_transport_channel()->SetRemoteFingerprint( | 163 peer1_.quic_transport_channel()->SetRemoteFingerprint( |
163 peer2_fingerprint->algorithm, | 164 peer2_fingerprint->algorithm, |
164 reinterpret_cast<const uint8_t*>(peer2_fingerprint->digest.data()), | 165 reinterpret_cast<const uint8_t*>(peer2_fingerprint->digest.data()), |
165 peer2_fingerprint->digest.size()); | 166 peer2_fingerprint->digest.size()); |
166 peer2_.quic_transport_channel()->SetRemoteFingerprint( | 167 peer2_.quic_transport_channel()->SetRemoteFingerprint( |
167 peer1_fingerprint->algorithm, | 168 peer1_fingerprint->algorithm, |
168 reinterpret_cast<const uint8_t*>(peer1_fingerprint->digest.data()), | 169 reinterpret_cast<const uint8_t*>(peer1_fingerprint->digest.data()), |
169 peer1_fingerprint->digest.size()); | 170 peer1_fingerprint->digest.size()); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 QuicTransportChannel* transport_channel = peer1_.quic_transport_channel(); | 347 QuicTransportChannel* transport_channel = peer1_.quic_transport_channel(); |
347 EXPECT_TRUE(quic_data_transport->SetTransportChannel(transport_channel)); | 348 EXPECT_TRUE(quic_data_transport->SetTransportChannel(transport_channel)); |
348 EXPECT_TRUE(quic_data_transport->SetTransportChannel(transport_channel)); | 349 EXPECT_TRUE(quic_data_transport->SetTransportChannel(transport_channel)); |
349 QuicTransportChannel* other_transport_channel = | 350 QuicTransportChannel* other_transport_channel = |
350 peer2_.quic_transport_channel(); | 351 peer2_.quic_transport_channel(); |
351 EXPECT_FALSE( | 352 EXPECT_FALSE( |
352 quic_data_transport->SetTransportChannel(other_transport_channel)); | 353 quic_data_transport->SetTransportChannel(other_transport_channel)); |
353 } | 354 } |
354 | 355 |
355 } // namespace | 356 } // namespace |
OLD | NEW |