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

Side by Side Diff: webrtc/p2p/base/faketransportcontroller.h

Issue 2606123002: Remove the dependency of TransportChannel and TransportChannelImpl. (Closed)
Patch Set: Revert the change of stun_unittests Created 3 years, 11 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 unified diff | Download patch
OLDNEW
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> 14 #include <map>
15 #include <memory> 15 #include <memory>
16 #include <string> 16 #include <string>
17 #include <vector> 17 #include <vector>
18 18
19 #include "webrtc/p2p/base/candidatepairinterface.h"
20 #include "webrtc/p2p/base/transportchannel.h"
21 #include "webrtc/p2p/base/transportcontroller.h"
22 #include "webrtc/p2p/base/transportchannelimpl.h"
23 #include "webrtc/base/bind.h" 19 #include "webrtc/base/bind.h"
24 #include "webrtc/base/buffer.h" 20 #include "webrtc/base/buffer.h"
25 #include "webrtc/base/fakesslidentity.h" 21 #include "webrtc/base/fakesslidentity.h"
26 #include "webrtc/base/messagequeue.h" 22 #include "webrtc/base/messagequeue.h"
27 #include "webrtc/base/sigslot.h" 23 #include "webrtc/base/sigslot.h"
28 #include "webrtc/base/sslfingerprint.h" 24 #include "webrtc/base/sslfingerprint.h"
29 #include "webrtc/base/thread.h" 25 #include "webrtc/base/thread.h"
26 #include "webrtc/p2p/base/candidatepairinterface.h"
27 #include "webrtc/p2p/base/dtlstransportinternal.h"
28 #include "webrtc/p2p/base/icetransportinternal.h"
29 #include "webrtc/p2p/base/transportcontroller.h"
30 30
31 #ifdef HAVE_QUIC 31 #ifdef HAVE_QUIC
32 #include "webrtc/p2p/quic/quictransport.h" 32 #include "webrtc/p2p/quic/quictransport.h"
33 #endif 33 #endif
34 34
35 namespace cricket { 35 namespace cricket {
36 36
37 namespace { 37 namespace {
38 struct PacketMessageData : public rtc::MessageData { 38 struct PacketMessageData : public rtc::MessageData {
39 PacketMessageData(const char* data, size_t len) : packet(data, len) {} 39 PacketMessageData(const char* data, size_t len) : packet(data, len) {}
40 rtc::Buffer packet; 40 rtc::Buffer packet;
41 }; 41 };
42 } // namespace 42 } // namespace
43 43
44 // Fake transport channel class, which can be passed to anything that needs a 44 class FakeIceTransport : public IceTransportInternal,
45 // transport channel. Can be informed of another FakeTransportChannel via 45 public rtc::MessageHandler {
46 // SetDestination.
47 // TODO(hbos): Move implementation to .cc file, this and other classes in file.
48 class FakeTransportChannel : public TransportChannelImpl,
49 public rtc::MessageHandler {
50 public: 46 public:
51 explicit FakeTransportChannel(const std::string& name, int component) 47 explicit FakeIceTransport(const std::string& name, int component)
52 : TransportChannelImpl(name, component), 48 : name_(name), component_(component) {}
53 dtls_fingerprint_("", nullptr, 0) {} 49 ~FakeIceTransport() { Reset(); }
54 ~FakeTransportChannel() { Reset(); }
55 50
51 const std::string& transport_name() const override { return name_; }
52 int component() const override { return component_; }
56 uint64_t IceTiebreaker() const { return tiebreaker_; } 53 uint64_t IceTiebreaker() const { return tiebreaker_; }
57 IceMode remote_ice_mode() const { return remote_ice_mode_; } 54 IceMode remote_ice_mode() const { return remote_ice_mode_; }
58 const std::string& ice_ufrag() const { return ice_ufrag_; } 55 const std::string& ice_ufrag() const { return ice_ufrag_; }
59 const std::string& ice_pwd() const { return ice_pwd_; } 56 const std::string& ice_pwd() const { return ice_pwd_; }
60 const std::string& remote_ice_ufrag() const { return remote_ice_ufrag_; } 57 const std::string& remote_ice_ufrag() const { return remote_ice_ufrag_; }
61 const std::string& remote_ice_pwd() const { return remote_ice_pwd_; } 58 const std::string& remote_ice_pwd() const { return remote_ice_pwd_; }
62 const rtc::SSLFingerprint& dtls_fingerprint() const {
63 return dtls_fingerprint_;
64 }
65 59
66 // If async, will send packets by "Post"-ing to message queue instead of 60 // If async, will send packets by "Post"-ing to message queue instead of
67 // synchronously "Send"-ing. 61 // synchronously "Send"-ing.
68 void SetAsync(bool async) { async_ = async; } 62 void SetAsync(bool async) { async_ = async; }
69 void SetAsyncDelay(int delay_ms) { async_delay_ms_ = delay_ms; } 63 void SetAsyncDelay(int delay_ms) { async_delay_ms_ = delay_ms; }
70 64
71 TransportChannelState GetState() const override { 65 IceTransportState GetState() const override {
72 if (connection_count_ == 0) { 66 if (connection_count_ == 0) {
73 return had_connection_ ? TransportChannelState::STATE_FAILED 67 return had_connection_ ? IceTransportState::STATE_FAILED
74 : TransportChannelState::STATE_INIT; 68 : IceTransportState::STATE_INIT;
75 } 69 }
76 70
77 if (connection_count_ == 1) { 71 if (connection_count_ == 1) {
78 return TransportChannelState::STATE_COMPLETED; 72 return IceTransportState::STATE_COMPLETED;
79 } 73 }
80 74
81 return TransportChannelState::STATE_CONNECTING; 75 return IceTransportState::STATE_CONNECTING;
82 } 76 }
83 77
84 void SetIceRole(IceRole role) override { role_ = role; } 78 void SetIceRole(IceRole role) override { role_ = role; }
85 IceRole GetIceRole() const override { return role_; } 79 IceRole GetIceRole() const override { return role_; }
86 void SetIceTiebreaker(uint64_t tiebreaker) override { 80 void SetIceTiebreaker(uint64_t tiebreaker) override {
87 tiebreaker_ = tiebreaker; 81 tiebreaker_ = tiebreaker;
88 } 82 }
89 void SetIceParameters(const IceParameters& ice_params) override { 83 void SetIceParameters(const IceParameters& ice_params) override {
90 ice_ufrag_ = ice_params.ufrag; 84 ice_ufrag_ = ice_params.ufrag;
91 ice_pwd_ = ice_params.pwd; 85 ice_pwd_ = ice_params.pwd;
92 } 86 }
93 void SetRemoteIceParameters(const IceParameters& params) override { 87 void SetRemoteIceParameters(const IceParameters& params) override {
94 remote_ice_ufrag_ = params.ufrag; 88 remote_ice_ufrag_ = params.ufrag;
95 remote_ice_pwd_ = params.pwd; 89 remote_ice_pwd_ = params.pwd;
96 } 90 }
97 91
98 void SetRemoteIceMode(IceMode mode) override { remote_ice_mode_ = mode; } 92 void SetRemoteIceMode(IceMode mode) override { remote_ice_mode_ = mode; }
99 bool SetRemoteFingerprint(const std::string& alg,
100 const uint8_t* digest,
101 size_t digest_len) override {
102 dtls_fingerprint_ = rtc::SSLFingerprint(alg, digest, digest_len);
103 return true;
104 }
105 bool SetSslRole(rtc::SSLRole role) override {
106 ssl_role_ = role;
107 return true;
108 }
109 bool GetSslRole(rtc::SSLRole* role) const override {
110 *role = ssl_role_;
111 return true;
112 }
113 93
114 void MaybeStartGathering() override { 94 void MaybeStartGathering() override {
115 if (gathering_state_ == kIceGatheringNew) { 95 if (gathering_state_ == kIceGatheringNew) {
116 gathering_state_ = kIceGatheringGathering; 96 gathering_state_ = kIceGatheringGathering;
117 SignalGatheringState(this); 97 SignalGatheringState(this);
118 } 98 }
119 } 99 }
120 100
121 IceGatheringState gathering_state() const override { 101 IceGatheringState gathering_state() const override {
122 return gathering_state_; 102 return gathering_state_;
123 } 103 }
124 104
125 void Reset() { 105 void Reset() {
126 if (state_ != STATE_INIT) { 106 if (state_ != STATE_INIT) {
127 state_ = STATE_INIT; 107 state_ = STATE_INIT;
128 if (dest_) { 108 if (dest_) {
129 dest_->state_ = STATE_INIT; 109 dest_->state_ = STATE_INIT;
130 dest_->dest_ = nullptr; 110 dest_->dest_ = nullptr;
131 dest_ = nullptr; 111 dest_ = nullptr;
132 } 112 }
133 } 113 }
134 } 114 }
135 115
136 void SetWritable(bool writable) { set_writable(writable); } 116 void SetWritable(bool writable) { set_writable(writable); }
137 117
138 // Simulates the two transport channels connecting to each other. 118 void set_writable(bool writable) {
139 // If |asymmetric| is true this method only affects this FakeTransportChannel. 119 if (writable_ == writable) {
120 return;
121 }
122 LOG(INFO) << "set_writable from:" << writable_ << " to " << writable;
123 writable_ = writable;
124 if (writable_) {
125 SignalReadyToSend(this);
126 }
127 SignalWritableState(this);
128 }
129 bool writable() const override { return writable_; }
130
131 // Simulates the two transports connecting to each other.
132 // If |asymmetric| is true this method only affects this FakeIceTransport.
140 // If false, it affects |dest| as well. 133 // If false, it affects |dest| as well.
141 void SetDestination(FakeTransportChannel* dest, bool asymmetric = false) { 134 void SetDestination(FakeIceTransport* dest, bool asymmetric = false) {
142 if (state_ == STATE_INIT && dest) { 135 if (state_ == STATE_INIT && dest) {
143 // This simulates the delivery of candidates. 136 // This simulates the delivery of candidates.
144 dest_ = dest; 137 dest_ = dest;
145 if (local_cert_ && dest_->local_cert_) {
146 do_dtls_ = true;
147 NegotiateSrtpCiphers();
148 }
149 state_ = STATE_CONNECTED; 138 state_ = STATE_CONNECTED;
150 set_writable(true); 139 set_writable(true);
151 if (!asymmetric) { 140 if (!asymmetric) {
152 dest->SetDestination(this, true); 141 dest->SetDestination(this, true);
153 } 142 }
154 } else if (state_ == STATE_CONNECTED && !dest) { 143 } else if (state_ == STATE_CONNECTED && !dest) {
155 // Simulates loss of connectivity, by asymmetrically forgetting dest_. 144 // Simulates loss of connectivity, by asymmetrically forgetting dest_.
156 dest_ = nullptr; 145 dest_ = nullptr;
157 state_ = STATE_INIT; 146 state_ = STATE_INIT;
158 set_writable(false); 147 set_writable(false);
(...skipping 13 matching lines...) Expand all
172 161
173 void SetCandidatesGatheringComplete() { 162 void SetCandidatesGatheringComplete() {
174 if (gathering_state_ != kIceGatheringComplete) { 163 if (gathering_state_ != kIceGatheringComplete) {
175 gathering_state_ = kIceGatheringComplete; 164 gathering_state_ = kIceGatheringComplete;
176 SignalGatheringState(this); 165 SignalGatheringState(this);
177 } 166 }
178 } 167 }
179 168
180 void SetReceiving(bool receiving) { set_receiving(receiving); } 169 void SetReceiving(bool receiving) { set_receiving(receiving); }
181 170
171 void set_receiving(bool receiving) {
172 if (receiving_ == receiving) {
173 return;
174 }
175 receiving_ = receiving;
176 SignalReceivingState(this);
177 }
178 bool receiving() const override { return receiving_; }
179
182 void SetIceConfig(const IceConfig& config) override { ice_config_ = config; } 180 void SetIceConfig(const IceConfig& config) override { ice_config_ = config; }
183 181
184 int receiving_timeout() const { return ice_config_.receiving_timeout; } 182 int receiving_timeout() const { return ice_config_.receiving_timeout; }
185 bool gather_continually() const { return ice_config_.gather_continually(); } 183 bool gather_continually() const { return ice_config_.gather_continually(); }
186 184
187 int SendPacket(const char* data, 185 int SendPacket(const char* data,
188 size_t len, 186 size_t len,
189 const rtc::PacketOptions& options, 187 const rtc::PacketOptions& options,
190 int flags) override { 188 int flags) override {
191 if (state_ != STATE_CONNECTED) { 189 if (state_ != STATE_CONNECTED) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 221
224 const Candidates& remote_candidates() const { return remote_candidates_; } 222 const Candidates& remote_candidates() const { return remote_candidates_; }
225 223
226 void OnMessage(rtc::Message* msg) override { 224 void OnMessage(rtc::Message* msg) override {
227 PacketMessageData* data = static_cast<PacketMessageData*>(msg->pdata); 225 PacketMessageData* data = static_cast<PacketMessageData*>(msg->pdata);
228 dest_->SignalReadPacket(dest_, data->packet.data<char>(), 226 dest_->SignalReadPacket(dest_, data->packet.data<char>(),
229 data->packet.size(), rtc::CreatePacketTime(0), 0); 227 data->packet.size(), rtc::CreatePacketTime(0), 0);
230 delete data; 228 delete data;
231 } 229 }
232 230
231 bool GetStats(ConnectionInfos* infos) override {
232 ConnectionInfo info;
233 infos->clear();
234 infos->push_back(info);
235 return true;
236 }
237
238 void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override {
239 }
240
241 private:
242 std::string name_;
243 int component_;
244 enum State { STATE_INIT, STATE_CONNECTED };
245 FakeIceTransport* dest_ = nullptr;
246 State state_ = STATE_INIT;
247 bool async_ = false;
248 int async_delay_ms_ = 0;
249 Candidates remote_candidates_;
250 IceConfig ice_config_;
251 IceRole role_ = ICEROLE_UNKNOWN;
252 uint64_t tiebreaker_ = 0;
253 std::string ice_ufrag_;
254 std::string ice_pwd_;
255 std::string remote_ice_ufrag_;
256 std::string remote_ice_pwd_;
257 IceMode remote_ice_mode_ = ICEMODE_FULL;
258 size_t connection_count_ = 0;
259 IceGatheringState gathering_state_ = kIceGatheringNew;
260 bool had_connection_ = false;
261 bool writable_ = false;
262 bool receiving_ = false;
263 };
264
265 class FakeDtlsTransport : public DtlsTransportInternal {
266 public:
267 explicit FakeDtlsTransport(FakeIceTransport* ice_transport)
268 : ice_transport_(ice_transport),
269 transport_name_(ice_transport->transport_name()),
270 component_(ice_transport->component()),
271 dtls_fingerprint_("", nullptr, 0) {
272 ice_transport_->SignalReadPacket.connect(
273 this, &FakeDtlsTransport::OnIceTransportReadPacket);
274 }
275
276 explicit FakeDtlsTransport(const std::string& name, int component)
277 : ice_transport_(new FakeIceTransport(name, component)),
278 transport_name_(ice_transport_->transport_name()),
279 component_(ice_transport_->component()),
280 dtls_fingerprint_("", nullptr, 0) {
281 ice_transport_->SignalReadPacket.connect(
282 this, &FakeDtlsTransport::OnIceTransportReadPacket);
283 }
284
285 ~FakeDtlsTransport() override { Reset(); }
286
287 uint64_t IceTiebreaker() const { return ice_transport_->IceTiebreaker(); }
288 IceMode remote_ice_mode() const { return ice_transport_->remote_ice_mode(); }
289 const std::string& ice_ufrag() const { return ice_transport_->ice_ufrag(); }
290 const std::string& ice_pwd() const { return ice_transport_->ice_pwd(); }
291 const std::string& remote_ice_ufrag() const {
292 return ice_transport_->remote_ice_ufrag();
293 }
294 const std::string& remote_ice_pwd() const {
295 return ice_transport_->remote_ice_pwd();
296 }
297
298 DtlsTransportState dtls_state() const override { return dtls_state_; }
299
300 const std::string& transport_name() const override { return transport_name_; }
301
302 int component() const override { return component_; }
303
304 const rtc::SSLFingerprint& dtls_fingerprint() const {
305 return dtls_fingerprint_;
306 }
307
308 // If async, will send packets by "Post"-ing to message queue instead of
309 // synchronously "Send"-ing.
310 void SetAsync(bool async) { ice_transport_->SetAsync(async); }
311 void SetAsyncDelay(int delay_ms) { ice_transport_->SetAsyncDelay(delay_ms); }
312
313 IceRole GetIceRole() const { return ice_transport_->GetIceRole(); }
314
315 bool SetRemoteFingerprint(const std::string& alg,
316 const uint8_t* digest,
317 size_t digest_len) override {
318 dtls_fingerprint_ = rtc::SSLFingerprint(alg, digest, digest_len);
319 return true;
320 }
321
322 bool SetSslRole(rtc::SSLRole role) override {
323 ssl_role_ = role;
324 return true;
325 }
326
327 bool GetSslRole(rtc::SSLRole* role) const override {
328 *role = ssl_role_;
329 return true;
330 }
331
332 IceGatheringState gathering_state() const {
333 return ice_transport_->gathering_state();
334 }
335
336 void Reset() {
337 if (state_ != STATE_INIT) {
338 state_ = STATE_INIT;
339 if (dest_) {
340 dest_->state_ = STATE_INIT;
341 dest_->dest_ = nullptr;
342 dest_ = nullptr;
343 }
344 }
345 }
346
347 void SetWritable(bool writable) { set_writable(writable); }
348
349 // Simulates the two transport channels connecting to each other.
350 // If |asymmetric| is true this method only affects this FakeDtlsTransport.
351 // If false, it affects |dest| as well.
352 void SetDestination(FakeDtlsTransport* dest, bool asymmetric = false) {
353 if (state_ == STATE_INIT && dest) {
354 // This simulates the delivery of candidates.
355 dest_ = dest;
356 if (local_cert_ && dest_->local_cert_) {
357 do_dtls_ = true;
358 NegotiateSrtpCiphers();
359 }
360 state_ = STATE_CONNECTED;
361 SetWritable(true);
362 if (!asymmetric) {
363 dest->SetDestination(this, true);
364 }
365 ice_transport_->SetDestination(
366 static_cast<FakeIceTransport*>(dest->ice_transport()), asymmetric);
367 } else if (state_ == STATE_CONNECTED && !dest) {
368 // Simulates loss of connectivity, by asymmetrically forgetting dest_.
369 dest_ = nullptr;
370 state_ = STATE_INIT;
371 SetWritable(false);
372 ice_transport_->SetDestination(nullptr, asymmetric);
373 }
374 }
375
376 void SetConnectionCount(size_t connection_count) {
377 ice_transport_->SetConnectionCount(connection_count);
378 }
379
380 void SetCandidatesGatheringComplete() {
381 ice_transport_->SetCandidatesGatheringComplete();
382 }
383
384 void SetReceiving(bool receiving) {
385 ice_transport_->SetReceiving(receiving);
386 set_receiving(receiving);
387 }
388
389 int receiving_timeout() const { return ice_transport_->receiving_timeout(); }
390 bool gather_continually() const {
391 return ice_transport_->gather_continually();
392 }
393
394 int SendPacket(const char* data,
395 size_t len,
396 const rtc::PacketOptions& options,
397 int flags) override {
398 return ice_transport_->SendPacket(data, len, options, flags);
399 }
400
401 bool GetOption(rtc::Socket::Option opt, int* value) override { return true; }
402
403 const Candidates& remote_candidates() const {
404 return ice_transport_->remote_candidates();
405 }
406
407 void OnIceTransportReadPacket(PacketTransportInterface* ice_,
408 const char* data,
409 size_t len,
410 const rtc::PacketTime& time,
411 int flags) {
412 SignalReadPacket(this, data, len, time, flags);
413 }
414
233 bool SetLocalCertificate( 415 bool SetLocalCertificate(
234 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override { 416 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override {
235 local_cert_ = certificate; 417 local_cert_ = certificate;
236 return true; 418 return true;
237 } 419 }
238 420
239 void SetRemoteSSLCertificate(rtc::FakeSSLCertificate* cert) { 421 void SetRemoteSSLCertificate(rtc::FakeSSLCertificate* cert) {
240 remote_cert_ = cert; 422 remote_cert_ = cert;
241 } 423 }
242 424
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 uint8_t* result, 457 uint8_t* result,
276 size_t result_len) override { 458 size_t result_len) override {
277 if (chosen_crypto_suite_ != rtc::SRTP_INVALID_CRYPTO_SUITE) { 459 if (chosen_crypto_suite_ != rtc::SRTP_INVALID_CRYPTO_SUITE) {
278 memset(result, 0xff, result_len); 460 memset(result, 0xff, result_len);
279 return true; 461 return true;
280 } 462 }
281 463
282 return false; 464 return false;
283 } 465 }
284 466
285 bool GetStats(ConnectionInfos* infos) override {
286 ConnectionInfo info;
287 infos->clear();
288 infos->push_back(info);
289 return true;
290 }
291
292 void set_ssl_max_protocol_version(rtc::SSLProtocolVersion version) { 467 void set_ssl_max_protocol_version(rtc::SSLProtocolVersion version) {
293 ssl_max_version_ = version; 468 ssl_max_version_ = version;
294 } 469 }
295 rtc::SSLProtocolVersion ssl_max_protocol_version() const { 470 rtc::SSLProtocolVersion ssl_max_protocol_version() const {
296 return ssl_max_version_; 471 return ssl_max_version_;
297 } 472 }
298 473
299 void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override { 474 IceTransportInternal* ice_transport() override { return ice_transport_; }
475
476 bool writable() const override { return writable_; }
477
478 bool receiving() const override { return receiving_; }
479
480 int GetError() override { return ice_transport_->GetError(); }
481
482 int SetOption(rtc::Socket::Option opt, int value) override {
483 return ice_transport_->SetOption(opt, value);
484 }
485
486 bool SetSrtpCiphers(const std::vector<std::string>& ciphers) override {
487 std::vector<int> crypto_suites;
488 for (const auto cipher : ciphers) {
489 crypto_suites.push_back(rtc::SrtpCryptoSuiteFromName(cipher));
490 }
491 return SetSrtpCryptoSuites(crypto_suites);
300 } 492 }
301 493
302 private: 494 private:
303 void NegotiateSrtpCiphers() { 495 void NegotiateSrtpCiphers() {
304 for (std::vector<int>::const_iterator it1 = srtp_ciphers_.begin(); 496 for (std::vector<int>::const_iterator it1 = srtp_ciphers_.begin();
305 it1 != srtp_ciphers_.end(); ++it1) { 497 it1 != srtp_ciphers_.end(); ++it1) {
306 for (std::vector<int>::const_iterator it2 = dest_->srtp_ciphers_.begin(); 498 for (std::vector<int>::const_iterator it2 = dest_->srtp_ciphers_.begin();
307 it2 != dest_->srtp_ciphers_.end(); ++it2) { 499 it2 != dest_->srtp_ciphers_.end(); ++it2) {
308 if (*it1 == *it2) { 500 if (*it1 == *it2) {
309 chosen_crypto_suite_ = *it1; 501 chosen_crypto_suite_ = *it1;
310 return; 502 return;
311 } 503 }
312 } 504 }
313 } 505 }
314 } 506 }
315 507
508 void set_receiving(bool receiving) {
509 if (receiving_ == receiving) {
510 return;
511 }
512 receiving_ = receiving;
513 SignalReceivingState(this);
514 }
515
516 void set_writable(bool writable) {
517 if (writable_ == writable) {
518 return;
519 }
520 writable_ = writable;
521 if (writable_) {
522 SignalReadyToSend(this);
523 }
524 SignalWritableState(this);
525 }
526
316 enum State { STATE_INIT, STATE_CONNECTED }; 527 enum State { STATE_INIT, STATE_CONNECTED };
317 FakeTransportChannel* dest_ = nullptr; 528 FakeIceTransport* ice_transport_;
529 std::string transport_name_;
530 int component_;
531 FakeDtlsTransport* dest_ = nullptr;
318 State state_ = STATE_INIT; 532 State state_ = STATE_INIT;
319 bool async_ = false;
320 int async_delay_ms_ = 0;
321 Candidates remote_candidates_; 533 Candidates remote_candidates_;
322 rtc::scoped_refptr<rtc::RTCCertificate> local_cert_; 534 rtc::scoped_refptr<rtc::RTCCertificate> local_cert_;
323 rtc::FakeSSLCertificate* remote_cert_ = nullptr; 535 rtc::FakeSSLCertificate* remote_cert_ = nullptr;
324 bool do_dtls_ = false; 536 bool do_dtls_ = false;
325 std::vector<int> srtp_ciphers_; 537 std::vector<int> srtp_ciphers_;
326 int chosen_crypto_suite_ = rtc::SRTP_INVALID_CRYPTO_SUITE; 538 int chosen_crypto_suite_ = rtc::SRTP_INVALID_CRYPTO_SUITE;
327 IceConfig ice_config_;
328 IceRole role_ = ICEROLE_UNKNOWN;
329 uint64_t tiebreaker_ = 0;
330 std::string ice_ufrag_;
331 std::string ice_pwd_;
332 std::string remote_ice_ufrag_;
333 std::string remote_ice_pwd_;
334 IceMode remote_ice_mode_ = ICEMODE_FULL;
335 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; 539 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12;
336 rtc::SSLFingerprint dtls_fingerprint_; 540 rtc::SSLFingerprint dtls_fingerprint_;
337 rtc::SSLRole ssl_role_ = rtc::SSL_CLIENT; 541 rtc::SSLRole ssl_role_ = rtc::SSL_CLIENT;
338 size_t connection_count_ = 0; 542
339 IceGatheringState gathering_state_ = kIceGatheringNew; 543 DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW;
340 bool had_connection_ = false; 544
545 bool receiving_ = false;
546 bool writable_ = false;
341 }; 547 };
342 548
343 // Fake candidate pair class, which can be passed to BaseChannel for testing 549 // Fake candidate pair class, which can be passed to BaseChannel for testing
344 // purposes. 550 // purposes.
345 class FakeCandidatePair : public CandidatePairInterface { 551 class FakeCandidatePair : public CandidatePairInterface {
346 public: 552 public:
347 FakeCandidatePair(const Candidate& local_candidate, 553 FakeCandidatePair(const Candidate& local_candidate,
348 const Candidate& remote_candidate) 554 const Candidate& remote_candidate)
349 : local_candidate_(local_candidate), 555 : local_candidate_(local_candidate),
350 remote_candidate_(remote_candidate) {} 556 remote_candidate_(remote_candidate) {}
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 591 }
386 592
387 explicit FakeTransportController(rtc::Thread* network_thread) 593 explicit FakeTransportController(rtc::Thread* network_thread)
388 : TransportController(rtc::Thread::Current(), network_thread, nullptr) {} 594 : TransportController(rtc::Thread::Current(), network_thread, nullptr) {}
389 595
390 FakeTransportController(rtc::Thread* network_thread, IceRole role) 596 FakeTransportController(rtc::Thread* network_thread, IceRole role)
391 : TransportController(rtc::Thread::Current(), network_thread, nullptr) { 597 : TransportController(rtc::Thread::Current(), network_thread, nullptr) {
392 SetIceRole(role); 598 SetIceRole(role);
393 } 599 }
394 600
395 FakeTransportChannel* GetFakeTransportChannel_n( 601 FakeDtlsTransport* GetFakeDtlsTransport_n(const std::string& transport_name,
396 const std::string& transport_name, 602 int component) {
397 int component) { 603 return static_cast<FakeDtlsTransport*>(
398 return static_cast<FakeTransportChannel*>(
399 get_channel_for_testing(transport_name, component)); 604 get_channel_for_testing(transport_name, component));
400 } 605 }
401 606
402 // Simulate the exchange of transport descriptions, and the gathering and 607 // Simulate the exchange of transport descriptions, and the gathering and
403 // exchange of ICE candidates. 608 // exchange of ICE candidates.
404 void Connect(FakeTransportController* dest) { 609 void Connect(FakeTransportController* dest) {
405 for (const std::string& transport_name : transport_names_for_testing()) { 610 for (const std::string& transport_name : transport_names_for_testing()) {
406 TransportDescription local_desc( 611 TransportDescription local_desc(
407 std::vector<std::string>(), 612 std::vector<std::string>(),
408 rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH), 613 rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 "foundation", local_network_id, 0); 645 "foundation", local_network_id, 0);
441 Candidate remote_candidate(0, "udp", remote_address, 0u, "", "", "local", 0, 646 Candidate remote_candidate(0, "udp", remote_address, 0u, "", "", "local", 0,
442 "foundation", remote_network_id, 0); 647 "foundation", remote_network_id, 0);
443 return new FakeCandidatePair(local_candidate, remote_candidate); 648 return new FakeCandidatePair(local_candidate, remote_candidate);
444 } 649 }
445 650
446 protected: 651 protected:
447 // The ICE channel is never actually used by TransportController directly, 652 // The ICE channel is never actually used by TransportController directly,
448 // since (currently) the DTLS channel pretends to be both ICE + DTLS. This 653 // since (currently) the DTLS channel pretends to be both ICE + DTLS. This
449 // will change when we get rid of TransportChannelImpl. 654 // will change when we get rid of TransportChannelImpl.
450 TransportChannelImpl* CreateIceTransportChannel_n( 655 IceTransportInternal* CreateIceTransportChannel_n(
451 const std::string& transport_name, 656 const std::string& transport_name,
452 int component) override { 657 int component) override {
453 return nullptr; 658 return new FakeIceTransport(transport_name, component);
454 } 659 }
455 660
456 TransportChannelImpl* CreateDtlsTransportChannel_n( 661 DtlsTransportInternal* CreateDtlsTransportChannel_n(
457 const std::string& transport_name, 662 const std::string& transport_name,
458 int component, 663 int component,
459 TransportChannelImpl*) override { 664 IceTransportInternal* ice) override {
460 return new FakeTransportChannel(transport_name, component); 665 return new FakeDtlsTransport(static_cast<FakeIceTransport*>(ice));
461 } 666 }
462 667
463 private: 668 private:
464 void SetChannelDestinations_n(FakeTransportController* dest) { 669 void SetChannelDestinations_n(FakeTransportController* dest) {
465 for (TransportChannelImpl* tc : channels_for_testing()) { 670 for (DtlsTransportInternal* tc : channels_for_testing()) {
466 FakeTransportChannel* local = static_cast<FakeTransportChannel*>(tc); 671 FakeDtlsTransport* local = static_cast<FakeDtlsTransport*>(tc);
467 FakeTransportChannel* remote = dest->GetFakeTransportChannel_n( 672 FakeDtlsTransport* remote = dest->GetFakeDtlsTransport_n(
468 local->transport_name(), local->component()); 673 local->transport_name(), local->component());
469 if (remote) { 674 if (remote) {
470 bool asymmetric = false; 675 bool asymmetric = false;
471 local->SetDestination(remote, asymmetric); 676 local->SetDestination(remote, asymmetric);
472 } 677 }
473 } 678 }
474 } 679 }
475 }; 680 };
476 681
477 } // namespace cricket 682 } // namespace cricket
478 683
479 #endif // WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_ 684 #endif // WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698