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

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: Add tests 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.
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 void set_check_restore_backup_connection_interval(int interval);
Taylor Brandstetter 2016/06/06 18:18:37 Can you add a TODO to remove this method and use t
honghaiz3 2016/06/07 16:42:06 Done.
200 208
201 private: 209 private:
202 rtc::Thread* thread() { return worker_thread_; } 210 rtc::Thread* thread() { return worker_thread_; }
203 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); } 211 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); }
212 // Start regathering on the given list of networks. If |networks| is nullptr,
213 // regathering on all active networks.
Taylor Brandstetter 2016/06/06 18:18:37 "regathering" => "start regathering"
honghaiz3 2016/06/07 16:42:06 Done.
214 void StartRegathering(std::vector<rtc::Network*>* networks);
204 215
205 // A transport channel is weak if the current best connection is either 216 // 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. 217 // not receiving or not writable, or if there is no best connection at all.
207 bool weak() const; 218 bool weak() const;
208 void UpdateConnectionStates(); 219 void UpdateConnectionStates();
209 void RequestSort(); 220 void RequestSort();
210 void SortConnections(); 221 void SortConnections();
211 void SwitchBestConnectionTo(Connection* conn); 222 void SwitchBestConnectionTo(Connection* conn);
212 void UpdateState(); 223 void UpdateState();
213 void HandleAllTimedOut(); 224 void HandleAllTimedOut();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 const rtc::PacketTime& packet_time); 261 const rtc::PacketTime& packet_time);
251 void OnSentPacket(const rtc::SentPacket& sent_packet); 262 void OnSentPacket(const rtc::SentPacket& sent_packet);
252 void OnReadyToSend(Connection* connection); 263 void OnReadyToSend(Connection* connection);
253 void OnConnectionDestroyed(Connection *connection); 264 void OnConnectionDestroyed(Connection *connection);
254 265
255 void OnNominated(Connection* conn); 266 void OnNominated(Connection* conn);
256 267
257 void OnMessage(rtc::Message* pmsg) override; 268 void OnMessage(rtc::Message* pmsg) override;
258 void OnSort(); 269 void OnSort();
259 void OnCheckAndPing(); 270 void OnCheckAndPing();
271 void OnCheckAndRestoreBackupConnection();
260 272
261 void PruneConnections(); 273 void PruneConnections();
262 Connection* best_nominated_connection() const; 274 Connection* best_nominated_connection() const;
263 bool IsBackupConnection(Connection* conn) const; 275 bool IsBackupConnection(Connection* conn) const;
264 276
265 Connection* FindConnectionToPing(int64_t now); 277 Connection* FindConnectionToPing(int64_t now);
266 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now); 278 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now);
267 // Between |conn1| and |conn2|, this function returns the one which should 279 // Between |conn1| and |conn2|, this function returns the one which should
268 // be pinged first. 280 // be pinged first.
269 Connection* SelectMostPingableConnection(Connection* conn1, 281 Connection* SelectMostPingableConnection(Connection* conn1,
(...skipping 15 matching lines...) Expand all
285 const IceParameters* FindRemoteIceFromUfrag(const std::string& ufrag, 297 const IceParameters* FindRemoteIceFromUfrag(const std::string& ufrag,
286 uint32_t* generation); 298 uint32_t* generation);
287 // Returns the index of the latest remote ICE parameters, or 0 if no remote 299 // Returns the index of the latest remote ICE parameters, or 0 if no remote
288 // ICE parameters have been received. 300 // ICE parameters have been received.
289 uint32_t remote_ice_generation() { 301 uint32_t remote_ice_generation() {
290 return remote_ice_parameters_.empty() 302 return remote_ice_parameters_.empty()
291 ? 0 303 ? 0
292 : static_cast<uint32_t>(remote_ice_parameters_.size() - 1); 304 : static_cast<uint32_t>(remote_ice_parameters_.size() - 1);
293 } 305 }
294 306
307 bool IsRecoveringConnectivity() const {
308 return recovering_start_time_ > 0 &&
309 rtc::TimeMillis() - recovering_start_time_ <= MAX_RECOVERING_TIME;
310 }
311
295 PortAllocator* allocator_; 312 PortAllocator* allocator_;
296 rtc::Thread* worker_thread_; 313 rtc::Thread* worker_thread_;
297 bool incoming_only_; 314 bool incoming_only_;
298 int error_; 315 int error_;
299 std::vector<std::unique_ptr<PortAllocatorSession>> allocator_sessions_; 316 std::vector<std::unique_ptr<PortAllocatorSession>> allocator_sessions_;
300 std::vector<PortInterface *> ports_; 317 std::vector<PortInterface *> ports_;
301 318
302 // |connections_| is a sorted list with the first one always be the 319 // |connections_| is a sorted list with the first one always be the
303 // |best_connection_| when it's not nullptr. The combination of 320 // |best_connection_| when it's not nullptr. The combination of
304 // |pinged_connections_| and |unpinged_connections_| has the same 321 // |pinged_connections_| and |unpinged_connections_| has the same
(...skipping 15 matching lines...) Expand all
320 OptionMap options_; 337 OptionMap options_;
321 std::string ice_ufrag_; 338 std::string ice_ufrag_;
322 std::string ice_pwd_; 339 std::string ice_pwd_;
323 std::vector<IceParameters> remote_ice_parameters_; 340 std::vector<IceParameters> remote_ice_parameters_;
324 IceMode remote_ice_mode_; 341 IceMode remote_ice_mode_;
325 IceRole ice_role_; 342 IceRole ice_role_;
326 uint64_t tiebreaker_; 343 uint64_t tiebreaker_;
327 IceGatheringState gathering_state_; 344 IceGatheringState gathering_state_;
328 345
329 int check_receiving_interval_; 346 int check_receiving_interval_;
347 int check_restore_backup_connection_interval_;
330 int64_t last_ping_sent_ms_ = 0; 348 int64_t last_ping_sent_ms_ = 0;
331 int weak_ping_interval_ = WEAK_PING_INTERVAL; 349 int weak_ping_interval_ = WEAK_PING_INTERVAL;
332 TransportChannelState state_ = TransportChannelState::STATE_INIT; 350 TransportChannelState state_ = TransportChannelState::STATE_INIT;
333 IceConfig config_; 351 IceConfig config_;
334 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before. 352 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before.
353 int64_t recovering_start_time_ = 0;
354 std::vector<Candidate> candidates_removed_;
335 355
336 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); 356 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel);
337 }; 357 };
338 358
339 } // namespace cricket 359 } // namespace cricket
340 360
341 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ 361 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698