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

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

Issue 1246913005: TransportController refactoring (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « webrtc/p2p/base/transportchannelproxy.cc ('k') | webrtc/p2p/base/transportcontroller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 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_TRANSPORTCONTROLLER_H_
12 #define WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_
13
14 #include <map>
15 #include <string>
16 #include <vector>
17
18 #include "webrtc/base/sigslot.h"
19 #include "webrtc/base/sslstreamadapter.h"
20 #include "webrtc/p2p/base/candidate.h"
21 #include "webrtc/p2p/base/transport.h"
22
23 namespace rtc {
24 class Thread;
25 }
26
27 namespace cricket {
28
29 class TransportController : public sigslot::has_slots<>,
30 public rtc::MessageHandler {
31 public:
32 TransportController(rtc::Thread* signaling_thread,
33 rtc::Thread* worker_thread,
34 PortAllocator* port_allocator);
35
36 virtual ~TransportController();
37
38 rtc::Thread* signaling_thread() const { return signaling_thread_; }
39 rtc::Thread* worker_thread() const { return worker_thread_; }
40
41 PortAllocator* port_allocator() const { return port_allocator_; }
42
43 // Can only be set before transports are created.
44 // TODO(deadbeef): Make this an argument to the constructor once BaseSession
45 // and WebRtcSession are combined
46 bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version);
47
48 void SetIceConnectionReceivingTimeout(int timeout_ms);
49 void SetIceRole(IceRole ice_role);
50
51 // TODO(deadbeef) - Return role of each transport, as role may differ from
52 // one another.
53 // In current implementaion we just return the role of the first transport
54 // alphabetically.
55 bool GetSslRole(rtc::SSLRole* role);
56
57 // Specifies the identity to use in this session.
58 // Can only be called once.
59 bool SetLocalCertificate(
60 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
61 bool GetLocalCertificate(
62 const std::string& transport_name,
63 rtc::scoped_refptr<rtc::RTCCertificate>* certificate);
64 // Caller owns returned certificate
65 bool GetRemoteSSLCertificate(const std::string& transport_name,
66 rtc::SSLCertificate** cert);
67 bool SetLocalTransportDescription(const std::string& transport_name,
68 const TransportDescription& tdesc,
69 ContentAction action,
70 std::string* err);
71 bool SetRemoteTransportDescription(const std::string& transport_name,
72 const TransportDescription& tdesc,
73 ContentAction action,
74 std::string* err);
75 bool AddRemoteCandidates(const std::string& transport_name,
76 const Candidates& candidates,
77 std::string* err);
78 bool ReadyForRemoteCandidates(const std::string& transport_name);
79 bool GetStats(const std::string& transport_name, TransportStats* stats);
80
81 virtual TransportChannel* CreateTransportChannel_w(
82 const std::string& transport_name,
83 int component);
84 virtual void DestroyTransportChannel_w(const std::string& transport_name,
85 int component);
86
87 // All of these signals are fired on the signalling thread.
88
89 // If any transport failed => failed,
90 // Else if all completed => completed,
91 // Else if all connected => connected,
92 // Else => connecting
93 sigslot::signal1<IceConnectionState> SignalConnectionState;
94
95 // Receiving if any transport is receiving
96 sigslot::signal1<bool> SignalReceiving;
97
98 // If all transports done gathering => complete,
99 // Else if any are gathering => gathering,
100 // Else => new
101 sigslot::signal1<IceGatheringState> SignalGatheringState;
102
103 // (transport_name, candidates)
104 sigslot::signal2<const std::string&, const Candidates&>
105 SignalCandidatesGathered;
106
107 // for unit test
108 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate_for_testing();
109
110 protected:
111 // Protected and virtual so we can override it in unit tests.
112 virtual Transport* CreateTransport_w(const std::string& transport_name);
113
114 // For unit tests
115 const std::map<std::string, Transport*>& transports() { return transports_; }
116 Transport* GetTransport_w(const std::string& transport_name);
117
118 private:
119 void OnMessage(rtc::Message* pmsg) override;
120
121 Transport* GetOrCreateTransport_w(const std::string& transport_name);
122 void DestroyTransport_w(const std::string& transport_name);
123 void DestroyAllTransports_w();
124
125 bool SetSslMaxProtocolVersion_w(rtc::SSLProtocolVersion version);
126 void SetIceConnectionReceivingTimeout_w(int timeout_ms);
127 void SetIceRole_w(IceRole ice_role);
128 bool GetSslRole_w(rtc::SSLRole* role);
129 bool SetLocalCertificate_w(
130 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
131 bool GetLocalCertificate_w(
132 const std::string& transport_name,
133 rtc::scoped_refptr<rtc::RTCCertificate>* certificate);
134 bool GetRemoteSSLCertificate_w(const std::string& transport_name,
135 rtc::SSLCertificate** cert);
136 bool SetLocalTransportDescription_w(const std::string& transport_name,
137 const TransportDescription& tdesc,
138 ContentAction action,
139 std::string* err);
140 bool SetRemoteTransportDescription_w(const std::string& transport_name,
141 const TransportDescription& tdesc,
142 ContentAction action,
143 std::string* err);
144 bool AddRemoteCandidates_w(const std::string& transport_name,
145 const Candidates& candidates,
146 std::string* err);
147 bool ReadyForRemoteCandidates_w(const std::string& transport_name);
148 bool GetStats_w(const std::string& transport_name, TransportStats* stats);
149
150 // Handlers for signals from Transport.
151 void OnTransportConnecting_w(Transport* transport);
152 void OnTransportWritableState_w(Transport* transport);
153 void OnTransportReceivingState_w(Transport* transport);
154 void OnTransportCompleted_w(Transport* transport);
155 void OnTransportFailed_w(Transport* transport);
156 void OnTransportGatheringState_w(Transport* transport);
157 void OnTransportCandidatesGathered_w(
158 Transport* transport,
159 const std::vector<Candidate>& candidates);
160 void OnTransportRoleConflict_w();
161
162 void UpdateAggregateStates_w();
163 bool HasChannels_w();
164
165 rtc::Thread* const signaling_thread_ = nullptr;
166 rtc::Thread* const worker_thread_ = nullptr;
167 typedef std::map<std::string, Transport*> TransportMap;
168 TransportMap transports_;
169
170 PortAllocator* const port_allocator_ = nullptr;
171 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_10;
172
173 // Aggregate state for Transports
174 IceConnectionState connection_state_ = kIceConnectionConnecting;
175 bool receiving_ = false;
176 IceGatheringState gathering_state_ = kIceGatheringNew;
177
178 // TODO(deadbeef): Move the fields below down to the transports themselves
179
180 // Timeout value in milliseconds for which no ICE connection receives
181 // any packets
182 int ice_receiving_timeout_ms_ = -1;
183 IceRole ice_role_ = ICEROLE_CONTROLLING;
184 // Flag which will be set to true after the first role switch
185 bool ice_role_switch_ = false;
186 uint64 ice_tiebreaker_ = rtc::CreateRandomId64();
187 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
188 };
189
190 } // namespace cricket
191
192 #endif // WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_
OLDNEW
« no previous file with comments | « webrtc/p2p/base/transportchannelproxy.cc ('k') | webrtc/p2p/base/transportcontroller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698