blob: 56ca57e11e8e45c3101287e19ed149281ed22524 [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
23#include <map>
kwiberg3ec46792016-04-27 07:22:53 -070024#include <memory>
guoweis36f01372016-03-02 18:02:40 -080025#include <set>
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000026#include <string>
27#include <vector>
kwiberg4485ffb2016-04-26 08:14:39 -070028
Patrik Höglunde2d6a062017-10-05 14:53:33 +020029#include "api/candidate.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "p2p/base/candidatepairinterface.h"
31#include "p2p/base/icetransportinternal.h"
32#include "p2p/base/portallocator.h"
33#include "p2p/base/portinterface.h"
34#include "rtc_base/asyncpacketsocket.h"
35#include "rtc_base/constructormagic.h"
36#include "rtc_base/random.h"
37#include "rtc_base/sigslot.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000038
39namespace cricket {
40
Honghai Zhangd93f50c2016-10-05 11:47:22 -070041// Enum for UMA metrics, used to record whether the channel is
42// connected/connecting/disconnected when ICE restart happens.
43enum class IceRestartState { CONNECTING, CONNECTED, DISCONNECTED, MAX_VALUE };
44
Honghai Zhang049fbb12016-03-07 11:13:07 -080045extern const int WEAK_PING_INTERVAL;
skvlad51072462017-02-02 11:50:14 -080046extern const int STRONG_PING_INTERVAL;
honghaiz7252a002016-11-08 20:04:09 -080047extern const int WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL;
48extern const int STRONG_AND_STABLE_WRITABLE_CONNECTION_PING_INTERVAL;
honghaiz524ecc22016-05-25 12:48:31 -070049static const int MIN_PINGS_AT_WEAK_PING_INTERVAL = 3;
guoweisb0bb77f2015-10-26 15:10:01 -070050
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000051// Adds the port on which the candidate originated.
52class RemoteCandidate : public Candidate {
53 public:
54 RemoteCandidate(const Candidate& c, PortInterface* origin_port)
55 : Candidate(c), origin_port_(origin_port) {}
56
57 PortInterface* origin_port() { return origin_port_; }
58
59 private:
60 PortInterface* origin_port_;
61};
62
63// P2PTransportChannel manages the candidates and connection process to keep
64// two P2P clients connected to each other.
zhihuangd06adf62017-01-12 15:58:31 -080065class P2PTransportChannel : public IceTransportInternal,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000066 public rtc::MessageHandler {
67 public:
deadbeefcbecd352015-09-23 11:50:27 -070068 P2PTransportChannel(const std::string& transport_name,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000069 int component,
mikescarlettb9dd7c52016-02-19 20:43:45 -080070 PortAllocator* allocator);
deadbeefcbecd352015-09-23 11:50:27 -070071 virtual ~P2PTransportChannel();
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000072
73 // From TransportChannelImpl:
zhihuangd06adf62017-01-12 15:58:31 -080074 IceTransportState GetState() const override;
75 const std::string& transport_name() const override { return transport_name_; }
76 int component() const override { return component_; }
77 bool writable() const override { return writable_; }
78 bool receiving() const override { return receiving_; }
Henrik Boströmf3ecdb92015-09-08 12:11:54 +020079 void SetIceRole(IceRole role) override;
80 IceRole GetIceRole() const override { return ice_role_; }
Peter Boström0c4e06b2015-10-07 12:23:21 +020081 void SetIceTiebreaker(uint64_t tiebreaker) override;
Honghai Zhang4cedf2b2016-08-31 08:18:11 -070082 void SetIceParameters(const IceParameters& ice_params) override;
83 void SetRemoteIceParameters(const IceParameters& ice_params) override;
Henrik Boströmf3ecdb92015-09-08 12:11:54 +020084 void SetRemoteIceMode(IceMode mode) override;
deadbeef886815b2016-06-29 15:21:04 -070085 // TODO(deadbeef): Deprecated. Remove when Chromium's
86 // IceTransportChannel does not depend on this.
87 void Connect() {}
deadbeefcbecd352015-09-23 11:50:27 -070088 void MaybeStartGathering() override;
89 IceGatheringState gathering_state() const override {
90 return gathering_state_;
91 }
92 void AddRemoteCandidate(const Candidate& candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -070093 void RemoveRemoteCandidate(const Candidate& candidate) override;
Honghai Zhang049fbb12016-03-07 11:13:07 -080094 // Sets the parameters in IceConfig. We do not set them blindly. Instead, we
95 // only update the parameter if it is considered set in |config|. For example,
96 // a negative value of receiving_timeout will be considered "not set" and we
97 // will not use it to update the respective parameter in |config_|.
deadbeef14f97f52016-06-22 17:14:15 -070098 // TODO(deadbeef): Use rtc::Optional instead of negative values.
honghaiz1f429e32015-09-28 07:57:34 -070099 void SetIceConfig(const IceConfig& config) override;
guoweis36f01372016-03-02 18:02:40 -0800100 const IceConfig& config() const;
Honghai Zhangd93f50c2016-10-05 11:47:22 -0700101 void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000102
103 // From TransportChannel:
deadbeefcbecd352015-09-23 11:50:27 -0700104 int SendPacket(const char* data,
105 size_t len,
106 const rtc::PacketOptions& options,
107 int flags) override;
Henrik Boströmf3ecdb92015-09-08 12:11:54 +0200108 int SetOption(rtc::Socket::Option opt, int value) override;
109 bool GetOption(rtc::Socket::Option opt, int* value) override;
110 int GetError() override { return error_; }
111 bool GetStats(std::vector<ConnectionInfo>* stats) override;
skvladd0309122017-02-02 17:18:37 -0800112 rtc::Optional<int> GetRttEstimate() override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000113
Honghai Zhang8cd7f222016-06-23 13:44:34 -0700114 // TODO(honghaiz): Remove this method once the reference of it in
115 // Chromoting is removed.
116 const Connection* best_connection() const { return selected_connection_; }
117
Honghai Zhang572b0942016-06-23 12:26:57 -0700118 const Connection* selected_connection() const { return selected_connection_; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000119 void set_incoming_only(bool value) { incoming_only_ = value; }
120
Honghai Zhanga74363c2016-07-28 18:06:15 -0700121 // Note: These are only for testing purpose.
122 // |ports_| and |pruned_ports| should not be changed from outside.
Peter Thatcher1fe120a2015-06-10 11:33:17 -0700123 const std::vector<PortInterface*>& ports() { return ports_; }
Honghai Zhanga74363c2016-07-28 18:06:15 -0700124 const std::vector<PortInterface*>& pruned_ports() { return pruned_ports_; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000125
126 IceMode remote_ice_mode() const { return remote_ice_mode_; }
127
Honghai Zhanga74363c2016-07-28 18:06:15 -0700128 void PruneAllPorts();
Honghai Zhang049fbb12016-03-07 11:13:07 -0800129 int receiving_timeout() const { return config_.receiving_timeout; }
130 int check_receiving_interval() const { return check_receiving_interval_; }
Peter Thatcher54360512015-07-08 11:08:35 -0700131
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000132 // Helper method used only in unittest.
133 rtc::DiffServCodePoint DefaultDscpValue() const;
134
Peter Thatcher7351f462015-04-02 16:39:16 -0700135 // Public for unit tests.
136 Connection* FindNextPingableConnection();
guoweis36f01372016-03-02 18:02:40 -0800137 void MarkConnectionPinged(Connection* conn);
Peter Thatcher7351f462015-04-02 16:39:16 -0700138
honghaiz77d0d6e2015-10-27 11:34:45 -0700139 // Public for unit tests.
140 const std::vector<Connection*>& connections() const { return connections_; }
141
honghaiz9b669572015-11-04 12:07:44 -0800142 // Public for unit tests.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000143 PortAllocatorSession* allocator_session() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700144 return allocator_sessions_.back().get();
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000145 }
146
honghaiz112fe432015-12-30 13:32:47 -0800147 // Public for unit tests.
148 const std::vector<RemoteCandidate>& remote_candidates() const {
149 return remote_candidates_;
150 }
151
zhihuangd06adf62017-01-12 15:58:31 -0800152 std::string ToString() const {
153 const char RECEIVING_ABBREV[2] = {'_', 'R'};
154 const char WRITABLE_ABBREV[2] = {'_', 'W'};
155 std::stringstream ss;
156 ss << "Channel[" << transport_name_ << "|" << component_ << "|"
157 << RECEIVING_ABBREV[receiving_] << WRITABLE_ABBREV[writable_] << "]";
158 return ss.str();
159 }
160
honghaiz9b669572015-11-04 12:07:44 -0800161 private:
johan0fd22ef2016-09-29 01:19:20 -0700162 rtc::Thread* thread() const { return network_thread_; }
honghaiz9b669572015-11-04 12:07:44 -0800163 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); }
164
honghaiza58ea782015-09-24 08:13:36 -0700165 // A transport channel is weak if the current best connection is either
166 // not receiving or not writable, or if there is no best connection at all.
Honghai Zhang2b342bf2015-09-30 09:51:58 -0700167 bool weak() const;
skvlad51072462017-02-02 11:50:14 -0800168
169 int weak_ping_interval() const {
170 if (config_.ice_check_min_interval &&
171 weak_ping_interval_ < *config_.ice_check_min_interval) {
172 return *config_.ice_check_min_interval;
173 }
174 return weak_ping_interval_;
175 }
176
177 int strong_ping_interval() const {
178 if (config_.ice_check_min_interval &&
179 STRONG_PING_INTERVAL < *config_.ice_check_min_interval) {
180 return *config_.ice_check_min_interval;
181 }
182 return STRONG_PING_INTERVAL;
183 }
184
Honghai Zhange05bcc22016-08-16 18:19:14 -0700185 // Returns true if it's possible to send packets on |connection|.
186 bool ReadyToSend(Connection* connection) const;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000187 void UpdateConnectionStates();
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700188 void RequestSortAndStateUpdate();
189 // Start pinging if we haven't already started, and we now have a connection
190 // that's pingable.
191 void MaybeStartPinging();
deadbeef14f97f52016-06-22 17:14:15 -0700192
honghaiz9ad0db52016-07-14 19:30:28 -0700193 // The methods below return a positive value if |a| is preferable to |b|,
194 // a negative value if |b| is preferable, and 0 if they're equally preferable.
195 // If |receiving_unchanged_threshold| is set, then when |b| is receiving and
196 // |a| is not, returns a negative value only if |b| has been in receiving
197 // state and |a| has been in not receiving state since
198 // |receiving_unchanged_threshold| and sets
199 // |missed_receiving_unchanged_threshold| to true otherwise.
200 int CompareConnectionStates(
201 const cricket::Connection* a,
202 const cricket::Connection* b,
203 rtc::Optional<int64_t> receiving_unchanged_threshold,
204 bool* missed_receiving_unchanged_threshold) const;
deadbeef14f97f52016-06-22 17:14:15 -0700205 int CompareConnectionCandidates(const cricket::Connection* a,
206 const cricket::Connection* b) const;
Honghai Zhang572b0942016-06-23 12:26:57 -0700207 // Compares two connections based on the connection states
208 // (writable/receiving/connected), nomination states, last data received time,
209 // and static preferences. Does not include latency. Used by both sorting
210 // and ShouldSwitchSelectedConnection().
211 // Returns a positive value if |a| is better than |b|.
deadbeef14f97f52016-06-22 17:14:15 -0700212 int CompareConnections(const cricket::Connection* a,
honghaiz9ad0db52016-07-14 19:30:28 -0700213 const cricket::Connection* b,
214 rtc::Optional<int64_t> receiving_unchanged_threshold,
215 bool* missed_receiving_unchanged_threshold) const;
Honghai Zhang572b0942016-06-23 12:26:57 -0700216
deadbeef14f97f52016-06-22 17:14:15 -0700217 bool PresumedWritable(const cricket::Connection* conn) const;
218
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700219 void SortConnectionsAndUpdateState();
Honghai Zhang572b0942016-06-23 12:26:57 -0700220 void SwitchSelectedConnection(Connection* conn);
Honghai Zhang381b4212015-12-04 12:24:03 -0800221 void UpdateState();
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000222 void HandleAllTimedOut();
honghaiz9b669572015-11-04 12:07:44 -0800223 void MaybeStopPortAllocatorSessions();
zhihuangd06adf62017-01-12 15:58:31 -0800224 IceTransportState ComputeState() const;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000225
sprang716978d2016-10-11 06:43:28 -0700226 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const;
Peter Thatcher04ac81f2015-09-21 11:48:28 -0700227 bool CreateConnections(const Candidate& remote_candidate,
228 PortInterface* origin_port);
229 bool CreateConnection(PortInterface* port,
230 const Candidate& remote_candidate,
231 PortInterface* origin_port);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000232 bool FindConnection(cricket::Connection* connection) const;
233
Peter Boström0c4e06b2015-10-07 12:23:21 +0200234 uint32_t GetRemoteCandidateGeneration(const Candidate& candidate);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000235 bool IsDuplicateRemoteCandidate(const Candidate& candidate);
236 void RememberRemoteCandidate(const Candidate& remote_candidate,
237 PortInterface* origin_port);
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700238 bool IsPingable(const Connection* conn, int64_t now) const;
honghaiz7252a002016-11-08 20:04:09 -0800239 // Whether a writable connection is past its ping interval and needs to be
240 // pinged again.
241 bool WritableConnectionPastPingInterval(const Connection* conn,
242 int64_t now) const;
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700243 int CalculateActiveWritablePingInterval(const Connection* conn,
244 int64_t now) const;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000245 void PingConnection(Connection* conn);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700246 void AddAllocatorSession(std::unique_ptr<PortAllocatorSession> session);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000247 void AddConnection(Connection* connection);
248
249 void OnPortReady(PortAllocatorSession *session, PortInterface* port);
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700250 void OnPortsPruned(PortAllocatorSession* session,
251 const std::vector<PortInterface*>& ports);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000252 void OnCandidatesReady(PortAllocatorSession *session,
253 const std::vector<Candidate>& candidates);
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700254 void OnCandidatesRemoved(PortAllocatorSession* session,
255 const std::vector<Candidate>& candidates);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000256 void OnCandidatesAllocationDone(PortAllocatorSession* session);
257 void OnUnknownAddress(PortInterface* port,
258 const rtc::SocketAddress& addr,
259 ProtocolType proto,
260 IceMessage* stun_msg,
261 const std::string& remote_username,
262 bool port_muxed);
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700263
264 // When a port is destroyed, remove it from both lists |ports_|
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700265 // and |pruned_ports_|.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000266 void OnPortDestroyed(PortInterface* port);
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700267 // When pruning a port, move it from |ports_| to |pruned_ports_|.
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700268 // Returns true if the port is found and removed from |ports_|.
Honghai Zhanga74363c2016-07-28 18:06:15 -0700269 bool PrunePort(PortInterface* port);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000270 void OnRoleConflict(PortInterface* port);
271
272 void OnConnectionStateChange(Connection* connection);
273 void OnReadPacket(Connection *connection, const char *data, size_t len,
274 const rtc::PacketTime& packet_time);
Stefan Holmer55674ff2016-01-14 15:49:16 +0100275 void OnSentPacket(const rtc::SentPacket& sent_packet);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000276 void OnReadyToSend(Connection* connection);
277 void OnConnectionDestroyed(Connection *connection);
278
honghaiz5a3acd82015-08-20 15:53:17 -0700279 void OnNominated(Connection* conn);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000280
deadbeefcbecd352015-09-23 11:50:27 -0700281 void OnMessage(rtc::Message* pmsg) override;
honghaiza58ea782015-09-24 08:13:36 -0700282 void OnCheckAndPing();
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700283 void OnRegatherOnFailedNetworks();
Steve Anton300bf8e2017-07-14 10:13:10 -0700284 void OnRegatherOnAllNetworks();
Peter Thatcher54360512015-07-08 11:08:35 -0700285
Honghai Zhang8cd8f812016-08-03 19:50:41 -0700286 uint32_t GetNominationAttr(Connection* conn) const;
287 bool GetUseCandidateAttr(Connection* conn, NominationMode mode) const;
288
honghaiz9ad0db52016-07-14 19:30:28 -0700289 // Returns true if we should switch to the new connection.
290 // sets |missed_receiving_unchanged_threshold| to true if either
291 // the selected connection or the new connection missed its
292 // receiving-unchanged-threshold.
293 bool ShouldSwitchSelectedConnection(
294 Connection* new_connection,
295 bool* missed_receiving_unchanged_threshold) const;
296 // Returns true if the new_connection is selected for transmission.
297 bool MaybeSwitchSelectedConnection(Connection* new_connection,
298 const std::string& reason);
honghaiz7252a002016-11-08 20:04:09 -0800299 // Gets the best connection for each network.
300 std::map<rtc::Network*, Connection*> GetBestConnectionByNetwork() const;
301 std::vector<Connection*> GetBestWritableConnectionPerNetwork() const;
honghaiz5a3acd82015-08-20 15:53:17 -0700302 void PruneConnections();
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700303 bool IsBackupConnection(const Connection* conn) const;
honghaiz5a3acd82015-08-20 15:53:17 -0700304
honghaiz34b11eb2016-03-16 08:55:44 -0700305 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now);
guoweis36f01372016-03-02 18:02:40 -0800306 // Between |conn1| and |conn2|, this function returns the one which should
307 // be pinged first.
honghaiz7252a002016-11-08 20:04:09 -0800308 Connection* MorePingable(Connection* conn1, Connection* conn2);
guoweis36f01372016-03-02 18:02:40 -0800309 // Select the connection which is Relay/Relay. If both of them are,
310 // UDP relay protocol takes precedence.
311 Connection* MostLikelyToWork(Connection* conn1, Connection* conn2);
312 // Compare the last_ping_sent time and return the one least recently pinged.
313 Connection* LeastRecentlyPinged(Connection* conn1, Connection* conn2);
314
honghaiza54a0802015-12-16 18:37:23 -0800315 // Returns the latest remote ICE parameters or nullptr if there are no remote
316 // ICE parameters yet.
317 IceParameters* remote_ice() {
318 return remote_ice_parameters_.empty() ? nullptr
319 : &remote_ice_parameters_.back();
320 }
honghaiz112fe432015-12-30 13:32:47 -0800321 // Returns the remote IceParameters and generation that match |ufrag|
322 // if found, and returns nullptr otherwise.
323 const IceParameters* FindRemoteIceFromUfrag(const std::string& ufrag,
324 uint32_t* generation);
honghaiza54a0802015-12-16 18:37:23 -0800325 // Returns the index of the latest remote ICE parameters, or 0 if no remote
326 // ICE parameters have been received.
327 uint32_t remote_ice_generation() {
328 return remote_ice_parameters_.empty()
329 ? 0
330 : static_cast<uint32_t>(remote_ice_parameters_.size() - 1);
331 }
332
Steve Anton300bf8e2017-07-14 10:13:10 -0700333 // Samples a delay from the uniform distribution defined by the
334 // regather_on_all_networks_interval ICE configuration pair.
335 int SampleRegatherAllNetworksInterval();
336
337 // Indicates if the given local port has been pruned.
338 bool IsPortPruned(const Port* port) const;
339
340 // Indicates if the given remote candidate has been pruned.
341 bool IsRemoteCandidatePruned(const Candidate& cand) const;
342
zhihuangd06adf62017-01-12 15:58:31 -0800343 // Sets the writable state, signaling if necessary.
344 void set_writable(bool writable);
345 // Sets the receiving state, signaling if necessary.
346 void set_receiving(bool receiving);
347
348 std::string transport_name_;
349 int component_;
deadbeefcbecd352015-09-23 11:50:27 -0700350 PortAllocator* allocator_;
johan0fd22ef2016-09-29 01:19:20 -0700351 rtc::Thread* network_thread_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000352 bool incoming_only_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000353 int error_;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700354 std::vector<std::unique_ptr<PortAllocatorSession>> allocator_sessions_;
deadbeefdfc42442016-06-21 14:19:48 -0700355 // |ports_| contains ports that are used to form new connections when
356 // new remote candidates are added.
357 std::vector<PortInterface*> ports_;
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700358 // |pruned_ports_| contains ports that have been removed from |ports_| and
deadbeefdfc42442016-06-21 14:19:48 -0700359 // are not being used to form new connections, but that aren't yet destroyed.
360 // They may have existing connections, and they still fire signals such as
361 // SignalUnknownAddress.
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700362 std::vector<PortInterface*> pruned_ports_;
guoweis36f01372016-03-02 18:02:40 -0800363
364 // |connections_| is a sorted list with the first one always be the
Honghai Zhang572b0942016-06-23 12:26:57 -0700365 // |selected_connection_| when it's not nullptr. The combination of
guoweis36f01372016-03-02 18:02:40 -0800366 // |pinged_connections_| and |unpinged_connections_| has the same
367 // connections as |connections_|. These 2 sets maintain whether a
368 // connection should be pinged next or not.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000369 std::vector<Connection *> connections_;
guoweis36f01372016-03-02 18:02:40 -0800370 std::set<Connection*> pinged_connections_;
371 std::set<Connection*> unpinged_connections_;
372
Honghai Zhang572b0942016-06-23 12:26:57 -0700373 Connection* selected_connection_ = nullptr;
guoweis36f01372016-03-02 18:02:40 -0800374
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000375 std::vector<RemoteCandidate> remote_candidates_;
376 bool sort_dirty_; // indicates whether another sort is needed right now
deadbeefcbecd352015-09-23 11:50:27 -0700377 bool had_connection_ = false; // if connections_ has ever been nonempty
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000378 typedef std::map<rtc::Socket::Option, int> OptionMap;
379 OptionMap options_;
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700380 IceParameters ice_parameters_;
honghaiza54a0802015-12-16 18:37:23 -0800381 std::vector<IceParameters> remote_ice_parameters_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000382 IceMode remote_ice_mode_;
383 IceRole ice_role_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200384 uint64_t tiebreaker_;
deadbeefcbecd352015-09-23 11:50:27 -0700385 IceGatheringState gathering_state_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000386
Steve Anton300bf8e2017-07-14 10:13:10 -0700387 // Used to generate random intervals for regather_all_networks_interval_range.
388 webrtc::Random rand_;
389
Honghai Zhang049fbb12016-03-07 11:13:07 -0800390 int check_receiving_interval_;
honghaiz34b11eb2016-03-16 08:55:44 -0700391 int64_t last_ping_sent_ms_ = 0;
Honghai Zhang049fbb12016-03-07 11:13:07 -0800392 int weak_ping_interval_ = WEAK_PING_INTERVAL;
zhihuangd06adf62017-01-12 15:58:31 -0800393 IceTransportState state_ = IceTransportState::STATE_INIT;
guoweis36f01372016-03-02 18:02:40 -0800394 IceConfig config_;
Honghai Zhang52dce732016-03-31 12:37:31 -0700395 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before.
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700396 bool started_pinging_ = false;
Honghai Zhang8cd8f812016-08-03 19:50:41 -0700397 // The value put in the "nomination" attribute for the next nominated
398 // connection. A zero-value indicates the connection will not be nominated.
399 uint32_t nomination_ = 0;
zhihuangd06adf62017-01-12 15:58:31 -0800400 bool receiving_ = false;
401 bool writable_ = false;
Peter Thatcher54360512015-07-08 11:08:35 -0700402
Honghai Zhangd93f50c2016-10-05 11:47:22 -0700403 webrtc::MetricsObserverInterface* metrics_observer_ = nullptr;
404
henrikg3c089d72015-09-16 05:37:44 -0700405 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000406};
407
408} // namespace cricket
409
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200410#endif // P2P_BASE_P2PTRANSPORTCHANNEL_H_