blob: d811b631bda39362ad64d5f26ecf8c528eabffe6 [file] [log] [blame]
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +00001/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11// P2PTransportChannel wraps up the state management of the connection between
12// two P2P clients. Clients have candidate ports for connecting, 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
15// Bob are used to make a connection, repeat to make many connections).
16//
17// When all of the available connections become invalid (non-writable), we
18// kick off a process of determining more candidates and more connections.
19//
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#ifndef P2P_BASE_P2PTRANSPORTCHANNEL_H_
21#define P2P_BASE_P2PTRANSPORTCHANNEL_H_
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000022
Qingsi Wange6826d22018-03-08 14:55:14 -080023#include <algorithm>
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000024#include <map>
kwiberg3ec46792016-04-27 07:22:53 -070025#include <memory>
guoweis36f01372016-03-02 18:02:40 -080026#include <set>
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000027#include <string>
28#include <vector>
kwiberg4485ffb2016-04-26 08:14:39 -070029
Patrik Höglunde2d6a062017-10-05 14:53:33 +020030#include "api/candidate.h"
Qingsi Wang93a84392018-01-30 17:13:09 -080031#include "logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h"
32#include "logging/rtc_event_log/icelogger.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020033#include "p2p/base/candidatepairinterface.h"
34#include "p2p/base/icetransportinternal.h"
Qingsi Wang866e08d2018-03-22 17:54:23 -070035#include "p2p/base/p2pconstants.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020036#include "p2p/base/portallocator.h"
37#include "p2p/base/portinterface.h"
38#include "rtc_base/asyncpacketsocket.h"
39#include "rtc_base/constructormagic.h"
40#include "rtc_base/random.h"
41#include "rtc_base/sigslot.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000042
Qingsi Wang93a84392018-01-30 17:13:09 -080043namespace webrtc {
44class RtcEventLog;
45} // namespace webrtc
46
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000047namespace cricket {
48
Honghai Zhangd93f50c2016-10-05 11:47:22 -070049// Enum for UMA metrics, used to record whether the channel is
50// connected/connecting/disconnected when ICE restart happens.
51enum class IceRestartState { CONNECTING, CONNECTED, DISCONNECTED, MAX_VALUE };
52
honghaiz524ecc22016-05-25 12:48:31 -070053static const int MIN_PINGS_AT_WEAK_PING_INTERVAL = 3;
guoweisb0bb77f2015-10-26 15:10:01 -070054
Taylor Brandstetter6e2e7ce2017-12-19 10:26:23 -080055bool IceCredentialsChanged(const std::string& old_ufrag,
56 const std::string& old_pwd,
57 const std::string& new_ufrag,
58 const std::string& new_pwd);
59
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000060// Adds the port on which the candidate originated.
61class RemoteCandidate : public Candidate {
62 public:
63 RemoteCandidate(const Candidate& c, PortInterface* origin_port)
64 : Candidate(c), origin_port_(origin_port) {}
65
66 PortInterface* origin_port() { return origin_port_; }
67
68 private:
69 PortInterface* origin_port_;
70};
71
72// P2PTransportChannel manages the candidates and connection process to keep
73// two P2P clients connected to each other.
zhihuangd06adf62017-01-12 15:58:31 -080074class P2PTransportChannel : public IceTransportInternal,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000075 public rtc::MessageHandler {
76 public:
deadbeefcbecd352015-09-23 11:50:27 -070077 P2PTransportChannel(const std::string& transport_name,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000078 int component,
Qingsi Wang93a84392018-01-30 17:13:09 -080079 PortAllocator* allocator,
80 webrtc::RtcEventLog* event_log = nullptr);
Steve Anton33f69db2017-10-30 10:01:15 -070081 ~P2PTransportChannel() override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000082
83 // From TransportChannelImpl:
zhihuangd06adf62017-01-12 15:58:31 -080084 IceTransportState GetState() const override;
Steve Anton33f69db2017-10-30 10:01:15 -070085 const std::string& transport_name() const override;
86 int component() const override;
87 bool writable() const override;
88 bool receiving() const override;
Henrik Boströmf3ecdb92015-09-08 12:11:54 +020089 void SetIceRole(IceRole role) override;
Steve Anton33f69db2017-10-30 10:01:15 -070090 IceRole GetIceRole() const override;
Peter Boström0c4e06b2015-10-07 12:23:21 +020091 void SetIceTiebreaker(uint64_t tiebreaker) override;
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070092 void SetIceParameters(const IceParameters& ice_params) override;
93 void SetRemoteIceParameters(const IceParameters& ice_params) override;
Henrik Boströmf3ecdb92015-09-08 12:11:54 +020094 void SetRemoteIceMode(IceMode mode) override;
deadbeef886815b2016-06-29 15:21:04 -070095 // TODO(deadbeef): Deprecated. Remove when Chromium's
96 // IceTransportChannel does not depend on this.
97 void Connect() {}
deadbeefcbecd352015-09-23 11:50:27 -070098 void MaybeStartGathering() override;
Steve Anton33f69db2017-10-30 10:01:15 -070099 IceGatheringState gathering_state() const override;
deadbeefcbecd352015-09-23 11:50:27 -0700100 void AddRemoteCandidate(const Candidate& candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700101 void RemoveRemoteCandidate(const Candidate& candidate) override;
Honghai Zhang049fbb12016-03-07 11:13:07 -0800102 // Sets the parameters in IceConfig. We do not set them blindly. Instead, we
103 // only update the parameter if it is considered set in |config|. For example,
104 // a negative value of receiving_timeout will be considered "not set" and we
105 // will not use it to update the respective parameter in |config_|.
deadbeef14f97f52016-06-22 17:14:15 -0700106 // TODO(deadbeef): Use rtc::Optional instead of negative values.
honghaiz1f429e32015-09-28 07:57:34 -0700107 void SetIceConfig(const IceConfig& config) override;
guoweis36f01372016-03-02 18:02:40 -0800108 const IceConfig& config() const;
Honghai Zhangd93f50c2016-10-05 11:47:22 -0700109 void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000110
111 // From TransportChannel:
deadbeefcbecd352015-09-23 11:50:27 -0700112 int SendPacket(const char* data,
113 size_t len,
114 const rtc::PacketOptions& options,
115 int flags) override;
Henrik Boströmf3ecdb92015-09-08 12:11:54 +0200116 int SetOption(rtc::Socket::Option opt, int value) override;
117 bool GetOption(rtc::Socket::Option opt, int* value) override;
Steve Anton33f69db2017-10-30 10:01:15 -0700118 int GetError() override;
Qingsi Wang72a43a12018-02-20 16:03:18 -0800119 bool GetStats(std::vector<ConnectionInfo>* candidate_pair_stats_list,
120 std::vector<CandidateStats>* candidate_stats_list) override;
skvladd0309122017-02-02 17:18:37 -0800121 rtc::Optional<int> GetRttEstimate() override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000122
Honghai Zhang8cd7f222016-06-23 13:44:34 -0700123 // TODO(honghaiz): Remove this method once the reference of it in
124 // Chromoting is removed.
125 const Connection* best_connection() const { return selected_connection_; }
126
Honghai Zhang572b0942016-06-23 12:26:57 -0700127 const Connection* selected_connection() const { return selected_connection_; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000128 void set_incoming_only(bool value) { incoming_only_ = value; }
129
Honghai Zhanga74363c2016-07-28 18:06:15 -0700130 // Note: These are only for testing purpose.
131 // |ports_| and |pruned_ports| should not be changed from outside.
Peter Thatcher1fe120a2015-06-10 11:33:17 -0700132 const std::vector<PortInterface*>& ports() { return ports_; }
Honghai Zhanga74363c2016-07-28 18:06:15 -0700133 const std::vector<PortInterface*>& pruned_ports() { return pruned_ports_; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000134
135 IceMode remote_ice_mode() const { return remote_ice_mode_; }
136
Honghai Zhanga74363c2016-07-28 18:06:15 -0700137 void PruneAllPorts();
Qingsi Wang866e08d2018-03-22 17:54:23 -0700138 int check_receiving_interval() const;
Zhi Huang942bc2e2017-11-13 13:26:07 -0800139 rtc::Optional<rtc::NetworkRoute> network_route() const override;
140
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000141 // Helper method used only in unittest.
142 rtc::DiffServCodePoint DefaultDscpValue() const;
143
Peter Thatcher7351f462015-04-02 16:39:16 -0700144 // Public for unit tests.
145 Connection* FindNextPingableConnection();
guoweis36f01372016-03-02 18:02:40 -0800146 void MarkConnectionPinged(Connection* conn);
Peter Thatcher7351f462015-04-02 16:39:16 -0700147
honghaiz77d0d6e2015-10-27 11:34:45 -0700148 // Public for unit tests.
149 const std::vector<Connection*>& connections() const { return connections_; }
150
honghaiz9b669572015-11-04 12:07:44 -0800151 // Public for unit tests.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000152 PortAllocatorSession* allocator_session() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700153 return allocator_sessions_.back().get();
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000154 }
155
honghaiz112fe432015-12-30 13:32:47 -0800156 // Public for unit tests.
157 const std::vector<RemoteCandidate>& remote_candidates() const {
158 return remote_candidates_;
159 }
160
zhihuangd06adf62017-01-12 15:58:31 -0800161 std::string ToString() const {
162 const char RECEIVING_ABBREV[2] = {'_', 'R'};
163 const char WRITABLE_ABBREV[2] = {'_', 'W'};
164 std::stringstream ss;
165 ss << "Channel[" << transport_name_ << "|" << component_ << "|"
166 << RECEIVING_ABBREV[receiving_] << WRITABLE_ABBREV[writable_] << "]";
167 return ss.str();
168 }
169
honghaiz9b669572015-11-04 12:07:44 -0800170 private:
johan0fd22ef2016-09-29 01:19:20 -0700171 rtc::Thread* thread() const { return network_thread_; }
honghaiz9b669572015-11-04 12:07:44 -0800172 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); }
173
honghaiza58ea782015-09-24 08:13:36 -0700174 // A transport channel is weak if the current best connection is either
175 // not receiving or not writable, or if there is no best connection at all.
Honghai Zhang2b342bf2015-09-30 09:51:58 -0700176 bool weak() const;
skvlad51072462017-02-02 11:50:14 -0800177
178 int weak_ping_interval() const {
Qingsi Wang866e08d2018-03-22 17:54:23 -0700179 return std::max(config_.ice_check_interval_weak_connectivity_or_default(),
180 config_.ice_check_min_interval_or_default());
skvlad51072462017-02-02 11:50:14 -0800181 }
182
183 int strong_ping_interval() const {
Qingsi Wang866e08d2018-03-22 17:54:23 -0700184 return std::max(config_.ice_check_interval_strong_connectivity_or_default(),
185 config_.ice_check_min_interval_or_default());
skvlad51072462017-02-02 11:50:14 -0800186 }
187
Honghai Zhange05bcc22016-08-16 18:19:14 -0700188 // Returns true if it's possible to send packets on |connection|.
189 bool ReadyToSend(Connection* connection) const;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000190 void UpdateConnectionStates();
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700191 void RequestSortAndStateUpdate();
192 // Start pinging if we haven't already started, and we now have a connection
193 // that's pingable.
194 void MaybeStartPinging();
deadbeef14f97f52016-06-22 17:14:15 -0700195
Qingsi Wang9a5c6f82018-02-01 10:38:40 -0800196 int CompareCandidatePairNetworks(
197 const Connection* a,
198 const Connection* b,
199 rtc::Optional<rtc::AdapterType> network_preference) const;
200
honghaiz9ad0db52016-07-14 19:30:28 -0700201 // The methods below return a positive value if |a| is preferable to |b|,
202 // a negative value if |b| is preferable, and 0 if they're equally preferable.
203 // If |receiving_unchanged_threshold| is set, then when |b| is receiving and
204 // |a| is not, returns a negative value only if |b| has been in receiving
205 // state and |a| has been in not receiving state since
206 // |receiving_unchanged_threshold| and sets
207 // |missed_receiving_unchanged_threshold| to true otherwise.
208 int CompareConnectionStates(
209 const cricket::Connection* a,
210 const cricket::Connection* b,
211 rtc::Optional<int64_t> receiving_unchanged_threshold,
212 bool* missed_receiving_unchanged_threshold) const;
deadbeef14f97f52016-06-22 17:14:15 -0700213 int CompareConnectionCandidates(const cricket::Connection* a,
214 const cricket::Connection* b) const;
Honghai Zhang572b0942016-06-23 12:26:57 -0700215 // Compares two connections based on the connection states
216 // (writable/receiving/connected), nomination states, last data received time,
217 // and static preferences. Does not include latency. Used by both sorting
218 // and ShouldSwitchSelectedConnection().
219 // Returns a positive value if |a| is better than |b|.
deadbeef14f97f52016-06-22 17:14:15 -0700220 int CompareConnections(const cricket::Connection* a,
honghaiz9ad0db52016-07-14 19:30:28 -0700221 const cricket::Connection* b,
222 rtc::Optional<int64_t> receiving_unchanged_threshold,
223 bool* missed_receiving_unchanged_threshold) const;
Honghai Zhang572b0942016-06-23 12:26:57 -0700224
deadbeef14f97f52016-06-22 17:14:15 -0700225 bool PresumedWritable(const cricket::Connection* conn) const;
226
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700227 void SortConnectionsAndUpdateState();
Honghai Zhang572b0942016-06-23 12:26:57 -0700228 void SwitchSelectedConnection(Connection* conn);
Honghai Zhang381b4212015-12-04 12:24:03 -0800229 void UpdateState();
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000230 void HandleAllTimedOut();
honghaiz9b669572015-11-04 12:07:44 -0800231 void MaybeStopPortAllocatorSessions();
zhihuangd06adf62017-01-12 15:58:31 -0800232 IceTransportState ComputeState() const;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000233
sprang716978d2016-10-11 06:43:28 -0700234 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const;
Peter Thatcher04ac81f2015-09-21 11:48:28 -0700235 bool CreateConnections(const Candidate& remote_candidate,
236 PortInterface* origin_port);
237 bool CreateConnection(PortInterface* port,
238 const Candidate& remote_candidate,
239 PortInterface* origin_port);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000240 bool FindConnection(cricket::Connection* connection) const;
241
Peter Boström0c4e06b2015-10-07 12:23:21 +0200242 uint32_t GetRemoteCandidateGeneration(const Candidate& candidate);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000243 bool IsDuplicateRemoteCandidate(const Candidate& candidate);
244 void RememberRemoteCandidate(const Candidate& remote_candidate,
245 PortInterface* origin_port);
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700246 bool IsPingable(const Connection* conn, int64_t now) const;
honghaiz7252a002016-11-08 20:04:09 -0800247 // Whether a writable connection is past its ping interval and needs to be
248 // pinged again.
249 bool WritableConnectionPastPingInterval(const Connection* conn,
250 int64_t now) const;
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700251 int CalculateActiveWritablePingInterval(const Connection* conn,
252 int64_t now) const;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000253 void PingConnection(Connection* conn);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700254 void AddAllocatorSession(std::unique_ptr<PortAllocatorSession> session);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000255 void AddConnection(Connection* connection);
256
257 void OnPortReady(PortAllocatorSession *session, PortInterface* port);
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700258 void OnPortsPruned(PortAllocatorSession* session,
259 const std::vector<PortInterface*>& ports);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000260 void OnCandidatesReady(PortAllocatorSession *session,
261 const std::vector<Candidate>& candidates);
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700262 void OnCandidatesRemoved(PortAllocatorSession* session,
263 const std::vector<Candidate>& candidates);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000264 void OnCandidatesAllocationDone(PortAllocatorSession* session);
265 void OnUnknownAddress(PortInterface* port,
266 const rtc::SocketAddress& addr,
267 ProtocolType proto,
268 IceMessage* stun_msg,
269 const std::string& remote_username,
270 bool port_muxed);
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700271
272 // When a port is destroyed, remove it from both lists |ports_|
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700273 // and |pruned_ports_|.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000274 void OnPortDestroyed(PortInterface* port);
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700275 // When pruning a port, move it from |ports_| to |pruned_ports_|.
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700276 // Returns true if the port is found and removed from |ports_|.
Honghai Zhanga74363c2016-07-28 18:06:15 -0700277 bool PrunePort(PortInterface* port);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000278 void OnRoleConflict(PortInterface* port);
279
280 void OnConnectionStateChange(Connection* connection);
281 void OnReadPacket(Connection *connection, const char *data, size_t len,
282 const rtc::PacketTime& packet_time);
Stefan Holmer55674ff2016-01-14 15:49:16 +0100283 void OnSentPacket(const rtc::SentPacket& sent_packet);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000284 void OnReadyToSend(Connection* connection);
285 void OnConnectionDestroyed(Connection *connection);
286
honghaiz5a3acd82015-08-20 15:53:17 -0700287 void OnNominated(Connection* conn);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000288
deadbeefcbecd352015-09-23 11:50:27 -0700289 void OnMessage(rtc::Message* pmsg) override;
honghaiza58ea782015-09-24 08:13:36 -0700290 void OnCheckAndPing();
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700291 void OnRegatherOnFailedNetworks();
Steve Anton300bf8e2017-07-14 10:13:10 -0700292 void OnRegatherOnAllNetworks();
Peter Thatcher54360512015-07-08 11:08:35 -0700293
Qingsi Wang93a84392018-01-30 17:13:09 -0800294 void LogCandidatePairEvent(Connection* conn,
295 webrtc::IceCandidatePairEventType type);
296
Honghai Zhang8cd8f812016-08-03 19:50:41 -0700297 uint32_t GetNominationAttr(Connection* conn) const;
298 bool GetUseCandidateAttr(Connection* conn, NominationMode mode) const;
299
honghaiz9ad0db52016-07-14 19:30:28 -0700300 // Returns true if we should switch to the new connection.
301 // sets |missed_receiving_unchanged_threshold| to true if either
302 // the selected connection or the new connection missed its
303 // receiving-unchanged-threshold.
304 bool ShouldSwitchSelectedConnection(
305 Connection* new_connection,
306 bool* missed_receiving_unchanged_threshold) const;
307 // Returns true if the new_connection is selected for transmission.
308 bool MaybeSwitchSelectedConnection(Connection* new_connection,
309 const std::string& reason);
honghaiz7252a002016-11-08 20:04:09 -0800310 // Gets the best connection for each network.
311 std::map<rtc::Network*, Connection*> GetBestConnectionByNetwork() const;
312 std::vector<Connection*> GetBestWritableConnectionPerNetwork() const;
honghaiz5a3acd82015-08-20 15:53:17 -0700313 void PruneConnections();
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700314 bool IsBackupConnection(const Connection* conn) const;
honghaiz5a3acd82015-08-20 15:53:17 -0700315
honghaiz34b11eb2016-03-16 08:55:44 -0700316 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now);
guoweis36f01372016-03-02 18:02:40 -0800317 // Between |conn1| and |conn2|, this function returns the one which should
318 // be pinged first.
honghaiz7252a002016-11-08 20:04:09 -0800319 Connection* MorePingable(Connection* conn1, Connection* conn2);
guoweis36f01372016-03-02 18:02:40 -0800320 // Select the connection which is Relay/Relay. If both of them are,
321 // UDP relay protocol takes precedence.
322 Connection* MostLikelyToWork(Connection* conn1, Connection* conn2);
323 // Compare the last_ping_sent time and return the one least recently pinged.
324 Connection* LeastRecentlyPinged(Connection* conn1, Connection* conn2);
325
honghaiza54a0802015-12-16 18:37:23 -0800326 // Returns the latest remote ICE parameters or nullptr if there are no remote
327 // ICE parameters yet.
328 IceParameters* remote_ice() {
329 return remote_ice_parameters_.empty() ? nullptr
330 : &remote_ice_parameters_.back();
331 }
honghaiz112fe432015-12-30 13:32:47 -0800332 // Returns the remote IceParameters and generation that match |ufrag|
333 // if found, and returns nullptr otherwise.
334 const IceParameters* FindRemoteIceFromUfrag(const std::string& ufrag,
335 uint32_t* generation);
honghaiza54a0802015-12-16 18:37:23 -0800336 // Returns the index of the latest remote ICE parameters, or 0 if no remote
337 // ICE parameters have been received.
338 uint32_t remote_ice_generation() {
339 return remote_ice_parameters_.empty()
340 ? 0
341 : static_cast<uint32_t>(remote_ice_parameters_.size() - 1);
342 }
343
Steve Anton300bf8e2017-07-14 10:13:10 -0700344 // Samples a delay from the uniform distribution defined by the
345 // regather_on_all_networks_interval ICE configuration pair.
346 int SampleRegatherAllNetworksInterval();
347
348 // Indicates if the given local port has been pruned.
349 bool IsPortPruned(const Port* port) const;
350
351 // Indicates if the given remote candidate has been pruned.
352 bool IsRemoteCandidatePruned(const Candidate& cand) const;
353
zhihuangd06adf62017-01-12 15:58:31 -0800354 // Sets the writable state, signaling if necessary.
355 void set_writable(bool writable);
356 // Sets the receiving state, signaling if necessary.
357 void set_receiving(bool receiving);
358
359 std::string transport_name_;
360 int component_;
deadbeefcbecd352015-09-23 11:50:27 -0700361 PortAllocator* allocator_;
johan0fd22ef2016-09-29 01:19:20 -0700362 rtc::Thread* network_thread_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000363 bool incoming_only_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000364 int error_;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700365 std::vector<std::unique_ptr<PortAllocatorSession>> allocator_sessions_;
deadbeefdfc42442016-06-21 14:19:48 -0700366 // |ports_| contains ports that are used to form new connections when
367 // new remote candidates are added.
368 std::vector<PortInterface*> ports_;
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700369 // |pruned_ports_| contains ports that have been removed from |ports_| and
deadbeefdfc42442016-06-21 14:19:48 -0700370 // are not being used to form new connections, but that aren't yet destroyed.
371 // They may have existing connections, and they still fire signals such as
372 // SignalUnknownAddress.
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700373 std::vector<PortInterface*> pruned_ports_;
guoweis36f01372016-03-02 18:02:40 -0800374
375 // |connections_| is a sorted list with the first one always be the
Honghai Zhang572b0942016-06-23 12:26:57 -0700376 // |selected_connection_| when it's not nullptr. The combination of
guoweis36f01372016-03-02 18:02:40 -0800377 // |pinged_connections_| and |unpinged_connections_| has the same
378 // connections as |connections_|. These 2 sets maintain whether a
379 // connection should be pinged next or not.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000380 std::vector<Connection *> connections_;
guoweis36f01372016-03-02 18:02:40 -0800381 std::set<Connection*> pinged_connections_;
382 std::set<Connection*> unpinged_connections_;
383
Honghai Zhang572b0942016-06-23 12:26:57 -0700384 Connection* selected_connection_ = nullptr;
guoweis36f01372016-03-02 18:02:40 -0800385
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000386 std::vector<RemoteCandidate> remote_candidates_;
387 bool sort_dirty_; // indicates whether another sort is needed right now
deadbeefcbecd352015-09-23 11:50:27 -0700388 bool had_connection_ = false; // if connections_ has ever been nonempty
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000389 typedef std::map<rtc::Socket::Option, int> OptionMap;
390 OptionMap options_;
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700391 IceParameters ice_parameters_;
honghaiza54a0802015-12-16 18:37:23 -0800392 std::vector<IceParameters> remote_ice_parameters_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000393 IceMode remote_ice_mode_;
394 IceRole ice_role_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200395 uint64_t tiebreaker_;
deadbeefcbecd352015-09-23 11:50:27 -0700396 IceGatheringState gathering_state_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000397
Steve Anton300bf8e2017-07-14 10:13:10 -0700398 // Used to generate random intervals for regather_all_networks_interval_range.
399 webrtc::Random rand_;
400
honghaiz34b11eb2016-03-16 08:55:44 -0700401 int64_t last_ping_sent_ms_ = 0;
Honghai Zhang049fbb12016-03-07 11:13:07 -0800402 int weak_ping_interval_ = WEAK_PING_INTERVAL;
zhihuangd06adf62017-01-12 15:58:31 -0800403 IceTransportState state_ = IceTransportState::STATE_INIT;
guoweis36f01372016-03-02 18:02:40 -0800404 IceConfig config_;
Honghai Zhang52dce732016-03-31 12:37:31 -0700405 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before.
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700406 bool started_pinging_ = false;
Honghai Zhang8cd8f812016-08-03 19:50:41 -0700407 // The value put in the "nomination" attribute for the next nominated
408 // connection. A zero-value indicates the connection will not be nominated.
409 uint32_t nomination_ = 0;
zhihuangd06adf62017-01-12 15:58:31 -0800410 bool receiving_ = false;
411 bool writable_ = false;
Peter Thatcher54360512015-07-08 11:08:35 -0700412
Honghai Zhangd93f50c2016-10-05 11:47:22 -0700413 webrtc::MetricsObserverInterface* metrics_observer_ = nullptr;
414
Zhi Huang942bc2e2017-11-13 13:26:07 -0800415 rtc::Optional<rtc::NetworkRoute> network_route_;
416
Qingsi Wang93a84392018-01-30 17:13:09 -0800417 webrtc::IceEventLog ice_event_log_;
418
henrikg3c089d72015-09-16 05:37:44 -0700419 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000420};
421
422} // namespace cricket
423
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200424#endif // P2P_BASE_P2PTRANSPORTCHANNEL_H_