Chromium Code Reviews| 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 25 matching lines...) Expand all Loading... | |
| 36 #include "webrtc/base/asyncpacketsocket.h" | 36 #include "webrtc/base/asyncpacketsocket.h" |
| 37 #include "webrtc/base/sigslot.h" | 37 #include "webrtc/base/sigslot.h" |
| 38 | 38 |
| 39 namespace cricket { | 39 namespace cricket { |
| 40 | 40 |
| 41 extern const int WEAK_PING_INTERVAL; | 41 extern const int WEAK_PING_INTERVAL; |
| 42 extern const int STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL; | 42 extern const int STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL; |
| 43 extern const int STABLE_WRITABLE_CONNECTION_PING_INTERVAL; | 43 extern const int STABLE_WRITABLE_CONNECTION_PING_INTERVAL; |
| 44 static const int MIN_PINGS_AT_WEAK_PING_INTERVAL = 3; | 44 static const int MIN_PINGS_AT_WEAK_PING_INTERVAL = 3; |
| 45 | 45 |
| 46 struct IceParameters { | |
| 47 std::string ufrag; | |
| 48 std::string pwd; | |
| 49 IceParameters(const std::string& ice_ufrag, const std::string& ice_pwd) | |
| 50 : ufrag(ice_ufrag), pwd(ice_pwd) {} | |
| 51 | |
| 52 bool operator==(const IceParameters& other) { | |
| 53 return ufrag == other.ufrag && pwd == other.pwd; | |
| 54 } | |
| 55 bool operator!=(const IceParameters& other) { return !(*this == other); } | |
| 56 }; | |
| 57 | |
| 58 // Adds the port on which the candidate originated. | 46 // Adds the port on which the candidate originated. |
| 59 class RemoteCandidate : public Candidate { | 47 class RemoteCandidate : public Candidate { |
| 60 public: | 48 public: |
| 61 RemoteCandidate(const Candidate& c, PortInterface* origin_port) | 49 RemoteCandidate(const Candidate& c, PortInterface* origin_port) |
| 62 : Candidate(c), origin_port_(origin_port) {} | 50 : Candidate(c), origin_port_(origin_port) {} |
| 63 | 51 |
| 64 PortInterface* origin_port() { return origin_port_; } | 52 PortInterface* origin_port() { return origin_port_; } |
| 65 | 53 |
| 66 private: | 54 private: |
| 67 PortInterface* origin_port_; | 55 PortInterface* origin_port_; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 81 int component, | 69 int component, |
| 82 P2PTransport* transport, | 70 P2PTransport* transport, |
| 83 PortAllocator* allocator); | 71 PortAllocator* allocator); |
| 84 virtual ~P2PTransportChannel(); | 72 virtual ~P2PTransportChannel(); |
| 85 | 73 |
| 86 // From TransportChannelImpl: | 74 // From TransportChannelImpl: |
| 87 TransportChannelState GetState() const override; | 75 TransportChannelState GetState() const override; |
| 88 void SetIceRole(IceRole role) override; | 76 void SetIceRole(IceRole role) override; |
| 89 IceRole GetIceRole() const override { return ice_role_; } | 77 IceRole GetIceRole() const override { return ice_role_; } |
| 90 void SetIceTiebreaker(uint64_t tiebreaker) override; | 78 void SetIceTiebreaker(uint64_t tiebreaker) override; |
| 91 void SetIceCredentials(const std::string& ice_ufrag, | 79 void SetIceParameters(const IceParameters& ice_params) override; |
| 92 const std::string& ice_pwd) override; | 80 void SetRemoteIceParameters(const IceParameters& ice_params) override; |
| 93 void SetRemoteIceCredentials(const std::string& ice_ufrag, | |
| 94 const std::string& ice_pwd) override; | |
| 95 void SetRemoteIceMode(IceMode mode) override; | 81 void SetRemoteIceMode(IceMode mode) override; |
| 96 // TODO(deadbeef): Deprecated. Remove when Chromium's | 82 // TODO(deadbeef): Deprecated. Remove when Chromium's |
| 97 // IceTransportChannel does not depend on this. | 83 // IceTransportChannel does not depend on this. |
| 98 void Connect() {} | 84 void Connect() {} |
| 99 void MaybeStartGathering() override; | 85 void MaybeStartGathering() override; |
| 100 IceGatheringState gathering_state() const override { | 86 IceGatheringState gathering_state() const override { |
| 101 return gathering_state_; | 87 return gathering_state_; |
| 102 } | 88 } |
| 103 void AddRemoteCandidate(const Candidate& candidate) override; | 89 void AddRemoteCandidate(const Candidate& candidate) override; |
| 104 void RemoveRemoteCandidate(const Candidate& candidate) override; | 90 void RemoveRemoteCandidate(const Candidate& candidate) override; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 PortAllocatorSession* allocator_session() { | 189 PortAllocatorSession* allocator_session() { |
| 204 return allocator_sessions_.back().get(); | 190 return allocator_sessions_.back().get(); |
| 205 } | 191 } |
| 206 | 192 |
| 207 // Public for unit tests. | 193 // Public for unit tests. |
| 208 const std::vector<RemoteCandidate>& remote_candidates() const { | 194 const std::vector<RemoteCandidate>& remote_candidates() const { |
| 209 return remote_candidates_; | 195 return remote_candidates_; |
| 210 } | 196 } |
| 211 | 197 |
| 212 // Public for unit tests. | 198 // Public for unit tests. |
| 213 void set_remote_supports_renomination(bool remote_supports_renomination) { | 199 const IceParameters& ice_parameters() const { return ice_parameters_; } |
| 214 remote_supports_renomination_ = remote_supports_renomination; | 200 |
| 201 // Public for unit tests. | |
| 202 // Returns the latest remote ICE parameters or nullptr if there are no remote | |
| 203 // ICE parameters yet. | |
| 204 IceParameters* remote_ice() { | |
| 205 return remote_ice_parameters_.empty() ? nullptr | |
| 206 : &remote_ice_parameters_.back(); | |
| 215 } | 207 } |
|
Taylor Brandstetter
2016/08/11 22:36:50
I hoped by using SetRemoteIceParameters we could a
honghaiz3
2016/08/12 18:26:40
Done.
| |
| 216 | 208 |
| 217 private: | 209 private: |
| 218 rtc::Thread* thread() const { return worker_thread_; } | 210 rtc::Thread* thread() const { return worker_thread_; } |
| 219 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); } | 211 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); } |
| 220 | 212 |
| 221 // A transport channel is weak if the current best connection is either | 213 // A transport channel is weak if the current best connection is either |
| 222 // not receiving or not writable, or if there is no best connection at all. | 214 // not receiving or not writable, or if there is no best connection at all. |
| 223 bool weak() const; | 215 bool weak() const; |
| 224 // Returns true if it's possible to send packets on this channel. | 216 // Returns true if it's possible to send packets on this channel. |
| 225 bool ReadyToSend() const; | 217 bool ReadyToSend() const; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 // Between |conn1| and |conn2|, this function returns the one which should | 332 // Between |conn1| and |conn2|, this function returns the one which should |
| 341 // be pinged first. | 333 // be pinged first. |
| 342 Connection* SelectMostPingableConnection(Connection* conn1, | 334 Connection* SelectMostPingableConnection(Connection* conn1, |
| 343 Connection* conn2); | 335 Connection* conn2); |
| 344 // Select the connection which is Relay/Relay. If both of them are, | 336 // Select the connection which is Relay/Relay. If both of them are, |
| 345 // UDP relay protocol takes precedence. | 337 // UDP relay protocol takes precedence. |
| 346 Connection* MostLikelyToWork(Connection* conn1, Connection* conn2); | 338 Connection* MostLikelyToWork(Connection* conn1, Connection* conn2); |
| 347 // Compare the last_ping_sent time and return the one least recently pinged. | 339 // Compare the last_ping_sent time and return the one least recently pinged. |
| 348 Connection* LeastRecentlyPinged(Connection* conn1, Connection* conn2); | 340 Connection* LeastRecentlyPinged(Connection* conn1, Connection* conn2); |
| 349 | 341 |
| 350 // Returns the latest remote ICE parameters or nullptr if there are no remote | |
| 351 // ICE parameters yet. | |
| 352 IceParameters* remote_ice() { | |
| 353 return remote_ice_parameters_.empty() ? nullptr | |
| 354 : &remote_ice_parameters_.back(); | |
| 355 } | |
| 356 // Returns the remote IceParameters and generation that match |ufrag| | 342 // Returns the remote IceParameters and generation that match |ufrag| |
| 357 // if found, and returns nullptr otherwise. | 343 // if found, and returns nullptr otherwise. |
| 358 const IceParameters* FindRemoteIceFromUfrag(const std::string& ufrag, | 344 const IceParameters* FindRemoteIceFromUfrag(const std::string& ufrag, |
| 359 uint32_t* generation); | 345 uint32_t* generation); |
| 360 // Returns the index of the latest remote ICE parameters, or 0 if no remote | 346 // Returns the index of the latest remote ICE parameters, or 0 if no remote |
| 361 // ICE parameters have been received. | 347 // ICE parameters have been received. |
| 362 uint32_t remote_ice_generation() { | 348 uint32_t remote_ice_generation() { |
| 363 return remote_ice_parameters_.empty() | 349 return remote_ice_parameters_.empty() |
| 364 ? 0 | 350 ? 0 |
| 365 : static_cast<uint32_t>(remote_ice_parameters_.size() - 1); | 351 : static_cast<uint32_t>(remote_ice_parameters_.size() - 1); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 388 std::set<Connection*> pinged_connections_; | 374 std::set<Connection*> pinged_connections_; |
| 389 std::set<Connection*> unpinged_connections_; | 375 std::set<Connection*> unpinged_connections_; |
| 390 | 376 |
| 391 Connection* selected_connection_ = nullptr; | 377 Connection* selected_connection_ = nullptr; |
| 392 | 378 |
| 393 std::vector<RemoteCandidate> remote_candidates_; | 379 std::vector<RemoteCandidate> remote_candidates_; |
| 394 bool sort_dirty_; // indicates whether another sort is needed right now | 380 bool sort_dirty_; // indicates whether another sort is needed right now |
| 395 bool had_connection_ = false; // if connections_ has ever been nonempty | 381 bool had_connection_ = false; // if connections_ has ever been nonempty |
| 396 typedef std::map<rtc::Socket::Option, int> OptionMap; | 382 typedef std::map<rtc::Socket::Option, int> OptionMap; |
| 397 OptionMap options_; | 383 OptionMap options_; |
| 398 std::string ice_ufrag_; | 384 IceParameters ice_parameters_; |
| 399 std::string ice_pwd_; | |
| 400 std::vector<IceParameters> remote_ice_parameters_; | 385 std::vector<IceParameters> remote_ice_parameters_; |
| 401 IceMode remote_ice_mode_; | 386 IceMode remote_ice_mode_; |
| 402 IceRole ice_role_; | 387 IceRole ice_role_; |
| 403 uint64_t tiebreaker_; | 388 uint64_t tiebreaker_; |
| 404 IceGatheringState gathering_state_; | 389 IceGatheringState gathering_state_; |
| 405 | 390 |
| 406 int check_receiving_interval_; | 391 int check_receiving_interval_; |
| 407 int64_t last_ping_sent_ms_ = 0; | 392 int64_t last_ping_sent_ms_ = 0; |
| 408 int weak_ping_interval_ = WEAK_PING_INTERVAL; | 393 int weak_ping_interval_ = WEAK_PING_INTERVAL; |
| 409 TransportChannelState state_ = TransportChannelState::STATE_INIT; | 394 TransportChannelState state_ = TransportChannelState::STATE_INIT; |
| 410 IceConfig config_; | 395 IceConfig config_; |
| 411 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before. | 396 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before. |
| 412 bool started_pinging_ = false; | 397 bool started_pinging_ = false; |
| 413 // TODO(honghaiz): Put this and ICE role inside ICEParameters and rename this | |
| 414 // as renomination. Set its value in subsequent CLs based on signaling | |
| 415 // exchange. | |
| 416 bool remote_supports_renomination_ = false; | |
| 417 // The value put in the "nomination" attribute for the next nominated | 398 // The value put in the "nomination" attribute for the next nominated |
| 418 // connection. A zero-value indicates the connection will not be nominated. | 399 // connection. A zero-value indicates the connection will not be nominated. |
| 419 uint32_t nomination_ = 0; | 400 uint32_t nomination_ = 0; |
| 420 | 401 |
| 421 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); | 402 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel); |
| 422 }; | 403 }; |
| 423 | 404 |
| 424 } // namespace cricket | 405 } // namespace cricket |
| 425 | 406 |
| 426 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ | 407 #endif // WEBRTC_P2P_BASE_P2PTRANSPORTCHANNEL_H_ |
| OLD | NEW |