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

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: Merge branch 'master' into nominate_on_controlled_side Created 4 years, 5 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
« no previous file with comments | « no previous file | webrtc/p2p/base/p2ptransportchannel.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // From TransportChannel: 111 // From TransportChannel:
112 int SendPacket(const char* data, 112 int SendPacket(const char* data,
113 size_t len, 113 size_t len,
114 const rtc::PacketOptions& options, 114 const rtc::PacketOptions& options,
115 int flags) override; 115 int flags) override;
116 int SetOption(rtc::Socket::Option opt, int value) override; 116 int SetOption(rtc::Socket::Option opt, int value) override;
117 bool GetOption(rtc::Socket::Option opt, int* value) override; 117 bool GetOption(rtc::Socket::Option opt, int* value) override;
118 int GetError() override { return error_; } 118 int GetError() override { return error_; }
119 bool GetStats(std::vector<ConnectionInfo>* stats) override; 119 bool GetStats(std::vector<ConnectionInfo>* stats) override;
120 120
121 const Connection* best_connection() const { return best_connection_; } 121 const Connection* selected_connection() const { return selected_connection_; }
122 void set_incoming_only(bool value) { incoming_only_ = value; } 122 void set_incoming_only(bool value) { incoming_only_ = value; }
123 123
124 // Note: This is only for testing purpose. 124 // Note: This is only for testing purpose.
125 // |ports_| should not be changed from outside. 125 // |ports_| should not be changed from outside.
126 const std::vector<PortInterface*>& ports() { return ports_; } 126 const std::vector<PortInterface*>& ports() { return ports_; }
127 127
128 IceMode remote_ice_mode() const { return remote_ice_mode_; } 128 IceMode remote_ice_mode() const { return remote_ice_mode_; }
129 129
130 // DTLS methods. 130 // DTLS methods.
131 bool IsDtlsActive() const override { return false; } 131 bool IsDtlsActive() const override { return false; }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 bool weak() const; 210 bool weak() const;
211 void UpdateConnectionStates(); 211 void UpdateConnectionStates();
212 void RequestSort(); 212 void RequestSort();
213 213
214 // The methods below return a positive value if a is preferable to b, 214 // The methods below return a positive value if a is preferable to b,
215 // a negative value if b is preferable, and 0 if they're equally preferable. 215 // a negative value if b is preferable, and 0 if they're equally preferable.
216 int CompareConnectionStates(const cricket::Connection* a, 216 int CompareConnectionStates(const cricket::Connection* a,
217 const cricket::Connection* b) const; 217 const cricket::Connection* b) const;
218 int CompareConnectionCandidates(const cricket::Connection* a, 218 int CompareConnectionCandidates(const cricket::Connection* a,
219 const cricket::Connection* b) const; 219 const cricket::Connection* b) const;
220 // Compares first on states, then on candidates, then on RTT. 220 // Compares two connections based on the connection states
221 // (writable/receiving/connected), nomination states, last data received time,
222 // and static preferences. Does not include latency. Used by both sorting
223 // and ShouldSwitchSelectedConnection().
224 // Returns a positive value if |a| is better than |b|.
221 int CompareConnections(const cricket::Connection* a, 225 int CompareConnections(const cricket::Connection* a,
222 const cricket::Connection* b) const; 226 const cricket::Connection* b) const;
227
223 bool PresumedWritable(const cricket::Connection* conn) const; 228 bool PresumedWritable(const cricket::Connection* conn) const;
224 229
225 bool ShouldSwitchSelectedConnection(const cricket::Connection* selected, 230 bool ShouldSwitchSelectedConnection(const cricket::Connection* selected,
226 const cricket::Connection* conn) const; 231 const cricket::Connection* conn) const;
227 void SortConnections(); 232 void SortConnections();
228 void SwitchBestConnectionTo(Connection* conn); 233 void SwitchSelectedConnection(Connection* conn);
229 void UpdateState(); 234 void UpdateState();
230 void HandleAllTimedOut(); 235 void HandleAllTimedOut();
231 void MaybeStopPortAllocatorSessions(); 236 void MaybeStopPortAllocatorSessions();
232 TransportChannelState ComputeState() const; 237 TransportChannelState ComputeState() const;
233 238
234 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const; 239 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const;
235 bool CreateConnections(const Candidate& remote_candidate, 240 bool CreateConnections(const Candidate& remote_candidate,
236 PortInterface* origin_port); 241 PortInterface* origin_port);
237 bool CreateConnection(PortInterface* port, 242 bool CreateConnection(PortInterface* port,
238 const Candidate& remote_candidate, 243 const Candidate& remote_candidate,
239 PortInterface* origin_port); 244 PortInterface* origin_port);
240 bool FindConnection(cricket::Connection* connection) const; 245 bool FindConnection(cricket::Connection* connection) const;
241 246
242 uint32_t GetRemoteCandidateGeneration(const Candidate& candidate); 247 uint32_t GetRemoteCandidateGeneration(const Candidate& candidate);
243 bool IsDuplicateRemoteCandidate(const Candidate& candidate); 248 bool IsDuplicateRemoteCandidate(const Candidate& candidate);
244 void RememberRemoteCandidate(const Candidate& remote_candidate, 249 void RememberRemoteCandidate(const Candidate& remote_candidate,
245 PortInterface* origin_port); 250 PortInterface* origin_port);
246 bool IsPingable(Connection* conn, int64_t now); 251 bool IsPingable(Connection* conn, int64_t now);
247 bool IsBestConnectionPingable(int64_t now); 252 bool IsSelectedConnectionPingable(int64_t now);
248 int CalculateActiveWritablePingInterval(Connection* conn, int64_t now); 253 int CalculateActiveWritablePingInterval(Connection* conn, int64_t now);
249 void PingConnection(Connection* conn); 254 void PingConnection(Connection* conn);
250 void AddAllocatorSession(std::unique_ptr<PortAllocatorSession> session); 255 void AddAllocatorSession(std::unique_ptr<PortAllocatorSession> session);
251 void AddConnection(Connection* connection); 256 void AddConnection(Connection* connection);
252 257
253 void OnPortReady(PortAllocatorSession *session, PortInterface* port); 258 void OnPortReady(PortAllocatorSession *session, PortInterface* port);
254 void OnCandidatesReady(PortAllocatorSession *session, 259 void OnCandidatesReady(PortAllocatorSession *session,
255 const std::vector<Candidate>& candidates); 260 const std::vector<Candidate>& candidates);
256 void OnCandidatesAllocationDone(PortAllocatorSession* session); 261 void OnCandidatesAllocationDone(PortAllocatorSession* session);
257 void OnUnknownAddress(PortInterface* port, 262 void OnUnknownAddress(PortInterface* port,
(...skipping 12 matching lines...) Expand all
270 void OnSentPacket(const rtc::SentPacket& sent_packet); 275 void OnSentPacket(const rtc::SentPacket& sent_packet);
271 void OnReadyToSend(Connection* connection); 276 void OnReadyToSend(Connection* connection);
272 void OnConnectionDestroyed(Connection *connection); 277 void OnConnectionDestroyed(Connection *connection);
273 278
274 void OnNominated(Connection* conn); 279 void OnNominated(Connection* conn);
275 280
276 void OnMessage(rtc::Message* pmsg) override; 281 void OnMessage(rtc::Message* pmsg) override;
277 void OnSort(); 282 void OnSort();
278 void OnCheckAndPing(); 283 void OnCheckAndPing();
279 284
285 // Returns true if the new_connection should be selected for transmission.
286 bool ShouldSwitchSelectedConnection(Connection* new_connection) const;
287
280 void PruneConnections(); 288 void PruneConnections();
281 Connection* best_nominated_connection() const;
282 bool IsBackupConnection(Connection* conn) const; 289 bool IsBackupConnection(Connection* conn) const;
283 290
284 Connection* FindConnectionToPing(int64_t now); 291 Connection* FindConnectionToPing(int64_t now);
285 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now); 292 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now);
286 // Between |conn1| and |conn2|, this function returns the one which should 293 // Between |conn1| and |conn2|, this function returns the one which should
287 // be pinged first. 294 // be pinged first.
288 Connection* SelectMostPingableConnection(Connection* conn1, 295 Connection* SelectMostPingableConnection(Connection* conn1,
289 Connection* conn2); 296 Connection* conn2);
290 // Select the connection which is Relay/Relay. If both of them are, 297 // Select the connection which is Relay/Relay. If both of them are,
291 // UDP relay protocol takes precedence. 298 // UDP relay protocol takes precedence.
(...skipping 27 matching lines...) Expand all
319 // |ports_| contains ports that are used to form new connections when 326 // |ports_| contains ports that are used to form new connections when
320 // new remote candidates are added. 327 // new remote candidates are added.
321 std::vector<PortInterface*> ports_; 328 std::vector<PortInterface*> ports_;
322 // |removed_ports_| contains ports that have been removed from |ports_| and 329 // |removed_ports_| contains ports that have been removed from |ports_| and
323 // are not being used to form new connections, but that aren't yet destroyed. 330 // are not being used to form new connections, but that aren't yet destroyed.
324 // They may have existing connections, and they still fire signals such as 331 // They may have existing connections, and they still fire signals such as
325 // SignalUnknownAddress. 332 // SignalUnknownAddress.
326 std::vector<PortInterface*> removed_ports_; 333 std::vector<PortInterface*> removed_ports_;
327 334
328 // |connections_| is a sorted list with the first one always be the 335 // |connections_| is a sorted list with the first one always be the
329 // |best_connection_| when it's not nullptr. The combination of 336 // |selected_connection_| when it's not nullptr. The combination of
330 // |pinged_connections_| and |unpinged_connections_| has the same 337 // |pinged_connections_| and |unpinged_connections_| has the same
331 // connections as |connections_|. These 2 sets maintain whether a 338 // connections as |connections_|. These 2 sets maintain whether a
332 // connection should be pinged next or not. 339 // connection should be pinged next or not.
333 std::vector<Connection *> connections_; 340 std::vector<Connection *> connections_;
334 std::set<Connection*> pinged_connections_; 341 std::set<Connection*> pinged_connections_;
335 std::set<Connection*> unpinged_connections_; 342 std::set<Connection*> unpinged_connections_;
336 343
337 Connection* best_connection_; 344 Connection* selected_connection_ = nullptr;
338 345
339 // Connection selected by the controlling agent. This should be used only
340 // at controlled side when protocol type is RFC5245.
341 Connection* pending_best_connection_;
342 std::vector<RemoteCandidate> remote_candidates_; 346 std::vector<RemoteCandidate> remote_candidates_;
343 bool sort_dirty_; // indicates whether another sort is needed right now 347 bool sort_dirty_; // indicates whether another sort is needed right now
344 bool had_connection_ = false; // if connections_ has ever been nonempty 348 bool had_connection_ = false; // if connections_ has ever been nonempty
345 typedef std::map<rtc::Socket::Option, int> OptionMap; 349 typedef std::map<rtc::Socket::Option, int> OptionMap;
346 OptionMap options_; 350 OptionMap options_;
347 std::string ice_ufrag_; 351 std::string ice_ufrag_;
348 std::string ice_pwd_; 352 std::string ice_pwd_;
349 std::vector<IceParameters> remote_ice_parameters_; 353 std::vector<IceParameters> remote_ice_parameters_;
350 IceMode remote_ice_mode_; 354 IceMode remote_ice_mode_;
351 IceRole ice_role_; 355 IceRole ice_role_;
352 uint64_t tiebreaker_; 356 uint64_t tiebreaker_;
353 IceGatheringState gathering_state_; 357 IceGatheringState gathering_state_;
354 358
355 int check_receiving_interval_; 359 int check_receiving_interval_;
356 int64_t last_ping_sent_ms_ = 0; 360 int64_t last_ping_sent_ms_ = 0;
357 int weak_ping_interval_ = WEAK_PING_INTERVAL; 361 int weak_ping_interval_ = WEAK_PING_INTERVAL;
358 TransportChannelState state_ = TransportChannelState::STATE_INIT; 362 TransportChannelState state_ = TransportChannelState::STATE_INIT;
359 IceConfig config_; 363 IceConfig config_;
360 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before. 364 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before.
361 365
362 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); 366 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel);
363 }; 367 };
364 368
365 } // namespace cricket 369 } // namespace cricket
366 370
367 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ 371 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/p2p/base/p2ptransportchannel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698