| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // From TransportChannel: | 110 // From TransportChannel: |
| 111 int SendPacket(const char* data, | 111 int SendPacket(const char* data, |
| 112 size_t len, | 112 size_t len, |
| 113 const rtc::PacketOptions& options, | 113 const rtc::PacketOptions& options, |
| 114 int flags) override; | 114 int flags) override; |
| 115 int SetOption(rtc::Socket::Option opt, int value) override; | 115 int SetOption(rtc::Socket::Option opt, int value) override; |
| 116 bool GetOption(rtc::Socket::Option opt, int* value) override; | 116 bool GetOption(rtc::Socket::Option opt, int* value) override; |
| 117 int GetError() override { return error_; } | 117 int GetError() override { return error_; } |
| 118 bool GetStats(std::vector<ConnectionInfo>* stats) override; | 118 bool GetStats(std::vector<ConnectionInfo>* stats) override; |
| 119 | 119 |
| 120 const Connection* best_connection() const { return best_connection_; } | 120 const Connection* selected_connection() const { return selected_connection_; } |
| 121 void set_incoming_only(bool value) { incoming_only_ = value; } | 121 void set_incoming_only(bool value) { incoming_only_ = value; } |
| 122 | 122 |
| 123 // Note: This is only for testing purpose. | 123 // Note: This is only for testing purpose. |
| 124 // |ports_| should not be changed from outside. | 124 // |ports_| should not be changed from outside. |
| 125 const std::vector<PortInterface*>& ports() { return ports_; } | 125 const std::vector<PortInterface*>& ports() { return ports_; } |
| 126 | 126 |
| 127 IceMode remote_ice_mode() const { return remote_ice_mode_; } | 127 IceMode remote_ice_mode() const { return remote_ice_mode_; } |
| 128 | 128 |
| 129 // DTLS methods. | 129 // DTLS methods. |
| 130 bool IsDtlsActive() const override { return false; } | 130 bool IsDtlsActive() const override { return false; } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 private: | 203 private: |
| 204 rtc::Thread* thread() { return worker_thread_; } | 204 rtc::Thread* thread() { return worker_thread_; } |
| 205 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); } | 205 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); } |
| 206 | 206 |
| 207 // A transport channel is weak if the current best connection is either | 207 // A transport channel is weak if the current best connection is either |
| 208 // not receiving or not writable, or if there is no best connection at all. | 208 // not receiving or not writable, or if there is no best connection at all. |
| 209 bool weak() const; | 209 bool weak() const; |
| 210 void UpdateConnectionStates(); | 210 void UpdateConnectionStates(); |
| 211 void RequestSort(); | 211 void RequestSort(); |
| 212 void SortConnections(); | 212 void SortConnections(); |
| 213 void SwitchBestConnectionTo(Connection* conn); | 213 void SwitchSelectedConnection(Connection* conn); |
| 214 void UpdateState(); | 214 void UpdateState(); |
| 215 void HandleAllTimedOut(); | 215 void HandleAllTimedOut(); |
| 216 void MaybeStopPortAllocatorSessions(); | 216 void MaybeStopPortAllocatorSessions(); |
| 217 TransportChannelState ComputeState() const; | 217 TransportChannelState ComputeState() const; |
| 218 | 218 |
| 219 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const; | 219 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const; |
| 220 bool CreateConnections(const Candidate& remote_candidate, | 220 bool CreateConnections(const Candidate& remote_candidate, |
| 221 PortInterface* origin_port); | 221 PortInterface* origin_port); |
| 222 bool CreateConnection(PortInterface* port, | 222 bool CreateConnection(PortInterface* port, |
| 223 const Candidate& remote_candidate, | 223 const Candidate& remote_candidate, |
| 224 PortInterface* origin_port); | 224 PortInterface* origin_port); |
| 225 bool FindConnection(cricket::Connection* connection) const; | 225 bool FindConnection(cricket::Connection* connection) const; |
| 226 | 226 |
| 227 uint32_t GetRemoteCandidateGeneration(const Candidate& candidate); | 227 uint32_t GetRemoteCandidateGeneration(const Candidate& candidate); |
| 228 bool IsDuplicateRemoteCandidate(const Candidate& candidate); | 228 bool IsDuplicateRemoteCandidate(const Candidate& candidate); |
| 229 void RememberRemoteCandidate(const Candidate& remote_candidate, | 229 void RememberRemoteCandidate(const Candidate& remote_candidate, |
| 230 PortInterface* origin_port); | 230 PortInterface* origin_port); |
| 231 bool IsPingable(Connection* conn, int64_t now); | 231 bool IsPingable(Connection* conn, int64_t now); |
| 232 bool IsBestConnectionPingable(int64_t now); | 232 bool IsSelectedConnectionPingable(int64_t now); |
| 233 int CalculateActiveWritablePingInterval(Connection* conn, int64_t now); | 233 int CalculateActiveWritablePingInterval(Connection* conn, int64_t now); |
| 234 void PingConnection(Connection* conn); | 234 void PingConnection(Connection* conn); |
| 235 void AddAllocatorSession(std::unique_ptr<PortAllocatorSession> session); | 235 void AddAllocatorSession(std::unique_ptr<PortAllocatorSession> session); |
| 236 void AddConnection(Connection* connection); | 236 void AddConnection(Connection* connection); |
| 237 | 237 |
| 238 void OnPortReady(PortAllocatorSession *session, PortInterface* port); | 238 void OnPortReady(PortAllocatorSession *session, PortInterface* port); |
| 239 void OnCandidatesReady(PortAllocatorSession *session, | 239 void OnCandidatesReady(PortAllocatorSession *session, |
| 240 const std::vector<Candidate>& candidates); | 240 const std::vector<Candidate>& candidates); |
| 241 void OnCandidatesAllocationDone(PortAllocatorSession* session); | 241 void OnCandidatesAllocationDone(PortAllocatorSession* session); |
| 242 void OnUnknownAddress(PortInterface* port, | 242 void OnUnknownAddress(PortInterface* port, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 255 void OnSentPacket(const rtc::SentPacket& sent_packet); | 255 void OnSentPacket(const rtc::SentPacket& sent_packet); |
| 256 void OnReadyToSend(Connection* connection); | 256 void OnReadyToSend(Connection* connection); |
| 257 void OnConnectionDestroyed(Connection *connection); | 257 void OnConnectionDestroyed(Connection *connection); |
| 258 | 258 |
| 259 void OnNominated(Connection* conn); | 259 void OnNominated(Connection* conn); |
| 260 | 260 |
| 261 void OnMessage(rtc::Message* pmsg) override; | 261 void OnMessage(rtc::Message* pmsg) override; |
| 262 void OnSort(); | 262 void OnSort(); |
| 263 void OnCheckAndPing(); | 263 void OnCheckAndPing(); |
| 264 | 264 |
| 265 // Compares two connections based on the connection states |
| 266 // (writable/receiving/connected), nomination states, last data received time, |
| 267 // and static preferences. Does not include latency. Used by both sorting |
| 268 // and ShouldSwitchSelectedConnection(). |
| 269 // Returns a positive value if |a| is better than |b|. |
| 270 int CompareConnections(const cricket::Connection* a, |
| 271 const cricket::Connection* b) const; |
| 272 // Returns true if the new_connection should be selected for transmission. |
| 273 bool ShouldSwitchSelectedConnection(Connection* new_connection) const; |
| 274 |
| 265 void PruneConnections(); | 275 void PruneConnections(); |
| 266 Connection* best_nominated_connection() const; | |
| 267 bool IsBackupConnection(Connection* conn) const; | 276 bool IsBackupConnection(Connection* conn) const; |
| 268 | 277 |
| 269 Connection* FindConnectionToPing(int64_t now); | 278 Connection* FindConnectionToPing(int64_t now); |
| 270 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now); | 279 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now); |
| 271 // Between |conn1| and |conn2|, this function returns the one which should | 280 // Between |conn1| and |conn2|, this function returns the one which should |
| 272 // be pinged first. | 281 // be pinged first. |
| 273 Connection* SelectMostPingableConnection(Connection* conn1, | 282 Connection* SelectMostPingableConnection(Connection* conn1, |
| 274 Connection* conn2); | 283 Connection* conn2); |
| 275 // Select the connection which is Relay/Relay. If both of them are, | 284 // Select the connection which is Relay/Relay. If both of them are, |
| 276 // UDP relay protocol takes precedence. | 285 // UDP relay protocol takes precedence. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 304 // |ports_| contains ports that are used to form new connections when | 313 // |ports_| contains ports that are used to form new connections when |
| 305 // new remote candidates are added. | 314 // new remote candidates are added. |
| 306 std::vector<PortInterface*> ports_; | 315 std::vector<PortInterface*> ports_; |
| 307 // |removed_ports_| contains ports that have been removed from |ports_| and | 316 // |removed_ports_| contains ports that have been removed from |ports_| and |
| 308 // are not being used to form new connections, but that aren't yet destroyed. | 317 // are not being used to form new connections, but that aren't yet destroyed. |
| 309 // They may have existing connections, and they still fire signals such as | 318 // They may have existing connections, and they still fire signals such as |
| 310 // SignalUnknownAddress. | 319 // SignalUnknownAddress. |
| 311 std::vector<PortInterface*> removed_ports_; | 320 std::vector<PortInterface*> removed_ports_; |
| 312 | 321 |
| 313 // |connections_| is a sorted list with the first one always be the | 322 // |connections_| is a sorted list with the first one always be the |
| 314 // |best_connection_| when it's not nullptr. The combination of | 323 // |selected_connection_| when it's not nullptr. The combination of |
| 315 // |pinged_connections_| and |unpinged_connections_| has the same | 324 // |pinged_connections_| and |unpinged_connections_| has the same |
| 316 // connections as |connections_|. These 2 sets maintain whether a | 325 // connections as |connections_|. These 2 sets maintain whether a |
| 317 // connection should be pinged next or not. | 326 // connection should be pinged next or not. |
| 318 std::vector<Connection *> connections_; | 327 std::vector<Connection *> connections_; |
| 319 std::set<Connection*> pinged_connections_; | 328 std::set<Connection*> pinged_connections_; |
| 320 std::set<Connection*> unpinged_connections_; | 329 std::set<Connection*> unpinged_connections_; |
| 321 | 330 |
| 322 Connection* best_connection_; | 331 Connection* selected_connection_ = nullptr; |
| 323 | 332 |
| 324 // Connection selected by the controlling agent. This should be used only | |
| 325 // at controlled side when protocol type is RFC5245. | |
| 326 Connection* pending_best_connection_; | |
| 327 std::vector<RemoteCandidate> remote_candidates_; | 333 std::vector<RemoteCandidate> remote_candidates_; |
| 328 bool sort_dirty_; // indicates whether another sort is needed right now | 334 bool sort_dirty_; // indicates whether another sort is needed right now |
| 329 bool had_connection_ = false; // if connections_ has ever been nonempty | 335 bool had_connection_ = false; // if connections_ has ever been nonempty |
| 330 typedef std::map<rtc::Socket::Option, int> OptionMap; | 336 typedef std::map<rtc::Socket::Option, int> OptionMap; |
| 331 OptionMap options_; | 337 OptionMap options_; |
| 332 std::string ice_ufrag_; | 338 std::string ice_ufrag_; |
| 333 std::string ice_pwd_; | 339 std::string ice_pwd_; |
| 334 std::vector<IceParameters> remote_ice_parameters_; | 340 std::vector<IceParameters> remote_ice_parameters_; |
| 335 IceMode remote_ice_mode_; | 341 IceMode remote_ice_mode_; |
| 336 IceRole ice_role_; | 342 IceRole ice_role_; |
| 337 uint64_t tiebreaker_; | 343 uint64_t tiebreaker_; |
| 338 IceGatheringState gathering_state_; | 344 IceGatheringState gathering_state_; |
| 339 | 345 |
| 340 int check_receiving_interval_; | 346 int check_receiving_interval_; |
| 341 int64_t last_ping_sent_ms_ = 0; | 347 int64_t last_ping_sent_ms_ = 0; |
| 342 int weak_ping_interval_ = WEAK_PING_INTERVAL; | 348 int weak_ping_interval_ = WEAK_PING_INTERVAL; |
| 343 TransportChannelState state_ = TransportChannelState::STATE_INIT; | 349 TransportChannelState state_ = TransportChannelState::STATE_INIT; |
| 344 IceConfig config_; | 350 IceConfig config_; |
| 345 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before. | 351 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before. |
| 346 | 352 |
| 347 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); | 353 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); |
| 348 }; | 354 }; |
| 349 | 355 |
| 350 } // namespace cricket | 356 } // namespace cricket |
| 351 | 357 |
| 352 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ | 358 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ |
| OLD | NEW |