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 #ifndef WEBRTC_P2P_BASE_UDPTRANSPORTCHANNEL_H_ |
| 12 #define WEBRTC_P2P_BASE_UDPTRANSPORTCHANNEL_H_ |
| 13 |
| 14 #include <memory> |
| 15 #include <string> |
| 16 |
| 17 #include "webrtc/base/socketaddress.h" |
| 18 #include "webrtc/base/thread_checker.h" |
| 19 #include "webrtc/p2p/base/transportchannel.h" |
| 20 #include "webrtc/p2p/base/transportchannelimpl.h" |
| 21 |
| 22 namespace rtc { |
| 23 class AsyncUDPSocket; |
| 24 class PhysicalSocketServer; |
| 25 class SocketServer; |
| 26 class Thread; |
| 27 } |
| 28 |
| 29 namespace cricket { |
| 30 |
| 31 class UdpTransportChannel : public TransportChannelImpl { |
| 32 public: |
| 33 UdpTransportChannel(const std::string& transport_name, int component); |
| 34 UdpTransportChannel(const std::string& transport_name, |
| 35 int component, |
| 36 rtc::SocketServer* ss); |
| 37 ~UdpTransportChannel(); |
| 38 int SendPacket(const char* data, |
| 39 size_t len, |
| 40 const rtc::PacketOptions& options, |
| 41 int flags) override; |
| 42 TransportChannelState GetState() const override { |
| 43 RTC_DCHECK_RUN_ON(&network_thread_checker_); |
| 44 return state_; |
| 45 } |
| 46 |
| 47 int SetOption(rtc::Socket::Option opt, int value) override { return 0; } |
| 48 |
| 49 int GetError() override { return send_error_; } |
| 50 |
| 51 bool GetStats(ConnectionInfos* infos) override { return false; } |
| 52 |
| 53 bool IsDtlsActive() const override { |
| 54 // TODO(johan) remove, when PacketTransportInterface is available. |
| 55 return false; |
| 56 } |
| 57 |
| 58 bool GetSslRole(rtc::SSLRole* role) const override { |
| 59 RTC_NOTREACHED(); |
| 60 return false; |
| 61 } |
| 62 |
| 63 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override { |
| 64 RTC_NOTREACHED(); |
| 65 return nullptr; |
| 66 } |
| 67 |
| 68 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate() |
| 69 const override { |
| 70 RTC_NOTREACHED(); |
| 71 return nullptr; |
| 72 } |
| 73 |
| 74 bool ExportKeyingMaterial(const std::string& label, |
| 75 const uint8_t* context, |
| 76 size_t context_len, |
| 77 bool use_context, |
| 78 uint8_t* result, |
| 79 size_t result_len) override { |
| 80 RTC_NOTREACHED(); |
| 81 return false; |
| 82 } |
| 83 |
| 84 // TransportChannelImpl overrides |
| 85 IceRole GetIceRole() const override { |
| 86 RTC_NOTREACHED(); |
| 87 return ICEROLE_UNKNOWN; |
| 88 } |
| 89 |
| 90 // TODO(johan): Remove all ICE- and DTLS-specific methods. |
| 91 void SetIceRole(IceRole role) override { RTC_NOTREACHED(); } |
| 92 |
| 93 void SetIceTiebreaker(uint64_t tiebreaker) override { RTC_NOTREACHED(); } |
| 94 |
| 95 void SetIceParameters(const IceParameters& ice_params) override { |
| 96 RTC_NOTREACHED(); |
| 97 } |
| 98 |
| 99 void SetRemoteIceParameters(const IceParameters& ice_params) override { |
| 100 RTC_NOTREACHED(); |
| 101 } |
| 102 |
| 103 void SetRemoteIceMode(IceMode mode) override { RTC_NOTREACHED(); } |
| 104 |
| 105 void SetIceConfig(const IceConfig& config) override { RTC_NOTREACHED(); } |
| 106 |
| 107 void MaybeStartGathering() override; |
| 108 |
| 109 void AddRemoteCandidate(const Candidate& candidate) override; |
| 110 |
| 111 // TransportChannelImpl overrides |
| 112 void RemoveRemoteCandidate(const Candidate& candidate) override { |
| 113 RTC_NOTREACHED(); |
| 114 } |
| 115 |
| 116 IceGatheringState gathering_state() const override { |
| 117 RTC_DCHECK_RUN_ON(&network_thread_checker_); |
| 118 return gathering_state_; |
| 119 } |
| 120 |
| 121 bool SetLocalCertificate( |
| 122 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override { |
| 123 RTC_NOTREACHED(); |
| 124 return false; |
| 125 } |
| 126 |
| 127 bool SetRemoteFingerprint(const std::string& digest_alg, |
| 128 const uint8_t* digest, |
| 129 size_t digest_len) override { |
| 130 RTC_NOTREACHED(); |
| 131 return false; |
| 132 } |
| 133 |
| 134 bool SetSslRole(rtc::SSLRole role) override { |
| 135 RTC_NOTREACHED(); |
| 136 return false; |
| 137 } |
| 138 |
| 139 void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override { |
| 140 } |
| 141 |
| 142 private: |
| 143 void OnSocketReadPacket(rtc::AsyncPacketSocket* socket, |
| 144 const char* data, |
| 145 size_t len, |
| 146 const rtc::SocketAddress& remote_addr, |
| 147 const rtc::PacketTime& packet_time); |
| 148 bool TryAllocateSockets(); |
| 149 void SetGatheringState( |
| 150 IceGatheringState gathering_state); // Set State and Signal. |
| 151 void SetTransportChannelState( |
| 152 TransportChannelState new_tch_state); // Set State and Signal. |
| 153 TransportChannelState state_ = STATE_INIT; |
| 154 IceGatheringState gathering_state_ = kIceGatheringNew; |
| 155 bool IsLocalConsistent(); |
| 156 bool IsRemoteConsistent(); |
| 157 void UpdateState(); |
| 158 int send_error_ = 0; |
| 159 std::unique_ptr<rtc::AsyncUDPSocket> socket_; |
| 160 // TODO(johan): use a non-ICE datatype for paramters with |
| 161 // PacketTransportInterface. |
| 162 rtc::Optional<Candidate> local_parameters_; |
| 163 rtc::Optional<Candidate> remote_parameters_; |
| 164 rtc::SocketServer* socket_server_; |
| 165 rtc::ThreadChecker network_thread_checker_; |
| 166 }; |
| 167 } // namespace cricket |
| 168 |
| 169 #endif // WEBRTC_P2P_BASE_UDPTRANSPORTCHANNEL_H_ |
OLD | NEW |