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

Unified Diff: webrtc/p2p/base/faketransportcontroller.h

Issue 1246913005: TransportController refactoring (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: minor cleanup Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/p2p/base/faketransportcontroller.h
diff --git a/webrtc/p2p/base/fakesession.h b/webrtc/p2p/base/faketransportcontroller.h
similarity index 74%
rename from webrtc/p2p/base/fakesession.h
rename to webrtc/p2p/base/faketransportcontroller.h
index 67b770ae5c1236b04e2869e01aaa27015f9769ec..991ffafa7133438f6d5dbd3904e8ec4cf527d737 100644
--- a/webrtc/p2p/base/fakesession.h
+++ b/webrtc/p2p/base/faketransportcontroller.h
@@ -8,22 +8,24 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#ifndef WEBRTC_P2P_BASE_FAKESESSION_H_
-#define WEBRTC_P2P_BASE_FAKESESSION_H_
+#ifndef WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_
+#define WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_
#include <map>
#include <string>
#include <vector>
-#include "webrtc/p2p/base/session.h"
#include "webrtc/p2p/base/transport.h"
#include "webrtc/p2p/base/transportchannel.h"
+#include "webrtc/p2p/base/transportcontroller.h"
#include "webrtc/p2p/base/transportchannelimpl.h"
+#include "webrtc/base/bind.h"
#include "webrtc/base/buffer.h"
#include "webrtc/base/fakesslidentity.h"
#include "webrtc/base/messagequeue.h"
#include "webrtc/base/sigslot.h"
#include "webrtc/base/sslfingerprint.h"
+#include "webrtc/base/thread.h"
namespace cricket {
@@ -46,18 +48,19 @@ class FakeTransportChannel : public TransportChannelImpl,
int component)
: TransportChannelImpl(content_name, component),
transport_(transport),
- dest_(NULL),
+ dest_(nullptr),
state_(STATE_INIT),
async_(false),
- identity_(NULL),
+ identity_(nullptr),
do_dtls_(false),
role_(ICEROLE_UNKNOWN),
tiebreaker_(0),
ice_proto_(ICEPROTO_HYBRID),
remote_ice_mode_(ICEMODE_FULL),
- dtls_fingerprint_("", NULL, 0),
+ dtls_fingerprint_("", nullptr, 0),
ssl_role_(rtc::SSL_CLIENT),
- connection_count_(0) {
+ connection_count_(0),
+ candidate_gathering_state_(Transport::kGatheringNew) {
}
~FakeTransportChannel() {
Reset();
@@ -133,13 +136,18 @@ class FakeTransportChannel : public TransportChannelImpl,
state_ = STATE_CONNECTING;
}
}
+
+ virtual Transport::CandidateGatheringState candidate_gathering_state() const {
+ return candidate_gathering_state_;
+ }
+
virtual void Reset() {
if (state_ != STATE_INIT) {
state_ = STATE_INIT;
if (dest_) {
dest_->state_ = STATE_INIT;
- dest_->dest_ = NULL;
- dest_ = NULL;
+ dest_->dest_ = nullptr;
+ dest_ = nullptr;
}
}
}
@@ -164,7 +172,7 @@ class FakeTransportChannel : public TransportChannelImpl,
dest_->set_writable(true);
} else if (state_ == STATE_CONNECTED && !dest) {
// Simulates loss of connectivity, by asymmetrically forgetting dest_.
- dest_ = NULL;
+ dest_ = nullptr;
state_ = STATE_CONNECTING;
set_writable(false);
}
@@ -177,6 +185,13 @@ class FakeTransportChannel : public TransportChannelImpl,
SignalConnectionRemoved(this);
}
+ void SetCandidatesAllocationDone() {
+ if (candidate_gathering_state_ != Transport::kGatheringDone) {
+ candidate_gathering_state_ = Transport::kGatheringDone;
+ SignalCandidatesAllocationDone(this);
+ }
+ }
+
void SetReceiving(bool receiving) {
set_receiving(receiving);
}
@@ -211,8 +226,6 @@ class FakeTransportChannel : public TransportChannelImpl,
return 0;
}
- virtual void OnSignalingReady() {
- }
virtual void OnCandidate(const Candidate& candidate) {
}
@@ -329,6 +342,7 @@ class FakeTransportChannel : public TransportChannelImpl,
rtc::SSLFingerprint dtls_fingerprint_;
rtc::SSLRole ssl_role_;
size_t connection_count_;
+ Transport::CandidateGatheringState candidate_gathering_state_;
};
// Fake transport class, which can be passed to anything that needs a Transport.
@@ -337,16 +351,14 @@ class FakeTransportChannel : public TransportChannelImpl,
class FakeTransport : public Transport {
public:
typedef std::map<int, FakeTransportChannel*> ChannelMap;
- FakeTransport(rtc::Thread* signaling_thread,
- rtc::Thread* worker_thread,
- const std::string& content_name,
- PortAllocator* alllocator = NULL)
- : Transport(signaling_thread, worker_thread,
- content_name, "test_type", NULL),
- dest_(NULL),
+ FakeTransport(const std::string& content_name,
+ PortAllocator* alllocator = nullptr)
+ : Transport(content_name, "test_type", nullptr),
+ dest_(nullptr),
async_(false),
- identity_(NULL) {
+ identity_(nullptr) {
}
+
~FakeTransport() {
DestroyAllChannels();
}
@@ -356,23 +368,28 @@ class FakeTransport : public Transport {
void SetAsync(bool async) { async_ = async; }
void SetDestination(FakeTransport* dest) {
dest_ = dest;
- for (ChannelMap::iterator it = channels_.begin(); it != channels_.end();
- ++it) {
- it->second->SetLocalIdentity(identity_);
- SetChannelDestination(it->first, it->second);
+ for (const auto& kv : channels_) {
+ kv.second->SetLocalIdentity(identity_);
+ SetChannelDestination(kv.first, kv.second);
}
}
void SetWritable(bool writable) {
- for (ChannelMap::iterator it = channels_.begin(); it != channels_.end();
- ++it) {
- it->second->SetWritable(writable);
+ for (const auto& kv : channels_) {
+ kv.second->SetWritable(writable);
}
}
- void set_identity(rtc::SSLIdentity* identity) {
+ virtual void SetIdentity(rtc::SSLIdentity* identity) {
identity_ = identity;
}
+ virtual bool GetIdentity(rtc::SSLIdentity** identity) {
+ if (!identity_)
+ return false;
+
+ *identity = identity_->GetReference();
+ return true;
+ }
using Transport::local_description;
using Transport::remote_description;
@@ -380,7 +397,7 @@ class FakeTransport : public Transport {
protected:
virtual TransportChannelImpl* CreateTransportChannel(int component) {
if (channels_.find(component) != channels_.end()) {
- return NULL;
+ return nullptr;
}
FakeTransportChannel* channel =
new FakeTransportChannel(this, content_name(), component);
@@ -389,29 +406,21 @@ class FakeTransport : public Transport {
channels_[component] = channel;
return channel;
}
+
virtual void DestroyTransportChannel(TransportChannelImpl* channel) {
channels_.erase(channel->component());
delete channel;
}
- virtual void SetIdentity_w(rtc::SSLIdentity* identity) {
- identity_ = identity;
- }
- virtual bool GetIdentity_w(rtc::SSLIdentity** identity) {
- if (!identity_)
- return false;
-
- *identity = identity_->GetReference();
- return true;
- }
private:
FakeTransportChannel* GetFakeChannel(int component) {
- ChannelMap::iterator it = channels_.find(component);
- return (it != channels_.end()) ? it->second : NULL;
+ auto it = channels_.find(component);
+ return (it != channels_.end()) ? it->second : nullptr;
}
+
void SetChannelDestination(int component,
FakeTransportChannel* channel) {
- FakeTransportChannel* dest_channel = NULL;
+ FakeTransportChannel* dest_channel = nullptr;
if (dest_) {
dest_channel = dest_->GetFakeChannel(component);
if (dest_channel) {
@@ -423,85 +432,85 @@ class FakeTransport : public Transport {
// Note, this is distinct from the Channel map owned by Transport.
// This map just tracks the FakeTransportChannels created by this class.
+ // It's mainly needed so that we can access a FakeTransportChannel directly,
+ // even if wrapped by a DtlsTransportChannelWrapper.
ChannelMap channels_;
FakeTransport* dest_;
bool async_;
rtc::SSLIdentity* identity_;
};
-// Fake session class, which can be passed into a BaseChannel object for
-// test purposes. Can be connected to other FakeSessions via Connect().
-class FakeSession : public BaseSession {
+// Fake TransportController class, which can be passed into a BaseChannel object
+// for test purposes. Can be connected to other FakeTransportControllers via
+// Connect().
+class FakeTransportController : public TransportController {
public:
- explicit FakeSession()
- : BaseSession(rtc::Thread::Current(),
- rtc::Thread::Current(),
- NULL, "", "", true),
- fail_create_channel_(false) {
- }
- explicit FakeSession(bool initiator)
- : BaseSession(rtc::Thread::Current(),
- rtc::Thread::Current(),
- NULL, "", "", initiator),
- fail_create_channel_(false) {
- }
- FakeSession(rtc::Thread* worker_thread, bool initiator)
- : BaseSession(rtc::Thread::Current(),
- worker_thread,
- NULL, "", "", initiator),
- fail_create_channel_(false) {
- }
-
- FakeTransport* GetTransport(const std::string& content_name) {
+ FakeTransportController()
+ : TransportController(rtc::Thread::Current(),
+ rtc::Thread::Current(),
+ nullptr),
+ fail_create_channel_(false) {
+ }
+
+ explicit FakeTransportController(bool initiator)
+ : TransportController(rtc::Thread::Current(),
+ rtc::Thread::Current(),
+ nullptr),
+ fail_create_channel_(false) {
+ SetIceRole(initiator ? ICEROLE_CONTROLLING : ICEROLE_CONTROLLED);
+ }
+
+ FakeTransportController(rtc::Thread* worker_thread, bool initiator)
+ : TransportController(rtc::Thread::Current(),
+ worker_thread,
+ nullptr),
+ fail_create_channel_(false) {
+ SetIceRole(initiator ? ICEROLE_CONTROLLING : ICEROLE_CONTROLLED);
+ }
+
+ FakeTransport* GetTransport_w(const std::string& transport_name) {
return static_cast<FakeTransport*>(
- BaseSession::GetTransport(content_name));
+ TransportController::GetTransport_w(transport_name));
}
- void Connect(FakeSession* dest) {
- // Simulate the exchange of candidates.
- CompleteNegotiation();
- dest->CompleteNegotiation();
- for (TransportMap::const_iterator it = transport_proxies().begin();
- it != transport_proxies().end(); ++it) {
- static_cast<FakeTransport*>(it->second->impl())->SetDestination(
- dest->GetTransport(it->first));
- }
+ void Connect(FakeTransportController* dest) {
+ worker_thread()->Invoke<void>(rtc::Bind(
+ &FakeTransportController::Connect_w, this, dest));
}
- virtual TransportChannel* CreateChannel(
- const std::string& content_name,
+ virtual TransportChannel* CreateTransportChannel_w(
+ const std::string& transport_name,
int component) {
if (fail_create_channel_) {
- return NULL;
+ return nullptr;
}
- return BaseSession::CreateChannel(content_name, component);
+ return TransportController::CreateTransportChannel_w(transport_name,
+ component);
}
void set_fail_channel_creation(bool fail_channel_creation) {
fail_create_channel_ = fail_channel_creation;
}
- // TODO: Hoist this into Session when we re-work the Session code.
- void set_ssl_identity(rtc::SSLIdentity* identity) {
- for (TransportMap::const_iterator it = transport_proxies().begin();
- it != transport_proxies().end(); ++it) {
- // We know that we have a FakeTransport*
-
- static_cast<FakeTransport*>(it->second->impl())->set_identity
- (identity);
- }
+ protected:
+ virtual Transport* CreateTransport_w(const std::string& transport_name) {
+ return new FakeTransport(transport_name);
}
- protected:
- virtual Transport* CreateTransport(const std::string& content_name) {
- return new FakeTransport(signaling_thread(), worker_thread(), content_name);
+ void Connect_w(FakeTransportController* dest) {
+ // Simulate the exchange of candidates.
+ ConnectChannels_w();
+ dest->ConnectChannels_w();
+ for (auto& kv : transports()) {
+ FakeTransport* transport = static_cast<FakeTransport*>(kv.second);
+ transport->SetDestination(dest->GetTransport_w(kv.first));
+ }
}
- void CompleteNegotiation() {
- for (TransportMap::const_iterator it = transport_proxies().begin();
- it != transport_proxies().end(); ++it) {
- it->second->CompleteNegotiation();
- it->second->ConnectChannels();
+ void ConnectChannels_w() {
+ for (auto& kv : transports()) {
+ FakeTransport* transport = static_cast<FakeTransport*>(kv.second);
+ transport->ConnectChannels();
}
}
@@ -511,4 +520,4 @@ class FakeSession : public BaseSession {
} // namespace cricket
-#endif // WEBRTC_P2P_BASE_FAKESESSION_H_
+#endif // WEBRTC_P2P_BASE_FAKETRANSPORTCONTROLLER_H_

Powered by Google App Engine
This is Rietveld 408576698