Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: webrtc/p2p/quic/quictransportchannel.cc

Issue 1721673004: Create QuicTransportChannel (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/p2p/quic/quictransportchannel.cc
diff --git a/webrtc/p2p/quic/quictransportchannel.cc b/webrtc/p2p/quic/quictransportchannel.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f1b1ee95f71bc850d896c0b87442339d23181eef
--- /dev/null
+++ b/webrtc/p2p/quic/quictransportchannel.cc
@@ -0,0 +1,607 @@
+/*
+ * Copyright 2016 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/p2p/quic/quictransportchannel.h"
+
+#include <utility>
+
+#include "net/quic/crypto/proof_source.h"
+#include "net/quic/crypto/proof_verifier.h"
+#include "net/quic/crypto/quic_crypto_client_config.h"
+#include "net/quic/crypto/quic_crypto_server_config.h"
+#include "net/quic/quic_connection.h"
+#include "net/quic/quic_crypto_client_stream.h"
+#include "net/quic/quic_crypto_server_stream.h"
+#include "net/quic/quic_protocol.h"
+#include "webrtc/base/checks.h"
+#include "webrtc/base/helpers.h"
+#include "webrtc/base/logging.h"
+#include "webrtc/base/socket.h"
+#include "webrtc/base/thread.h"
+#include "webrtc/p2p/base/common.h"
+
+namespace {
+
+// QUIC public header constants for net::QuicConnection. These are arbitrary
+// given that |channel_| only receives packets specific to this channel,
+// in which case we already know the QUIC packets have the correct destination.
+const net::QuicConnectionId kConnectionId = 0;
+const net::IPAddressNumber kConnectionIpAddress(net::kIPv4AddressSize, 0);
+const net::IPEndPoint kConnectionIpEndpoint(kConnectionIpAddress, 0);
+
+// Arbitrary server port number for net::QuicCryptoClientConfig.
+const int kQuicServerPort = 0;
+
+// QUIC connection timeout in seconds. This is large so that |channel_| can
+// be responsible for connection timeout.
+const int kIdleConnectionStateLifetime = 1000;
pthatcher1 2016/02/25 08:24:25 Is this in ms? If so, I don't think 1000 is long
mikescarlett 2016/02/26 00:54:13 Seconds. This is roughly 16.7 minutes.
pthatcher1 2016/02/27 01:14:19 Ah... that's long enough :). But can you put a co
mikescarlett 2016/03/01 00:02:10 Done.
+
+// Length of HKDF input keying material, equal to its number of bytes.
+const size_t kInputKeyingMaterialLength = 32;
pthatcher1 2016/02/25 08:24:25 Where does this come from?
mikescarlett 2016/02/26 00:54:14 I added the link where HKDF input keying material
+
+// We don't pull the RTP constants from rtputils.h, to avoid a layer violation.
+const size_t kMinRtpPacketLen = 12;
+
+bool IsRtpPacket(const char* data, size_t len) {
+ const uint8_t* u = reinterpret_cast<const uint8_t*>(data);
+ return (len >= kMinRtpPacketLen && (u[0] & 0xC0) == 0x80);
+}
+
+// Function for detecting QUIC packets based off
+// https://tools.ietf.org/html/draft-tsvwg-quic-protocol-02#section-6.
+const size_t kMinQuicPacketLen = 2;
+
+bool IsQuicPacket(const char* data, size_t len) {
+ const uint8_t* u = reinterpret_cast<const uint8_t*>(data);
+ return (len >= kMinQuicPacketLen && (u[0] & 0x80) == 0);
+}
+
+// Used by QuicCryptoServerConfig to provide dummy proof credentials.
+// TODO(mikescarlett): Remove when secure P2P QUIC handshake is possible.
+class InsecureProofSource : public net::ProofSource {
pthatcher1 2016/02/25 08:24:24 Might as well call this DummyProofSource
mikescarlett 2016/02/26 00:54:13 Done.
+ public:
+ InsecureProofSource() {}
+ ~InsecureProofSource() override {}
+
+ // ProofSource override.
+ bool GetProof(const net::IPAddressNumber& server_ip,
+ const std::string& hostname,
+ const std::string& server_config,
+ bool ecdsa_ok,
+ const std::vector<std::string>** out_certs,
+ std::string* out_signature,
+ std::string* out_leaf_cert_sct) override {
+ LOG(LS_INFO) << "GetProof() providing dummy credentials for insecure QUIC";
+ std::vector<std::string>* certs = new std::vector<std::string>();
+ certs->push_back("Required to establish handshake");
pthatcher1 2016/02/25 08:24:24 And say "Dummy cert"
mikescarlett 2016/02/26 00:54:14 Done.
+ std::string signature("Signature");
pthatcher1 2016/02/25 08:24:25 And "Dummy signature"
mikescarlett 2016/02/26 00:54:13 Done.
+
+ *out_certs = certs;
+ *out_signature = signature;
+
+ return true;
+ }
+};
+
+// Used by QuicCryptoClientConfig to ignore the peer's credentials
+// and establish an insecure QUIC connection.
+// TODO(mikescarlett): Remove when secure P2P QUIC handshake is possible.
+class InsecureProofVerifier : public net::ProofVerifier {
+ public:
+ InsecureProofVerifier() {}
+ ~InsecureProofVerifier() override {}
+
+ // ProofVerifier override.
+ net::QuicAsyncStatus VerifyProof(
+ const std::string& hostname,
+ const std::string& server_config,
+ const std::vector<std::string>& certs,
+ const std::string& cert_sct,
+ const std::string& signature,
+ const net::ProofVerifyContext* verify_context,
+ std::string* error_details,
+ scoped_ptr<net::ProofVerifyDetails>* verify_details,
+ net::ProofVerifierCallback* callback) override {
+ LOG(LS_INFO) << "VerifyProof() ignoring credentials and returning success";
+ return net::QUIC_SUCCESS;
+ }
+};
+
+} // namespace
+
+namespace cricket {
+
+QuicTransportChannel::QuicTransportChannel(TransportChannelImpl* channel)
+ : TransportChannelImpl(channel->transport_name(), channel->component()),
+ worker_thread_(rtc::Thread::Current()),
+ channel_(channel),
+ helper_(worker_thread_),
+ ssl_role_(rtc::SSL_CLIENT) {
+ channel_->SignalWritableState.connect(this,
+ &QuicTransportChannel::OnWritableState);
+ channel_->SignalReadPacket.connect(this, &QuicTransportChannel::OnReadPacket);
+ channel_->SignalSentPacket.connect(this, &QuicTransportChannel::OnSentPacket);
+ channel_->SignalReadyToSend.connect(this,
+ &QuicTransportChannel::OnReadyToSend);
+ channel_->SignalGatheringState.connect(
+ this, &QuicTransportChannel::OnGatheringState);
+ channel_->SignalCandidateGathered.connect(
+ this, &QuicTransportChannel::OnCandidateGathered);
+ channel_->SignalRoleConflict.connect(this,
+ &QuicTransportChannel::OnRoleConflict);
+ channel_->SignalRouteChange.connect(this,
+ &QuicTransportChannel::OnRouteChange);
+ channel_->SignalConnectionRemoved.connect(
+ this, &QuicTransportChannel::OnConnectionRemoved);
+ channel_->SignalReceivingState.connect(
+ this, &QuicTransportChannel::OnReceivingState);
+
+ config_.SetIdleConnectionStateLifetime(
+ net::QuicTime::Delta::FromSeconds(kIdleConnectionStateLifetime),
+ net::QuicTime::Delta::FromSeconds(kIdleConnectionStateLifetime));
+ config_.SetBytesForConnectionIdToSend(0);
pthatcher1 2016/02/25 08:24:24 What's this?
mikescarlett 2016/02/26 00:54:14 Added a comment. This should set the bytes reserve
+}
+
+QuicTransportChannel::~QuicTransportChannel() {}
+
+void QuicTransportChannel::Connect() {
+ // We should only get a single call to Connect.
+ ASSERT(quic_state() == QUIC_TRANSPORT_NEW);
+ channel_->Connect();
+}
+
+bool QuicTransportChannel::SetLocalCertificate(
+ const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) {
+ if (quic_active_) {
+ if (certificate == local_certificate_) {
+ // This may happen during renegotiation.
+ LOG_J(LS_INFO, this) << "Ignoring identical certificate";
pthatcher1 2016/02/25 08:24:24 Just use INFO (like you do ERROR) with no "LS_".
mikescarlett 2016/02/26 00:54:13 Done.
+ return true;
+ } else {
+ LOG_J(ERROR, this) << "Can't change local certificate in this state";
pthatcher1 2016/02/25 08:24:24 This could be a little more details, perhaps somet
mikescarlett 2016/02/26 00:54:14 Done.
+ return false;
+ }
+ }
+ if (certificate) {
+ local_certificate_ = certificate;
+ quic_active_ = true;
+ } else {
+ LOG_J(LS_INFO, this) << "NULL identity supplied. Not doing QUIC.";
pthatcher1 2016/02/25 08:24:25 Should this be WARN instead of INFO? And should i
mikescarlett 2016/02/26 00:54:13 Yes it should. I think ERROR seems more appropriat
+ }
+ return true;
pthatcher1 2016/02/25 08:24:25 The whole method could be rearranged a bit to be m
mikescarlett 2016/02/26 00:54:13 Done.
+}
+
+rtc::scoped_refptr<rtc::RTCCertificate>
+QuicTransportChannel::GetLocalCertificate() const {
+ return local_certificate_;
+}
+
+bool QuicTransportChannel::SetSslRole(rtc::SSLRole role) {
+ if (quic_state() == QUIC_TRANSPORT_CONNECTED) {
+ if (ssl_role_ != role) {
+ LOG_J(LS_ERROR, this)
+ << "SSL Role can't be reversed after the session is setup.";
+ return false;
+ }
+ return true;
+ }
+ ssl_role_ = role;
+ set_ssl_role_ = true;
+ return true;
pthatcher1 2016/02/25 08:24:24 Same here with the early returns: if (ssl_role_
mikescarlett 2016/02/26 00:54:13 Done.
+}
+
+bool QuicTransportChannel::GetSslRole(rtc::SSLRole* role) const {
+ *role = ssl_role_;
+ return true;
+}
+
+bool QuicTransportChannel::SetRemoteFingerprint(const std::string& digest_alg,
+ const uint8_t* digest,
+ size_t digest_len) {
+ std::string remote_fingerprint_value(reinterpret_cast<const char*>(digest),
+ digest_len);
+
+ // Once we have the local certificate, the same remote fingerprint can be set
+ // multiple times.
+ if (quic_active_ && remote_fingerprint_value_ == remote_fingerprint_value &&
+ !digest_alg.empty()) {
pthatcher1 2016/02/25 08:24:24 Wouldn't we ignore an identical remote_fingerprint
mikescarlett 2016/02/26 00:54:14 Yes. Fixed now.
+ // This may happen during renegotiation.
+ LOG_J(LS_INFO, this) << "Ignoring identical remote fingerprint";
+ return true;
+ }
+
+ // If the other side doesn't support digest algorithm, turn off
+ // |quic_active_|.
+ if (digest_alg.empty()) {
+ RTC_DCHECK(!digest_len);
+ LOG_J(LS_INFO, this) << "Other side didn't support digest algorithm.";
+ quic_active_ = false;
+ return true;
+ }
pthatcher1 2016/02/25 08:24:25 I think it would make sense to make this one first
mikescarlett 2016/02/26 00:54:13 Done. Also I think this should log an error and re
+
+ // At this point we know we are doing QUIC
+ remote_fingerprint_value_ = std::move(remote_fingerprint_value);
+ remote_fingerprint_algorithm_ = digest_alg;
+ set_remote_fingerprint_ = true;
+
+ return true;
+}
+
+bool QuicTransportChannel::ExportKeyingMaterial(const std::string& label,
+ const uint8_t* context,
+ size_t context_len,
+ bool use_context,
+ uint8_t* result,
+ size_t result_len) {
+ std::string quic_context(reinterpret_cast<const char*>(context), context_len);
+ std::string quic_result;
+ if (!quic_->ExportKeyingMaterial(label, quic_context, result_len,
+ &quic_result)) {
+ return false;
+ }
+ quic_result.copy(reinterpret_cast<char*>(result), result_len);
+ return true;
+}
+
+bool QuicTransportChannel::GetSrtpCryptoSuite(int* cipher) {
+ *cipher = rtc::SRTP_AES128_CM_SHA1_80;
+ return true;
+}
+
+// Called from upper layers to send a media packet.
+int QuicTransportChannel::SendPacket(const char* data,
+ size_t size,
+ const rtc::PacketOptions& options,
+ int flags) {
+ if (!quic_active_) {
+ // Not doing QUIC.
+ return channel_->SendPacket(data, size, options);
pthatcher1 2016/02/25 08:24:25 I think we can remove this.
mikescarlett 2016/02/26 00:54:13 Done.
+ }
+
+ switch (quic_state()) {
+ case QUIC_TRANSPORT_NEW:
+ // Can't send data until the connection is active.
+ return -1;
+ case QUIC_TRANSPORT_CONNECTING:
+ // Can't send data until the connection is active.
+ return -1;
pthatcher1 2016/02/25 08:24:25 If it's SRTP_BYPASS, we can, can't we? I think th
mikescarlett 2016/02/26 00:54:14 Done. That seems reasonable since SRTP is always e
+ case QUIC_TRANSPORT_CONNECTED:
+ if (flags & PF_SRTP_BYPASS) {
+ if (!IsRtpPacket(data, size)) {
+ return -1;
+ }
+ return channel_->SendPacket(data, size, options);
+ }
+ return -1;
+ case QUIC_TRANSPORT_FAILED:
+ // Can't send anything when we're closed.
+ return -1;
+ default:
+ ASSERT(false);
+ return -1;
+ }
+}
+
+// The state transition logic here is as follows:
+// (1) If we're not doing QUIC, then the state is equivalent to the
+// state of |channel_|.
+// (2) If we're doing QUIC:
+// - Prior to the QUIC handshake, the state is neither receiving nor
+// writable.
+// - When |channel_| goes writable for the first time we
+// start the QUIC handshake.
+// - Once the QUIC handshake completes, the state is that of the
+// |channel_| again.
+void QuicTransportChannel::OnWritableState(TransportChannel* channel) {
+ ASSERT(rtc::Thread::Current() == worker_thread_);
+ ASSERT(channel == channel_);
+ LOG_J(LS_VERBOSE, this)
+ << "QuicTransportChannel: channel writable state changed to "
+ << channel_->writable();
+
+ if (!quic_active_) {
+ // Not doing QUIC.
+ // Note: SignalWritableState fired by set_writable.
+ set_writable(channel_->writable());
pthatcher1 2016/02/25 08:24:25 I think we can remove this.
mikescarlett 2016/02/26 00:54:13 I removed it. So the QUIC channel is not writable
+ return;
+ }
+
+ switch (quic_state()) {
+ case QUIC_TRANSPORT_NEW:
+ // This should never fail:
+ // Because we are operating in a nonblocking mode and all
+ // incoming packets come in via OnReadPacket(), which rejects
+ // packets in this state, the incoming queue must be empty. We
+ // ignore write errors, thus any errors must be because of
+ // configuration and therefore are our fault.
+ // Note that in non-debug configurations, failure in
+ // MaybeStartQuic() changes the state to QUIC_TRANSPORT_FAILED.
+ VERIFY(MaybeStartQuic());
+ break;
+ case QUIC_TRANSPORT_CONNECTED:
+ // Note: SignalWritableState fired by set_writable.
+ set_writable(channel_->writable());
+ break;
+ case QUIC_TRANSPORT_CONNECTING:
+ // This channel is not writable until QUIC handshake finishes. It might
+ // have been write blocked.
+ if (HasDataToWrite()) {
+ OnCanWrite();
+ }
pthatcher1 2016/02/25 08:24:25 Should we do this for QUIC_TRANSPORT_CONNECTED als
mikescarlett 2016/02/26 00:54:14 Yes. Fixed this.
+ break;
+ case QUIC_TRANSPORT_FAILED:
+ // Should not happen. Do nothing.
+ break;
+ }
+}
+
+void QuicTransportChannel::OnReceivingState(TransportChannel* channel) {
+ ASSERT(rtc::Thread::Current() == worker_thread_);
+ ASSERT(channel == channel_);
+ LOG_J(LS_VERBOSE, this)
+ << "QuicTransportChannel: channel receiving state changed to "
+ << channel_->receiving();
+ if (!quic_active_ || quic_state() == QUIC_TRANSPORT_CONNECTED) {
pthatcher1 2016/02/25 08:24:25 I think we can remove the !quic_active_ part of th
mikescarlett 2016/02/26 00:54:14 Done. !quic_active_ would essentially be false sin
+ // Note: SignalReceivingState fired by set_receiving.
+ set_receiving(channel_->receiving());
+ }
+}
+
+void QuicTransportChannel::OnReadPacket(TransportChannel* channel,
+ const char* data,
+ size_t size,
+ const rtc::PacketTime& packet_time,
+ int flags) {
+ ASSERT(rtc::Thread::Current() == worker_thread_);
+ ASSERT(channel == channel_);
+ ASSERT(flags == 0);
+
+ if (!quic_active_) {
+ // Not doing QUIC.
+ SignalReadPacket(this, data, size, packet_time, 0);
+ return;
+ }
pthatcher1 2016/02/25 08:24:24 I think we can remove this.
mikescarlett 2016/02/26 00:54:14 Removed.
+
+ switch (quic_state()) {
+ case QUIC_TRANSPORT_NEW:
+ if (set_remote_fingerprint_) {
+ // This would occur if other peer is ready to start QUIC but this peer
+ // hasn't started QUIC.
+ LOG_J(LS_INFO, this) << "Dropping packet received before QUIC started.";
+ } else {
+ // Currently drop the packet, but we might in future
+ // decide to take this as evidence that the other
+ // side is ready to do QUIC and start the handshake
+ // on our end.
+ LOG_J(LS_WARNING, this) << "Received packet before we know if we are "
+ << "doing QUIC or not; dropping.";
+ }
+ break;
+ case QUIC_TRANSPORT_CONNECTING:
+ case QUIC_TRANSPORT_CONNECTED:
+ // We should only get QUIC or SRTP packets; STUN's already been demuxed.
+ // Is this potentially a QUIC packet?
+ if (IsQuicPacket(data, size)) {
+ if (!HandleQuicPacket(data, size)) {
+ LOG_J(ERROR, this) << "Failed to handle QUIC packet.";
+ return;
+ }
+ } else {
+ // Not a QUIC packet; our handshake should be complete.
+ if (quic_state() != QUIC_TRANSPORT_CONNECTED) {
+ LOG_J(ERROR, this) << "Received non-QUIC packet before QUIC "
+ << "complete.";
+ return;
+ }
pthatcher1 2016/02/25 08:24:24 We can probably just pass RTP packet through even
mikescarlett 2016/02/26 00:54:13 True. Removed the extra if statement.
+ // And it had better be a SRTP packet.
+ if (!IsRtpPacket(data, size)) {
+ LOG_J(ERROR, this) << "Received unexpected non-QUIC packet.";
pthatcher1 2016/02/25 08:24:24 non-QUIC, non-RTP packet :).
mikescarlett 2016/02/26 00:54:14 Done.
+ return;
+ }
+ // Signal this upwards as a bypass packet.
+ SignalReadPacket(this, data, size, packet_time, PF_SRTP_BYPASS);
+ }
+ break;
+ case QUIC_TRANSPORT_FAILED:
+ // This shouldn't be happening. Drop the packet.
+ break;
+ }
+}
+
+void QuicTransportChannel::OnSentPacket(TransportChannel* channel,
+ const rtc::SentPacket& sent_packet) {
+ ASSERT(rtc::Thread::Current() == worker_thread_);
+ SignalSentPacket(this, sent_packet);
+}
+
+void QuicTransportChannel::OnReadyToSend(TransportChannel* channel) {
+ if (writable()) {
+ SignalReadyToSend(this);
+ }
+}
+
+void QuicTransportChannel::OnGatheringState(TransportChannelImpl* channel) {
+ ASSERT(channel == channel_);
+ SignalGatheringState(this);
+}
+
+void QuicTransportChannel::OnCandidateGathered(TransportChannelImpl* channel,
+ const Candidate& c) {
+ ASSERT(channel == channel_);
+ SignalCandidateGathered(this, c);
+}
+
+void QuicTransportChannel::OnRoleConflict(TransportChannelImpl* channel) {
+ ASSERT(channel == channel_);
+ SignalRoleConflict(this);
+}
+
+void QuicTransportChannel::OnRouteChange(TransportChannel* channel,
+ const Candidate& candidate) {
+ ASSERT(channel == channel_);
+ SignalRouteChange(this, candidate);
+}
+
+void QuicTransportChannel::OnConnectionRemoved(TransportChannelImpl* channel) {
+ ASSERT(channel == channel_);
+ SignalConnectionRemoved(this);
+}
+
+bool QuicTransportChannel::MaybeStartQuic() {
+ if (!channel_->writable()) {
pthatcher1 2016/02/25 08:24:25 That seems a bit drastic. Just because we're not
mikescarlett 2016/02/26 00:54:13 Seems fine.
+ LOG_J(ERROR, this) << "Couldn't start QUIC handshake";
+ set_quic_state(QUIC_TRANSPORT_FAILED);
+ return false;
+ }
+ if (!CreateQuicSession() || !StartQuicHandshake()) {
pthatcher1 2016/02/25 08:24:25 This could use a LOG_J(ERROR) or LOG_J(WARN).
mikescarlett 2016/02/26 00:54:13 Done. I agree.
+ return false;
+ }
+ // Verify connection is not closed due to QUIC bug or network failure.
+ // A closed connection should not happen since |channel_| is writable.
+ RTC_DCHECK(quic_->connection()->connected());
pthatcher1 2016/02/25 08:24:25 It seems like it would be a good idea to just log
mikescarlett 2016/02/26 00:54:14 Ok I'll do that so QUIC bugs don't crash everythin
+ // Indicate that |quic_| is ready to receive QUIC packets.
+ set_quic_state(QUIC_TRANSPORT_CONNECTING);
+ return true;
+}
+
+bool QuicTransportChannel::CreateQuicSession() {
+ if (!set_ssl_role_) {
+ return false;
+ }
+ net::Perspective perspective = (ssl_role_ == rtc::SSL_CLIENT)
+ ? net::Perspective::IS_CLIENT
+ : net::Perspective::IS_SERVER;
+ bool owns_writer = false;
+ scoped_ptr<net::QuicConnection> connection(new net::QuicConnection(
+ kConnectionId, kConnectionIpEndpoint, &helper_, this, owns_writer,
+ perspective, net::QuicSupportedVersions()));
+ quic_.reset(new QuicSession(std::move(connection), config_));
+ quic_->SignalHandshakeComplete.connect(
+ this, &QuicTransportChannel::OnHandshakeComplete);
+ quic_->SignalConnectionClosed.connect(
+ this, &QuicTransportChannel::OnConnectionClosed);
+ return true;
+}
+
+bool QuicTransportChannel::StartQuicHandshake() {
+ if (ssl_role_ == rtc::SSL_CLIENT) {
+ // Unique identifier for remote peer.
+ net::QuicServerId server_id(remote_fingerprint_value_, kQuicServerPort);
+ // Performs authentication of remote peer; owned by QuicCryptoClientConfig.
+ // TODO(mikescarlett): Actually verify proof.
+ net::ProofVerifier* proof_verifier = new InsecureProofVerifier();
+ quic_crypto_client_config_.reset(
+ new net::QuicCryptoClientConfig(proof_verifier));
+ net::QuicCryptoClientStream* crypto_stream =
+ new net::QuicCryptoClientStream(server_id, quic_.get(),
+ new net::ProofVerifyContext(),
+ quic_crypto_client_config_.get(), this);
+ quic_->StartClientHandshake(crypto_stream);
+ LOG_J(LS_INFO, this) << "QuicTransportChannel: Started client handshake.";
+ } else {
+ RTC_DCHECK_EQ(ssl_role_, rtc::SSL_SERVER);
+ // Provides credentials to remote peer; owned by QuicCryptoServerConfig.
+ // TODO(mikescarlett): Actually provide credentials.
+ net::ProofSource* proof_source = new InsecureProofSource();
+ // Input keying material to HKDF, per http://tools.ietf.org/html/rfc5869.
+ // This is pseudorandom so that HKDF-Extract outputs a pseudorandom key,
+ // since QuicCryptoServerConfig does not use a salt value.
+ std::string source_address_token_secret;
+ if (!rtc::CreateRandomString(kInputKeyingMaterialLength,
+ &source_address_token_secret)) {
+ LOG_J(ERROR, this) << "Error generating input keying material for HKDF.";
+ return false;
+ }
+ quic_crypto_server_config_.reset(new net::QuicCryptoServerConfig(
+ source_address_token_secret, helper_.GetRandomGenerator(),
+ proof_source));
+ // Provides server with serialized config string to prove ownership.
+ net::QuicCryptoServerConfig::ConfigOptions options;
+ quic_crypto_server_config_->AddDefaultConfig(helper_.GetRandomGenerator(),
+ helper_.GetClock(), options);
+ net::QuicCryptoServerStream* crypto_stream =
+ new net::QuicCryptoServerStream(quic_crypto_server_config_.get(),
+ quic_.get());
+ quic_->StartServerHandshake(crypto_stream);
+ LOG_J(LS_INFO, this) << "QuicTransportChannel: Started server handshake.";
+ }
+ return true;
+}
+
+bool QuicTransportChannel::HandleQuicPacket(const char* data, size_t size) {
+ ASSERT(rtc::Thread::Current() == worker_thread_);
+ return quic_->OnReadPacket(data, size);
+}
+
+net::WriteResult QuicTransportChannel::WritePacket(
+ const char* buffer,
+ size_t buf_len,
+ const net::IPAddressNumber& self_address,
+ const net::IPEndPoint& peer_address) {
+ int sent = channel_->SendPacket(buffer, buf_len, rtc::PacketOptions());
+ if (sent <= 0) {
+ int error = GetError();
+ LOG_J(LS_WARNING, this) << "Write failed with socket error " << error;
+ // Since net::WRITE_STATUS_ERROR irreversibly shuts down the QUIC
+ // connection, write status is net::WRITE_STATUS_BLOCKED so that QUIC
+ // packets are queued.
+ return net::WriteResult(net::WRITE_STATUS_BLOCKED, error);
pthatcher1 2016/02/25 08:24:24 There error is only blocking if IsBlockingError(er
mikescarlett 2016/02/26 00:54:13 I believe net::WRITE_STATUS_ERROR was closing the
mikescarlett 2016/02/26 16:52:36 Strangely the QuicSession gets torn down on net::W
+ }
+ return net::WriteResult(net::WRITE_STATUS_OK, sent);
+}
+
+// TODO(mikescarlett): |channel_| can be writable but write blocked. Since
+// channel_->GetError() is not updated when there is no error, the only option
+// seems to be writing the packet anyway in this case.
+bool QuicTransportChannel::IsWriteBlocked() const {
+ return !channel_->writable();
+}
+
+void QuicTransportChannel::OnHandshakeComplete() {
+ set_quic_state(QUIC_TRANSPORT_CONNECTED);
+ set_writable(true);
+}
+
+void QuicTransportChannel::OnConnectionClosed(net::QuicErrorCode error,
+ bool from_peer) {
+ LOG_J(LS_INFO, this) << "Connection closed by "
+ << (from_peer ? "other" : "this") << " peer "
+ << "with QUIC error " << error;
+ set_quic_state(QUIC_TRANSPORT_FAILED);
+ set_writable(false);
+}
+
+void QuicTransportChannel::OnProofValid(
+ const net::QuicCryptoClientConfig::CachedState& cached) {
+ LOG_J(LS_INFO, this) << "Cached proof marked valid";
+}
+
+void QuicTransportChannel::OnProofVerifyDetailsAvailable(
+ const net::ProofVerifyDetails& verify_details) {
+ LOG_J(LS_INFO, this) << "Proof verify details available from"
+ << " QuicCryptoClientStream";
+}
+
+bool QuicTransportChannel::HasDataToWrite() const {
+ return quic_ && quic_->HasDataToWrite();
+}
+
+void QuicTransportChannel::OnCanWrite() {
+ RTC_DCHECK(quic_ != nullptr);
+ quic_->connection()->OnCanWrite();
+}
+
+void QuicTransportChannel::set_quic_state(QuicTransportState state) {
+ LOG_J(LS_VERBOSE, this) << "set_quic_state from:" << quic_state_ << " to "
+ << state;
+ quic_state_ = state;
+}
+
+} // namespace cricket

Powered by Google App Engine
This is Rietveld 408576698