Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(858)

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel.h

Issue 2025573002: Use continual gathering to restore backup connections (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Address Taylor comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 22 matching lines...) Expand all
33 #include "webrtc/p2p/base/portallocator.h" 33 #include "webrtc/p2p/base/portallocator.h"
34 #include "webrtc/p2p/base/portinterface.h" 34 #include "webrtc/p2p/base/portinterface.h"
35 #include "webrtc/p2p/base/transportchannelimpl.h" 35 #include "webrtc/p2p/base/transportchannelimpl.h"
36 #include "webrtc/base/asyncpacketsocket.h" 36 #include "webrtc/base/asyncpacketsocket.h"
37 #include "webrtc/base/sigslot.h" 37 #include "webrtc/base/sigslot.h"
38 38
39 namespace cricket { 39 namespace cricket {
40 40
41 extern const int WEAK_PING_INTERVAL; 41 extern const int WEAK_PING_INTERVAL;
42 static const int MIN_PINGS_AT_WEAK_PING_INTERVAL = 3; 42 static const int MIN_PINGS_AT_WEAK_PING_INTERVAL = 3;
43 // When the selected connection is suddenly deleted and no other connection
44 // is available, we will try to recover the ICE connectivity via continual
45 // gathering on the local client. If no writable connection is established
46 // after this amount of time, will declare the transport channel to be
47 // unwritable.
48 static const int MAX_RECOVERING_TIME = 5000; // 5 seconds.
pthatcher1 2016/06/07 18:54:33 I think this needs a more clear name. This isn't
43 49
44 struct IceParameters { 50 struct IceParameters {
45 std::string ufrag; 51 std::string ufrag;
46 std::string pwd; 52 std::string pwd;
47 IceParameters(const std::string& ice_ufrag, const std::string& ice_pwd) 53 IceParameters(const std::string& ice_ufrag, const std::string& ice_pwd)
48 : ufrag(ice_ufrag), pwd(ice_pwd) {} 54 : ufrag(ice_ufrag), pwd(ice_pwd) {}
49 55
50 bool operator==(const IceParameters& other) { 56 bool operator==(const IceParameters& other) {
51 return ufrag == other.ufrag && pwd == other.pwd; 57 return ufrag == other.ufrag && pwd == other.pwd;
52 } 58 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 196
191 // Public for unit tests. 197 // Public for unit tests.
192 PortAllocatorSession* allocator_session() { 198 PortAllocatorSession* allocator_session() {
193 return allocator_sessions_.back().get(); 199 return allocator_sessions_.back().get();
194 } 200 }
195 201
196 // Public for unit tests. 202 // Public for unit tests.
197 const std::vector<RemoteCandidate>& remote_candidates() const { 203 const std::vector<RemoteCandidate>& remote_candidates() const {
198 return remote_candidates_; 204 return remote_candidates_;
199 } 205 }
206 // For testing.
207 // TODO(honghaiz): Remove this method and use the fake clock for the test.
208 void set_check_restore_backup_connection_interval(int interval);
pthatcher1 2016/06/07 18:54:34 Can we just use the fake clock now? This looks ki
200 209
201 private: 210 private:
202 rtc::Thread* thread() { return worker_thread_; } 211 rtc::Thread* thread() { return worker_thread_; }
203 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); } 212 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); }
213 // Start regathering on the given list of networks. If |networks| is nullptr,
214 // start regathering on all active networks.
215 void StartRegathering(std::vector<rtc::Network*>* networks);
pthatcher1 2016/06/07 18:54:34 It think it would be more clear to have two method
204 216
205 // A transport channel is weak if the current best connection is either 217 // A transport channel is weak if the current best connection is either
206 // not receiving or not writable, or if there is no best connection at all. 218 // not receiving or not writable, or if there is no best connection at all.
207 bool weak() const; 219 bool weak() const;
208 void UpdateConnectionStates(); 220 void UpdateConnectionStates();
209 void RequestSort(); 221 void RequestSort();
210 void SortConnections(); 222 void SortConnections();
211 void SwitchBestConnectionTo(Connection* conn); 223 void SwitchBestConnectionTo(Connection* conn);
212 void UpdateState(); 224 void UpdateState();
213 void HandleAllTimedOut(); 225 void HandleAllTimedOut();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 const rtc::PacketTime& packet_time); 262 const rtc::PacketTime& packet_time);
251 void OnSentPacket(const rtc::SentPacket& sent_packet); 263 void OnSentPacket(const rtc::SentPacket& sent_packet);
252 void OnReadyToSend(Connection* connection); 264 void OnReadyToSend(Connection* connection);
253 void OnConnectionDestroyed(Connection *connection); 265 void OnConnectionDestroyed(Connection *connection);
254 266
255 void OnNominated(Connection* conn); 267 void OnNominated(Connection* conn);
256 268
257 void OnMessage(rtc::Message* pmsg) override; 269 void OnMessage(rtc::Message* pmsg) override;
258 void OnSort(); 270 void OnSort();
259 void OnCheckAndPing(); 271 void OnCheckAndPing();
272 void OnCheckAndRestoreBackupConnection();
260 273
261 void PruneConnections(); 274 void PruneConnections();
262 Connection* best_nominated_connection() const; 275 Connection* best_nominated_connection() const;
263 bool IsBackupConnection(Connection* conn) const; 276 bool IsBackupConnection(Connection* conn) const;
264 277
265 Connection* FindConnectionToPing(int64_t now); 278 Connection* FindConnectionToPing(int64_t now);
266 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now); 279 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now);
267 // Between |conn1| and |conn2|, this function returns the one which should 280 // Between |conn1| and |conn2|, this function returns the one which should
268 // be pinged first. 281 // be pinged first.
269 Connection* SelectMostPingableConnection(Connection* conn1, 282 Connection* SelectMostPingableConnection(Connection* conn1,
(...skipping 15 matching lines...) Expand all
285 const IceParameters* FindRemoteIceFromUfrag(const std::string& ufrag, 298 const IceParameters* FindRemoteIceFromUfrag(const std::string& ufrag,
286 uint32_t* generation); 299 uint32_t* generation);
287 // Returns the index of the latest remote ICE parameters, or 0 if no remote 300 // Returns the index of the latest remote ICE parameters, or 0 if no remote
288 // ICE parameters have been received. 301 // ICE parameters have been received.
289 uint32_t remote_ice_generation() { 302 uint32_t remote_ice_generation() {
290 return remote_ice_parameters_.empty() 303 return remote_ice_parameters_.empty()
291 ? 0 304 ? 0
292 : static_cast<uint32_t>(remote_ice_parameters_.size() - 1); 305 : static_cast<uint32_t>(remote_ice_parameters_.size() - 1);
293 } 306 }
294 307
308 bool IsRecoveringConnectivity() const {
309 return recovering_start_time_ > 0 &&
310 rtc::TimeMillis() - recovering_start_time_ <= MAX_RECOVERING_TIME;
311 }
pthatcher1 2016/06/07 18:54:34 ***
312
295 PortAllocator* allocator_; 313 PortAllocator* allocator_;
296 rtc::Thread* worker_thread_; 314 rtc::Thread* worker_thread_;
297 bool incoming_only_; 315 bool incoming_only_;
298 int error_; 316 int error_;
299 std::vector<std::unique_ptr<PortAllocatorSession>> allocator_sessions_; 317 std::vector<std::unique_ptr<PortAllocatorSession>> allocator_sessions_;
300 std::vector<PortInterface *> ports_; 318 std::vector<PortInterface *> ports_;
301 319
302 // |connections_| is a sorted list with the first one always be the 320 // |connections_| is a sorted list with the first one always be the
303 // |best_connection_| when it's not nullptr. The combination of 321 // |best_connection_| when it's not nullptr. The combination of
304 // |pinged_connections_| and |unpinged_connections_| has the same 322 // |pinged_connections_| and |unpinged_connections_| has the same
(...skipping 15 matching lines...) Expand all
320 OptionMap options_; 338 OptionMap options_;
321 std::string ice_ufrag_; 339 std::string ice_ufrag_;
322 std::string ice_pwd_; 340 std::string ice_pwd_;
323 std::vector<IceParameters> remote_ice_parameters_; 341 std::vector<IceParameters> remote_ice_parameters_;
324 IceMode remote_ice_mode_; 342 IceMode remote_ice_mode_;
325 IceRole ice_role_; 343 IceRole ice_role_;
326 uint64_t tiebreaker_; 344 uint64_t tiebreaker_;
327 IceGatheringState gathering_state_; 345 IceGatheringState gathering_state_;
328 346
329 int check_receiving_interval_; 347 int check_receiving_interval_;
348 int check_restore_backup_connection_interval_;
330 int64_t last_ping_sent_ms_ = 0; 349 int64_t last_ping_sent_ms_ = 0;
331 int weak_ping_interval_ = WEAK_PING_INTERVAL; 350 int weak_ping_interval_ = WEAK_PING_INTERVAL;
332 TransportChannelState state_ = TransportChannelState::STATE_INIT; 351 TransportChannelState state_ = TransportChannelState::STATE_INIT;
333 IceConfig config_; 352 IceConfig config_;
334 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before. 353 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before.
354 int64_t recovering_start_time_ = 0;
355 std::vector<Candidate> candidates_removed_;
335 356
336 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); 357 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel);
337 }; 358 };
338 359
339 } // namespace cricket 360 } // namespace cricket
340 361
341 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ 362 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698