Modified PeerConnection and WebRtcSession for end-to-end QuicDataChannel usage.
To allow end-to-end QuicDataChannel usage with a
PeerConnection, RTCConfiguration has been modified to
include a boolean for whether to do QUIC, since negotiation of
QUIC is not implemented. If one peer does QUIC, then it will be
assumed that the other peer must do QUIC or the connection
will fail.
PeerConnection has been modified to create data channels of type
QuicDataChannel when the peer wants to do QUIC.
WebRtcSession has ben modified to use a QuicDataTransport
instead of a DtlsTransportChannelWrapper/DataChannel
when QUIC should be used
QuicDataTransport implements the generic functions of
BaseChannel to manage the QuicTransportChannel.
Review-Url: https://codereview.webrtc.org/2166873002
Cr-Commit-Position: refs/heads/master@{#13645}
diff --git a/webrtc/api/quicdatatransport_unittest.cc b/webrtc/api/quicdatatransport_unittest.cc
index 975898e..a9c605f 100644
--- a/webrtc/api/quicdatatransport_unittest.cc
+++ b/webrtc/api/quicdatatransport_unittest.cc
@@ -30,6 +30,7 @@
using webrtc::QuicDataChannel;
using webrtc::QuicDataTransport;
using cricket::FakeTransportChannel;
+using cricket::FakeTransportController;
using cricket::QuicTransportChannel;
using cricket::ReliableQuicStream;
@@ -37,6 +38,7 @@
// Timeout for asynchronous operations.
static const int kTimeoutMs = 1000; // milliseconds
+static const char kTransportName[] = "data";
// FakeObserver receives messages from the data channel.
class FakeObserver : public DataChannelObserver {
@@ -64,11 +66,16 @@
class QuicDataTransportPeer {
public:
QuicDataTransportPeer()
- : quic_data_transport_(rtc::Thread::Current(),
+ : fake_transport_controller_(new FakeTransportController()),
+ quic_data_transport_(rtc::Thread::Current(),
rtc::Thread::Current(),
- rtc::Thread::Current()),
- ice_transport_channel_(new FakeTransportChannel("data", 0)),
- quic_transport_channel_(ice_transport_channel_) {
+ rtc::Thread::Current(),
+ fake_transport_controller_.get()) {
+ fake_transport_controller_->use_quic();
+ quic_data_transport_.set_content_name("data");
+ quic_data_transport_.SetTransport(kTransportName);
+ ice_transport_channel_ = static_cast<FakeTransportChannel*>(
+ quic_data_transport_.quic_transport_channel()->ice_transport_channel());
ice_transport_channel_->SetAsync(true);
}
@@ -76,7 +83,8 @@
rtc::scoped_refptr<rtc::RTCCertificate> local_cert =
rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
rtc::SSLIdentity::Generate("cert_name", rtc::KT_DEFAULT)));
- quic_transport_channel_.SetLocalCertificate(local_cert);
+ quic_data_transport_.quic_transport_channel()->SetLocalCertificate(
+ local_cert);
local_fingerprint_.reset(CreateFingerprint(local_cert.get()));
}
@@ -90,14 +98,15 @@
}
QuicTransportChannel* quic_transport_channel() {
- return &quic_transport_channel_;
+ return quic_data_transport_.quic_transport_channel();
}
// Write a messge directly to the ReliableQuicStream.
void WriteMessage(int data_channel_id,
uint64_t message_id,
const std::string& message) {
- ReliableQuicStream* stream = quic_transport_channel_.CreateQuicStream();
+ ReliableQuicStream* stream =
+ quic_data_transport_.quic_transport_channel()->CreateQuicStream();
rtc::CopyOnWriteBuffer payload;
webrtc::WriteQuicDataChannelMessageHeader(data_channel_id, message_id,
&payload);
@@ -122,9 +131,9 @@
return fingerprint.release();
}
+ std::unique_ptr<FakeTransportController> fake_transport_controller_;
QuicDataTransport quic_data_transport_;
FakeTransportChannel* ice_transport_channel_;
- QuicTransportChannel quic_transport_channel_;
std::unique_ptr<rtc::SSLFingerprint> local_fingerprint_;
};
@@ -140,13 +149,6 @@
kTimeoutMs);
}
- void SetTransportChannels() {
- ASSERT_TRUE(peer1_.quic_data_transport()->SetTransportChannel(
- peer1_.quic_transport_channel()));
- ASSERT_TRUE(peer2_.quic_data_transport()->SetTransportChannel(
- peer2_.quic_transport_channel()));
- }
-
// Sets crypto parameters required for the QUIC handshake.
void SetCryptoParameters() {
peer1_.GenerateCertificateAndFingerprint();
@@ -207,7 +209,7 @@
}
// Tests that any data channels created by the QuicDataTransport are in state
-// kConnecting before the QuicTransportChannel is set, then transiton to state
+// kConnecting before the QuicTransportChannel is set, then transition to state
// kOpen when the transport channel becomes writable.
TEST_F(QuicDataTransportTest, DataChannelsOpenWhenTransportChannelWritable) {
webrtc::DataChannelInit config1;
@@ -215,7 +217,6 @@
rtc::scoped_refptr<DataChannelInterface> data_channel1 =
peer2_.CreateDataChannel(&config1);
EXPECT_EQ(webrtc::DataChannelInterface::kConnecting, data_channel1->state());
- SetTransportChannels();
EXPECT_EQ(webrtc::DataChannelInterface::kConnecting, data_channel1->state());
webrtc::DataChannelInit config2;
config2.id = 14;
@@ -239,7 +240,6 @@
// Tests that the QuicTransport dispatches messages for one QuicDataChannel.
TEST_F(QuicDataTransportTest, ReceiveMessagesForSingleDataChannel) {
ConnectTransportChannels();
- SetTransportChannels();
int data_channel_id = 1337;
webrtc::DataChannelInit config;
@@ -269,7 +269,6 @@
// when multiple are in use.
TEST_F(QuicDataTransportTest, ReceiveMessagesForMultipleDataChannels) {
ConnectTransportChannels();
- SetTransportChannels();
std::vector<rtc::scoped_refptr<DataChannelInterface>> data_channels;
for (int data_channel_id = 0; data_channel_id < 5; ++data_channel_id) {
@@ -299,7 +298,6 @@
// send/receive messages using a QuicDataTransport.
TEST_F(QuicDataTransportTest, EndToEndSendReceiveMessages) {
ConnectTransportChannels();
- SetTransportChannels();
std::vector<rtc::scoped_refptr<DataChannelInterface>> peer1_data_channels;
std::vector<rtc::scoped_refptr<DataChannelInterface>> peer2_data_channels;
@@ -339,18 +337,14 @@
}
}
-// Tests that SetTransportChannel returns false when setting a NULL transport
-// channel or a transport channel that is not equivalent to the one already set.
-TEST_F(QuicDataTransportTest, SetTransportChannelReturnValue) {
+// Tests that SetTransport returns false when setting a transport that is not
+// equivalent to the one already set.
+TEST_F(QuicDataTransportTest, SetTransportReturnValue) {
QuicDataTransport* quic_data_transport = peer1_.quic_data_transport();
- EXPECT_FALSE(quic_data_transport->SetTransportChannel(nullptr));
- QuicTransportChannel* transport_channel = peer1_.quic_transport_channel();
- EXPECT_TRUE(quic_data_transport->SetTransportChannel(transport_channel));
- EXPECT_TRUE(quic_data_transport->SetTransportChannel(transport_channel));
- QuicTransportChannel* other_transport_channel =
- peer2_.quic_transport_channel();
- EXPECT_FALSE(
- quic_data_transport->SetTransportChannel(other_transport_channel));
+ // Ignore the same transport name.
+ EXPECT_TRUE(quic_data_transport->SetTransport(kTransportName));
+ // Return false when setting a different transport name.
+ EXPECT_FALSE(quic_data_transport->SetTransport("another transport name"));
}
} // namespace