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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 PortAllocatorSession* allocator_session() { | 201 PortAllocatorSession* allocator_session() { |
202 return allocator_sessions_.back().get(); | 202 return allocator_sessions_.back().get(); |
203 } | 203 } |
204 | 204 |
205 // Public for unit tests. | 205 // Public for unit tests. |
206 const std::vector<RemoteCandidate>& remote_candidates() const { | 206 const std::vector<RemoteCandidate>& remote_candidates() const { |
207 return remote_candidates_; | 207 return remote_candidates_; |
208 } | 208 } |
209 | 209 |
210 private: | 210 private: |
211 rtc::Thread* thread() { return worker_thread_; } | 211 rtc::Thread* thread() const { return worker_thread_; } |
212 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); } | 212 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); } |
213 | 213 |
214 // A transport channel is weak if the current best connection is either | 214 // A transport channel is weak if the current best connection is either |
215 // not receiving or not writable, or if there is no best connection at all. | 215 // not receiving or not writable, or if there is no best connection at all. |
216 bool weak() const; | 216 bool weak() const; |
217 // Returns true if it's possible to send packets on this channel. | 217 // Returns true if it's possible to send packets on this channel. |
218 bool ReadyToSend() const; | 218 bool ReadyToSend() const; |
219 void UpdateConnectionStates(); | 219 void UpdateConnectionStates(); |
220 void RequestSortAndStateUpdate(); | 220 void RequestSortAndStateUpdate(); |
221 // Start pinging if we haven't already started, and we now have a connection | 221 // Start pinging if we haven't already started, and we now have a connection |
222 // that's pingable. | 222 // that's pingable. |
223 void MaybeStartPinging(); | 223 void MaybeStartPinging(); |
224 | 224 |
225 // The methods below return a positive value if a is preferable to b, | 225 // The methods below return a positive value if |a| is preferable to |b|, |
226 // a negative value if b is preferable, and 0 if they're equally preferable. | 226 // a negative value if |b| is preferable, and 0 if they're equally preferable. |
227 int CompareConnectionStates(const cricket::Connection* a, | 227 // If |receiving_unchanged_threshold| is set, then when |b| is receiving and |
228 const cricket::Connection* b) const; | 228 // |a| is not, returns a negative value only if |b| has been in receiving |
| 229 // state and |a| has been in not receiving state since |
| 230 // |receiving_unchanged_threshold| and sets |
| 231 // |missed_receiving_unchanged_threshold| to true otherwise. |
| 232 int CompareConnectionStates( |
| 233 const cricket::Connection* a, |
| 234 const cricket::Connection* b, |
| 235 rtc::Optional<int64_t> receiving_unchanged_threshold, |
| 236 bool* missed_receiving_unchanged_threshold) const; |
229 int CompareConnectionCandidates(const cricket::Connection* a, | 237 int CompareConnectionCandidates(const cricket::Connection* a, |
230 const cricket::Connection* b) const; | 238 const cricket::Connection* b) const; |
231 // Compares two connections based on the connection states | 239 // Compares two connections based on the connection states |
232 // (writable/receiving/connected), nomination states, last data received time, | 240 // (writable/receiving/connected), nomination states, last data received time, |
233 // and static preferences. Does not include latency. Used by both sorting | 241 // and static preferences. Does not include latency. Used by both sorting |
234 // and ShouldSwitchSelectedConnection(). | 242 // and ShouldSwitchSelectedConnection(). |
235 // Returns a positive value if |a| is better than |b|. | 243 // Returns a positive value if |a| is better than |b|. |
236 int CompareConnections(const cricket::Connection* a, | 244 int CompareConnections(const cricket::Connection* a, |
237 const cricket::Connection* b) const; | 245 const cricket::Connection* b, |
| 246 rtc::Optional<int64_t> receiving_unchanged_threshold, |
| 247 bool* missed_receiving_unchanged_threshold) const; |
238 | 248 |
239 bool PresumedWritable(const cricket::Connection* conn) const; | 249 bool PresumedWritable(const cricket::Connection* conn) const; |
240 | 250 |
241 bool ShouldSwitchSelectedConnection(const cricket::Connection* selected, | |
242 const cricket::Connection* conn) const; | |
243 void SortConnectionsAndUpdateState(); | 251 void SortConnectionsAndUpdateState(); |
244 void SwitchSelectedConnection(Connection* conn); | 252 void SwitchSelectedConnection(Connection* conn); |
245 void UpdateState(); | 253 void UpdateState(); |
246 void HandleAllTimedOut(); | 254 void HandleAllTimedOut(); |
247 void MaybeStopPortAllocatorSessions(); | 255 void MaybeStopPortAllocatorSessions(); |
248 TransportChannelState ComputeState() const; | 256 TransportChannelState ComputeState() const; |
249 | 257 |
250 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const; | 258 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const; |
251 bool CreateConnections(const Candidate& remote_candidate, | 259 bool CreateConnections(const Candidate& remote_candidate, |
252 PortInterface* origin_port); | 260 PortInterface* origin_port); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 void OnSentPacket(const rtc::SentPacket& sent_packet); | 307 void OnSentPacket(const rtc::SentPacket& sent_packet); |
300 void OnReadyToSend(Connection* connection); | 308 void OnReadyToSend(Connection* connection); |
301 void OnConnectionDestroyed(Connection *connection); | 309 void OnConnectionDestroyed(Connection *connection); |
302 | 310 |
303 void OnNominated(Connection* conn); | 311 void OnNominated(Connection* conn); |
304 | 312 |
305 void OnMessage(rtc::Message* pmsg) override; | 313 void OnMessage(rtc::Message* pmsg) override; |
306 void OnCheckAndPing(); | 314 void OnCheckAndPing(); |
307 void OnRegatherOnFailedNetworks(); | 315 void OnRegatherOnFailedNetworks(); |
308 | 316 |
309 // Returns true if the new_connection should be selected for transmission. | 317 // Returns true if we should switch to the new connection. |
310 bool ShouldSwitchSelectedConnection(Connection* new_connection) const; | 318 // sets |missed_receiving_unchanged_threshold| to true if either |
| 319 // the selected connection or the new connection missed its |
| 320 // receiving-unchanged-threshold. |
| 321 bool ShouldSwitchSelectedConnection( |
| 322 Connection* new_connection, |
| 323 bool* missed_receiving_unchanged_threshold) const; |
| 324 // Returns true if the new_connection is selected for transmission. |
| 325 bool MaybeSwitchSelectedConnection(Connection* new_connection, |
| 326 const std::string& reason); |
311 | 327 |
312 void PruneConnections(); | 328 void PruneConnections(); |
313 bool IsBackupConnection(const Connection* conn) const; | 329 bool IsBackupConnection(const Connection* conn) const; |
314 | 330 |
315 Connection* FindConnectionToPing(int64_t now); | 331 Connection* FindConnectionToPing(int64_t now); |
316 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now); | 332 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now); |
317 // Between |conn1| and |conn2|, this function returns the one which should | 333 // Between |conn1| and |conn2|, this function returns the one which should |
318 // be pinged first. | 334 // be pinged first. |
319 Connection* SelectMostPingableConnection(Connection* conn1, | 335 Connection* SelectMostPingableConnection(Connection* conn1, |
320 Connection* conn2); | 336 Connection* conn2); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 IceConfig config_; | 403 IceConfig config_; |
388 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before. | 404 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before. |
389 bool started_pinging_ = false; | 405 bool started_pinging_ = false; |
390 | 406 |
391 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); | 407 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); |
392 }; | 408 }; |
393 | 409 |
394 } // namespace cricket | 410 } // namespace cricket |
395 | 411 |
396 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ | 412 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ |
OLD | NEW |