| 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 // All of these signals are fired on the signalling thread. | 94 // All of these signals are fired on the signalling thread. |
| 95 | 95 |
| 96 // If any transport failed => failed, | 96 // If any transport failed => failed, |
| 97 // Else if all completed => completed, | 97 // Else if all completed => completed, |
| 98 // Else if all connected => connected, | 98 // Else if all connected => connected, |
| 99 // Else => connecting | 99 // Else => connecting |
| 100 sigslot::signal1<IceConnectionState> SignalConnectionState; | 100 sigslot::signal1<IceConnectionState> SignalConnectionState; |
| 101 | 101 |
| 102 // Receiving if any transport is receiving | 102 // Receiving if any transport is receiving |
| 103 sigslot::signal1<bool> SignalReceiving; | 103 sigslot::signal1<bool> SignalReceiving; |
| 104 | 104 |
| 105 // If all transports done gathering => complete, | 105 // If all transports done gathering => complete, |
| 106 // Else if any are gathering => gathering, | 106 // Else if any are gathering => gathering, |
| 107 // Else => new | 107 // Else => new |
| 108 sigslot::signal1<IceGatheringState> SignalGatheringState; | 108 sigslot::signal1<IceGatheringState> SignalGatheringState; |
| 109 | 109 |
| 110 // (transport_name, candidates) | 110 // (transport_name, candidates) |
| 111 sigslot::signal2<const std::string&, const Candidates&> | 111 sigslot::signal2<const std::string&, const Candidates&> |
| 112 SignalCandidatesGathered; | 112 SignalCandidatesGathered; |
| 113 | 113 |
| 114 sigslot::signal1<const Candidates&> SignalCandidatesRemoved; | 114 sigslot::signal1<const Candidates&> SignalCandidatesRemoved; |
| 115 | 115 |
| 116 // for unit test | 116 // for unit test |
| 117 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate_for_testing(); | 117 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate_for_testing(); |
| 118 | 118 |
| 119 protected: | 119 protected: |
| 120 // Protected and virtual so we can override it in unit tests. | 120 // Protected and virtual so we can override it in unit tests. |
| 121 virtual Transport* CreateTransport_w(const std::string& transport_name); | 121 virtual Transport* CreateTransport_n(const std::string& transport_name); |
| 122 | 122 |
| 123 // For unit tests | 123 // For unit tests |
| 124 const std::map<std::string, Transport*>& transports() { return transports_; } | 124 const std::map<std::string, Transport*>& transports() { return transports_; } |
| 125 Transport* GetTransport_w(const std::string& transport_name); | 125 Transport* GetTransport_n(const std::string& transport_name); |
| 126 | 126 |
| 127 private: | 127 private: |
| 128 void OnMessage(rtc::Message* pmsg) override; | 128 void OnMessage(rtc::Message* pmsg) override; |
| 129 | 129 |
| 130 // It's the Transport that's currently responsible for creating/destroying | 130 // It's the Transport that's currently responsible for creating/destroying |
| 131 // channels, but the TransportController keeps track of how many external | 131 // channels, but the TransportController keeps track of how many external |
| 132 // objects (BaseChannels) reference each channel. | 132 // objects (BaseChannels) reference each channel. |
| 133 struct RefCountedChannel { | 133 struct RefCountedChannel { |
| 134 RefCountedChannel() : impl_(nullptr), ref_(0) {} | 134 RefCountedChannel() : impl_(nullptr), ref_(0) {} |
| 135 explicit RefCountedChannel(TransportChannelImpl* impl) | 135 explicit RefCountedChannel(TransportChannelImpl* impl) |
| 136 : impl_(impl), ref_(0) {} | 136 : impl_(impl), ref_(0) {} |
| 137 | 137 |
| 138 void AddRef() { ++ref_; } | 138 void AddRef() { ++ref_; } |
| 139 void DecRef() { | 139 void DecRef() { |
| 140 ASSERT(ref_ > 0); | 140 ASSERT(ref_ > 0); |
| 141 --ref_; | 141 --ref_; |
| 142 } | 142 } |
| 143 int ref() const { return ref_; } | 143 int ref() const { return ref_; } |
| 144 | 144 |
| 145 TransportChannelImpl* get() const { return impl_; } | 145 TransportChannelImpl* get() const { return impl_; } |
| 146 TransportChannelImpl* operator->() const { return impl_; } | 146 TransportChannelImpl* operator->() const { return impl_; } |
| 147 | 147 |
| 148 private: | 148 private: |
| 149 TransportChannelImpl* impl_; | 149 TransportChannelImpl* impl_; |
| 150 int ref_; | 150 int ref_; |
| 151 }; | 151 }; |
| 152 | 152 |
| 153 std::vector<RefCountedChannel>::iterator FindChannel_w( | 153 std::vector<RefCountedChannel>::iterator FindChannel_n( |
| 154 const std::string& transport_name, | 154 const std::string& transport_name, |
| 155 int component); | 155 int component); |
| 156 | 156 |
| 157 Transport* GetOrCreateTransport_w(const std::string& transport_name); | 157 Transport* GetOrCreateTransport_n(const std::string& transport_name); |
| 158 void DestroyTransport_w(const std::string& transport_name); | 158 void DestroyTransport_n(const std::string& transport_name); |
| 159 void DestroyAllTransports_w(); | 159 void DestroyAllTransports_n(); |
| 160 | 160 |
| 161 bool SetSslMaxProtocolVersion_w(rtc::SSLProtocolVersion version); | 161 bool SetSslMaxProtocolVersion_n(rtc::SSLProtocolVersion version); |
| 162 void SetIceConfig_w(const IceConfig& config); | 162 void SetIceConfig_n(const IceConfig& config); |
| 163 void SetIceRole_w(IceRole ice_role); | 163 void SetIceRole_n(IceRole ice_role); |
| 164 bool GetSslRole_w(const std::string& transport_name, rtc::SSLRole* role); | 164 bool GetSslRole_n(const std::string& transport_name, rtc::SSLRole* role); |
| 165 bool SetLocalCertificate_w( | 165 bool SetLocalCertificate_n( |
| 166 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); | 166 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
| 167 bool GetLocalCertificate_w( | 167 bool GetLocalCertificate_n( |
| 168 const std::string& transport_name, | 168 const std::string& transport_name, |
| 169 rtc::scoped_refptr<rtc::RTCCertificate>* certificate); | 169 rtc::scoped_refptr<rtc::RTCCertificate>* certificate); |
| 170 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate_w( | 170 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate_n( |
| 171 const std::string& transport_name); | 171 const std::string& transport_name); |
| 172 bool SetLocalTransportDescription_w(const std::string& transport_name, | 172 bool SetLocalTransportDescription_n(const std::string& transport_name, |
| 173 const TransportDescription& tdesc, | 173 const TransportDescription& tdesc, |
| 174 ContentAction action, | 174 ContentAction action, |
| 175 std::string* err); | 175 std::string* err); |
| 176 bool SetRemoteTransportDescription_w(const std::string& transport_name, | 176 bool SetRemoteTransportDescription_n(const std::string& transport_name, |
| 177 const TransportDescription& tdesc, | 177 const TransportDescription& tdesc, |
| 178 ContentAction action, | 178 ContentAction action, |
| 179 std::string* err); | 179 std::string* err); |
| 180 void MaybeStartGathering_w(); | 180 void MaybeStartGathering_n(); |
| 181 bool AddRemoteCandidates_w(const std::string& transport_name, | 181 bool AddRemoteCandidates_n(const std::string& transport_name, |
| 182 const Candidates& candidates, | 182 const Candidates& candidates, |
| 183 std::string* err); | 183 std::string* err); |
| 184 bool RemoveRemoteCandidates_w(const Candidates& candidates, std::string* err); | 184 bool RemoveRemoteCandidates_n(const Candidates& candidates, std::string* err); |
| 185 bool ReadyForRemoteCandidates_w(const std::string& transport_name); | 185 bool ReadyForRemoteCandidates_n(const std::string& transport_name); |
| 186 bool GetStats_w(const std::string& transport_name, TransportStats* stats); | 186 bool GetStats_n(const std::string& transport_name, TransportStats* stats); |
| 187 | 187 |
| 188 // Handlers for signals from Transport. | 188 // Handlers for signals from Transport. |
| 189 void OnChannelWritableState_w(TransportChannel* channel); | 189 void OnChannelWritableState_n(TransportChannel* channel); |
| 190 void OnChannelReceivingState_w(TransportChannel* channel); | 190 void OnChannelReceivingState_n(TransportChannel* channel); |
| 191 void OnChannelGatheringState_w(TransportChannelImpl* channel); | 191 void OnChannelGatheringState_n(TransportChannelImpl* channel); |
| 192 void OnChannelCandidateGathered_w(TransportChannelImpl* channel, | 192 void OnChannelCandidateGathered_n(TransportChannelImpl* channel, |
| 193 const Candidate& candidate); | 193 const Candidate& candidate); |
| 194 void OnChannelCandidatesRemoved(const Candidates& candidates); | 194 void OnChannelCandidatesRemoved(const Candidates& candidates); |
| 195 void OnChannelCandidatesRemoved_w(TransportChannelImpl* channel, | 195 void OnChannelCandidatesRemoved_n(TransportChannelImpl* channel, |
| 196 const Candidates& candidates); | 196 const Candidates& candidates); |
| 197 void OnChannelRoleConflict_w(TransportChannelImpl* channel); | 197 void OnChannelRoleConflict_n(TransportChannelImpl* channel); |
| 198 void OnChannelConnectionRemoved_w(TransportChannelImpl* channel); | 198 void OnChannelConnectionRemoved_n(TransportChannelImpl* channel); |
| 199 | 199 |
| 200 void UpdateAggregateStates_w(); | 200 void UpdateAggregateStates_n(); |
| 201 | 201 |
| 202 rtc::Thread* const signaling_thread_ = nullptr; | 202 rtc::Thread* const signaling_thread_ = nullptr; |
| 203 rtc::Thread* const worker_thread_ = nullptr; | 203 rtc::Thread* const network_thread_ = nullptr; |
| 204 typedef std::map<std::string, Transport*> TransportMap; | 204 typedef std::map<std::string, Transport*> TransportMap; |
| 205 TransportMap transports_; | 205 TransportMap transports_; |
| 206 | 206 |
| 207 std::vector<RefCountedChannel> channels_; | 207 std::vector<RefCountedChannel> channels_; |
| 208 | 208 |
| 209 PortAllocator* const port_allocator_ = nullptr; | 209 PortAllocator* const port_allocator_ = nullptr; |
| 210 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; | 210 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; |
| 211 | 211 |
| 212 // Aggregate state for TransportChannelImpls. | 212 // Aggregate state for TransportChannelImpls. |
| 213 IceConnectionState connection_state_ = kIceConnectionConnecting; | 213 IceConnectionState connection_state_ = kIceConnectionConnecting; |
| 214 bool receiving_ = false; | 214 bool receiving_ = false; |
| 215 IceGatheringState gathering_state_ = kIceGatheringNew; | 215 IceGatheringState gathering_state_ = kIceGatheringNew; |
| 216 | 216 |
| 217 // TODO(deadbeef): Move the fields below down to the transports themselves | 217 // TODO(deadbeef): Move the fields below down to the transports themselves |
| 218 IceConfig ice_config_; | 218 IceConfig ice_config_; |
| 219 IceRole ice_role_ = ICEROLE_CONTROLLING; | 219 IceRole ice_role_ = ICEROLE_CONTROLLING; |
| 220 // Flag which will be set to true after the first role switch | 220 // Flag which will be set to true after the first role switch |
| 221 bool ice_role_switch_ = false; | 221 bool ice_role_switch_ = false; |
| 222 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64(); | 222 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64(); |
| 223 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; | 223 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; |
| 224 rtc::AsyncInvoker invoker_; | 224 rtc::AsyncInvoker invoker_; |
| 225 }; | 225 }; |
| 226 | 226 |
| 227 } // namespace cricket | 227 } // namespace cricket |
| 228 | 228 |
| 229 #endif // WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_ | 229 #endif // WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_ |
| OLD | NEW |