| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 namespace rtc { | 25 namespace rtc { |
| 26 class Thread; | 26 class Thread; |
| 27 } | 27 } |
| 28 | 28 |
| 29 namespace cricket { | 29 namespace cricket { |
| 30 | 30 |
| 31 class TransportController : public sigslot::has_slots<>, | 31 class TransportController : public sigslot::has_slots<>, |
| 32 public rtc::MessageHandler { | 32 public rtc::MessageHandler { |
| 33 public: | 33 public: |
| 34 TransportController(rtc::Thread* signaling_thread, | 34 TransportController(rtc::Thread* signaling_thread, |
| 35 rtc::Thread* worker_thread, | 35 rtc::Thread* network_thread, |
| 36 PortAllocator* port_allocator); | 36 PortAllocator* port_allocator); |
| 37 | 37 |
| 38 virtual ~TransportController(); | 38 virtual ~TransportController(); |
| 39 | 39 |
| 40 rtc::Thread* signaling_thread() const { return signaling_thread_; } | 40 rtc::Thread* signaling_thread() const { return signaling_thread_; } |
| 41 rtc::Thread* worker_thread() const { return worker_thread_; } | 41 rtc::Thread* network_thread() const { return network_thread_; } |
| 42 | 42 |
| 43 PortAllocator* port_allocator() const { return port_allocator_; } | 43 PortAllocator* port_allocator() const { return port_allocator_; } |
| 44 | 44 |
| 45 // Can only be set before transports are created. | 45 // Can only be set before transports are created. |
| 46 // TODO(deadbeef): Make this an argument to the constructor once BaseSession | 46 // TODO(deadbeef): Make this an argument to the constructor once BaseSession |
| 47 // and WebRtcSession are combined | 47 // and WebRtcSession are combined |
| 48 bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version); | 48 bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version); |
| 49 | 49 |
| 50 void SetIceConfig(const IceConfig& config); | 50 void SetIceConfig(const IceConfig& config); |
| 51 void SetIceRole(IceRole ice_role); | 51 void SetIceRole(IceRole ice_role); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 75 void MaybeStartGathering(); | 75 void MaybeStartGathering(); |
| 76 bool AddRemoteCandidates(const std::string& transport_name, | 76 bool AddRemoteCandidates(const std::string& transport_name, |
| 77 const Candidates& candidates, | 77 const Candidates& candidates, |
| 78 std::string* err); | 78 std::string* err); |
| 79 bool RemoveRemoteCandidates(const Candidates& candidates, std::string* err); | 79 bool RemoveRemoteCandidates(const Candidates& candidates, std::string* err); |
| 80 bool ReadyForRemoteCandidates(const std::string& transport_name); | 80 bool ReadyForRemoteCandidates(const std::string& transport_name); |
| 81 bool GetStats(const std::string& transport_name, TransportStats* stats); | 81 bool GetStats(const std::string& transport_name, TransportStats* stats); |
| 82 | 82 |
| 83 // Creates a channel if it doesn't exist. Otherwise, increments a reference | 83 // Creates a channel if it doesn't exist. Otherwise, increments a reference |
| 84 // count and returns an existing channel. | 84 // count and returns an existing channel. |
| 85 virtual TransportChannel* CreateTransportChannel_w( | 85 virtual TransportChannel* CreateTransportChannel_n( |
| 86 const std::string& transport_name, | 86 const std::string& transport_name, |
| 87 int component); | 87 int component); |
| 88 | 88 |
| 89 // Decrements a channel's reference count, and destroys the channel if | 89 // Decrements a channel's reference count, and destroys the channel if |
| 90 // nothing is referencing it. | 90 // nothing is referencing it. |
| 91 virtual void DestroyTransportChannel_w(const std::string& transport_name, | 91 virtual void DestroyTransportChannel_n(const std::string& transport_name, |
| 92 int component); | 92 int component); |
| 93 | 93 |
| 94 void use_quic() { quic_ = true; } | 94 void use_quic() { quic_ = true; } |
| 95 bool quic() const { return quic_; } | 95 bool quic() const { return quic_; } |
| 96 | 96 |
| 97 // All of these signals are fired on the signalling thread. | 97 // All of these signals are fired on the signalling thread. |
| 98 | 98 |
| 99 // If any transport failed => failed, | 99 // If any transport failed => failed, |
| 100 // Else if all completed => completed, | 100 // Else if all completed => completed, |
| 101 // Else if all connected => connected, | 101 // Else if all connected => connected, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 114 sigslot::signal2<const std::string&, const Candidates&> | 114 sigslot::signal2<const std::string&, const Candidates&> |
| 115 SignalCandidatesGathered; | 115 SignalCandidatesGathered; |
| 116 | 116 |
| 117 sigslot::signal1<const Candidates&> SignalCandidatesRemoved; | 117 sigslot::signal1<const Candidates&> SignalCandidatesRemoved; |
| 118 | 118 |
| 119 // for unit test | 119 // for unit test |
| 120 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate_for_testing(); | 120 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate_for_testing(); |
| 121 | 121 |
| 122 protected: | 122 protected: |
| 123 // Protected and virtual so we can override it in unit tests. | 123 // Protected and virtual so we can override it in unit tests. |
| 124 virtual Transport* CreateTransport_w(const std::string& transport_name); | 124 virtual Transport* CreateTransport_n(const std::string& transport_name); |
| 125 | 125 |
| 126 // For unit tests | 126 // For unit tests |
| 127 const std::map<std::string, Transport*>& transports() { return transports_; } | 127 const std::map<std::string, Transport*>& transports() { return transports_; } |
| 128 Transport* GetTransport_w(const std::string& transport_name); | 128 Transport* GetTransport_n(const std::string& transport_name); |
| 129 | 129 |
| 130 private: | 130 private: |
| 131 void OnMessage(rtc::Message* pmsg) override; | 131 void OnMessage(rtc::Message* pmsg) override; |
| 132 | 132 |
| 133 // It's the Transport that's currently responsible for creating/destroying | 133 // It's the Transport that's currently responsible for creating/destroying |
| 134 // channels, but the TransportController keeps track of how many external | 134 // channels, but the TransportController keeps track of how many external |
| 135 // objects (BaseChannels) reference each channel. | 135 // objects (BaseChannels) reference each channel. |
| 136 struct RefCountedChannel { | 136 struct RefCountedChannel { |
| 137 RefCountedChannel() : impl_(nullptr), ref_(0) {} | 137 RefCountedChannel() : impl_(nullptr), ref_(0) {} |
| 138 explicit RefCountedChannel(TransportChannelImpl* impl) | 138 explicit RefCountedChannel(TransportChannelImpl* impl) |
| 139 : impl_(impl), ref_(0) {} | 139 : impl_(impl), ref_(0) {} |
| 140 | 140 |
| 141 void AddRef() { ++ref_; } | 141 void AddRef() { ++ref_; } |
| 142 void DecRef() { | 142 void DecRef() { |
| 143 ASSERT(ref_ > 0); | 143 ASSERT(ref_ > 0); |
| 144 --ref_; | 144 --ref_; |
| 145 } | 145 } |
| 146 int ref() const { return ref_; } | 146 int ref() const { return ref_; } |
| 147 | 147 |
| 148 TransportChannelImpl* get() const { return impl_; } | 148 TransportChannelImpl* get() const { return impl_; } |
| 149 TransportChannelImpl* operator->() const { return impl_; } | 149 TransportChannelImpl* operator->() const { return impl_; } |
| 150 | 150 |
| 151 private: | 151 private: |
| 152 TransportChannelImpl* impl_; | 152 TransportChannelImpl* impl_; |
| 153 int ref_; | 153 int ref_; |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 std::vector<RefCountedChannel>::iterator FindChannel_w( | 156 std::vector<RefCountedChannel>::iterator FindChannel_n( |
| 157 const std::string& transport_name, | 157 const std::string& transport_name, |
| 158 int component); | 158 int component); |
| 159 | 159 |
| 160 Transport* GetOrCreateTransport_w(const std::string& transport_name); | 160 Transport* GetOrCreateTransport_n(const std::string& transport_name); |
| 161 void DestroyTransport_w(const std::string& transport_name); | 161 void DestroyTransport_n(const std::string& transport_name); |
| 162 void DestroyAllTransports_w(); | 162 void DestroyAllTransports_n(); |
| 163 | 163 |
| 164 bool SetSslMaxProtocolVersion_w(rtc::SSLProtocolVersion version); | 164 bool SetSslMaxProtocolVersion_n(rtc::SSLProtocolVersion version); |
| 165 void SetIceConfig_w(const IceConfig& config); | 165 void SetIceConfig_n(const IceConfig& config); |
| 166 void SetIceRole_w(IceRole ice_role); | 166 void SetIceRole_n(IceRole ice_role); |
| 167 bool GetSslRole_w(const std::string& transport_name, rtc::SSLRole* role); | 167 bool GetSslRole_n(const std::string& transport_name, rtc::SSLRole* role); |
| 168 bool SetLocalCertificate_w( | 168 bool SetLocalCertificate_n( |
| 169 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); | 169 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
| 170 bool GetLocalCertificate_w( | 170 bool GetLocalCertificate_n( |
| 171 const std::string& transport_name, | 171 const std::string& transport_name, |
| 172 rtc::scoped_refptr<rtc::RTCCertificate>* certificate); | 172 rtc::scoped_refptr<rtc::RTCCertificate>* certificate); |
| 173 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate_w( | 173 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate_n( |
| 174 const std::string& transport_name); | 174 const std::string& transport_name); |
| 175 bool SetLocalTransportDescription_w(const std::string& transport_name, | 175 bool SetLocalTransportDescription_n(const std::string& transport_name, |
| 176 const TransportDescription& tdesc, | 176 const TransportDescription& tdesc, |
| 177 ContentAction action, | 177 ContentAction action, |
| 178 std::string* err); | 178 std::string* err); |
| 179 bool SetRemoteTransportDescription_w(const std::string& transport_name, | 179 bool SetRemoteTransportDescription_n(const std::string& transport_name, |
| 180 const TransportDescription& tdesc, | 180 const TransportDescription& tdesc, |
| 181 ContentAction action, | 181 ContentAction action, |
| 182 std::string* err); | 182 std::string* err); |
| 183 void MaybeStartGathering_w(); | 183 void MaybeStartGathering_n(); |
| 184 bool AddRemoteCandidates_w(const std::string& transport_name, | 184 bool AddRemoteCandidates_n(const std::string& transport_name, |
| 185 const Candidates& candidates, | 185 const Candidates& candidates, |
| 186 std::string* err); | 186 std::string* err); |
| 187 bool RemoveRemoteCandidates_w(const Candidates& candidates, std::string* err); | 187 bool RemoveRemoteCandidates_n(const Candidates& candidates, std::string* err); |
| 188 bool ReadyForRemoteCandidates_w(const std::string& transport_name); | 188 bool ReadyForRemoteCandidates_n(const std::string& transport_name); |
| 189 bool GetStats_w(const std::string& transport_name, TransportStats* stats); | 189 bool GetStats_n(const std::string& transport_name, TransportStats* stats); |
| 190 | 190 |
| 191 // Handlers for signals from Transport. | 191 // Handlers for signals from Transport. |
| 192 void OnChannelWritableState_w(TransportChannel* channel); | 192 void OnChannelWritableState_n(TransportChannel* channel); |
| 193 void OnChannelReceivingState_w(TransportChannel* channel); | 193 void OnChannelReceivingState_n(TransportChannel* channel); |
| 194 void OnChannelGatheringState_w(TransportChannelImpl* channel); | 194 void OnChannelGatheringState_n(TransportChannelImpl* channel); |
| 195 void OnChannelCandidateGathered_w(TransportChannelImpl* channel, | 195 void OnChannelCandidateGathered_n(TransportChannelImpl* channel, |
| 196 const Candidate& candidate); | 196 const Candidate& candidate); |
| 197 void OnChannelCandidatesRemoved(const Candidates& candidates); | 197 void OnChannelCandidatesRemoved(const Candidates& candidates); |
| 198 void OnChannelCandidatesRemoved_w(TransportChannelImpl* channel, | 198 void OnChannelCandidatesRemoved_n(TransportChannelImpl* channel, |
| 199 const Candidates& candidates); | 199 const Candidates& candidates); |
| 200 void OnChannelRoleConflict_w(TransportChannelImpl* channel); | 200 void OnChannelRoleConflict_n(TransportChannelImpl* channel); |
| 201 void OnChannelConnectionRemoved_w(TransportChannelImpl* channel); | 201 void OnChannelConnectionRemoved_n(TransportChannelImpl* channel); |
| 202 | 202 |
| 203 void UpdateAggregateStates_w(); | 203 void UpdateAggregateStates_n(); |
| 204 | 204 |
| 205 rtc::Thread* const signaling_thread_ = nullptr; | 205 rtc::Thread* const signaling_thread_ = nullptr; |
| 206 rtc::Thread* const worker_thread_ = nullptr; | 206 rtc::Thread* const network_thread_ = nullptr; |
| 207 typedef std::map<std::string, Transport*> TransportMap; | 207 typedef std::map<std::string, Transport*> TransportMap; |
| 208 TransportMap transports_; | 208 TransportMap transports_; |
| 209 | 209 |
| 210 std::vector<RefCountedChannel> channels_; | 210 std::vector<RefCountedChannel> channels_; |
| 211 | 211 |
| 212 PortAllocator* const port_allocator_ = nullptr; | 212 PortAllocator* const port_allocator_ = nullptr; |
| 213 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; | 213 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; |
| 214 | 214 |
| 215 // Aggregate state for TransportChannelImpls. | 215 // Aggregate state for TransportChannelImpls. |
| 216 IceConnectionState connection_state_ = kIceConnectionConnecting; | 216 IceConnectionState connection_state_ = kIceConnectionConnecting; |
| 217 bool receiving_ = false; | 217 bool receiving_ = false; |
| 218 IceGatheringState gathering_state_ = kIceGatheringNew; | 218 IceGatheringState gathering_state_ = kIceGatheringNew; |
| 219 | 219 |
| 220 // TODO(deadbeef): Move the fields below down to the transports themselves | 220 // TODO(deadbeef): Move the fields below down to the transports themselves |
| 221 IceConfig ice_config_; | 221 IceConfig ice_config_; |
| 222 IceRole ice_role_ = ICEROLE_CONTROLLING; | 222 IceRole ice_role_ = ICEROLE_CONTROLLING; |
| 223 // Flag which will be set to true after the first role switch | 223 // Flag which will be set to true after the first role switch |
| 224 bool ice_role_switch_ = false; | 224 bool ice_role_switch_ = false; |
| 225 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64(); | 225 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64(); |
| 226 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; | 226 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; |
| 227 rtc::AsyncInvoker invoker_; | 227 rtc::AsyncInvoker invoker_; |
| 228 // True if QUIC is used instead of DTLS. | 228 // True if QUIC is used instead of DTLS. |
| 229 bool quic_ = false; | 229 bool quic_ = false; |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 } // namespace cricket | 232 } // namespace cricket |
| 233 | 233 |
| 234 #endif // WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_ | 234 #endif // WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_ |
| OLD | NEW |