Piotr (Peter) Slatala | 2b5baee | 2019-01-16 08:25:21 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018 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 <algorithm> |
| 12 | #include <memory> |
| 13 | #include <utility> |
| 14 | |
| 15 | #include "p2p/base/no_op_dtls_transport.h" |
| 16 | |
| 17 | #include "absl/memory/memory.h" |
| 18 | #include "logging/rtc_event_log/events/rtc_event_dtls_transport_state.h" |
| 19 | #include "logging/rtc_event_log/events/rtc_event_dtls_writable_state.h" |
| 20 | #include "logging/rtc_event_log/rtc_event_log.h" |
| 21 | #include "p2p/base/packet_transport_internal.h" |
| 22 | #include "rtc_base/buffer.h" |
| 23 | #include "rtc_base/checks.h" |
| 24 | #include "rtc_base/dscp.h" |
| 25 | #include "rtc_base/logging.h" |
| 26 | #include "rtc_base/message_queue.h" |
| 27 | #include "rtc_base/rtc_certificate.h" |
| 28 | #include "rtc_base/ssl_stream_adapter.h" |
| 29 | #include "rtc_base/stream.h" |
| 30 | #include "rtc_base/thread.h" |
| 31 | |
| 32 | namespace cricket { |
| 33 | |
| 34 | NoOpDtlsTransport::NoOpDtlsTransport( |
| 35 | std::unique_ptr<IceTransportInternal> ice_transport, |
| 36 | const webrtc::CryptoOptions& crypto_options) |
| 37 | : crypto_options_(webrtc::CryptoOptions::NoGcm()), |
| 38 | ice_transport_(std::move(ice_transport)) { |
| 39 | RTC_DCHECK(ice_transport_); |
| 40 | ice_transport_->SignalWritableState.connect( |
| 41 | this, &NoOpDtlsTransport::OnWritableState); |
| 42 | ice_transport_->SignalReadyToSend.connect(this, |
| 43 | &NoOpDtlsTransport::OnReadyToSend); |
| 44 | } |
| 45 | |
| 46 | NoOpDtlsTransport::~NoOpDtlsTransport() {} |
| 47 | const webrtc::CryptoOptions& NoOpDtlsTransport::crypto_options() const { |
| 48 | return crypto_options_; |
| 49 | } |
| 50 | DtlsTransportState NoOpDtlsTransport::dtls_state() const { |
| 51 | return DTLS_TRANSPORT_CONNECTED; |
| 52 | } |
| 53 | int NoOpDtlsTransport::component() const { |
| 54 | return kNoOpDtlsTransportComponent; |
| 55 | } |
| 56 | bool NoOpDtlsTransport::IsDtlsActive() const { |
| 57 | return true; |
| 58 | } |
| 59 | bool NoOpDtlsTransport::GetDtlsRole(rtc::SSLRole* role) const { |
| 60 | return false; |
| 61 | } |
| 62 | bool NoOpDtlsTransport::SetDtlsRole(rtc::SSLRole role) { |
| 63 | return false; |
| 64 | } |
| 65 | bool NoOpDtlsTransport::GetSrtpCryptoSuite(int* cipher) { |
| 66 | return false; |
| 67 | } |
| 68 | bool NoOpDtlsTransport::GetSslCipherSuite(int* cipher) { |
| 69 | return false; |
| 70 | } |
| 71 | rtc::scoped_refptr<rtc::RTCCertificate> NoOpDtlsTransport::GetLocalCertificate() |
| 72 | const { |
| 73 | return rtc::scoped_refptr<rtc::RTCCertificate>(); |
| 74 | } |
| 75 | bool NoOpDtlsTransport::SetLocalCertificate( |
| 76 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { |
| 77 | return false; |
| 78 | } |
| 79 | std::unique_ptr<rtc::SSLCertChain> NoOpDtlsTransport::GetRemoteSSLCertChain() |
| 80 | const { |
| 81 | return std::unique_ptr<rtc::SSLCertChain>(); |
| 82 | } |
| 83 | bool NoOpDtlsTransport::ExportKeyingMaterial(const std::string& label, |
| 84 | const uint8_t* context, |
| 85 | size_t context_len, |
| 86 | bool use_context, |
| 87 | uint8_t* result, |
| 88 | size_t result_len) { |
| 89 | return false; |
| 90 | } |
| 91 | bool NoOpDtlsTransport::SetRemoteFingerprint(const std::string& digest_alg, |
| 92 | const uint8_t* digest, |
| 93 | size_t digest_len) { |
| 94 | return true; |
| 95 | } |
| 96 | bool NoOpDtlsTransport::SetSslMaxProtocolVersion( |
| 97 | rtc::SSLProtocolVersion version) { |
| 98 | return true; |
| 99 | } |
| 100 | IceTransportInternal* NoOpDtlsTransport::ice_transport() { |
| 101 | return ice_transport_.get(); |
| 102 | } |
| 103 | |
| 104 | void NoOpDtlsTransport::OnReadyToSend(rtc::PacketTransportInternal* transport) { |
| 105 | RTC_DCHECK_RUN_ON(&thread_checker_); |
| 106 | if (is_writable_) { |
| 107 | SignalReadyToSend(this); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | void NoOpDtlsTransport::OnWritableState( |
| 112 | rtc::PacketTransportInternal* transport) { |
| 113 | RTC_DCHECK_RUN_ON(&thread_checker_); |
| 114 | is_writable_ = ice_transport_->writable(); |
| 115 | if (is_writable_) { |
| 116 | SignalWritableState(this); |
| 117 | } |
| 118 | } |
| 119 | const std::string& NoOpDtlsTransport::transport_name() const { |
| 120 | return ice_transport_->transport_name(); |
| 121 | } |
| 122 | bool NoOpDtlsTransport::writable() const { |
| 123 | return ice_transport_->writable(); |
| 124 | } |
| 125 | bool NoOpDtlsTransport::receiving() const { |
| 126 | return ice_transport_->receiving(); |
| 127 | } |
| 128 | int NoOpDtlsTransport::SendPacket(const char* data, |
| 129 | size_t len, |
| 130 | const rtc::PacketOptions& options, |
| 131 | int flags) { |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | int NoOpDtlsTransport::SetOption(rtc::Socket::Option opt, int value) { |
| 136 | return ice_transport_->SetOption(opt, value); |
| 137 | } |
| 138 | |
| 139 | int NoOpDtlsTransport::GetError() { |
| 140 | return ice_transport_->GetError(); |
| 141 | } |
| 142 | |
| 143 | } // namespace cricket |