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

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

Issue 1577233006: Implement Turn/Turn first logic for connection selection. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: missed to rename a var Created 4 years, 9 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
11 // P2PTransportChannel wraps up the state management of the connection between 11 // P2PTransportChannel wraps up the state management of the connection between
12 // two P2P clients. Clients have candidate ports for connecting, and 12 // two P2P clients. Clients have candidate ports for connecting, and
13 // connections which are combinations of candidates from each end (Alice and 13 // connections which are combinations of candidates from each end (Alice and
14 // Bob each have candidates, one candidate from Alice and one candidate from 14 // Bob each have candidates, one candidate from Alice and one candidate from
15 // Bob are used to make a connection, repeat to make many connections). 15 // Bob are used to make a connection, repeat to make many connections).
16 // 16 //
17 // When all of the available connections become invalid (non-writable), we 17 // When all of the available connections become invalid (non-writable), we
18 // kick off a process of determining more candidates and more connections. 18 // kick off a process of determining more candidates and more connections.
19 // 19 //
20 #ifndef WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ 20 #ifndef WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_
21 #define WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ 21 #define WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_
22 22
23 #include <map> 23 #include <map>
24 #include <set>
24 #include <string> 25 #include <string>
25 #include <vector> 26 #include <vector>
26 #include "webrtc/p2p/base/candidate.h" 27 #include "webrtc/p2p/base/candidate.h"
27 #include "webrtc/p2p/base/p2ptransport.h" 28 #include "webrtc/p2p/base/p2ptransport.h"
28 #include "webrtc/p2p/base/portallocator.h" 29 #include "webrtc/p2p/base/portallocator.h"
29 #include "webrtc/p2p/base/portinterface.h" 30 #include "webrtc/p2p/base/portinterface.h"
30 #include "webrtc/p2p/base/transportchannelimpl.h" 31 #include "webrtc/p2p/base/transportchannelimpl.h"
31 #include "webrtc/base/asyncpacketsocket.h" 32 #include "webrtc/base/asyncpacketsocket.h"
32 #include "webrtc/base/sigslot.h" 33 #include "webrtc/base/sigslot.h"
33 34
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 void SetRemoteIceMode(IceMode mode) override; 88 void SetRemoteIceMode(IceMode mode) override;
88 void Connect() override; 89 void Connect() override;
89 void MaybeStartGathering() override; 90 void MaybeStartGathering() override;
90 IceGatheringState gathering_state() const override { 91 IceGatheringState gathering_state() const override {
91 return gathering_state_; 92 return gathering_state_;
92 } 93 }
93 void AddRemoteCandidate(const Candidate& candidate) override; 94 void AddRemoteCandidate(const Candidate& candidate) override;
94 // Sets the receiving timeout and gather_continually. 95 // Sets the receiving timeout and gather_continually.
95 // This also sets the check_receiving_delay proportionally. 96 // This also sets the check_receiving_delay proportionally.
96 void SetIceConfig(const IceConfig& config) override; 97 void SetIceConfig(const IceConfig& config) override;
98 const IceConfig& GetIceConfig() const;
97 99
98 // From TransportChannel: 100 // From TransportChannel:
99 int SendPacket(const char* data, 101 int SendPacket(const char* data,
100 size_t len, 102 size_t len,
101 const rtc::PacketOptions& options, 103 const rtc::PacketOptions& options,
102 int flags) override; 104 int flags) override;
103 int SetOption(rtc::Socket::Option opt, int value) override; 105 int SetOption(rtc::Socket::Option opt, int value) override;
104 bool GetOption(rtc::Socket::Option opt, int* value) override; 106 bool GetOption(rtc::Socket::Option opt, int* value) override;
105 int GetError() override { return error_; } 107 int GetError() override { return error_; }
106 bool GetStats(std::vector<ConnectionInfo>* stats) override; 108 bool GetStats(std::vector<ConnectionInfo>* stats) override;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 return false; 159 return false;
158 } 160 }
159 161
160 // Set DTLS Remote fingerprint. Must be after local identity set. 162 // Set DTLS Remote fingerprint. Must be after local identity set.
161 bool SetRemoteFingerprint(const std::string& digest_alg, 163 bool SetRemoteFingerprint(const std::string& digest_alg,
162 const uint8_t* digest, 164 const uint8_t* digest,
163 size_t digest_len) override { 165 size_t digest_len) override {
164 return false; 166 return false;
165 } 167 }
166 168
167 int receiving_timeout() const { return receiving_timeout_; } 169 int receiving_timeout() const { return config_.receiving_timeout_ms; }
168 int check_receiving_delay() const { return check_receiving_delay_; } 170 int check_receiving_delay() const { return check_receiving_delay_; }
169 171
170 // Helper method used only in unittest. 172 // Helper method used only in unittest.
171 rtc::DiffServCodePoint DefaultDscpValue() const; 173 rtc::DiffServCodePoint DefaultDscpValue() const;
172 174
173 // Public for unit tests. 175 // Public for unit tests.
174 Connection* FindNextPingableConnection(); 176 Connection* FindNextPingableConnection();
175 177
176 // Public for unit tests. 178 // Public for unit tests.
177 const std::vector<Connection*>& connections() const { return connections_; } 179 const std::vector<Connection*>& connections() const { return connections_; }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 void OnNominated(Connection* conn); 245 void OnNominated(Connection* conn);
244 246
245 void OnMessage(rtc::Message* pmsg) override; 247 void OnMessage(rtc::Message* pmsg) override;
246 void OnSort(); 248 void OnSort();
247 void OnCheckAndPing(); 249 void OnCheckAndPing();
248 250
249 void PruneConnections(); 251 void PruneConnections();
250 Connection* best_nominated_connection() const; 252 Connection* best_nominated_connection() const;
251 bool IsBackupConnection(Connection* conn) const; 253 bool IsBackupConnection(Connection* conn) const;
252 254
255 Connection* FindConnectionToPing(uint32_t now);
256 Connection* FindOldestConnectionNeedingTriggeredCheck(uint32_t now);
257 // Between |conn1| and |conn2|, this function returns the one which should
258 // be pinged first.
259 Connection* SelectMorePingableConnection(Connection* conn1,
260 Connection* conn2);
261 // Select the connection which is Relay/Relay. If both of them are,
262 // UDP relay protocol takes precedence.
263 Connection* MostLikelyToWork(Connection* conn1, Connection* conn2);
264 // Compare the last_ping_sent time and return the one least recently pinged.
265 Connection* LeastRecentlyPinged(Connection* conn1, Connection* conn2);
266
253 // Returns the latest remote ICE parameters or nullptr if there are no remote 267 // Returns the latest remote ICE parameters or nullptr if there are no remote
254 // ICE parameters yet. 268 // ICE parameters yet.
255 IceParameters* remote_ice() { 269 IceParameters* remote_ice() {
256 return remote_ice_parameters_.empty() ? nullptr 270 return remote_ice_parameters_.empty() ? nullptr
257 : &remote_ice_parameters_.back(); 271 : &remote_ice_parameters_.back();
258 } 272 }
259 // Returns the remote IceParameters and generation that match |ufrag| 273 // Returns the remote IceParameters and generation that match |ufrag|
260 // if found, and returns nullptr otherwise. 274 // if found, and returns nullptr otherwise.
261 const IceParameters* FindRemoteIceFromUfrag(const std::string& ufrag, 275 const IceParameters* FindRemoteIceFromUfrag(const std::string& ufrag,
262 uint32_t* generation); 276 uint32_t* generation);
263 // Returns the index of the latest remote ICE parameters, or 0 if no remote 277 // Returns the index of the latest remote ICE parameters, or 0 if no remote
264 // ICE parameters have been received. 278 // ICE parameters have been received.
265 uint32_t remote_ice_generation() { 279 uint32_t remote_ice_generation() {
266 return remote_ice_parameters_.empty() 280 return remote_ice_parameters_.empty()
267 ? 0 281 ? 0
268 : static_cast<uint32_t>(remote_ice_parameters_.size() - 1); 282 : static_cast<uint32_t>(remote_ice_parameters_.size() - 1);
269 } 283 }
270 284
271 PortAllocator* allocator_; 285 PortAllocator* allocator_;
272 rtc::Thread* worker_thread_; 286 rtc::Thread* worker_thread_;
273 bool incoming_only_; 287 bool incoming_only_;
274 int error_; 288 int error_;
275 std::vector<PortAllocatorSession*> allocator_sessions_; 289 std::vector<PortAllocatorSession*> allocator_sessions_;
276 std::vector<PortInterface *> ports_; 290 std::vector<PortInterface *> ports_;
291
292 // |connections_| is a sorted list with the first one always be the
293 // |best_connection_| when it's not nullptr. The combination of
294 // |pinged_connections_| and |unpinged_connections_| has the same
295 // connections as |connections_|. These 2 sets maintain whether a
296 // connection should be pinged next or not.
277 std::vector<Connection *> connections_; 297 std::vector<Connection *> connections_;
298 std::set<Connection*> pinged_connections_;
299 std::set<Connection*> unpinged_connections_;
300
278 Connection* best_connection_; 301 Connection* best_connection_;
302
279 // Connection selected by the controlling agent. This should be used only 303 // Connection selected by the controlling agent. This should be used only
280 // at controlled side when protocol type is RFC5245. 304 // at controlled side when protocol type is RFC5245.
281 Connection* pending_best_connection_; 305 Connection* pending_best_connection_;
282 std::vector<RemoteCandidate> remote_candidates_; 306 std::vector<RemoteCandidate> remote_candidates_;
283 bool sort_dirty_; // indicates whether another sort is needed right now 307 bool sort_dirty_; // indicates whether another sort is needed right now
284 bool had_connection_ = false; // if connections_ has ever been nonempty 308 bool had_connection_ = false; // if connections_ has ever been nonempty
285 typedef std::map<rtc::Socket::Option, int> OptionMap; 309 typedef std::map<rtc::Socket::Option, int> OptionMap;
286 OptionMap options_; 310 OptionMap options_;
287 std::string ice_ufrag_; 311 std::string ice_ufrag_;
288 std::string ice_pwd_; 312 std::string ice_pwd_;
289 std::vector<IceParameters> remote_ice_parameters_; 313 std::vector<IceParameters> remote_ice_parameters_;
290 IceMode remote_ice_mode_; 314 IceMode remote_ice_mode_;
291 IceRole ice_role_; 315 IceRole ice_role_;
292 uint64_t tiebreaker_; 316 uint64_t tiebreaker_;
293 IceGatheringState gathering_state_; 317 IceGatheringState gathering_state_;
294 318
295 int check_receiving_delay_; 319 int check_receiving_delay_;
296 int receiving_timeout_;
297 int backup_connection_ping_interval_;
298 uint32_t last_ping_sent_ms_ = 0; 320 uint32_t last_ping_sent_ms_ = 0;
299 bool gather_continually_ = false;
300 int weak_ping_delay_ = WEAK_PING_DELAY; 321 int weak_ping_delay_ = WEAK_PING_DELAY;
301 TransportChannelState state_ = TransportChannelState::STATE_INIT; 322 TransportChannelState state_ = TransportChannelState::STATE_INIT;
323 IceConfig config_;
302 324
303 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); 325 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel);
304 }; 326 };
305 327
306 } // namespace cricket 328 } // namespace cricket
307 329
308 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ 330 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698