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 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // From TransportChannelImpl: | 86 // From TransportChannelImpl: |
87 TransportChannelState GetState() const override; | 87 TransportChannelState GetState() const override; |
88 void SetIceRole(IceRole role) override; | 88 void SetIceRole(IceRole role) override; |
89 IceRole GetIceRole() const override { return ice_role_; } | 89 IceRole GetIceRole() const override { return ice_role_; } |
90 void SetIceTiebreaker(uint64_t tiebreaker) override; | 90 void SetIceTiebreaker(uint64_t tiebreaker) override; |
91 void SetIceCredentials(const std::string& ice_ufrag, | 91 void SetIceCredentials(const std::string& ice_ufrag, |
92 const std::string& ice_pwd) override; | 92 const std::string& ice_pwd) override; |
93 void SetRemoteIceCredentials(const std::string& ice_ufrag, | 93 void SetRemoteIceCredentials(const std::string& ice_ufrag, |
94 const std::string& ice_pwd) override; | 94 const std::string& ice_pwd) override; |
95 void SetRemoteIceMode(IceMode mode) override; | 95 void SetRemoteIceMode(IceMode mode) override; |
96 void Connect() override; | |
97 void MaybeStartGathering() override; | 96 void MaybeStartGathering() override; |
98 IceGatheringState gathering_state() const override { | 97 IceGatheringState gathering_state() const override { |
99 return gathering_state_; | 98 return gathering_state_; |
100 } | 99 } |
101 void AddRemoteCandidate(const Candidate& candidate) override; | 100 void AddRemoteCandidate(const Candidate& candidate) override; |
102 void RemoveRemoteCandidate(const Candidate& candidate) override; | 101 void RemoveRemoteCandidate(const Candidate& candidate) override; |
103 // Sets the parameters in IceConfig. We do not set them blindly. Instead, we | 102 // Sets the parameters in IceConfig. We do not set them blindly. Instead, we |
104 // only update the parameter if it is considered set in |config|. For example, | 103 // only update the parameter if it is considered set in |config|. For example, |
105 // a negative value of receiving_timeout will be considered "not set" and we | 104 // a negative value of receiving_timeout will be considered "not set" and we |
106 // will not use it to update the respective parameter in |config_|. | 105 // will not use it to update the respective parameter in |config_|. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 private: | 207 private: |
209 rtc::Thread* thread() { return worker_thread_; } | 208 rtc::Thread* thread() { return worker_thread_; } |
210 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); } | 209 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); } |
211 | 210 |
212 // A transport channel is weak if the current best connection is either | 211 // A transport channel is weak if the current best connection is either |
213 // not receiving or not writable, or if there is no best connection at all. | 212 // not receiving or not writable, or if there is no best connection at all. |
214 bool weak() const; | 213 bool weak() const; |
215 // Returns true if it's possible to send packets on this channel. | 214 // Returns true if it's possible to send packets on this channel. |
216 bool ReadyToSend() const; | 215 bool ReadyToSend() const; |
217 void UpdateConnectionStates(); | 216 void UpdateConnectionStates(); |
218 void RequestSort(); | 217 void RequestSortAndStateUpdate(); |
| 218 // Start pinging if we haven't already started, and we now have a connection |
| 219 // that's pingable. |
| 220 void MaybeStartPinging(); |
219 | 221 |
220 // The methods below return a positive value if a is preferable to b, | 222 // The methods below return a positive value if a is preferable to b, |
221 // a negative value if b is preferable, and 0 if they're equally preferable. | 223 // a negative value if b is preferable, and 0 if they're equally preferable. |
222 int CompareConnectionStates(const cricket::Connection* a, | 224 int CompareConnectionStates(const cricket::Connection* a, |
223 const cricket::Connection* b) const; | 225 const cricket::Connection* b) const; |
224 int CompareConnectionCandidates(const cricket::Connection* a, | 226 int CompareConnectionCandidates(const cricket::Connection* a, |
225 const cricket::Connection* b) const; | 227 const cricket::Connection* b) const; |
226 // Compares two connections based on the connection states | 228 // Compares two connections based on the connection states |
227 // (writable/receiving/connected), nomination states, last data received time, | 229 // (writable/receiving/connected), nomination states, last data received time, |
228 // and static preferences. Does not include latency. Used by both sorting | 230 // and static preferences. Does not include latency. Used by both sorting |
229 // and ShouldSwitchSelectedConnection(). | 231 // and ShouldSwitchSelectedConnection(). |
230 // Returns a positive value if |a| is better than |b|. | 232 // Returns a positive value if |a| is better than |b|. |
231 int CompareConnections(const cricket::Connection* a, | 233 int CompareConnections(const cricket::Connection* a, |
232 const cricket::Connection* b) const; | 234 const cricket::Connection* b) const; |
233 | 235 |
234 bool PresumedWritable(const cricket::Connection* conn) const; | 236 bool PresumedWritable(const cricket::Connection* conn) const; |
235 | 237 |
236 void SortConnections(); | 238 bool ShouldSwitchSelectedConnection(const cricket::Connection* selected, |
| 239 const cricket::Connection* conn) const; |
| 240 void SortConnectionsAndUpdateState(); |
237 void SwitchSelectedConnection(Connection* conn); | 241 void SwitchSelectedConnection(Connection* conn); |
238 void UpdateState(); | 242 void UpdateState(); |
239 void HandleAllTimedOut(); | 243 void HandleAllTimedOut(); |
240 void MaybeStopPortAllocatorSessions(); | 244 void MaybeStopPortAllocatorSessions(); |
241 TransportChannelState ComputeState() const; | 245 TransportChannelState ComputeState() const; |
242 | 246 |
243 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const; | 247 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const; |
244 bool CreateConnections(const Candidate& remote_candidate, | 248 bool CreateConnections(const Candidate& remote_candidate, |
245 PortInterface* origin_port); | 249 PortInterface* origin_port); |
246 bool CreateConnection(PortInterface* port, | 250 bool CreateConnection(PortInterface* port, |
247 const Candidate& remote_candidate, | 251 const Candidate& remote_candidate, |
248 PortInterface* origin_port); | 252 PortInterface* origin_port); |
249 bool FindConnection(cricket::Connection* connection) const; | 253 bool FindConnection(cricket::Connection* connection) const; |
250 | 254 |
251 uint32_t GetRemoteCandidateGeneration(const Candidate& candidate); | 255 uint32_t GetRemoteCandidateGeneration(const Candidate& candidate); |
252 bool IsDuplicateRemoteCandidate(const Candidate& candidate); | 256 bool IsDuplicateRemoteCandidate(const Candidate& candidate); |
253 void RememberRemoteCandidate(const Candidate& remote_candidate, | 257 void RememberRemoteCandidate(const Candidate& remote_candidate, |
254 PortInterface* origin_port); | 258 PortInterface* origin_port); |
255 bool IsPingable(Connection* conn, int64_t now); | 259 bool IsPingable(const Connection* conn, int64_t now) const; |
256 bool IsSelectedConnectionPingable(int64_t now); | 260 bool IsSelectedConnectionPingable(int64_t now); |
257 int CalculateActiveWritablePingInterval(Connection* conn, int64_t now); | 261 int CalculateActiveWritablePingInterval(const Connection* conn, |
| 262 int64_t now) const; |
258 void PingConnection(Connection* conn); | 263 void PingConnection(Connection* conn); |
259 void AddAllocatorSession(std::unique_ptr<PortAllocatorSession> session); | 264 void AddAllocatorSession(std::unique_ptr<PortAllocatorSession> session); |
260 void AddConnection(Connection* connection); | 265 void AddConnection(Connection* connection); |
261 | 266 |
262 void OnPortReady(PortAllocatorSession *session, PortInterface* port); | 267 void OnPortReady(PortAllocatorSession *session, PortInterface* port); |
263 void OnCandidatesReady(PortAllocatorSession *session, | 268 void OnCandidatesReady(PortAllocatorSession *session, |
264 const std::vector<Candidate>& candidates); | 269 const std::vector<Candidate>& candidates); |
265 void OnCandidatesAllocationDone(PortAllocatorSession* session); | 270 void OnCandidatesAllocationDone(PortAllocatorSession* session); |
266 void OnUnknownAddress(PortInterface* port, | 271 void OnUnknownAddress(PortInterface* port, |
267 const rtc::SocketAddress& addr, | 272 const rtc::SocketAddress& addr, |
268 ProtocolType proto, | 273 ProtocolType proto, |
269 IceMessage* stun_msg, | 274 IceMessage* stun_msg, |
270 const std::string& remote_username, | 275 const std::string& remote_username, |
271 bool port_muxed); | 276 bool port_muxed); |
272 void OnPortDestroyed(PortInterface* port); | 277 void OnPortDestroyed(PortInterface* port); |
273 void OnPortNetworkInactive(PortInterface* port); | 278 void OnPortNetworkInactive(PortInterface* port); |
274 void OnRoleConflict(PortInterface* port); | 279 void OnRoleConflict(PortInterface* port); |
275 | 280 |
276 void OnConnectionStateChange(Connection* connection); | 281 void OnConnectionStateChange(Connection* connection); |
277 void OnReadPacket(Connection *connection, const char *data, size_t len, | 282 void OnReadPacket(Connection *connection, const char *data, size_t len, |
278 const rtc::PacketTime& packet_time); | 283 const rtc::PacketTime& packet_time); |
279 void OnSentPacket(const rtc::SentPacket& sent_packet); | 284 void OnSentPacket(const rtc::SentPacket& sent_packet); |
280 void OnReadyToSend(Connection* connection); | 285 void OnReadyToSend(Connection* connection); |
281 void OnConnectionDestroyed(Connection *connection); | 286 void OnConnectionDestroyed(Connection *connection); |
282 | 287 |
283 void OnNominated(Connection* conn); | 288 void OnNominated(Connection* conn); |
284 | 289 |
285 void OnMessage(rtc::Message* pmsg) override; | 290 void OnMessage(rtc::Message* pmsg) override; |
286 void OnSort(); | |
287 void OnCheckAndPing(); | 291 void OnCheckAndPing(); |
288 | 292 |
289 // Returns true if the new_connection should be selected for transmission. | 293 // Returns true if the new_connection should be selected for transmission. |
290 bool ShouldSwitchSelectedConnection(Connection* new_connection) const; | 294 bool ShouldSwitchSelectedConnection(Connection* new_connection) const; |
291 | 295 |
292 void PruneConnections(); | 296 void PruneConnections(); |
293 bool IsBackupConnection(Connection* conn) const; | 297 bool IsBackupConnection(const Connection* conn) const; |
294 | 298 |
295 Connection* FindConnectionToPing(int64_t now); | 299 Connection* FindConnectionToPing(int64_t now); |
296 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now); | 300 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now); |
297 // Between |conn1| and |conn2|, this function returns the one which should | 301 // Between |conn1| and |conn2|, this function returns the one which should |
298 // be pinged first. | 302 // be pinged first. |
299 Connection* SelectMostPingableConnection(Connection* conn1, | 303 Connection* SelectMostPingableConnection(Connection* conn1, |
300 Connection* conn2); | 304 Connection* conn2); |
301 // Select the connection which is Relay/Relay. If both of them are, | 305 // Select the connection which is Relay/Relay. If both of them are, |
302 // UDP relay protocol takes precedence. | 306 // UDP relay protocol takes precedence. |
303 Connection* MostLikelyToWork(Connection* conn1, Connection* conn2); | 307 Connection* MostLikelyToWork(Connection* conn1, Connection* conn2); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 IceRole ice_role_; | 363 IceRole ice_role_; |
360 uint64_t tiebreaker_; | 364 uint64_t tiebreaker_; |
361 IceGatheringState gathering_state_; | 365 IceGatheringState gathering_state_; |
362 | 366 |
363 int check_receiving_interval_; | 367 int check_receiving_interval_; |
364 int64_t last_ping_sent_ms_ = 0; | 368 int64_t last_ping_sent_ms_ = 0; |
365 int weak_ping_interval_ = WEAK_PING_INTERVAL; | 369 int weak_ping_interval_ = WEAK_PING_INTERVAL; |
366 TransportChannelState state_ = TransportChannelState::STATE_INIT; | 370 TransportChannelState state_ = TransportChannelState::STATE_INIT; |
367 IceConfig config_; | 371 IceConfig config_; |
368 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before. | 372 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before. |
| 373 bool started_pinging_ = false; |
369 | 374 |
370 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); | 375 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); |
371 }; | 376 }; |
372 | 377 |
373 } // namespace cricket | 378 } // namespace cricket |
374 | 379 |
375 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ | 380 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ |
OLD | NEW |