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

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: Fixing problems with "failed" state; a channel isn't failed if it's never added a connection 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
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 bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version);
43
44 void SetIceConnectionReceivingTimeout(int timeout_ms);
45 void SetIceRole(IceRole ice_role);
46 bool GetSslRole(rtc::SSLRole* role);
47
48 // Takes ownership of identity and passes it down to transports.
49 // Can only be called once.
50 bool SetIdentity(rtc::SSLIdentity* identity);
51 // Caller owns returned identity
52 bool GetIdentity(const std::string& transport_name,
53 rtc::SSLIdentity** identity);
54 // Caller owns returned certificate
55 bool GetRemoteCertificate(const std::string& transport_name,
56 rtc::SSLCertificate** cert);
57 bool SetLocalTransportDescription(const std::string& transport_name,
58 const TransportDescription& tdesc,
59 ContentAction action,
60 std::string* err);
61 bool SetRemoteTransportDescription(const std::string& transport_name,
62 const TransportDescription& tdesc,
63 ContentAction action,
64 std::string* err);
65 bool AddRemoteCandidates(const std::string& transport_name,
66 const Candidates& candidates,
67 std::string* err);
68 bool ReadyForRemoteCandidates(const std::string& transport_name);
69 bool GetStats(const std::string& transport_name, TransportStats* stats);
70
71 virtual TransportChannel* CreateTransportChannel_w(
72 const std::string& transport_name,
73 int component);
74 virtual void DestroyTransportChannel_w(const std::string& transport_name,
75 int component);
76
77 // All of these signals are fired on the signalling thread.
78 sigslot::signal1<IceConnectionState> SignalConnectionState;
79 sigslot::signal1<bool> SignalReceiving;
80 sigslot::signal1<IceGatheringState> SignalGatheringState;
81 // (transport_name, candidates)
82 sigslot::signal2<const std::string&, const Candidates&>
83 SignalCandidatesGathered;
84
85 protected:
86 virtual void OnMessage(rtc::Message* pmsg);
87
88 // protected and virtual so we can override it in unit tests.
89 virtual Transport* CreateTransport_w(const std::string& transport_name);
90
91 // for unit tests
92 const std::map<std::string, Transport*>& transports() { return transports_; }
93 Transport* GetTransport_w(const std::string& transport_name);
94
95 private:
96 Transport* GetOrCreateTransport_w(const std::string& transport_name);
97 void DestroyTransport_w(const std::string& transport_name);
98 void DestroyAllTransports_w();
99
100 bool SetSslMaxProtocolVersion_w(rtc::SSLProtocolVersion version);
101 void SetIceConnectionReceivingTimeout_w(int timeout_ms);
102 void SetIceRole_w(IceRole ice_role);
103 bool GetSslRole_w(rtc::SSLRole* role);
104 bool SetIdentity_w(rtc::SSLIdentity* identity);
105 bool GetIdentity_w(const std::string& transport_name,
106 rtc::SSLIdentity** identity);
107 bool GetRemoteCertificate_w(const std::string& transport_name,
108 rtc::SSLCertificate** cert);
109 bool SetLocalTransportDescription_w(const std::string& transport_name,
110 const TransportDescription& tdesc,
111 ContentAction action,
112 std::string* err);
113 bool SetRemoteTransportDescription_w(const std::string& transport_name,
114 const TransportDescription& tdesc,
115 ContentAction action,
116 std::string* err);
117 bool AddRemoteCandidates_w(const std::string& transport_name,
118 const Candidates& candidates,
119 std::string* err);
120 bool ReadyForRemoteCandidates_w(const std::string& transport_name);
121 bool GetStats_w(const std::string& transport_name, TransportStats* stats);
122
123 // Handlers for signals from Transport.
124 void OnTransportConnecting_w(Transport* transport);
125 void OnTransportWritableState_w(Transport* transport);
126 void OnTransportReceivingState_w(Transport* transport);
127 void OnTransportCompleted_w(Transport* transport);
128 void OnTransportFailed_w(Transport* transport);
129 void OnTransportGatheringState_w(Transport* transport);
130 void OnTransportCandidatesGathered_w(
131 Transport* transport,
132 const std::vector<Candidate>& candidates);
133 void OnTransportRoleConflict_w();
134
135 void UpdateAggregateStates_w();
136
137 rtc::Thread* const signaling_thread_ = nullptr;
138 rtc::Thread* const worker_thread_ = nullptr;
139 typedef std::map<std::string, Transport*> TransportMap;
140 TransportMap transports_;
141
142 PortAllocator* const port_allocator_ = nullptr;
143 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_10;
144
145 // Aggregate state for Transports
146 IceConnectionState connection_state_ = kIceConnectionConnecting;
147 bool receiving_ = false;
148 IceGatheringState gathering_state_ = kIceGatheringNew;
149
150 // TODO(deadbeef): Move the field below down to the transports themselves
151
152 // Timeout value in milliseconds for which no ICE connection receives
153 // any packets
154 int ice_receiving_timeout_ms_ = -1;
155 IceRole ice_role_ = ICEROLE_CONTROLLING;
156 // Flag which will be set to true after the first role switch
157 bool ice_role_switch_ = false;
158 uint64 ice_tiebreaker_ = rtc::CreateRandomId64();
159 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
160 };
161
162 } // namespace cricket
163
164 #endif // WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698