Commit b96caf16 authored by Seth Hampson's avatar Seth Hampson Committed by Commit Bot

QUIC core library shim for RTCQuicTransport.

The RTCQuicTransport web API needs to use the underlying core QUIC
library. In order to use this API we need to create a shim of the
library that subclasses the QuicSession and QuicStream. This change
subclasses the QuicSession and has some basic implementation for
establishing a connection.

Bug: 874296
Change-Id: I63acd4913abc23733521157bd1aca4a3d1301c65
Reviewed-on: https://chromium-review.googlesource.com/1170125Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarHenrik Boström <hbos@chromium.org>
Commit-Queue: Seth Hampson <shampson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594845}
parent 3225e1d5
......@@ -83,6 +83,7 @@ target("jumbo_" + modules_target_type, "modules") {
deps = [
":make_modules_generated",
":module_names",
"//net:net",
"//third_party/blink/renderer/bindings/modules:generated",
"//third_party/blink/renderer/bindings/modules/v8:bindings_modules_impl",
"//third_party/blink/renderer/bindings/modules/v8:bindings_modules_origin_trial_features",
......@@ -164,6 +165,7 @@ target("jumbo_" + modules_target_type, "modules") {
"//third_party/blink/renderer/modules/xr",
"//third_party/icu",
"//third_party/webrtc/pc:libjingle_peerconnection",
"//third_party/webrtc/rtc_base:rtc_base",
"//third_party/webrtc_overrides:init_webrtc",
"//third_party/zlib",
]
......@@ -297,6 +299,7 @@ jumbo_source_set("unit_tests") {
"payments/payment_test_helper.cc",
"payments/payment_test_helper.h",
"payments/payments_validators_test.cc",
"peerconnection/adapters/p2p_quic_transport_test.cc",
"peerconnection/rtc_data_channel_test.cc",
"peerconnection/rtc_ice_transport_test.cc",
"peerconnection/rtc_peer_connection_test.cc",
......@@ -339,6 +342,7 @@ jumbo_source_set("unit_tests") {
deps = [
":modules",
":modules_testing",
"//net:quic_test_tools",
"//services/device/public/cpp/test:test_support",
"//services/viz/public/interfaces:interfaces_blink",
"//skia",
......@@ -349,6 +353,7 @@ jumbo_source_set("unit_tests") {
"//third_party/blink/renderer/modules/storage:unit_tests",
"//third_party/blink/renderer/platform",
"//third_party/blink/renderer/platform/wtf",
"//third_party/webrtc/rtc_base:rtc_base",
"//v8",
]
}
......@@ -14,6 +14,13 @@ blink_modules_sources("peerconnection") {
"adapters/ice_transport_host.h",
"adapters/ice_transport_proxy.cc",
"adapters/ice_transport_proxy.h",
"adapters/p2p_quic_packet_transport.h",
"adapters/p2p_quic_transport.h",
"adapters/p2p_quic_transport_factory.h",
"adapters/p2p_quic_transport_factory_impl.cc",
"adapters/p2p_quic_transport_factory_impl.h",
"adapters/p2p_quic_transport_impl.cc",
"adapters/p2p_quic_transport_impl.h",
"adapters/web_rtc_cross_thread_copier.cc",
"adapters/web_rtc_cross_thread_copier.h",
"rtc_certificate.cc",
......
......@@ -7,4 +7,8 @@ include_rules = [
"+third_party/blink/renderer/modules/mediastream",
"+third_party/blink/renderer/modules/modules_export.h",
"+third_party/blink/renderer/modules/peerconnection",
"+net/third_party/quic",
"+net/quic/chromium",
"+net/quic",
"+net/test",
]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_PACKET_TRANSPORT_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_PACKET_TRANSPORT_H_
#include "net/third_party/quic/core/quic_packet_writer.h"
#include "net/third_party/quic/core/quic_types.h"
#include "net/third_party/quic/platform/api/quic_export.h"
namespace blink {
// This is the interface for the underlying packet transport used by the
// P2PQuicTransport for receiving and writing data. The standard
// implementation of this interface uses an ICE transport.
//
// This object should be run entirely on the webrtc worker thread.
class P2PQuicPacketTransport {
public:
// This is subclassed by the P2PQuicTransport so that it can receive incoming
// data. The standard case is for this to be the P2PQuicTransport.
// The P2PQuicPacketTransport will outlive the ReceiveDelegate.
class ReceiveDelegate {
public:
virtual ~ReceiveDelegate() = default;
virtual void OnPacketDataReceived(const char* data, size_t data_len) = 0;
};
// This is subclassed by the Writer, so that it is aware when the
// P2PQuicPacketTransport is ready to write data. The
// P2PQuicPacketTransport will outlive the WriteObserver.
class WriteObserver {
public:
virtual ~WriteObserver() = default;
virtual void OnCanWrite() = 0;
};
struct QuicPacket {
// This is taken from the quic::QuicConnection, and 0 means that it is not
// set. Packet numbers are used to provide metadata to the implementation of
// the P2PQuicPacketTransport, but this number is not used by the QUIC
// library itself.
quic::QuicPacketNumber packet_number;
const char* buffer;
size_t buf_len;
};
virtual ~P2PQuicPacketTransport() = default;
// Called by the P2PQuicPacketWriter (in quic_transport_factory_impl.cc) when
// writing QUIC packets to the network. Return the number of written bytes.
// Return 0 if the write is blocked.
virtual int WritePacket(const QuicPacket& packet) = 0;
// Sets the ReceiveDelegate for receiving packets.
// Since the ReceiveDelegate has a shorter lifetime than the
// P2PQuicPacketTransport, it must unset itself upon destruction.
virtual void SetReceiveDelegate(ReceiveDelegate* receive_delegate) = 0;
// Sets the WriteObserver for obsererving when it can write to the
// P2PQuicPacketTransport. Since the WriteObserver has a shorter lifetime than
// the P2PQuicPacketTransport, it must unset itself upon destruction.
virtual void SetWriteObserver(WriteObserver* write_observer) = 0;
// Returns true if the P2PQuicPacketTransport can write.
virtual bool Writable() = 0;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_PACKET_TRANSPORT_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_TRANSPORT_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_TRANSPORT_H_
#include "third_party/webrtc/rtc_base/sslfingerprint.h"
namespace blink {
// Used by the RTCQuicTransport Web API. This transport creates and manages
// streams, handles negotiation, state changes and errors. Every
// P2PQuicTransport function maps directly to a method in the RTCQuicTransport
// Web API, i.e. RTCQuicTransport::stop() -->
// P2PQuicTransport::Stop(). This allows posting just one task across
// thread boundaries to execute a function.
//
// This object should be run entirely on the webrtc worker thread.
class P2PQuicTransport {
public:
// Used for receiving callbacks from the P2PQuicTransport regarding QUIC
// connection changes, handshake success/failures and new QuicStreams being
// added from the remote side.
class Delegate {
public:
virtual ~Delegate() = default;
// Called when receiving a close frame from the remote side, due to
// calling P2PQuicTransport::Stop().
virtual void OnRemoteStopped() {}
// Called when the connection is closed due to a QUIC error. This can happen
// locally by the framer, or remotely by the peer.
virtual void OnConnectionFailed(const std::string& error_details,
bool from_remote) {}
// Called when the crypto handshake has completed and fingerprints have been
// verified.
virtual void OnConnected() {}
// TODO(https://crbug.com/874296): Add OnStream once streams are
// implemented.
};
virtual ~P2PQuicTransport() = default;
// Closes the QuicConnection and sends a close frame to the remote side.
// This will trigger P2PQuicTransport::Delegate::OnRemoteClosed() on the
// remote side.
virtual void Stop() = 0;
// Starts the QUIC handshake negotiation and sets the remote fingerprints
// that were signaled through a secure channel. These fingerprints are used to
// verify the self signed remote certificate used in the QUIC handshake. See:
// https://w3c.github.io/webrtc-quic/#quic-transport*
virtual void Start(std::vector<std::unique_ptr<rtc::SSLFingerprint>>
remote_fingerprints) = 0;
// TODO(https://crbug.com/874296): Consider adding a getter for the
// local fingerprints of the certificate(s) set in the constructor.
// TODO(https://crbug.com/874296): Add CreateStream once streams are
// implemented.
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_TRANSPORT_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_TRANSPORT_FACTORY_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_TRANSPORT_FACTORY_H_
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/modules/peerconnection/adapters/p2p_quic_packet_transport.h"
#include "third_party/blink/renderer/modules/peerconnection/adapters/p2p_quic_transport.h"
#include "third_party/webrtc/rtc_base/rtccertificate.h"
#include "third_party/webrtc/rtc_base/scoped_ref_ptr.h"
namespace blink {
// A simple config object for creating a P2PQuicTransport. It's constructor
// guarantees that the required objects for creating a P2PQuicTransport are part
// of the P2PQuicTransportConfig.
struct P2PQuicTransportConfig final {
// This object is only moveable.
explicit P2PQuicTransportConfig(
P2PQuicTransport::Delegate* const delegate_in,
P2PQuicPacketTransport* const packet_transport_in,
const std::vector<rtc::scoped_refptr<rtc::RTCCertificate>>
certificates_in)
: packet_transport(packet_transport_in),
certificates(certificates_in),
delegate(delegate_in) {
DCHECK_GT(certificates.size(), 0u);
DCHECK(packet_transport);
DCHECK(delegate);
}
P2PQuicTransportConfig(const P2PQuicTransportConfig&) = delete;
P2PQuicTransportConfig& operator=(const P2PQuicTransportConfig&) = delete;
P2PQuicTransportConfig(P2PQuicTransportConfig&&) = default;
P2PQuicTransportConfig& operator=(P2PQuicTransportConfig&&) = default;
~P2PQuicTransportConfig() = default;
// The standard case is an ICE transport. It's lifetime will be managed by
// the ICE transport objects and outlive the P2PQuicTransport.
P2PQuicPacketTransport* const packet_transport;
bool is_server = true;
// The certificates are owned by the P2PQuicTransport. These come from
// blink::RTCCertificates: https://www.w3.org/TR/webrtc/#dom-rtccertificate
const std::vector<rtc::scoped_refptr<rtc::RTCCertificate>> certificates;
// Mandatory for creating a P2PQuicTransport and must outlive
// the P2PQuicTransport. In the standard case the |delegate_| will be
// the object that owns the P2PQuicTransport.
P2PQuicTransport::Delegate* const delegate;
// When set to true the P2PQuicTransport will immediately be able
// to listen and respond to a crypto handshake upon construction.
// This will NOT start a handshake.
bool can_respond_to_crypto_handshake = true;
};
// For creating a P2PQuicTransport. This factory should be injected into
// whichever object plans to own and use a P2PQuicTransport. The
// P2PQuicTransportFactory needs to outlive the P2PQuicTransport it creates.
//
// This object should be run entirely on the webrtc worker thread.
class P2PQuicTransportFactory {
public:
virtual ~P2PQuicTransportFactory() = default;
// Creates the P2PQuicTransport. This should be called on the same
// thread that the P2PQuicTransport will be used on.
virtual std::unique_ptr<P2PQuicTransport> CreateQuicTransport(
P2PQuicTransportConfig config) = 0;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_TRANSPORT_FACTORY_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/peerconnection/adapters/p2p_quic_transport_factory_impl.h"
#include "net/third_party/quic/core/quic_packet_writer.h"
#include "third_party/blink/renderer/modules/peerconnection/adapters/p2p_quic_packet_transport.h"
#include "third_party/blink/renderer/modules/peerconnection/adapters/p2p_quic_transport_impl.h"
#include "third_party/webrtc/rtc_base/rtccertificate.h"
namespace blink {
namespace {
// The P2PQuicPacketWriter is a private helper class that implements the
// QuicPacketWriter using a P2PQuicPacketTransport. This allows us to
// connect our own packet transport for writing into the QuicConnection.
// The normal case is using an ICE transport (packet_transport) for writing.
class P2PQuicPacketWriter : public quic::QuicPacketWriter,
public P2PQuicPacketTransport::WriteObserver {
public:
P2PQuicPacketWriter(P2PQuicPacketTransport* packet_transport)
: packet_transport_(packet_transport) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(packet_transport_);
packet_transport_->SetWriteObserver(this);
}
// This way the packet transport knows it no longer has a write observer and
// can DCHECK this on destruction.
~P2PQuicPacketWriter() override {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
packet_transport_->SetWriteObserver(nullptr);
}
// Sets the QuicConnection (which owns this packet writer). This allows us
// to get the packet numbers of QUIC packets we write. The QuicConnection
// is created with a quic::QuicPacketWriter, so we can't set the connection
// in the constructor.
void InitializeWithQuicConnection(
const quic::QuicConnection* const connection) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(connection);
if (packet_transport_->Writable()) {
SetWritable();
}
connection_ = connection;
}
// quic::QuicPacketWriter overrides.
// Writes a QUIC packet to the network with the packet number as additional
// packet info.
quic::WriteResult WritePacket(const char* buffer,
size_t buf_len,
const quic::QuicIpAddress& self_address,
const quic::QuicSocketAddress& peer_address,
quic::PerPacketOptions* options) override {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(connection_);
if (IsWriteBlocked()) {
return quic::WriteResult(quic::WRITE_STATUS_BLOCKED, EWOULDBLOCK);
}
P2PQuicPacketTransport::QuicPacket packet;
packet.packet_number = connection_->packet_generator().packet_number();
packet.buffer = buffer;
packet.buf_len = buf_len;
int bytes_written = packet_transport_->WritePacket(packet);
if (bytes_written <= 0) {
writable_ = false;
return quic::WriteResult(quic::WRITE_STATUS_BLOCKED, EWOULDBLOCK);
}
return quic::WriteResult(quic::WRITE_STATUS_OK, bytes_written);
}
bool IsWriteBlockedDataBuffered() const override {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
return false;
}
bool IsWriteBlocked() const override {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
return !writable_;
}
quic::QuicByteCount GetMaxPacketSize(
const quic::QuicSocketAddress& peer_address) const override {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
// This can be configured later.
return 1200;
}
void SetWritable() override {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
writable_ = true;
}
bool SupportsReleaseTime() const override {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
return false;
}
bool IsBatchMode() const override {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
return false;
}
char* GetNextWriteLocation(
const quic::QuicIpAddress& self_address,
const quic::QuicSocketAddress& peer_address) override {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
return nullptr;
}
quic::WriteResult Flush() override {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
return quic::WriteResult(quic::WRITE_STATUS_OK, 0);
}
// P2PQuicPacketTransport::WriteDelegate override.
void OnCanWrite() override {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
SetWritable();
}
private:
// The packet transport is owned by the P2PQuicSession, not the
// BlinkPacketWriter.
P2PQuicPacketTransport* packet_transport_;
// The QuicConnection owns this packet writer and will outlive it.
const quic::QuicConnection* connection_;
bool writable_ = false;
THREAD_CHECKER(thread_checker_);
};
// Creates the QuicConnection for the QuicSession. Currently this connection
// uses a dummy address and ID. The |packet_writer| is a basic implementation
// using the QuicTransportConfig::packet_transport for writing. The |helper|
// and |alarm_factory| should be chromium specific implementations.
std::unique_ptr<quic::QuicConnection> CreateQuicConnection(
bool is_server,
quic::QuicConnectionHelperInterface* helper,
quic::QuicPacketWriter* packet_writer,
quic::QuicAlarmFactory* alarm_factory) {
quic::QuicIpAddress ip;
ip.FromString("0.0.0.0");
quic::QuicSocketAddress dummy_address(ip, 0 /* Port */);
quic::Perspective perspective =
is_server ? quic::Perspective::IS_SERVER : quic::Perspective::IS_CLIENT;
return std::make_unique<quic::QuicConnection>(
0 /* dummy ID */, dummy_address, helper, alarm_factory, packet_writer,
/* owns_writer */ true, perspective, quic::CurrentSupportedVersions());
}
} // namespace
P2PQuicTransportFactoryImpl::P2PQuicTransportFactoryImpl(
quic::QuicClock* clock,
std::unique_ptr<quic::QuicAlarmFactory> alarm_factory)
: clock_(clock), alarm_factory_(std::move(alarm_factory)) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
}
// The P2PQuicTransportImpl is created with Chromium specific QUIC objects:
// QuicClock, QuicRandom, QuicConnectionHelper and QuicAlarmFactory.
std::unique_ptr<P2PQuicTransport>
P2PQuicTransportFactoryImpl::CreateQuicTransport(
P2PQuicTransportConfig config) {
DCHECK(config.packet_transport);
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
quic::QuicRandom* quic_random = quic::QuicRandom::GetInstance();
// The P2PQuicSession owns these chromium specific objects required
// by the QuicConnection. These outlive the QuicConnection itself.
std::unique_ptr<net::QuicChromiumConnectionHelper> helper =
std::make_unique<net::QuicChromiumConnectionHelper>(clock_, quic_random);
P2PQuicPacketWriter* packet_writer =
new P2PQuicPacketWriter(config.packet_transport);
std::unique_ptr<quic::QuicConnection> quic_connection = CreateQuicConnection(
config.is_server, helper.get(), packet_writer, alarm_factory_.get());
// It's okay for the quic::QuicConnection to have a P2PQuicPacketWriter before
// the P2PQuicPacketWriter is initialized, because the P2QuicPacketWriter
// won't be writable until this occurs.
packet_writer->InitializeWithQuicConnection(quic_connection.get());
// QUIC configurations for the session are specified here.
quic::QuicConfig quic_config;
return std::make_unique<P2PQuicTransportImpl>(
std::move(config), std::move(helper), std::move(quic_connection),
quic_config, clock_);
}
} // namespace blink
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_TRANSPORT_FACTORY_IMPL_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_TRANSPORT_FACTORY_IMPL_H_
#include "net/third_party/quic/core/quic_connection.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/modules/peerconnection/adapters/p2p_quic_transport_factory.h"
#include "third_party/blink/renderer/modules/peerconnection/adapters/p2p_quic_transport_impl.h"
namespace blink {
// For creating a P2PQuicTransportImpl to be used for the blink Web API -
// RTCQuicTransport.
//
// This object should be run entirely on the webrtc worker thread.
class MODULES_EXPORT P2PQuicTransportFactoryImpl final
: public P2PQuicTransportFactory {
public:
P2PQuicTransportFactoryImpl(
quic::QuicClock* clock,
std::unique_ptr<quic::QuicAlarmFactory> alarm_factory);
~P2PQuicTransportFactoryImpl() override {}
// QuicTransportFactoryInterface override.
std::unique_ptr<P2PQuicTransport> CreateQuicTransport(
P2PQuicTransportConfig config) override;
private:
// This is used to create a QuicChromiumConnectionHelper for the session.
// Should outlive the P2PQuicTransportFactoryImpl.
quic::QuicClock* clock_;
// Used for alarms that drive the underlying QUIC library. Should use the same
// clock as |clock_|.
std::unique_ptr<quic::QuicAlarmFactory> alarm_factory_;
THREAD_CHECKER(thread_checker_);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_TRANSPORT_FACTORY_IMPL_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_TRANSPORT_IMPL_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_TRANSPORT_IMPL_H_
#include "base/threading/thread_checker.h"
#include "net/quic/quic_chromium_connection_helper.h"
#include "net/third_party/quic/core/crypto/quic_crypto_client_config.h"
#include "net/third_party/quic/core/crypto/quic_crypto_server_config.h"
#include "net/third_party/quic/core/quic_crypto_client_stream.h"
#include "net/third_party/quic/core/quic_crypto_server_stream.h"
#include "net/third_party/quic/core/quic_packet_writer.h"
#include "net/third_party/quic/core/quic_session.h"
#include "net/third_party/quic/tools/quic_simple_crypto_server_stream_helper.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/modules/peerconnection/adapters/p2p_quic_packet_transport.h"
#include "third_party/blink/renderer/modules/peerconnection/adapters/p2p_quic_transport.h"
#include "third_party/blink/renderer/modules/peerconnection/adapters/p2p_quic_transport_factory.h"
#include "third_party/webrtc/rtc_base/rtccertificate.h"
namespace blink {
// The P2PQuicTransportImpl subclasses the quic::QuicSession in order to expose
// QUIC as a P2P transport. This specific subclass implements the crypto
// handshake for a peer to peer connection, which requires verifying the remote
// certificate's fingerprint, but otherwise exposes a raw quic::QuicSession.
//
// At a high level, the quic::QuicConnection manages the actual connection
// between two endpoints, while the quic::QuicSession owns and manages the
// quic::QuicStreams. The quic::QuicSession also handles the negotiation between
// endpoints, session control (reset, window updates, control frames, etc.), and
// callbacks from either the connection (quic::QuicConnectionVisitorInterface),
// frames being acked or lost (quic::SessionNotifierInterface), or handshake
// state changes.
//
// This object should be run entirely on the webrtc worker thread.
class MODULES_EXPORT P2PQuicTransportImpl final
: public quic::QuicSession,
public P2PQuicTransport,
public P2PQuicPacketTransport::ReceiveDelegate,
public quic::QuicCryptoClientStream::ProofHandler {
public:
P2PQuicTransportImpl(
P2PQuicTransportConfig p2p_transport_config,
std::unique_ptr<net::QuicChromiumConnectionHelper> helper,
std::unique_ptr<quic::QuicConnection> connection,
const quic::QuicConfig& quic_config,
quic::QuicClock* clock);
~P2PQuicTransportImpl() override;
// P2PQuicTransport overrides.
void Stop() override;
// Sets the remote fingerprints, and if the the P2PQuicTransportImpl is a
// client starts the QUIC handshake . This handshake is currently insecure,
// meaning that the certificates used are fake and are not verified. It also
// assumes a handshake for a server/client case. This must be called before
// creating any streams.
//
// TODO(https://crbug.com/874300): Verify both the client and server
// certificates with the signaled remote fingerprints. Until the TLS 1.3
// handshake is supported in the QUIC core library we can only verify the
// server's certificate, but not the client's. Note that this means
// implementing the handshake for a P2P case, in which case verification
// completes after both receiving the signaled remote fingerprint and getting
// a client hello. Because either can come first, a synchronous call to verify
// the remote fingerprint is not possible.
void Start(std::vector<std::unique_ptr<rtc::SSLFingerprint>>
remote_fingerprints) override;
// P2PQuicPacketTransport::Delegate override.
void OnPacketDataReceived(const char* data, size_t data_len) override;
// quic::QuicCryptoClientStream::ProofHandler overrides used in a client
// connection to get certificate verification details.
// Called when the proof verification completes. This information is used
// for 0 RTT handshakes, which isn't relevant for our P2P handshake.
void OnProofValid(
const quic::QuicCryptoClientConfig::CachedState& cached) override{};
// Called when proof verification become available.
void OnProofVerifyDetailsAvailable(
const quic::ProofVerifyDetails& verify_details) override{};
// quic::QuicConnectionVisitorInterface override.
void OnConnectionClosed(quic::QuicErrorCode error,
const std::string& error_details,
quic::ConnectionCloseSource source) override;
protected:
// quic::QuicSession overrides.
// TODO(https://crbug.com/874296): Subclass QuicStream and implement these
// functions.
// Creates a new stream initiated from the remote side. The caller does not
// own the stream, so the stream is activated and ownership is moved to the
// quic::QuicSession.
quic::QuicStream* CreateIncomingDynamicStream(quic::QuicStreamId id) override;
// Creates a new outgoing stream. The caller does not own the
// stream, so the stream is activated and ownership is moved to the
// quic::QuicSession.
quic::QuicStream* CreateOutgoingDynamicStream() override;
void OnCryptoHandshakeEvent(CryptoHandshakeEvent event) override;
private:
// This is for testing connection failures and handshake failures.
friend class P2PQuicTransportTest;
// These functions are used for testing.
//
// Returns true if the quic::QuicConnection has been closed remotely or
// locally.
bool IsClosed();
quic::QuicConnection* connection() { return connection_.get(); }
// Allows the test to set its own proof verification.
void set_crypto_client_config(
std::unique_ptr<quic::QuicCryptoClientConfig> crypto_client_config);
// quic::QuicSession overrides.
const quic::QuicCryptoStream* GetCryptoStream() const override;
quic::QuicCryptoStream* GetMutableCryptoStream() override;
// Creates the crypto stream necessary for handshake negotiation, and
// initializes the parent class (quic::QuicSession). This must be called on
// both sides before communicating between endpoints (Start, Close, etc.).
void InitializeCryptoStream();
// The server_config and client_config are used for setting up the crypto
// connection. The ownership of these objects or the objects they own
// (quic::ProofSource, quic::ProofVerifier, etc.), are not passed on to the
// QUIC library for the handshake, so we must own them here. A client
// |perspective_| will not have a crypto_server_config and vice versa.
std::unique_ptr<quic::QuicCryptoServerConfig> crypto_server_config_;
std::unique_ptr<quic::QuicCryptoClientConfig> crypto_client_config_;
// Used by server |crypto_stream_| to track most recently compressed certs.
std::unique_ptr<quic::QuicCompressedCertsCache> compressed_certs_cache_;
std::unique_ptr<quic::QuicCryptoServerStream::Helper> server_stream_helper_;
// Owned by the P2PQuicTransportImpl. |helper_| is placed before
// |connection_| to ensure it outlives it.
std::unique_ptr<net::QuicChromiumConnectionHelper> helper_;
std::unique_ptr<quic::QuicConnection> connection_;
std::unique_ptr<quic::QuicCryptoStream> crypto_stream_;
// Crypto information. Note that currently the handshake is insecure and these
// are not used...
rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
std::vector<std::unique_ptr<rtc::SSLFingerprint>> remote_fingerprints_;
quic::Perspective perspective_;
// Outlives the P2PQuicTransport.
P2PQuicPacketTransport* packet_transport_;
P2PQuicTransport::Delegate* delegate_ = nullptr;
// Owned by whatever creates the P2PQuicTransportImpl. The |clock_| needs to
// outlive the P2PQuicTransportImpl.
quic::QuicClock* clock_ = nullptr;
THREAD_CHECKER(thread_checker_);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_PEERCONNECTION_ADAPTERS_P2P_QUIC_TRANSPORT_IMPL_H_
......@@ -422,6 +422,7 @@ _CONFIG = [
'cricket::.*',
'rtc::.+',
'webrtc::.+',
'quic::.+',
]
},
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment