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

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

Issue 2069493002: Do not switch best connection on the controlled side too frequently (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Updates a comment 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // From TransportChannel: 108 // From TransportChannel:
109 int SendPacket(const char* data, 109 int SendPacket(const char* data,
110 size_t len, 110 size_t len,
111 const rtc::PacketOptions& options, 111 const rtc::PacketOptions& options,
112 int flags) override; 112 int flags) override;
113 int SetOption(rtc::Socket::Option opt, int value) override; 113 int SetOption(rtc::Socket::Option opt, int value) override;
114 bool GetOption(rtc::Socket::Option opt, int* value) override; 114 bool GetOption(rtc::Socket::Option opt, int* value) override;
115 int GetError() override { return error_; } 115 int GetError() override { return error_; }
116 bool GetStats(std::vector<ConnectionInfo>* stats) override; 116 bool GetStats(std::vector<ConnectionInfo>* stats) override;
117 117
118 const Connection* best_connection() const { return best_connection_; } 118 const Connection* selected_connection() const { return selected_connection_; }
119 void set_incoming_only(bool value) { incoming_only_ = value; } 119 void set_incoming_only(bool value) { incoming_only_ = value; }
120 120
121 // Note: This is only for testing purpose. 121 // Note: This is only for testing purpose.
122 // |ports_| should not be changed from outside. 122 // |ports_| should not be changed from outside.
123 const std::vector<PortInterface*>& ports() { return ports_; } 123 const std::vector<PortInterface*>& ports() { return ports_; }
124 124
125 IceMode remote_ice_mode() const { return remote_ice_mode_; } 125 IceMode remote_ice_mode() const { return remote_ice_mode_; }
126 126
127 // DTLS methods. 127 // DTLS methods.
128 bool IsDtlsActive() const override { return false; } 128 bool IsDtlsActive() const override { return false; }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 private: 201 private:
202 rtc::Thread* thread() { return worker_thread_; } 202 rtc::Thread* thread() { return worker_thread_; }
203 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); } 203 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); }
204 204
205 // A transport channel is weak if the current best connection is either 205 // 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. 206 // not receiving or not writable, or if there is no best connection at all.
207 bool weak() const; 207 bool weak() const;
208 void UpdateConnectionStates(); 208 void UpdateConnectionStates();
209 void RequestSort(); 209 void RequestSort();
210 void SortConnections(); 210 void SortConnections();
211 void SwitchBestConnectionTo(Connection* conn); 211 void SwitchSelectedConnection(Connection* conn);
212 void UpdateState(); 212 void UpdateState();
213 void HandleAllTimedOut(); 213 void HandleAllTimedOut();
214 void MaybeStopPortAllocatorSessions(); 214 void MaybeStopPortAllocatorSessions();
215 TransportChannelState ComputeState() const; 215 TransportChannelState ComputeState() const;
216 216
217 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const; 217 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const;
218 bool CreateConnections(const Candidate& remote_candidate, 218 bool CreateConnections(const Candidate& remote_candidate,
219 PortInterface* origin_port); 219 PortInterface* origin_port);
220 bool CreateConnection(PortInterface* port, 220 bool CreateConnection(PortInterface* port,
221 const Candidate& remote_candidate, 221 const Candidate& remote_candidate,
(...skipping 29 matching lines...) Expand all
251 void OnSentPacket(const rtc::SentPacket& sent_packet); 251 void OnSentPacket(const rtc::SentPacket& sent_packet);
252 void OnReadyToSend(Connection* connection); 252 void OnReadyToSend(Connection* connection);
253 void OnConnectionDestroyed(Connection *connection); 253 void OnConnectionDestroyed(Connection *connection);
254 254
255 void OnNominated(Connection* conn); 255 void OnNominated(Connection* conn);
256 256
257 void OnMessage(rtc::Message* pmsg) override; 257 void OnMessage(rtc::Message* pmsg) override;
258 void OnSort(); 258 void OnSort();
259 void OnCheckAndPing(); 259 void OnCheckAndPing();
260 260
261 // Compares two connections based on the connection states
262 // (writable/receiving/connected), nomination states, last data received time,
263 // and static preferences. Does not include latency. Used by both sorting
264 // and ShouldSwitchConnection().
265 // Returns a positive value if |a| is better than |b|.
266 int CompareConnections(const cricket::Connection* a,
267 const cricket::Connection* b) const;
268 // This is similar to CompareConnections but excludes the connection states
269 // from the comparison criteria. It is used when determining whether a
270 // connection need to be pruned.
pthatcher1 2016/06/21 07:16:53 need to be => needs to be
honghaiz3 2016/06/22 08:03:16 Done.
271 // Returns a positive value if |a| is better than |b|
Taylor Brandstetter 2016/06/21 18:33:26 Missing period.
honghaiz3 2016/06/22 08:03:16 Done.
272 int CompareConnectionsBase(const cricket::Connection* a,
Taylor Brandstetter 2016/06/21 18:33:26 I think this method can be removed. But if it's ke
honghaiz3 2016/06/22 08:03:16 Done.
273 const cricket::Connection* b) const;
274 // Returns true if the new_connection should be selected for transmission.
275 bool ShouldSwitchConnection(Connection* new_connection) const;
276
261 void PruneConnections(); 277 void PruneConnections();
262 Connection* best_nominated_connection() const; 278 Connection* selected_nominated_connection() const;
263 bool IsBackupConnection(Connection* conn) const; 279 bool IsBackupConnection(Connection* conn) const;
264 280
265 Connection* FindConnectionToPing(int64_t now); 281 Connection* FindConnectionToPing(int64_t now);
266 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now); 282 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now);
267 // Between |conn1| and |conn2|, this function returns the one which should 283 // Between |conn1| and |conn2|, this function returns the one which should
268 // be pinged first. 284 // be pinged first.
269 Connection* SelectMostPingableConnection(Connection* conn1, 285 Connection* SelectMostPingableConnection(Connection* conn1,
270 Connection* conn2); 286 Connection* conn2);
271 // Select the connection which is Relay/Relay. If both of them are, 287 // Select the connection which is Relay/Relay. If both of them are,
272 // UDP relay protocol takes precedence. 288 // UDP relay protocol takes precedence.
(...skipping 20 matching lines...) Expand all
293 } 309 }
294 310
295 PortAllocator* allocator_; 311 PortAllocator* allocator_;
296 rtc::Thread* worker_thread_; 312 rtc::Thread* worker_thread_;
297 bool incoming_only_; 313 bool incoming_only_;
298 int error_; 314 int error_;
299 std::vector<std::unique_ptr<PortAllocatorSession>> allocator_sessions_; 315 std::vector<std::unique_ptr<PortAllocatorSession>> allocator_sessions_;
300 std::vector<PortInterface *> ports_; 316 std::vector<PortInterface *> ports_;
301 317
302 // |connections_| is a sorted list with the first one always be the 318 // |connections_| is a sorted list with the first one always be the
303 // |best_connection_| when it's not nullptr. The combination of 319 // |selected_connection_| when it's not nullptr. The combination of
304 // |pinged_connections_| and |unpinged_connections_| has the same 320 // |pinged_connections_| and |unpinged_connections_| has the same
305 // connections as |connections_|. These 2 sets maintain whether a 321 // connections as |connections_|. These 2 sets maintain whether a
306 // connection should be pinged next or not. 322 // connection should be pinged next or not.
307 std::vector<Connection *> connections_; 323 std::vector<Connection *> connections_;
308 std::set<Connection*> pinged_connections_; 324 std::set<Connection*> pinged_connections_;
309 std::set<Connection*> unpinged_connections_; 325 std::set<Connection*> unpinged_connections_;
310 326
311 Connection* best_connection_; 327 Connection* selected_connection_ = nullptr;
312 328
313 // Connection selected by the controlling agent. This should be used only
314 // at controlled side when protocol type is RFC5245.
315 Connection* pending_best_connection_;
316 std::vector<RemoteCandidate> remote_candidates_; 329 std::vector<RemoteCandidate> remote_candidates_;
317 bool sort_dirty_; // indicates whether another sort is needed right now 330 bool sort_dirty_; // indicates whether another sort is needed right now
318 bool had_connection_ = false; // if connections_ has ever been nonempty 331 bool had_connection_ = false; // if connections_ has ever been nonempty
319 typedef std::map<rtc::Socket::Option, int> OptionMap; 332 typedef std::map<rtc::Socket::Option, int> OptionMap;
320 OptionMap options_; 333 OptionMap options_;
321 std::string ice_ufrag_; 334 std::string ice_ufrag_;
322 std::string ice_pwd_; 335 std::string ice_pwd_;
323 std::vector<IceParameters> remote_ice_parameters_; 336 std::vector<IceParameters> remote_ice_parameters_;
324 IceMode remote_ice_mode_; 337 IceMode remote_ice_mode_;
325 IceRole ice_role_; 338 IceRole ice_role_;
326 uint64_t tiebreaker_; 339 uint64_t tiebreaker_;
327 IceGatheringState gathering_state_; 340 IceGatheringState gathering_state_;
328 341
329 int check_receiving_interval_; 342 int check_receiving_interval_;
330 int64_t last_ping_sent_ms_ = 0; 343 int64_t last_ping_sent_ms_ = 0;
331 int weak_ping_interval_ = WEAK_PING_INTERVAL; 344 int weak_ping_interval_ = WEAK_PING_INTERVAL;
332 TransportChannelState state_ = TransportChannelState::STATE_INIT; 345 TransportChannelState state_ = TransportChannelState::STATE_INIT;
333 IceConfig config_; 346 IceConfig config_;
334 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before. 347 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before.
335 348
336 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); 349 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel);
337 }; 350 };
338 351
339 } // namespace cricket 352 } // namespace cricket
340 353
341 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ 354 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/p2p/base/p2ptransportchannel.cc » ('j') | webrtc/p2p/base/p2ptransportchannel.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698