OLD | NEW |
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 Loading... |
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& config() 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 Loading... |
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(); |
| 177 void MarkConnectionPinged(Connection* conn); |
175 | 178 |
176 // Public for unit tests. | 179 // Public for unit tests. |
177 const std::vector<Connection*>& connections() const { return connections_; } | 180 const std::vector<Connection*>& connections() const { return connections_; } |
178 | 181 |
179 // Public for unit tests. | 182 // Public for unit tests. |
180 PortAllocatorSession* allocator_session() { | 183 PortAllocatorSession* allocator_session() { |
181 return allocator_sessions_.back(); | 184 return allocator_sessions_.back(); |
182 } | 185 } |
183 | 186 |
184 // Public for unit tests. | 187 // Public for unit tests. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 void OnNominated(Connection* conn); | 246 void OnNominated(Connection* conn); |
244 | 247 |
245 void OnMessage(rtc::Message* pmsg) override; | 248 void OnMessage(rtc::Message* pmsg) override; |
246 void OnSort(); | 249 void OnSort(); |
247 void OnCheckAndPing(); | 250 void OnCheckAndPing(); |
248 | 251 |
249 void PruneConnections(); | 252 void PruneConnections(); |
250 Connection* best_nominated_connection() const; | 253 Connection* best_nominated_connection() const; |
251 bool IsBackupConnection(Connection* conn) const; | 254 bool IsBackupConnection(Connection* conn) const; |
252 | 255 |
| 256 Connection* FindConnectionToPing(uint32_t now); |
| 257 Connection* FindOldestConnectionNeedingTriggeredCheck(uint32_t now); |
| 258 // Between |conn1| and |conn2|, this function returns the one which should |
| 259 // be pinged first. |
| 260 Connection* SelectMostPingableConnection(Connection* conn1, |
| 261 Connection* conn2); |
| 262 // Select the connection which is Relay/Relay. If both of them are, |
| 263 // UDP relay protocol takes precedence. |
| 264 Connection* MostLikelyToWork(Connection* conn1, Connection* conn2); |
| 265 // Compare the last_ping_sent time and return the one least recently pinged. |
| 266 Connection* LeastRecentlyPinged(Connection* conn1, Connection* conn2); |
| 267 |
253 // Returns the latest remote ICE parameters or nullptr if there are no remote | 268 // Returns the latest remote ICE parameters or nullptr if there are no remote |
254 // ICE parameters yet. | 269 // ICE parameters yet. |
255 IceParameters* remote_ice() { | 270 IceParameters* remote_ice() { |
256 return remote_ice_parameters_.empty() ? nullptr | 271 return remote_ice_parameters_.empty() ? nullptr |
257 : &remote_ice_parameters_.back(); | 272 : &remote_ice_parameters_.back(); |
258 } | 273 } |
259 // Returns the remote IceParameters and generation that match |ufrag| | 274 // Returns the remote IceParameters and generation that match |ufrag| |
260 // if found, and returns nullptr otherwise. | 275 // if found, and returns nullptr otherwise. |
261 const IceParameters* FindRemoteIceFromUfrag(const std::string& ufrag, | 276 const IceParameters* FindRemoteIceFromUfrag(const std::string& ufrag, |
262 uint32_t* generation); | 277 uint32_t* generation); |
263 // Returns the index of the latest remote ICE parameters, or 0 if no remote | 278 // Returns the index of the latest remote ICE parameters, or 0 if no remote |
264 // ICE parameters have been received. | 279 // ICE parameters have been received. |
265 uint32_t remote_ice_generation() { | 280 uint32_t remote_ice_generation() { |
266 return remote_ice_parameters_.empty() | 281 return remote_ice_parameters_.empty() |
267 ? 0 | 282 ? 0 |
268 : static_cast<uint32_t>(remote_ice_parameters_.size() - 1); | 283 : static_cast<uint32_t>(remote_ice_parameters_.size() - 1); |
269 } | 284 } |
270 | 285 |
271 PortAllocator* allocator_; | 286 PortAllocator* allocator_; |
272 rtc::Thread* worker_thread_; | 287 rtc::Thread* worker_thread_; |
273 bool incoming_only_; | 288 bool incoming_only_; |
274 int error_; | 289 int error_; |
275 std::vector<PortAllocatorSession*> allocator_sessions_; | 290 std::vector<PortAllocatorSession*> allocator_sessions_; |
276 std::vector<PortInterface *> ports_; | 291 std::vector<PortInterface *> ports_; |
| 292 |
| 293 // |connections_| is a sorted list with the first one always be the |
| 294 // |best_connection_| when it's not nullptr. The combination of |
| 295 // |pinged_connections_| and |unpinged_connections_| has the same |
| 296 // connections as |connections_|. These 2 sets maintain whether a |
| 297 // connection should be pinged next or not. |
277 std::vector<Connection *> connections_; | 298 std::vector<Connection *> connections_; |
| 299 std::set<Connection*> pinged_connections_; |
| 300 std::set<Connection*> unpinged_connections_; |
| 301 |
278 Connection* best_connection_; | 302 Connection* best_connection_; |
| 303 |
279 // Connection selected by the controlling agent. This should be used only | 304 // Connection selected by the controlling agent. This should be used only |
280 // at controlled side when protocol type is RFC5245. | 305 // at controlled side when protocol type is RFC5245. |
281 Connection* pending_best_connection_; | 306 Connection* pending_best_connection_; |
282 std::vector<RemoteCandidate> remote_candidates_; | 307 std::vector<RemoteCandidate> remote_candidates_; |
283 bool sort_dirty_; // indicates whether another sort is needed right now | 308 bool sort_dirty_; // indicates whether another sort is needed right now |
284 bool had_connection_ = false; // if connections_ has ever been nonempty | 309 bool had_connection_ = false; // if connections_ has ever been nonempty |
285 typedef std::map<rtc::Socket::Option, int> OptionMap; | 310 typedef std::map<rtc::Socket::Option, int> OptionMap; |
286 OptionMap options_; | 311 OptionMap options_; |
287 std::string ice_ufrag_; | 312 std::string ice_ufrag_; |
288 std::string ice_pwd_; | 313 std::string ice_pwd_; |
289 std::vector<IceParameters> remote_ice_parameters_; | 314 std::vector<IceParameters> remote_ice_parameters_; |
290 IceMode remote_ice_mode_; | 315 IceMode remote_ice_mode_; |
291 IceRole ice_role_; | 316 IceRole ice_role_; |
292 uint64_t tiebreaker_; | 317 uint64_t tiebreaker_; |
293 IceGatheringState gathering_state_; | 318 IceGatheringState gathering_state_; |
294 | 319 |
295 int check_receiving_delay_; | 320 int check_receiving_delay_; |
296 int receiving_timeout_; | |
297 int backup_connection_ping_interval_; | |
298 uint32_t last_ping_sent_ms_ = 0; | 321 uint32_t last_ping_sent_ms_ = 0; |
299 bool gather_continually_ = false; | |
300 int weak_ping_delay_ = WEAK_PING_DELAY; | 322 int weak_ping_delay_ = WEAK_PING_DELAY; |
301 TransportChannelState state_ = TransportChannelState::STATE_INIT; | 323 TransportChannelState state_ = TransportChannelState::STATE_INIT; |
| 324 IceConfig config_; |
302 | 325 |
303 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); | 326 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); |
304 }; | 327 }; |
305 | 328 |
306 } // namespace cricket | 329 } // namespace cricket |
307 | 330 |
308 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ | 331 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ |
OLD | NEW |