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

Unified Diff: webrtc/p2p/base/transportcontroller.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/transportcontroller.h
diff --git a/webrtc/p2p/base/transportcontroller.h b/webrtc/p2p/base/transportcontroller.h
new file mode 100644
index 0000000000000000000000000000000000000000..a6edff9254ad23e6ceb0a2a26f6f5d3508031f84
--- /dev/null
+++ b/webrtc/p2p/base/transportcontroller.h
@@ -0,0 +1,196 @@
+/*
+ * Copyright 2015 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_
+#define WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "webrtc/base/sigslot.h"
+#include "webrtc/base/sslstreamadapter.h"
+#include "webrtc/p2p/base/candidate.h"
+#include "webrtc/p2p/base/transport.h"
+
+namespace rtc {
+class Thread;
+}
+
+namespace cricket {
+
+class TransportController : public sigslot::has_slots<>,
+ public rtc::MessageHandler {
+ public:
+ enum ConnectionState {
+ // Default state; either there are no transports, or one is still connecting
+ kConnecting,
+ // At least one transport has failed
+ kFailed,
+ // All transports are connected
+ kConnected,
+ // All transports are connected AND completed
+ kCompleted,
+ };
+
+ TransportController(rtc::Thread* signaling_thread,
+ rtc::Thread* worker_thread,
+ PortAllocator* port_allocator);
+
+ virtual ~TransportController();
+
+ rtc::Thread* signaling_thread() const { return signaling_thread_; }
+ rtc::Thread* worker_thread() const { return worker_thread_; }
+ PortAllocator* port_allocator() const { return port_allocator_; }
+
+ void SetIceConnectionReceivingTimeout(int timeout_ms);
+ void SetIceRole(IceRole ice_role);
+
+ // Takes ownership of identity and passes it down to transports
+ bool SetIdentity(rtc::SSLIdentity* identity);
+
+ // Caller owns returned identity
+ bool GetIdentity(const std::string& transport_name,
+ rtc::SSLIdentity** identity);
+
+ // Caller owns returned certificate
+ bool GetRemoteCertificate(const std::string& transport_name,
+ rtc::SSLCertificate** cert);
+
+ bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version);
+ bool SetLocalTransportDescription(
+ const std::string& transport_name,
+ const TransportDescription& tdesc,
+ ContentAction action,
+ std::string* err);
+ bool SetRemoteTransportDescription(
+ const std::string& transport_name,
+ const TransportDescription& tdesc,
+ ContentAction action,
+ std::string* err);
+ bool AddRemoteCandidates(
+ const std::string& transport_name,
+ const Candidates& candidates,
+ std::string* err);
+
+ bool ReadyForRemoteCandidates(const std::string& transport_name);
+
+ bool GetSslRole(rtc::SSLRole* role);
+ bool GetStats(
+ const std::string& transport_name,
+ TransportStats* stats);
+
+ virtual TransportChannel* CreateTransportChannel_w(
+ const std::string& transport_name, int component);
+ virtual void DestroyTransportChannel_w(
+ const std::string& transport_name, int component);
+
+ void ConnectChannels();
+
+ // All of these signals are fired on the signalling thread.
+ sigslot::signal1<ConnectionState> SignalConnectionStateChanged;
+ sigslot::signal1<bool> SignalReceiving;
+ sigslot::signal0<> SignalCandidatesAllocationStarted;
+ // (transport_name, candidates)
+ sigslot::signal2<const std::string&, const Candidates&> SignalCandidatesReady;
+ sigslot::signal0<> SignalCandidatesAllocationDone;
+
+ protected:
+ virtual void OnMessage(rtc::Message* pmsg);
+
+ // protected and virtual so we can override it in unit tests.
+ virtual Transport* CreateTransport_w(const std::string& transport_name);
+
+ // for unit tests
+ const std::map<std::string, Transport*>& transports() { return transports_; }
+
+ Transport* GetOrCreateTransport_w(const std::string& transport_name);
+ Transport* GetTransport_w(const std::string& transport_name);
+ void DestroyTransport_w(const std::string& transport_name);
+ void DestroyAllTransports_w();
+
+ private:
+ void SetIceConnectionReceivingTimeout_w(int timeout_ms);
+ void SetIceRole_w(IceRole ice_role);
+ bool SetIdentity_w(rtc::SSLIdentity* identity);
+ bool GetIdentity_w(const std::string& transport_name,
+ rtc::SSLIdentity** identity);
+ bool GetRemoteCertificate_w(const std::string& transport_name,
+ rtc::SSLCertificate** cert);
+ bool SetSslMaxProtocolVersion_w(rtc::SSLProtocolVersion version);
+ void ConnectChannels_w();
+ bool SetLocalTransportDescription_w(
+ const std::string& transport_name,
+ const TransportDescription& tdesc,
+ ContentAction action,
+ std::string* err);
+ bool SetRemoteTransportDescription_w(
+ const std::string& transport_name,
+ const TransportDescription& tdesc,
+ ContentAction action,
+ std::string* err);
+ bool AddRemoteCandidates_w(
+ const std::string& transport_name,
+ const Candidates& candidates,
+ std::string* err);
+ bool ReadyForRemoteCandidates_w(const std::string& transport_name);
+ bool GetSslRole_w(rtc::SSLRole* role);
+ bool GetStats_w(
+ const std::string& transport_name,
+ TransportStats* stats);
+
+ // Handlers for signals from Transport.
+ void OnTransportConnecting_w(Transport* transport);
+ void OnTransportWritableState_w(Transport* transport);
+ void OnTransportReceivingState_w(Transport* transport);
+ void OnTransportCandidatesAllocationStarted_w(Transport* transport);
+ void OnTransportRouteChange_w(Transport* transport,
+ int component,
+ const Candidate& candidate);
+ void OnTransportCandidatesAllocationDone_w(Transport* transport);
+ void OnTransportRoleConflict_w();
+ void OnTransportCompleted_w(Transport* transport);
+ void OnTransportFailed_w(Transport* transport);
+ void OnTransportCandidatesReady_w(Transport* transport,
+ const std::vector<Candidate>& candidates);
+
+ // Update our internal aggregate Transport states,
+ // and signal if they changed.
+ void UpdateState_w();
+
+ // Check if allocation done for all Transports, and if so, emit signal
+ void CheckIfCandidatesAllocationDone_w();
+
+ rtc::Thread* const signaling_thread_;
+ rtc::Thread* const worker_thread_;
+ PortAllocator* const port_allocator_;
+
+ // Timeout value in milliseconds for which no ICE connection receives
+ // any packets
+ int ice_receiving_timeout_ms_;
+ IceRole ice_role_;
+ rtc::scoped_ptr<rtc::SSLIdentity> identity_;
+ rtc::SSLProtocolVersion ssl_max_version_;
+ std::map<std::string, Transport*> transports_;
+
+ // Flag which will be set to true after the first role switch
+ bool ice_role_switch_;
+ uint64 ice_tiebreaker_;
+
+ // Aggregate state for Transports
+ ConnectionState connection_state_;
+ bool receiving_;
+ bool candidates_allocated_;
+ Transport::CandidateGatheringState candidate_gathering_state_;
+};
+
+} // namespace cricket
+
+#endif // WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_

Powered by Google App Engine
This is Rietveld 408576698