| 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 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 // Peer who establishes a handshake using a QuicTransportChannel, which wraps | 89 // Peer who establishes a handshake using a QuicTransportChannel, which wraps |
| 90 // a FailableTransportChannel to simulate network connectivity and ICE | 90 // a FailableTransportChannel to simulate network connectivity and ICE |
| 91 // negotiation. | 91 // negotiation. |
| 92 class QuicTestPeer : public sigslot::has_slots<> { | 92 class QuicTestPeer : public sigslot::has_slots<> { |
| 93 public: | 93 public: |
| 94 explicit QuicTestPeer(const std::string& name) | 94 explicit QuicTestPeer(const std::string& name) |
| 95 : name_(name), | 95 : name_(name), |
| 96 bytes_sent_(0), | 96 bytes_sent_(0), |
| 97 ice_channel_(name_, 0), | 97 ice_channel_(new FailableTransportChannel(name_, 0)), |
| 98 quic_channel_(&ice_channel_), | 98 quic_channel_(ice_channel_), |
| 99 incoming_stream_count_(0) { | 99 incoming_stream_count_(0) { |
| 100 quic_channel_.SignalReadPacket.connect( | 100 quic_channel_.SignalReadPacket.connect( |
| 101 this, &QuicTestPeer::OnTransportChannelReadPacket); | 101 this, &QuicTestPeer::OnTransportChannelReadPacket); |
| 102 quic_channel_.SignalIncomingStream.connect(this, | 102 quic_channel_.SignalIncomingStream.connect(this, |
| 103 &QuicTestPeer::OnIncomingStream); | 103 &QuicTestPeer::OnIncomingStream); |
| 104 quic_channel_.SignalClosed.connect(this, &QuicTestPeer::OnClosed); | 104 quic_channel_.SignalClosed.connect(this, &QuicTestPeer::OnClosed); |
| 105 ice_channel_.SetAsync(true); | 105 ice_channel_->SetAsync(true); |
| 106 rtc::scoped_refptr<rtc::RTCCertificate> local_cert = | 106 rtc::scoped_refptr<rtc::RTCCertificate> local_cert = |
| 107 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( | 107 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( |
| 108 rtc::SSLIdentity::Generate(name_, rtc::KT_DEFAULT))); | 108 rtc::SSLIdentity::Generate(name_, rtc::KT_DEFAULT))); |
| 109 quic_channel_.SetLocalCertificate(local_cert); | 109 quic_channel_.SetLocalCertificate(local_cert); |
| 110 local_fingerprint_.reset(CreateFingerprint(local_cert.get())); | 110 local_fingerprint_.reset(CreateFingerprint(local_cert.get())); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Connects |ice_channel_| to that of the other peer. | 113 // Connects |ice_channel_| to that of the other peer. |
| 114 void Connect(QuicTestPeer* other_peer) { | 114 void Connect(QuicTestPeer* other_peer) { |
| 115 ice_channel_.Connect(); | 115 ice_channel_->Connect(); |
| 116 other_peer->ice_channel_.Connect(); | 116 other_peer->ice_channel_->Connect(); |
| 117 ice_channel_.SetDestination(&other_peer->ice_channel_); | 117 ice_channel_->SetDestination(other_peer->ice_channel_); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Disconnects |ice_channel_|. | 120 // Disconnects |ice_channel_|. |
| 121 void Disconnect() { ice_channel_.SetDestination(nullptr); } | 121 void Disconnect() { ice_channel_->SetDestination(nullptr); } |
| 122 | 122 |
| 123 // Generates ICE credentials and passes them to |quic_channel_|. | 123 // Generates ICE credentials and passes them to |quic_channel_|. |
| 124 void SetIceParameters(IceRole local_ice_role, | 124 void SetIceParameters(IceRole local_ice_role, |
| 125 ConnectionRole local_connection_role, | 125 ConnectionRole local_connection_role, |
| 126 ConnectionRole remote_connection_role, | 126 ConnectionRole remote_connection_role, |
| 127 rtc::SSLFingerprint* remote_fingerprint) { | 127 rtc::SSLFingerprint* remote_fingerprint) { |
| 128 quic_channel_.SetIceRole(local_ice_role); | 128 quic_channel_.SetIceRole(local_ice_role); |
| 129 quic_channel_.SetIceTiebreaker( | 129 quic_channel_.SetIceTiebreaker( |
| 130 (local_ice_role == cricket::ICEROLE_CONTROLLING) ? 1 : 2); | 130 (local_ice_role == cricket::ICEROLE_CONTROLLING) ? 1 : 2); |
| 131 | 131 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 char packet[kPacketSize]; | 182 char packet[kPacketSize]; |
| 183 packet[0] = 0x80; // Make the packet header look like RTP. | 183 packet[0] = 0x80; // Make the packet header look like RTP. |
| 184 return quic_channel_.SendPacket(&packet[0], kPacketSize, | 184 return quic_channel_.SendPacket(&packet[0], kPacketSize, |
| 185 rtc::PacketOptions(), 0); | 185 rtc::PacketOptions(), 0); |
| 186 } | 186 } |
| 187 | 187 |
| 188 void ClearBytesSent() { bytes_sent_ = 0; } | 188 void ClearBytesSent() { bytes_sent_ = 0; } |
| 189 | 189 |
| 190 void ClearBytesReceived() { bytes_received_ = 0; } | 190 void ClearBytesReceived() { bytes_received_ = 0; } |
| 191 | 191 |
| 192 void SetWriteError(int error) { ice_channel_.SetError(error); } | 192 void SetWriteError(int error) { ice_channel_->SetError(error); } |
| 193 | 193 |
| 194 size_t bytes_received() const { return bytes_received_; } | 194 size_t bytes_received() const { return bytes_received_; } |
| 195 | 195 |
| 196 size_t bytes_sent() const { return bytes_sent_; } | 196 size_t bytes_sent() const { return bytes_sent_; } |
| 197 | 197 |
| 198 FailableTransportChannel* ice_channel() { return &ice_channel_; } | 198 FailableTransportChannel* ice_channel() { return ice_channel_; } |
| 199 | 199 |
| 200 QuicTransportChannel* quic_channel() { return &quic_channel_; } | 200 QuicTransportChannel* quic_channel() { return &quic_channel_; } |
| 201 | 201 |
| 202 std::unique_ptr<rtc::SSLFingerprint>& local_fingerprint() { | 202 std::unique_ptr<rtc::SSLFingerprint>& local_fingerprint() { |
| 203 return local_fingerprint_; | 203 return local_fingerprint_; |
| 204 } | 204 } |
| 205 | 205 |
| 206 ReliableQuicStream* incoming_quic_stream() { return incoming_quic_stream_; } | 206 ReliableQuicStream* incoming_quic_stream() { return incoming_quic_stream_; } |
| 207 | 207 |
| 208 size_t incoming_stream_count() const { return incoming_stream_count_; } | 208 size_t incoming_stream_count() const { return incoming_stream_count_; } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 223 } | 223 } |
| 224 void OnIncomingStream(ReliableQuicStream* stream) { | 224 void OnIncomingStream(ReliableQuicStream* stream) { |
| 225 incoming_quic_stream_ = stream; | 225 incoming_quic_stream_ = stream; |
| 226 ++incoming_stream_count_; | 226 ++incoming_stream_count_; |
| 227 } | 227 } |
| 228 void OnClosed() { signal_closed_emitted_ = true; } | 228 void OnClosed() { signal_closed_emitted_ = true; } |
| 229 | 229 |
| 230 std::string name_; // Channel name. | 230 std::string name_; // Channel name. |
| 231 size_t bytes_sent_; // Bytes sent by QUIC channel. | 231 size_t bytes_sent_; // Bytes sent by QUIC channel. |
| 232 size_t bytes_received_; // Bytes received by QUIC channel. | 232 size_t bytes_received_; // Bytes received by QUIC channel. |
| 233 FailableTransportChannel ice_channel_; // Simulates an ICE channel. | 233 FailableTransportChannel* ice_channel_; // Simulates an ICE channel. |
| 234 QuicTransportChannel quic_channel_; // QUIC channel to test. | 234 QuicTransportChannel quic_channel_; // QUIC channel to test. |
| 235 std::unique_ptr<rtc::SSLFingerprint> local_fingerprint_; | 235 std::unique_ptr<rtc::SSLFingerprint> local_fingerprint_; |
| 236 ReliableQuicStream* incoming_quic_stream_ = nullptr; | 236 ReliableQuicStream* incoming_quic_stream_ = nullptr; |
| 237 size_t incoming_stream_count_; | 237 size_t incoming_stream_count_; |
| 238 bool signal_closed_emitted_ = false; | 238 bool signal_closed_emitted_ = false; |
| 239 }; | 239 }; |
| 240 | 240 |
| 241 class QuicTransportChannelTest : public testing::Test { | 241 class QuicTransportChannelTest : public testing::Test { |
| 242 public: | 242 public: |
| 243 QuicTransportChannelTest() : peer1_("P1"), peer2_("P2") {} | 243 QuicTransportChannelTest() : peer1_("P1"), peer2_("P2") {} |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 Connect(); | 547 Connect(); |
| 548 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs); | 548 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs); |
| 549 ASSERT_FALSE(peer1_.signal_closed_emitted()); | 549 ASSERT_FALSE(peer1_.signal_closed_emitted()); |
| 550 ReliableQuicStream* stream = peer1_.quic_channel()->CreateQuicStream(); | 550 ReliableQuicStream* stream = peer1_.quic_channel()->CreateQuicStream(); |
| 551 ASSERT_NE(nullptr, stream); | 551 ASSERT_NE(nullptr, stream); |
| 552 stream->CloseConnectionWithDetails(net::QuicErrorCode::QUIC_NO_ERROR, | 552 stream->CloseConnectionWithDetails(net::QuicErrorCode::QUIC_NO_ERROR, |
| 553 "Closing QUIC for testing"); | 553 "Closing QUIC for testing"); |
| 554 EXPECT_TRUE(peer1_.signal_closed_emitted()); | 554 EXPECT_TRUE(peer1_.signal_closed_emitted()); |
| 555 EXPECT_TRUE_WAIT(peer2_.signal_closed_emitted(), kTimeoutMs); | 555 EXPECT_TRUE_WAIT(peer2_.signal_closed_emitted(), kTimeoutMs); |
| 556 } | 556 } |
| OLD | NEW |