Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | |
| 3 * | |
| 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 | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include "webrtc/p2p/quic/quictransport.h" | |
| 12 | |
| 13 #include "webrtc/p2p/base/p2ptransportchannel.h" | |
| 14 | |
| 15 namespace cricket { | |
| 16 | |
| 17 QuicTransport::QuicTransport( | |
| 18 const std::string& name, | |
| 19 PortAllocator* allocator, | |
| 20 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) | |
| 21 : Transport(name, allocator), local_certificate_(certificate) {} | |
| 22 | |
| 23 QuicTransport::~QuicTransport() { | |
| 24 DestroyAllChannels(); | |
| 25 } | |
| 26 | |
| 27 void QuicTransport::SetLocalCertificate( | |
| 28 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { | |
| 29 local_certificate_ = certificate; | |
| 30 } | |
| 31 bool QuicTransport::GetLocalCertificate( | |
| 32 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { | |
| 33 if (!local_certificate_) { | |
| 34 return false; | |
| 35 } | |
| 36 *certificate = local_certificate_; | |
| 37 return true; | |
| 38 } | |
| 39 | |
| 40 bool QuicTransport::ApplyLocalTransportDescription( | |
| 41 TransportChannelImpl* channel, | |
| 42 std::string* error_desc) { | |
| 43 rtc::SSLFingerprint* local_fp = | |
| 44 local_description()->identity_fingerprint.get(); | |
| 45 if (!VerifyCertificateFingerprint(local_certificate_.get(), local_fp, | |
| 46 error_desc)) { | |
| 47 return false; | |
| 48 } | |
| 49 if (!channel->SetLocalCertificate(local_certificate_)) { | |
| 50 return BadTransportDescription("Failed to set local identity.", error_desc); | |
| 51 } | |
| 52 return Transport::ApplyLocalTransportDescription(channel, error_desc); | |
| 53 } | |
| 54 | |
| 55 bool QuicTransport::NegotiateTransportDescription(ContentAction action, | |
| 56 std::string* error_desc) { | |
| 57 rtc::SSLFingerprint* local_fp = | |
| 58 remote_description()->identity_fingerprint.get(); | |
|
Taylor Brandstetter
2016/04/12 22:33:11
This should be local_description(), right? And aga
pthatcher1
2016/04/12 23:26:59
Yeah, similar to what I said earlier. We should d
mikescarlett
2016/04/13 00:58:24
I added a check similar to DtlsTransport.
mikescarlett
2016/04/13 00:58:24
Done.
| |
| 59 rtc::SSLFingerprint* remote_fp = | |
| 60 remote_description()->identity_fingerprint.get(); | |
| 61 if (!local_fp || !remote_fp) { | |
| 62 return BadTransportDescription("Fingerprints must be supplied for QUIC.", | |
| 63 error_desc); | |
| 64 } | |
| 65 remote_fingerprint_.reset(new rtc::SSLFingerprint(*remote_fp)); | |
| 66 if (!NegotiateRole(action, &local_role_, error_desc)) { | |
| 67 return false; | |
| 68 } | |
| 69 // Now run the negotiation for the Transport class. | |
| 70 return Transport::NegotiateTransportDescription(action, error_desc); | |
| 71 } | |
| 72 | |
| 73 QuicTransportChannel* QuicTransport::CreateTransportChannel(int component) { | |
| 74 P2PTransportChannel* ice_channel = | |
| 75 new P2PTransportChannel(name(), component, port_allocator()); | |
| 76 return new QuicTransportChannel(ice_channel); | |
| 77 } | |
| 78 | |
| 79 void QuicTransport::DestroyTransportChannel(TransportChannelImpl* channel) { | |
| 80 RTC_DCHECK(channel != nullptr); | |
| 81 QuicTransportChannel* quic_transport_channel = | |
| 82 static_cast<QuicTransportChannel*>(channel); | |
| 83 delete quic_transport_channel->channel(); | |
| 84 delete quic_transport_channel; | |
| 85 } | |
| 86 | |
| 87 bool QuicTransport::GetSslRole(rtc::SSLRole* ssl_role) const { | |
| 88 ASSERT(ssl_role != NULL); | |
| 89 *ssl_role = local_role_; | |
| 90 return true; | |
| 91 } | |
| 92 | |
| 93 bool QuicTransport::ApplyNegotiatedTransportDescription( | |
| 94 TransportChannelImpl* channel, | |
| 95 std::string* error_desc) { | |
| 96 // Set ssl role and remote fingerprint. These are required for QUIC setup. | |
| 97 if (!channel->SetSslRole(local_role_)) { | |
| 98 return BadTransportDescription("Failed to set ssl role for the channel.", | |
| 99 error_desc); | |
| 100 } | |
| 101 // Apply remote fingerprint. | |
| 102 if (!channel->SetRemoteFingerprint( | |
| 103 remote_fingerprint_->algorithm, | |
| 104 reinterpret_cast<const uint8_t*>(remote_fingerprint_->digest.data()), | |
| 105 remote_fingerprint_->digest.size())) { | |
| 106 return BadTransportDescription("Failed to apply remote fingerprint.", | |
| 107 error_desc); | |
| 108 } | |
| 109 return Transport::ApplyNegotiatedTransportDescription(channel, error_desc); | |
| 110 } | |
| 111 | |
| 112 } // namespace cricket | |
| OLD | NEW |