OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // From TransportChannelImpl: | 86 // From TransportChannelImpl: |
87 TransportChannelState GetState() const override; | 87 TransportChannelState GetState() const override; |
88 void SetIceRole(IceRole role) override; | 88 void SetIceRole(IceRole role) override; |
89 IceRole GetIceRole() const override { return ice_role_; } | 89 IceRole GetIceRole() const override { return ice_role_; } |
90 void SetIceTiebreaker(uint64_t tiebreaker) override; | 90 void SetIceTiebreaker(uint64_t tiebreaker) override; |
91 void SetIceCredentials(const std::string& ice_ufrag, | 91 void SetIceCredentials(const std::string& ice_ufrag, |
92 const std::string& ice_pwd) override; | 92 const std::string& ice_pwd) override; |
93 void SetRemoteIceCredentials(const std::string& ice_ufrag, | 93 void SetRemoteIceCredentials(const std::string& ice_ufrag, |
94 const std::string& ice_pwd) override; | 94 const std::string& ice_pwd) override; |
95 void SetRemoteIceMode(IceMode mode) override; | 95 void SetRemoteIceMode(IceMode mode) override; |
96 void Connect() override; | |
97 void MaybeStartGathering() override; | 96 void MaybeStartGathering() override; |
98 IceGatheringState gathering_state() const override { | 97 IceGatheringState gathering_state() const override { |
99 return gathering_state_; | 98 return gathering_state_; |
100 } | 99 } |
101 void AddRemoteCandidate(const Candidate& candidate) override; | 100 void AddRemoteCandidate(const Candidate& candidate) override; |
102 void RemoveRemoteCandidate(const Candidate& candidate) override; | 101 void RemoveRemoteCandidate(const Candidate& candidate) override; |
103 // Sets the parameters in IceConfig. We do not set them blindly. Instead, we | 102 // Sets the parameters in IceConfig. We do not set them blindly. Instead, we |
104 // only update the parameter if it is considered set in |config|. For example, | 103 // only update the parameter if it is considered set in |config|. For example, |
105 // a negative value of receiving_timeout will be considered "not set" and we | 104 // a negative value of receiving_timeout will be considered "not set" and we |
106 // will not use it to update the respective parameter in |config_|. | 105 // will not use it to update the respective parameter in |config_|. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 } | 205 } |
207 | 206 |
208 private: | 207 private: |
209 rtc::Thread* thread() { return worker_thread_; } | 208 rtc::Thread* thread() { return worker_thread_; } |
210 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); } | 209 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); } |
211 | 210 |
212 // A transport channel is weak if the current best connection is either | 211 // A transport channel is weak if the current best connection is either |
213 // not receiving or not writable, or if there is no best connection at all. | 212 // not receiving or not writable, or if there is no best connection at all. |
214 bool weak() const; | 213 bool weak() const; |
215 void UpdateConnectionStates(); | 214 void UpdateConnectionStates(); |
216 void RequestSort(); | 215 void RequestSortAndStateUpdate(); |
| 216 // Start pinging if we haven't already started, and we now have a connection |
| 217 // that's pingable. |
| 218 void MaybeStartPinging(); |
217 | 219 |
218 // The methods below return a positive value if a is preferable to b, | 220 // The methods below return a positive value if a is preferable to b, |
219 // a negative value if b is preferable, and 0 if they're equally preferable. | 221 // a negative value if b is preferable, and 0 if they're equally preferable. |
220 int CompareConnectionStates(const cricket::Connection* a, | 222 int CompareConnectionStates(const cricket::Connection* a, |
221 const cricket::Connection* b) const; | 223 const cricket::Connection* b) const; |
222 int CompareConnectionCandidates(const cricket::Connection* a, | 224 int CompareConnectionCandidates(const cricket::Connection* a, |
223 const cricket::Connection* b) const; | 225 const cricket::Connection* b) const; |
224 // Compares two connections based on the connection states | 226 // Compares two connections based on the connection states |
225 // (writable/receiving/connected), nomination states, last data received time, | 227 // (writable/receiving/connected), nomination states, last data received time, |
226 // and static preferences. Does not include latency. Used by both sorting | 228 // and static preferences. Does not include latency. Used by both sorting |
227 // and ShouldSwitchSelectedConnection(). | 229 // and ShouldSwitchSelectedConnection(). |
228 // Returns a positive value if |a| is better than |b|. | 230 // Returns a positive value if |a| is better than |b|. |
229 int CompareConnections(const cricket::Connection* a, | 231 int CompareConnections(const cricket::Connection* a, |
230 const cricket::Connection* b) const; | 232 const cricket::Connection* b) const; |
231 | 233 |
232 bool PresumedWritable(const cricket::Connection* conn) const; | 234 bool PresumedWritable(const cricket::Connection* conn) const; |
233 | 235 |
234 bool ShouldSwitchSelectedConnection(const cricket::Connection* selected, | 236 bool ShouldSwitchSelectedConnection(const cricket::Connection* selected, |
235 const cricket::Connection* conn) const; | 237 const cricket::Connection* conn) const; |
236 void SortConnections(); | 238 void SortConnectionsAndUpdateState(); |
237 void SwitchSelectedConnection(Connection* conn); | 239 void SwitchSelectedConnection(Connection* conn); |
238 void UpdateState(); | 240 void UpdateState(); |
239 void HandleAllTimedOut(); | 241 void HandleAllTimedOut(); |
240 void MaybeStopPortAllocatorSessions(); | 242 void MaybeStopPortAllocatorSessions(); |
241 TransportChannelState ComputeState() const; | 243 TransportChannelState ComputeState() const; |
242 | 244 |
243 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const; | 245 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const; |
244 bool CreateConnections(const Candidate& remote_candidate, | 246 bool CreateConnections(const Candidate& remote_candidate, |
245 PortInterface* origin_port); | 247 PortInterface* origin_port); |
246 bool CreateConnection(PortInterface* port, | 248 bool CreateConnection(PortInterface* port, |
247 const Candidate& remote_candidate, | 249 const Candidate& remote_candidate, |
248 PortInterface* origin_port); | 250 PortInterface* origin_port); |
249 bool FindConnection(cricket::Connection* connection) const; | 251 bool FindConnection(cricket::Connection* connection) const; |
250 | 252 |
251 uint32_t GetRemoteCandidateGeneration(const Candidate& candidate); | 253 uint32_t GetRemoteCandidateGeneration(const Candidate& candidate); |
252 bool IsDuplicateRemoteCandidate(const Candidate& candidate); | 254 bool IsDuplicateRemoteCandidate(const Candidate& candidate); |
253 void RememberRemoteCandidate(const Candidate& remote_candidate, | 255 void RememberRemoteCandidate(const Candidate& remote_candidate, |
254 PortInterface* origin_port); | 256 PortInterface* origin_port); |
255 bool IsPingable(Connection* conn, int64_t now); | 257 bool IsPingable(const Connection* conn, int64_t now) const; |
256 bool IsSelectedConnectionPingable(int64_t now); | 258 bool IsSelectedConnectionPingable(int64_t now); |
257 int CalculateActiveWritablePingInterval(Connection* conn, int64_t now); | 259 int CalculateActiveWritablePingInterval(const Connection* conn, |
| 260 int64_t now) const; |
258 void PingConnection(Connection* conn); | 261 void PingConnection(Connection* conn); |
259 void AddAllocatorSession(std::unique_ptr<PortAllocatorSession> session); | 262 void AddAllocatorSession(std::unique_ptr<PortAllocatorSession> session); |
260 void AddConnection(Connection* connection); | 263 void AddConnection(Connection* connection); |
261 | 264 |
262 void OnPortReady(PortAllocatorSession *session, PortInterface* port); | 265 void OnPortReady(PortAllocatorSession *session, PortInterface* port); |
263 void OnCandidatesReady(PortAllocatorSession *session, | 266 void OnCandidatesReady(PortAllocatorSession *session, |
264 const std::vector<Candidate>& candidates); | 267 const std::vector<Candidate>& candidates); |
265 void OnCandidatesAllocationDone(PortAllocatorSession* session); | 268 void OnCandidatesAllocationDone(PortAllocatorSession* session); |
266 void OnUnknownAddress(PortInterface* port, | 269 void OnUnknownAddress(PortInterface* port, |
267 const rtc::SocketAddress& addr, | 270 const rtc::SocketAddress& addr, |
268 ProtocolType proto, | 271 ProtocolType proto, |
269 IceMessage* stun_msg, | 272 IceMessage* stun_msg, |
270 const std::string& remote_username, | 273 const std::string& remote_username, |
271 bool port_muxed); | 274 bool port_muxed); |
272 void OnPortDestroyed(PortInterface* port); | 275 void OnPortDestroyed(PortInterface* port); |
273 void OnPortNetworkInactive(PortInterface* port); | 276 void OnPortNetworkInactive(PortInterface* port); |
274 void OnRoleConflict(PortInterface* port); | 277 void OnRoleConflict(PortInterface* port); |
275 | 278 |
276 void OnConnectionStateChange(Connection* connection); | 279 void OnConnectionStateChange(Connection* connection); |
277 void OnReadPacket(Connection *connection, const char *data, size_t len, | 280 void OnReadPacket(Connection *connection, const char *data, size_t len, |
278 const rtc::PacketTime& packet_time); | 281 const rtc::PacketTime& packet_time); |
279 void OnSentPacket(const rtc::SentPacket& sent_packet); | 282 void OnSentPacket(const rtc::SentPacket& sent_packet); |
280 void OnReadyToSend(Connection* connection); | 283 void OnReadyToSend(Connection* connection); |
281 void OnConnectionDestroyed(Connection *connection); | 284 void OnConnectionDestroyed(Connection *connection); |
282 | 285 |
283 void OnNominated(Connection* conn); | 286 void OnNominated(Connection* conn); |
284 | 287 |
285 void OnMessage(rtc::Message* pmsg) override; | 288 void OnMessage(rtc::Message* pmsg) override; |
286 void OnSort(); | |
287 void OnCheckAndPing(); | 289 void OnCheckAndPing(); |
288 | 290 |
289 // Returns true if the new_connection should be selected for transmission. | 291 // Returns true if the new_connection should be selected for transmission. |
290 bool ShouldSwitchSelectedConnection(Connection* new_connection) const; | 292 bool ShouldSwitchSelectedConnection(Connection* new_connection) const; |
291 | 293 |
292 void PruneConnections(); | 294 void PruneConnections(); |
293 bool IsBackupConnection(Connection* conn) const; | 295 bool IsBackupConnection(const Connection* conn) const; |
294 | 296 |
295 Connection* FindConnectionToPing(int64_t now); | 297 Connection* FindConnectionToPing(int64_t now); |
296 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now); | 298 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now); |
297 // Between |conn1| and |conn2|, this function returns the one which should | 299 // Between |conn1| and |conn2|, this function returns the one which should |
298 // be pinged first. | 300 // be pinged first. |
299 Connection* SelectMostPingableConnection(Connection* conn1, | 301 Connection* SelectMostPingableConnection(Connection* conn1, |
300 Connection* conn2); | 302 Connection* conn2); |
301 // Select the connection which is Relay/Relay. If both of them are, | 303 // Select the connection which is Relay/Relay. If both of them are, |
302 // UDP relay protocol takes precedence. | 304 // UDP relay protocol takes precedence. |
303 Connection* MostLikelyToWork(Connection* conn1, Connection* conn2); | 305 Connection* MostLikelyToWork(Connection* conn1, Connection* conn2); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 IceRole ice_role_; | 361 IceRole ice_role_; |
360 uint64_t tiebreaker_; | 362 uint64_t tiebreaker_; |
361 IceGatheringState gathering_state_; | 363 IceGatheringState gathering_state_; |
362 | 364 |
363 int check_receiving_interval_; | 365 int check_receiving_interval_; |
364 int64_t last_ping_sent_ms_ = 0; | 366 int64_t last_ping_sent_ms_ = 0; |
365 int weak_ping_interval_ = WEAK_PING_INTERVAL; | 367 int weak_ping_interval_ = WEAK_PING_INTERVAL; |
366 TransportChannelState state_ = TransportChannelState::STATE_INIT; | 368 TransportChannelState state_ = TransportChannelState::STATE_INIT; |
367 IceConfig config_; | 369 IceConfig config_; |
368 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before. | 370 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before. |
| 371 bool started_pinging_ = false; |
369 | 372 |
370 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); | 373 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); |
371 }; | 374 }; |
372 | 375 |
373 } // namespace cricket | 376 } // namespace cricket |
374 | 377 |
375 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ | 378 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ |
OLD | NEW |