OLD | NEW |
---|---|
(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 | |
pthatcher1
2015/09/01 17:05:21
make => Make
Taylor Brandstetter
2015/09/01 23:53:31
Done.
| |
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 first transport in the | |
pthatcher1
2015/09/01 17:05:21
"in the transport map" isn't really needed.
Taylor Brandstetter
2015/09/01 23:53:31
I think it's a little relavant, since otherwise on
| |
54 // transport map. | |
55 bool GetSslRole(rtc::SSLRole* role); | |
56 | |
57 // Specifies the identity to use in this session. | |
58 // Can only be called once. | |
pthatcher1
2015/09/01 17:05:21
Can we call it SetLocalCertificate and GetLocalCer
Taylor Brandstetter
2015/09/01 23:53:31
Yeah.. I'll do that on Transport etc. as well.
| |
59 bool SetCertificate( | |
60 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); | |
61 bool GetCertificate(const std::string& transport_name, | |
62 rtc::scoped_refptr<rtc::RTCCertificate>* certificate); | |
63 // Caller owns returned certificate | |
64 bool GetRemoteCertificate(const std::string& transport_name, | |
65 rtc::SSLCertificate** cert); | |
66 bool SetLocalTransportDescription(const std::string& transport_name, | |
67 const TransportDescription& tdesc, | |
68 ContentAction action, | |
69 std::string* err); | |
70 bool SetRemoteTransportDescription(const std::string& transport_name, | |
71 const TransportDescription& tdesc, | |
72 ContentAction action, | |
73 std::string* err); | |
74 bool AddRemoteCandidates(const std::string& transport_name, | |
75 const Candidates& candidates, | |
76 std::string* err); | |
77 bool ReadyForRemoteCandidates(const std::string& transport_name); | |
78 bool GetStats(const std::string& transport_name, TransportStats* stats); | |
79 | |
80 virtual TransportChannel* CreateTransportChannel_w( | |
81 const std::string& transport_name, | |
82 int component); | |
83 virtual void DestroyTransportChannel_w(const std::string& transport_name, | |
84 int component); | |
85 | |
86 // All of these signals are fired on the signalling thread. | |
87 | |
88 // If any transport failed => failed, | |
89 // Else if all completed => completed, | |
90 // Else if all connected => connected, | |
91 // Else => connecting | |
92 sigslot::signal1<IceConnectionState> SignalConnectionState; | |
93 | |
94 // Receiving if any transport is receiving | |
95 sigslot::signal1<bool> SignalReceiving; | |
96 | |
97 // If all transports done gathering => complete, | |
98 // Else if any are gathering => gathering, | |
99 // Else => new | |
100 sigslot::signal1<IceGatheringState> SignalGatheringState; | |
101 | |
102 // (transport_name, candidates) | |
103 sigslot::signal2<const std::string&, const Candidates&> | |
104 SignalCandidatesGathered; | |
105 | |
106 // for unit test | |
107 rtc::scoped_refptr<rtc::RTCCertificate> certificate_for_testing(); | |
pthatcher1
2015/09/01 17:05:21
Can you explain why this is needed? It seems awkw
Taylor Brandstetter
2015/09/01 23:53:31
Again, this is part of a merge; I'd ask hbos
| |
108 | |
109 protected: | |
110 virtual void OnMessage(rtc::Message* pmsg); | |
pthatcher1
2015/09/01 17:05:21
Does this need to be protected?
Taylor Brandstetter
2015/09/01 23:53:31
I guess not; moved to private.
| |
111 | |
112 // protected and virtual so we can override it in unit tests. | |
pthatcher1
2015/09/01 17:05:21
protected => Protected
Taylor Brandstetter
2015/09/01 23:53:31
Done.
| |
113 virtual Transport* CreateTransport_w(const std::string& transport_name); | |
114 | |
115 // for unit tests | |
pthatcher1
2015/09/01 17:05:21
for => For
Taylor Brandstetter
2015/09/01 23:53:31
Done.
| |
116 const std::map<std::string, Transport*>& transports() { return transports_; } | |
117 Transport* GetTransport_w(const std::string& transport_name); | |
118 | |
119 private: | |
120 Transport* GetOrCreateTransport_w(const std::string& transport_name); | |
121 void DestroyTransport_w(const std::string& transport_name); | |
122 void DestroyAllTransports_w(); | |
123 | |
124 bool SetSslMaxProtocolVersion_w(rtc::SSLProtocolVersion version); | |
125 void SetIceConnectionReceivingTimeout_w(int timeout_ms); | |
126 void SetIceRole_w(IceRole ice_role); | |
127 bool GetSslRole_w(rtc::SSLRole* role); | |
128 bool SetCertificate_w( | |
129 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); | |
130 bool GetCertificate_w(const std::string& transport_name, | |
131 rtc::scoped_refptr<rtc::RTCCertificate>* certificate); | |
132 bool GetRemoteCertificate_w(const std::string& transport_name, | |
133 rtc::SSLCertificate** cert); | |
134 bool SetLocalTransportDescription_w(const std::string& transport_name, | |
135 const TransportDescription& tdesc, | |
136 ContentAction action, | |
137 std::string* err); | |
138 bool SetRemoteTransportDescription_w(const std::string& transport_name, | |
139 const TransportDescription& tdesc, | |
140 ContentAction action, | |
141 std::string* err); | |
142 bool AddRemoteCandidates_w(const std::string& transport_name, | |
143 const Candidates& candidates, | |
144 std::string* err); | |
145 bool ReadyForRemoteCandidates_w(const std::string& transport_name); | |
146 bool GetStats_w(const std::string& transport_name, TransportStats* stats); | |
147 | |
148 // Handlers for signals from Transport. | |
149 void OnTransportConnecting_w(Transport* transport); | |
150 void OnTransportWritableState_w(Transport* transport); | |
151 void OnTransportReceivingState_w(Transport* transport); | |
152 void OnTransportCompleted_w(Transport* transport); | |
153 void OnTransportFailed_w(Transport* transport); | |
154 void OnTransportGatheringState_w(Transport* transport); | |
155 void OnTransportCandidatesGathered_w( | |
156 Transport* transport, | |
157 const std::vector<Candidate>& candidates); | |
158 void OnTransportRoleConflict_w(); | |
159 | |
160 void UpdateAggregateStates_w(); | |
161 | |
162 rtc::Thread* const signaling_thread_ = nullptr; | |
163 rtc::Thread* const worker_thread_ = nullptr; | |
164 typedef std::map<std::string, Transport*> TransportMap; | |
165 TransportMap transports_; | |
166 | |
167 PortAllocator* const port_allocator_ = nullptr; | |
168 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_10; | |
169 | |
170 // Aggregate state for Transports | |
171 IceConnectionState connection_state_ = kIceConnectionConnecting; | |
172 bool receiving_ = false; | |
173 IceGatheringState gathering_state_ = kIceGatheringNew; | |
174 | |
175 // TODO(deadbeef): Move the fields below down to the transports themselves | |
176 | |
177 // Timeout value in milliseconds for which no ICE connection receives | |
178 // any packets | |
179 int ice_receiving_timeout_ms_ = -1; | |
180 IceRole ice_role_ = ICEROLE_CONTROLLING; | |
181 // Flag which will be set to true after the first role switch | |
182 bool ice_role_switch_ = false; | |
183 uint64 ice_tiebreaker_ = rtc::CreateRandomId64(); | |
184 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; | |
185 }; | |
186 | |
187 } // namespace cricket | |
188 | |
189 #endif // WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_ | |
OLD | NEW |