| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ | 11 #ifndef WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ |
| 12 #define WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ | 12 #define WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ |
| 13 | 13 |
| 14 #include <map> | |
| 15 #include <memory> | 14 #include <memory> |
| 16 #include <string> | 15 #include <string> |
| 17 #include <vector> | 16 #include <vector> |
| 18 | 17 |
| 19 #include "webrtc/base/bind.h" | 18 #include "webrtc/base/bind.h" |
| 20 #include "webrtc/base/buffer.h" | |
| 21 #include "webrtc/base/fakesslidentity.h" | |
| 22 #include "webrtc/base/messagequeue.h" | |
| 23 #include "webrtc/base/sigslot.h" | |
| 24 #include "webrtc/base/sslfingerprint.h" | 19 #include "webrtc/base/sslfingerprint.h" |
| 25 #include "webrtc/base/thread.h" | 20 #include "webrtc/base/thread.h" |
| 26 #include "webrtc/p2p/base/candidatepairinterface.h" | 21 #include "webrtc/p2p/base/fakedtlstransport.h" |
| 27 #include "webrtc/p2p/base/dtlstransportinternal.h" | 22 #include "webrtc/p2p/base/fakeicetransport.h" |
| 28 #include "webrtc/p2p/base/icetransportinternal.h" | |
| 29 | |
| 30 #include "webrtc/p2p/base/transportcontroller.h" | 23 #include "webrtc/p2p/base/transportcontroller.h" |
| 31 | 24 |
| 32 #ifdef HAVE_QUIC | |
| 33 #include "webrtc/p2p/quic/quictransport.h" | |
| 34 #endif | |
| 35 | |
| 36 namespace cricket { | 25 namespace cricket { |
| 37 | 26 |
| 38 namespace { | 27 // Fake TransportController class, which can be passed into a WebRtcSession |
| 39 struct PacketMessageData : public rtc::MessageData { | 28 // object for test purposes. Can be connected to other FakeTransportControllers |
| 40 PacketMessageData(const char* data, size_t len) : packet(data, len) {} | 29 // via Connect(). |
| 41 rtc::Buffer packet; | |
| 42 }; | |
| 43 } // namespace | |
| 44 | |
| 45 class FakeIceTransport : public IceTransportInternal, | |
| 46 public rtc::MessageHandler { | |
| 47 public: | |
| 48 explicit FakeIceTransport(const std::string& name, int component) | |
| 49 : name_(name), component_(component) {} | |
| 50 ~FakeIceTransport() { Reset(); } | |
| 51 | |
| 52 const std::string& transport_name() const override { return name_; } | |
| 53 int component() const override { return component_; } | |
| 54 uint64_t IceTiebreaker() const { return tiebreaker_; } | |
| 55 IceMode remote_ice_mode() const { return remote_ice_mode_; } | |
| 56 const std::string& ice_ufrag() const { return ice_ufrag_; } | |
| 57 const std::string& ice_pwd() const { return ice_pwd_; } | |
| 58 const std::string& remote_ice_ufrag() const { return remote_ice_ufrag_; } | |
| 59 const std::string& remote_ice_pwd() const { return remote_ice_pwd_; } | |
| 60 | |
| 61 // If async, will send packets by "Post"-ing to message queue instead of | |
| 62 // synchronously "Send"-ing. | |
| 63 void SetAsync(bool async) { async_ = async; } | |
| 64 void SetAsyncDelay(int delay_ms) { async_delay_ms_ = delay_ms; } | |
| 65 | |
| 66 IceTransportState GetState() const override { | |
| 67 if (connection_count_ == 0) { | |
| 68 return had_connection_ ? IceTransportState::STATE_FAILED | |
| 69 : IceTransportState::STATE_INIT; | |
| 70 } | |
| 71 | |
| 72 if (connection_count_ == 1) { | |
| 73 return IceTransportState::STATE_COMPLETED; | |
| 74 } | |
| 75 | |
| 76 return IceTransportState::STATE_CONNECTING; | |
| 77 } | |
| 78 | |
| 79 void SetIceRole(IceRole role) override { role_ = role; } | |
| 80 IceRole GetIceRole() const override { return role_; } | |
| 81 void SetIceTiebreaker(uint64_t tiebreaker) override { | |
| 82 tiebreaker_ = tiebreaker; | |
| 83 } | |
| 84 void SetIceParameters(const IceParameters& ice_params) override { | |
| 85 ice_ufrag_ = ice_params.ufrag; | |
| 86 ice_pwd_ = ice_params.pwd; | |
| 87 } | |
| 88 void SetRemoteIceParameters(const IceParameters& params) override { | |
| 89 remote_ice_ufrag_ = params.ufrag; | |
| 90 remote_ice_pwd_ = params.pwd; | |
| 91 } | |
| 92 | |
| 93 void SetRemoteIceMode(IceMode mode) override { remote_ice_mode_ = mode; } | |
| 94 | |
| 95 void MaybeStartGathering() override { | |
| 96 if (gathering_state_ == kIceGatheringNew) { | |
| 97 gathering_state_ = kIceGatheringGathering; | |
| 98 SignalGatheringState(this); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 IceGatheringState gathering_state() const override { | |
| 103 return gathering_state_; | |
| 104 } | |
| 105 | |
| 106 void Reset() { | |
| 107 if (state_ != STATE_INIT) { | |
| 108 state_ = STATE_INIT; | |
| 109 if (dest_) { | |
| 110 dest_->state_ = STATE_INIT; | |
| 111 dest_->dest_ = nullptr; | |
| 112 dest_ = nullptr; | |
| 113 } | |
| 114 } | |
| 115 } | |
| 116 | |
| 117 void SetWritable(bool writable) { set_writable(writable); } | |
| 118 | |
| 119 void set_writable(bool writable) { | |
| 120 if (writable_ == writable) { | |
| 121 return; | |
| 122 } | |
| 123 LOG(INFO) << "set_writable from:" << writable_ << " to " << writable; | |
| 124 writable_ = writable; | |
| 125 if (writable_) { | |
| 126 SignalReadyToSend(this); | |
| 127 } | |
| 128 SignalWritableState(this); | |
| 129 } | |
| 130 bool writable() const override { return writable_; } | |
| 131 | |
| 132 // Simulates the two transports connecting to each other. | |
| 133 // If |asymmetric| is true this method only affects this FakeIceTransport. | |
| 134 // If false, it affects |dest| as well. | |
| 135 void SetDestination(FakeIceTransport* dest, bool asymmetric = false) { | |
| 136 if (state_ == STATE_INIT && dest) { | |
| 137 // This simulates the delivery of candidates. | |
| 138 dest_ = dest; | |
| 139 state_ = STATE_CONNECTED; | |
| 140 set_writable(true); | |
| 141 if (!asymmetric) { | |
| 142 dest->SetDestination(this, true); | |
| 143 } | |
| 144 } else if (state_ == STATE_CONNECTED && !dest) { | |
| 145 // Simulates loss of connectivity, by asymmetrically forgetting dest_. | |
| 146 dest_ = nullptr; | |
| 147 state_ = STATE_INIT; | |
| 148 set_writable(false); | |
| 149 } | |
| 150 } | |
| 151 | |
| 152 void SetConnectionCount(size_t connection_count) { | |
| 153 size_t old_connection_count = connection_count_; | |
| 154 connection_count_ = connection_count; | |
| 155 if (connection_count) | |
| 156 had_connection_ = true; | |
| 157 // In this fake transport channel, |connection_count_| determines the | |
| 158 // transport channel state. | |
| 159 if (connection_count_ < old_connection_count) | |
| 160 SignalStateChanged(this); | |
| 161 } | |
| 162 | |
| 163 void SetCandidatesGatheringComplete() { | |
| 164 if (gathering_state_ != kIceGatheringComplete) { | |
| 165 gathering_state_ = kIceGatheringComplete; | |
| 166 SignalGatheringState(this); | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 void SetReceiving(bool receiving) { set_receiving(receiving); } | |
| 171 | |
| 172 void set_receiving(bool receiving) { | |
| 173 if (receiving_ == receiving) { | |
| 174 return; | |
| 175 } | |
| 176 receiving_ = receiving; | |
| 177 SignalReceivingState(this); | |
| 178 } | |
| 179 bool receiving() const override { return receiving_; } | |
| 180 | |
| 181 void SetIceConfig(const IceConfig& config) override { ice_config_ = config; } | |
| 182 | |
| 183 int receiving_timeout() const { return ice_config_.receiving_timeout; } | |
| 184 bool gather_continually() const { return ice_config_.gather_continually(); } | |
| 185 | |
| 186 int SendPacket(const char* data, | |
| 187 size_t len, | |
| 188 const rtc::PacketOptions& options, | |
| 189 int flags) override { | |
| 190 if (state_ != STATE_CONNECTED) { | |
| 191 return -1; | |
| 192 } | |
| 193 | |
| 194 if (flags != PF_SRTP_BYPASS && flags != 0) { | |
| 195 return -1; | |
| 196 } | |
| 197 | |
| 198 PacketMessageData* packet = new PacketMessageData(data, len); | |
| 199 if (async_) { | |
| 200 if (async_delay_ms_) { | |
| 201 rtc::Thread::Current()->PostDelayed(RTC_FROM_HERE, async_delay_ms_, | |
| 202 this, 0, packet); | |
| 203 } else { | |
| 204 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, 0, packet); | |
| 205 } | |
| 206 } else { | |
| 207 rtc::Thread::Current()->Send(RTC_FROM_HERE, this, 0, packet); | |
| 208 } | |
| 209 rtc::SentPacket sent_packet(options.packet_id, rtc::TimeMillis()); | |
| 210 SignalSentPacket(this, sent_packet); | |
| 211 return static_cast<int>(len); | |
| 212 } | |
| 213 int SetOption(rtc::Socket::Option opt, int value) override { return true; } | |
| 214 bool GetOption(rtc::Socket::Option opt, int* value) override { return true; } | |
| 215 int GetError() override { return 0; } | |
| 216 | |
| 217 void AddRemoteCandidate(const Candidate& candidate) override { | |
| 218 remote_candidates_.push_back(candidate); | |
| 219 } | |
| 220 | |
| 221 void RemoveRemoteCandidate(const Candidate& candidate) override {} | |
| 222 | |
| 223 const Candidates& remote_candidates() const { return remote_candidates_; } | |
| 224 | |
| 225 void OnMessage(rtc::Message* msg) override { | |
| 226 PacketMessageData* data = static_cast<PacketMessageData*>(msg->pdata); | |
| 227 dest_->SignalReadPacket(dest_, data->packet.data<char>(), | |
| 228 data->packet.size(), rtc::CreatePacketTime(0), 0); | |
| 229 delete data; | |
| 230 } | |
| 231 | |
| 232 bool GetStats(ConnectionInfos* infos) override { | |
| 233 ConnectionInfo info; | |
| 234 infos->clear(); | |
| 235 infos->push_back(info); | |
| 236 return true; | |
| 237 } | |
| 238 | |
| 239 void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override { | |
| 240 } | |
| 241 | |
| 242 private: | |
| 243 std::string name_; | |
| 244 int component_; | |
| 245 enum State { STATE_INIT, STATE_CONNECTED }; | |
| 246 FakeIceTransport* dest_ = nullptr; | |
| 247 State state_ = STATE_INIT; | |
| 248 bool async_ = false; | |
| 249 int async_delay_ms_ = 0; | |
| 250 Candidates remote_candidates_; | |
| 251 IceConfig ice_config_; | |
| 252 IceRole role_ = ICEROLE_UNKNOWN; | |
| 253 uint64_t tiebreaker_ = 0; | |
| 254 std::string ice_ufrag_; | |
| 255 std::string ice_pwd_; | |
| 256 std::string remote_ice_ufrag_; | |
| 257 std::string remote_ice_pwd_; | |
| 258 IceMode remote_ice_mode_ = ICEMODE_FULL; | |
| 259 size_t connection_count_ = 0; | |
| 260 IceGatheringState gathering_state_ = kIceGatheringNew; | |
| 261 bool had_connection_ = false; | |
| 262 bool writable_ = false; | |
| 263 bool receiving_ = false; | |
| 264 }; | |
| 265 | |
| 266 class FakeDtlsTransport : public DtlsTransportInternal { | |
| 267 public: | |
| 268 explicit FakeDtlsTransport(FakeIceTransport* ice_transport) | |
| 269 : ice_transport_(ice_transport), | |
| 270 transport_name_(ice_transport->transport_name()), | |
| 271 component_(ice_transport->component()), | |
| 272 dtls_fingerprint_("", nullptr, 0) { | |
| 273 ice_transport_->SignalReadPacket.connect( | |
| 274 this, &FakeDtlsTransport::OnIceTransportReadPacket); | |
| 275 } | |
| 276 | |
| 277 // If this constructor is called, a new fake ice transport will be created, | |
| 278 // and this FakeDtlsTransport will take the ownership. | |
| 279 explicit FakeDtlsTransport(const std::string& name, int component) | |
| 280 : owned_ice_transport_(new FakeIceTransport(name, component)), | |
| 281 transport_name_(owned_ice_transport_->transport_name()), | |
| 282 component_(owned_ice_transport_->component()), | |
| 283 dtls_fingerprint_("", nullptr, 0) { | |
| 284 ice_transport_ = owned_ice_transport_.get(); | |
| 285 ice_transport_->SignalReadPacket.connect( | |
| 286 this, &FakeDtlsTransport::OnIceTransportReadPacket); | |
| 287 } | |
| 288 | |
| 289 ~FakeDtlsTransport() override { Reset(); } | |
| 290 | |
| 291 uint64_t IceTiebreaker() const { return ice_transport_->IceTiebreaker(); } | |
| 292 IceMode remote_ice_mode() const { return ice_transport_->remote_ice_mode(); } | |
| 293 const std::string& ice_ufrag() const { return ice_transport_->ice_ufrag(); } | |
| 294 const std::string& ice_pwd() const { return ice_transport_->ice_pwd(); } | |
| 295 const std::string& remote_ice_ufrag() const { | |
| 296 return ice_transport_->remote_ice_ufrag(); | |
| 297 } | |
| 298 const std::string& remote_ice_pwd() const { | |
| 299 return ice_transport_->remote_ice_pwd(); | |
| 300 } | |
| 301 | |
| 302 DtlsTransportState dtls_state() const override { return dtls_state_; } | |
| 303 | |
| 304 const std::string& transport_name() const override { return transport_name_; } | |
| 305 | |
| 306 int component() const override { return component_; } | |
| 307 | |
| 308 const rtc::SSLFingerprint& dtls_fingerprint() const { | |
| 309 return dtls_fingerprint_; | |
| 310 } | |
| 311 | |
| 312 // If async, will send packets by "Post"-ing to message queue instead of | |
| 313 // synchronously "Send"-ing. | |
| 314 void SetAsync(bool async) { ice_transport_->SetAsync(async); } | |
| 315 void SetAsyncDelay(int delay_ms) { ice_transport_->SetAsyncDelay(delay_ms); } | |
| 316 | |
| 317 IceRole GetIceRole() const { return ice_transport_->GetIceRole(); } | |
| 318 | |
| 319 bool SetRemoteFingerprint(const std::string& alg, | |
| 320 const uint8_t* digest, | |
| 321 size_t digest_len) override { | |
| 322 dtls_fingerprint_ = rtc::SSLFingerprint(alg, digest, digest_len); | |
| 323 return true; | |
| 324 } | |
| 325 | |
| 326 bool SetSslRole(rtc::SSLRole role) override { | |
| 327 ssl_role_ = role; | |
| 328 return true; | |
| 329 } | |
| 330 | |
| 331 bool GetSslRole(rtc::SSLRole* role) const override { | |
| 332 *role = ssl_role_; | |
| 333 return true; | |
| 334 } | |
| 335 | |
| 336 IceGatheringState gathering_state() const { | |
| 337 return ice_transport_->gathering_state(); | |
| 338 } | |
| 339 | |
| 340 void Reset() { | |
| 341 if (state_ != STATE_INIT) { | |
| 342 state_ = STATE_INIT; | |
| 343 if (dest_) { | |
| 344 dest_->state_ = STATE_INIT; | |
| 345 dest_->dest_ = nullptr; | |
| 346 dest_ = nullptr; | |
| 347 } | |
| 348 } | |
| 349 } | |
| 350 | |
| 351 void SetWritable(bool writable) { set_writable(writable); } | |
| 352 | |
| 353 // Simulates the two transport channels connecting to each other. | |
| 354 // If |asymmetric| is true this method only affects this FakeDtlsTransport. | |
| 355 // If false, it affects |dest| as well. | |
| 356 void SetDestination(FakeDtlsTransport* dest, bool asymmetric = false) { | |
| 357 if (state_ == STATE_INIT && dest) { | |
| 358 // This simulates the delivery of candidates. | |
| 359 dest_ = dest; | |
| 360 if (local_cert_ && dest_->local_cert_) { | |
| 361 do_dtls_ = true; | |
| 362 NegotiateSrtpCiphers(); | |
| 363 } | |
| 364 state_ = STATE_CONNECTED; | |
| 365 SetWritable(true); | |
| 366 if (!asymmetric) { | |
| 367 dest->SetDestination(this, true); | |
| 368 } | |
| 369 ice_transport_->SetDestination( | |
| 370 static_cast<FakeIceTransport*>(dest->ice_transport()), asymmetric); | |
| 371 } else if (state_ == STATE_CONNECTED && !dest) { | |
| 372 // Simulates loss of connectivity, by asymmetrically forgetting dest_. | |
| 373 dest_ = nullptr; | |
| 374 state_ = STATE_INIT; | |
| 375 SetWritable(false); | |
| 376 ice_transport_->SetDestination(nullptr, asymmetric); | |
| 377 } | |
| 378 } | |
| 379 | |
| 380 void SetConnectionCount(size_t connection_count) { | |
| 381 ice_transport_->SetConnectionCount(connection_count); | |
| 382 } | |
| 383 | |
| 384 void SetCandidatesGatheringComplete() { | |
| 385 ice_transport_->SetCandidatesGatheringComplete(); | |
| 386 } | |
| 387 | |
| 388 void SetReceiving(bool receiving) { | |
| 389 ice_transport_->SetReceiving(receiving); | |
| 390 set_receiving(receiving); | |
| 391 } | |
| 392 | |
| 393 int receiving_timeout() const { return ice_transport_->receiving_timeout(); } | |
| 394 bool gather_continually() const { | |
| 395 return ice_transport_->gather_continually(); | |
| 396 } | |
| 397 | |
| 398 int SendPacket(const char* data, | |
| 399 size_t len, | |
| 400 const rtc::PacketOptions& options, | |
| 401 int flags) override { | |
| 402 return ice_transport_->SendPacket(data, len, options, flags); | |
| 403 } | |
| 404 | |
| 405 bool GetOption(rtc::Socket::Option opt, int* value) override { return true; } | |
| 406 | |
| 407 const Candidates& remote_candidates() const { | |
| 408 return ice_transport_->remote_candidates(); | |
| 409 } | |
| 410 | |
| 411 void OnIceTransportReadPacket(PacketTransportInterface* ice_, | |
| 412 const char* data, | |
| 413 size_t len, | |
| 414 const rtc::PacketTime& time, | |
| 415 int flags) { | |
| 416 SignalReadPacket(this, data, len, time, flags); | |
| 417 } | |
| 418 | |
| 419 bool SetLocalCertificate( | |
| 420 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override { | |
| 421 local_cert_ = certificate; | |
| 422 return true; | |
| 423 } | |
| 424 | |
| 425 void SetRemoteSSLCertificate(rtc::FakeSSLCertificate* cert) { | |
| 426 remote_cert_ = cert; | |
| 427 } | |
| 428 | |
| 429 bool IsDtlsActive() const override { return do_dtls_; } | |
| 430 | |
| 431 bool SetSrtpCryptoSuites(const std::vector<int>& ciphers) override { | |
| 432 srtp_ciphers_ = ciphers; | |
| 433 return true; | |
| 434 } | |
| 435 | |
| 436 bool GetSrtpCryptoSuite(int* crypto_suite) override { | |
| 437 if (chosen_crypto_suite_ != rtc::SRTP_INVALID_CRYPTO_SUITE) { | |
| 438 *crypto_suite = chosen_crypto_suite_; | |
| 439 return true; | |
| 440 } | |
| 441 return false; | |
| 442 } | |
| 443 | |
| 444 bool GetSslCipherSuite(int* cipher_suite) override { return false; } | |
| 445 | |
| 446 rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override { | |
| 447 return local_cert_; | |
| 448 } | |
| 449 | |
| 450 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate() | |
| 451 const override { | |
| 452 return remote_cert_ ? std::unique_ptr<rtc::SSLCertificate>( | |
| 453 remote_cert_->GetReference()) | |
| 454 : nullptr; | |
| 455 } | |
| 456 | |
| 457 bool ExportKeyingMaterial(const std::string& label, | |
| 458 const uint8_t* context, | |
| 459 size_t context_len, | |
| 460 bool use_context, | |
| 461 uint8_t* result, | |
| 462 size_t result_len) override { | |
| 463 if (chosen_crypto_suite_ != rtc::SRTP_INVALID_CRYPTO_SUITE) { | |
| 464 memset(result, 0xff, result_len); | |
| 465 return true; | |
| 466 } | |
| 467 | |
| 468 return false; | |
| 469 } | |
| 470 | |
| 471 void set_ssl_max_protocol_version(rtc::SSLProtocolVersion version) { | |
| 472 ssl_max_version_ = version; | |
| 473 } | |
| 474 rtc::SSLProtocolVersion ssl_max_protocol_version() const { | |
| 475 return ssl_max_version_; | |
| 476 } | |
| 477 | |
| 478 IceTransportInternal* ice_transport() override { return ice_transport_; } | |
| 479 | |
| 480 bool writable() const override { return writable_; } | |
| 481 | |
| 482 bool receiving() const override { return receiving_; } | |
| 483 | |
| 484 int GetError() override { return ice_transport_->GetError(); } | |
| 485 | |
| 486 int SetOption(rtc::Socket::Option opt, int value) override { | |
| 487 return ice_transport_->SetOption(opt, value); | |
| 488 } | |
| 489 | |
| 490 bool SetSrtpCiphers(const std::vector<std::string>& ciphers) override { | |
| 491 std::vector<int> crypto_suites; | |
| 492 for (const auto cipher : ciphers) { | |
| 493 crypto_suites.push_back(rtc::SrtpCryptoSuiteFromName(cipher)); | |
| 494 } | |
| 495 return SetSrtpCryptoSuites(crypto_suites); | |
| 496 } | |
| 497 | |
| 498 private: | |
| 499 void NegotiateSrtpCiphers() { | |
| 500 for (std::vector<int>::const_iterator it1 = srtp_ciphers_.begin(); | |
| 501 it1 != srtp_ciphers_.end(); ++it1) { | |
| 502 for (std::vector<int>::const_iterator it2 = dest_->srtp_ciphers_.begin(); | |
| 503 it2 != dest_->srtp_ciphers_.end(); ++it2) { | |
| 504 if (*it1 == *it2) { | |
| 505 chosen_crypto_suite_ = *it1; | |
| 506 return; | |
| 507 } | |
| 508 } | |
| 509 } | |
| 510 } | |
| 511 | |
| 512 void set_receiving(bool receiving) { | |
| 513 if (receiving_ == receiving) { | |
| 514 return; | |
| 515 } | |
| 516 receiving_ = receiving; | |
| 517 SignalReceivingState(this); | |
| 518 } | |
| 519 | |
| 520 void set_writable(bool writable) { | |
| 521 if (writable_ == writable) { | |
| 522 return; | |
| 523 } | |
| 524 writable_ = writable; | |
| 525 if (writable_) { | |
| 526 SignalReadyToSend(this); | |
| 527 } | |
| 528 SignalWritableState(this); | |
| 529 } | |
| 530 | |
| 531 enum State { STATE_INIT, STATE_CONNECTED }; | |
| 532 FakeIceTransport* ice_transport_; | |
| 533 std::unique_ptr<FakeIceTransport> owned_ice_transport_; | |
| 534 std::string transport_name_; | |
| 535 int component_; | |
| 536 FakeDtlsTransport* dest_ = nullptr; | |
| 537 State state_ = STATE_INIT; | |
| 538 Candidates remote_candidates_; | |
| 539 rtc::scoped_refptr<rtc::RTCCertificate> local_cert_; | |
| 540 rtc::FakeSSLCertificate* remote_cert_ = nullptr; | |
| 541 bool do_dtls_ = false; | |
| 542 std::vector<int> srtp_ciphers_; | |
| 543 int chosen_crypto_suite_ = rtc::SRTP_INVALID_CRYPTO_SUITE; | |
| 544 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; | |
| 545 rtc::SSLFingerprint dtls_fingerprint_; | |
| 546 rtc::SSLRole ssl_role_ = rtc::SSL_CLIENT; | |
| 547 | |
| 548 DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW; | |
| 549 | |
| 550 bool receiving_ = false; | |
| 551 bool writable_ = false; | |
| 552 }; | |
| 553 | |
| 554 // Fake candidate pair class, which can be passed to BaseChannel for testing | |
| 555 // purposes. | |
| 556 class FakeCandidatePair : public CandidatePairInterface { | |
| 557 public: | |
| 558 FakeCandidatePair(const Candidate& local_candidate, | |
| 559 const Candidate& remote_candidate) | |
| 560 : local_candidate_(local_candidate), | |
| 561 remote_candidate_(remote_candidate) {} | |
| 562 const Candidate& local_candidate() const override { return local_candidate_; } | |
| 563 const Candidate& remote_candidate() const override { | |
| 564 return remote_candidate_; | |
| 565 } | |
| 566 | |
| 567 private: | |
| 568 Candidate local_candidate_; | |
| 569 Candidate remote_candidate_; | |
| 570 }; | |
| 571 | |
| 572 // Fake TransportController class, which can be passed into a BaseChannel object | |
| 573 // for test purposes. Can be connected to other FakeTransportControllers via | |
| 574 // Connect(). | |
| 575 // | 30 // |
| 576 // This fake is unusual in that for the most part, it's implemented with the | 31 // This fake is unusual in that for the most part, it's implemented with the |
| 577 // real TransportController code, but with fake TransportChannels underneath. | 32 // real TransportController code, but with fake TransportChannels underneath. |
| 578 class FakeTransportController : public TransportController { | 33 class FakeTransportController : public TransportController { |
| 579 public: | 34 public: |
| 580 FakeTransportController() | 35 FakeTransportController() |
| 581 : TransportController(rtc::Thread::Current(), | 36 : TransportController(rtc::Thread::Current(), |
| 582 rtc::Thread::Current(), | 37 rtc::Thread::Current(), |
| 583 nullptr) {} | 38 nullptr) {} |
| 584 | 39 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 cricket::CA_ANSWER, &err); | 101 cricket::CA_ANSWER, &err); |
| 647 } | 102 } |
| 648 MaybeStartGathering(); | 103 MaybeStartGathering(); |
| 649 dest->MaybeStartGathering(); | 104 dest->MaybeStartGathering(); |
| 650 network_thread()->Invoke<void>( | 105 network_thread()->Invoke<void>( |
| 651 RTC_FROM_HERE, | 106 RTC_FROM_HERE, |
| 652 rtc::Bind(&FakeTransportController::SetChannelDestinations_n, this, | 107 rtc::Bind(&FakeTransportController::SetChannelDestinations_n, this, |
| 653 dest)); | 108 dest)); |
| 654 } | 109 } |
| 655 | 110 |
| 656 FakeCandidatePair* CreateFakeCandidatePair( | |
| 657 const rtc::SocketAddress& local_address, | |
| 658 int16_t local_network_id, | |
| 659 const rtc::SocketAddress& remote_address, | |
| 660 int16_t remote_network_id) { | |
| 661 Candidate local_candidate(0, "udp", local_address, 0u, "", "", "local", 0, | |
| 662 "foundation", local_network_id, 0); | |
| 663 Candidate remote_candidate(0, "udp", remote_address, 0u, "", "", "local", 0, | |
| 664 "foundation", remote_network_id, 0); | |
| 665 return new FakeCandidatePair(local_candidate, remote_candidate); | |
| 666 } | |
| 667 | |
| 668 void DestroyRtcpTransport(const std::string& transport_name) { | 111 void DestroyRtcpTransport(const std::string& transport_name) { |
| 669 DestroyDtlsTransport_n(transport_name, | 112 DestroyDtlsTransport_n(transport_name, |
| 670 cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 113 cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
| 671 } | 114 } |
| 672 | 115 |
| 673 protected: | 116 protected: |
| 674 // The ICE channel is never actually used by TransportController directly, | |
| 675 // since (currently) the DTLS channel pretends to be both ICE + DTLS. This | |
| 676 // will change when we get rid of TransportChannelImpl. | |
| 677 IceTransportInternal* CreateIceTransportChannel_n( | 117 IceTransportInternal* CreateIceTransportChannel_n( |
| 678 const std::string& transport_name, | 118 const std::string& transport_name, |
| 679 int component) override { | 119 int component) override { |
| 680 return new FakeIceTransport(transport_name, component); | 120 return new FakeIceTransport(transport_name, component); |
| 681 } | 121 } |
| 682 | 122 |
| 683 DtlsTransportInternal* CreateDtlsTransportChannel_n( | 123 DtlsTransportInternal* CreateDtlsTransportChannel_n( |
| 684 const std::string& transport_name, | 124 const std::string& transport_name, |
| 685 int component, | 125 int component, |
| 686 IceTransportInternal* ice) override { | 126 IceTransportInternal* ice) override { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 697 bool asymmetric = false; | 137 bool asymmetric = false; |
| 698 local->SetDestination(remote, asymmetric); | 138 local->SetDestination(remote, asymmetric); |
| 699 } | 139 } |
| 700 } | 140 } |
| 701 } | 141 } |
| 702 }; | 142 }; |
| 703 | 143 |
| 704 } // namespace cricket | 144 } // namespace cricket |
| 705 | 145 |
| 706 #endif // WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ | 146 #endif // WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ |
| OLD | NEW |