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

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: Fix test issues Created 4 years, 11 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/transport.h" 31 #include "webrtc/p2p/base/transport.h"
31 #include "webrtc/p2p/base/transportchannelimpl.h" 32 #include "webrtc/p2p/base/transportchannelimpl.h"
32 #include "webrtc/base/asyncpacketsocket.h" 33 #include "webrtc/base/asyncpacketsocket.h"
33 #include "webrtc/base/sigslot.h" 34 #include "webrtc/base/sigslot.h"
34 35
35 namespace cricket { 36 namespace cricket {
36 37
37 extern const uint32_t WEAK_PING_DELAY; 38 extern const uint32_t WEAK_PING_DELAY;
39 extern const uint32_t MAX_CURRENT_STRONG_DELAY;
38 40
39 struct IceParameters { 41 struct IceParameters {
40 std::string ufrag; 42 std::string ufrag;
41 std::string pwd; 43 std::string pwd;
42 IceParameters(const std::string& ice_ufrag, const std::string& ice_pwd) 44 IceParameters(const std::string& ice_ufrag, const std::string& ice_pwd)
43 : ufrag(ice_ufrag), pwd(ice_pwd) {} 45 : ufrag(ice_ufrag), pwd(ice_pwd) {}
44 46
45 bool operator==(const IceParameters& other) { 47 bool operator==(const IceParameters& other) {
46 return ufrag == other.ufrag && pwd == other.pwd; 48 return ufrag == other.ufrag && pwd == other.pwd;
47 } 49 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 void SetRemoteIceMode(IceMode mode) override; 86 void SetRemoteIceMode(IceMode mode) override;
85 void Connect() override; 87 void Connect() override;
86 void MaybeStartGathering() override; 88 void MaybeStartGathering() override;
87 IceGatheringState gathering_state() const override { 89 IceGatheringState gathering_state() const override {
88 return gathering_state_; 90 return gathering_state_;
89 } 91 }
90 void AddRemoteCandidate(const Candidate& candidate) override; 92 void AddRemoteCandidate(const Candidate& candidate) override;
91 // Sets the receiving timeout and gather_continually. 93 // Sets the receiving timeout and gather_continually.
92 // This also sets the check_receiving_delay proportionally. 94 // This also sets the check_receiving_delay proportionally.
93 void SetIceConfig(const IceConfig& config) override; 95 void SetIceConfig(const IceConfig& config) override;
96 IceConfig GetIceConfig() const;
94 97
95 // From TransportChannel: 98 // From TransportChannel:
96 int SendPacket(const char* data, 99 int SendPacket(const char* data,
97 size_t len, 100 size_t len,
98 const rtc::PacketOptions& options, 101 const rtc::PacketOptions& options,
99 int flags) override; 102 int flags) override;
100 int SetOption(rtc::Socket::Option opt, int value) override; 103 int SetOption(rtc::Socket::Option opt, int value) override;
101 bool GetOption(rtc::Socket::Option opt, int* value) override; 104 bool GetOption(rtc::Socket::Option opt, int* value) override;
102 int GetError() override { return error_; } 105 int GetError() override { return error_; }
103 bool GetStats(std::vector<ConnectionInfo>* stats) override; 106 bool GetStats(std::vector<ConnectionInfo>* stats) override;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 PortAllocatorSession* allocator_session() { 180 PortAllocatorSession* allocator_session() {
178 return allocator_sessions_.back(); 181 return allocator_sessions_.back();
179 } 182 }
180 183
181 // Public for unit tests. 184 // Public for unit tests.
182 const std::vector<RemoteCandidate>& remote_candidates() const { 185 const std::vector<RemoteCandidate>& remote_candidates() const {
183 return remote_candidates_; 186 return remote_candidates_;
184 } 187 }
185 188
186 private: 189 private:
190 // This class maintains the std::vector interface to allow enumeration and
191 // wraps the logic of determining the next pingable connection. Connections[0]
192 // is always the candidate of the best connection after sorted.
193 class Connections : public std::vector<Connection*> {
pthatcher1 2016/01/27 19:59:58 This seems a little crazy.
guoweis_webrtc 2016/02/29 18:03:00 Removed the class.
194 public:
195 typedef std::vector<Connection*> Base;
196 Connections(P2PTransportChannel* channel);
197 void enable_most_likely_first(bool enable);
198 bool most_likely_first() const { return ping_most_likely_first_; }
199 iterator erase(iterator pos);
200 void push_back(Connection*& connection);
201 Connection* FindNextPingableConnection(uint32_t now);
202 void MarkConnectionPinged(Connection* connection);
203
204 private:
205 // Disallow any modifier functions.
206 using Base::erase;
207 using Base::insert;
208 using Base::emplace;
209 using Base::emplace_back;
210 using Base::pop_back;
211 using Base::push_back;
212 using Base::clear;
213 using Base::resize;
214 using Base::swap;
215
216 // Between |conn1| and |conn2|, this function returns the one which should
217 // be pinged first.
218 Connection* Compare(Connection* conn1, Connection* conn2);
219
220 bool IsTurnTurn(Connection* conn);
221
222 P2PTransportChannel* channel_ = nullptr;
223 bool ping_most_likely_first_ = false;
224
225 std::set<Connection*> pinged_connections_;
226 std::set<Connection*> unpinged_connections_;
227 };
228
187 rtc::Thread* thread() { return worker_thread_; } 229 rtc::Thread* thread() { return worker_thread_; }
188 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); } 230 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); }
189 231
190 // A transport channel is weak if the current best connection is either 232 // A transport channel is weak if the current best connection is either
191 // not receiving or not writable, or if there is no best connection at all. 233 // not receiving or not writable, or if there is no best connection at all.
192 bool weak() const; 234 bool weak() const;
193 void UpdateConnectionStates(); 235 void UpdateConnectionStates();
194 void RequestSort(); 236 void RequestSort();
195 void SortConnections(); 237 void SortConnections();
196 void SwitchBestConnectionTo(Connection* conn); 238 void SwitchBestConnectionTo(Connection* conn);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 : static_cast<uint32_t>(remote_ice_parameters_.size() - 1); 306 : static_cast<uint32_t>(remote_ice_parameters_.size() - 1);
265 } 307 }
266 308
267 P2PTransport* transport_; 309 P2PTransport* transport_;
268 PortAllocator* allocator_; 310 PortAllocator* allocator_;
269 rtc::Thread* worker_thread_; 311 rtc::Thread* worker_thread_;
270 bool incoming_only_; 312 bool incoming_only_;
271 int error_; 313 int error_;
272 std::vector<PortAllocatorSession*> allocator_sessions_; 314 std::vector<PortAllocatorSession*> allocator_sessions_;
273 std::vector<PortInterface *> ports_; 315 std::vector<PortInterface *> ports_;
274 std::vector<Connection *> connections_; 316 Connections connections_;
275 Connection* best_connection_; 317 Connection* best_connection_;
276 // Connection selected by the controlling agent. This should be used only 318 // Connection selected by the controlling agent. This should be used only
277 // at controlled side when protocol type is RFC5245. 319 // at controlled side when protocol type is RFC5245.
278 Connection* pending_best_connection_; 320 Connection* pending_best_connection_;
279 std::vector<RemoteCandidate> remote_candidates_; 321 std::vector<RemoteCandidate> remote_candidates_;
280 bool sort_dirty_; // indicates whether another sort is needed right now 322 bool sort_dirty_; // indicates whether another sort is needed right now
281 bool had_connection_ = false; // if connections_ has ever been nonempty 323 bool had_connection_ = false; // if connections_ has ever been nonempty
282 typedef std::map<rtc::Socket::Option, int> OptionMap; 324 typedef std::map<rtc::Socket::Option, int> OptionMap;
283 OptionMap options_; 325 OptionMap options_;
284 std::string ice_ufrag_; 326 std::string ice_ufrag_;
(...skipping 11 matching lines...) Expand all
296 bool gather_continually_ = false; 338 bool gather_continually_ = false;
297 int weak_ping_delay_ = WEAK_PING_DELAY; 339 int weak_ping_delay_ = WEAK_PING_DELAY;
298 TransportChannelState state_ = TransportChannelState::STATE_INIT; 340 TransportChannelState state_ = TransportChannelState::STATE_INIT;
299 341
300 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); 342 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel);
301 }; 343 };
302 344
303 } // namespace cricket 345 } // namespace cricket
304 346
305 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ 347 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698