blob: f9e9a53761dd4899a14c9034db4ee4bc722b3536 [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);
Steve Anton33f69db2017-10-30 10:01:15 -070071 ~P2PTransportChannel() override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000072
73 // From TransportChannelImpl:
zhihuangd06adf62017-01-12 15:58:31 -080074 IceTransportState GetState() const override;
Steve Anton33f69db2017-10-30 10:01:15 -070075 const std::string& transport_name() const override;
76 int component() const override;
77 bool writable() const override;
78 bool receiving() const override;
Henrik Boströmf3ecdb92015-09-08 12:11:54 +020079 void SetIceRole(IceRole role) override;
Steve Anton33f69db2017-10-30 10:01:15 -070080 IceRole GetIceRole() const override;
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;
Steve Anton33f69db2017-10-30 10:01:15 -070089 IceGatheringState gathering_state() const override;
deadbeefcbecd352015-09-23 11:50:27 -070090 void AddRemoteCandidate(const Candidate& candidate) override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -070091 void RemoveRemoteCandidate(const Candidate& candidate) override;
Honghai Zhang049fbb12016-03-07 11:13:07 -080092 // Sets the parameters in IceConfig. We do not set them blindly. Instead, we
93 // only update the parameter if it is considered set in |config|. For example,
94 // a negative value of receiving_timeout will be considered "not set" and we
95 // will not use it to update the respective parameter in |config_|.
deadbeef14f97f52016-06-22 17:14:15 -070096 // TODO(deadbeef): Use rtc::Optional instead of negative values.
honghaiz1f429e32015-09-28 07:57:34 -070097 void SetIceConfig(const IceConfig& config) override;
guoweis36f01372016-03-02 18:02:40 -080098 const IceConfig& config() const;
Honghai Zhangd93f50c2016-10-05 11:47:22 -070099 void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000100
101 // From TransportChannel:
deadbeefcbecd352015-09-23 11:50:27 -0700102 int SendPacket(const char* data,
103 size_t len,
104 const rtc::PacketOptions& options,
105 int flags) override;
Henrik Boströmf3ecdb92015-09-08 12:11:54 +0200106 int SetOption(rtc::Socket::Option opt, int value) override;
107 bool GetOption(rtc::Socket::Option opt, int* value) override;
Steve Anton33f69db2017-10-30 10:01:15 -0700108 int GetError() override;
Henrik Boströmf3ecdb92015-09-08 12:11:54 +0200109 bool GetStats(std::vector<ConnectionInfo>* stats) override;
skvladd0309122017-02-02 17:18:37 -0800110 rtc::Optional<int> GetRttEstimate() override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000111
Honghai Zhang8cd7f222016-06-23 13:44:34 -0700112 // TODO(honghaiz): Remove this method once the reference of it in
113 // Chromoting is removed.
114 const Connection* best_connection() const { return selected_connection_; }
115
Honghai Zhang572b0942016-06-23 12:26:57 -0700116 const Connection* selected_connection() const { return selected_connection_; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000117 void set_incoming_only(bool value) { incoming_only_ = value; }
118
Honghai Zhanga74363c2016-07-28 18:06:15 -0700119 // Note: These are only for testing purpose.
120 // |ports_| and |pruned_ports| should not be changed from outside.
Peter Thatcher1fe120a2015-06-10 11:33:17 -0700121 const std::vector<PortInterface*>& ports() { return ports_; }
Honghai Zhanga74363c2016-07-28 18:06:15 -0700122 const std::vector<PortInterface*>& pruned_ports() { return pruned_ports_; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000123
124 IceMode remote_ice_mode() const { return remote_ice_mode_; }
125
Honghai Zhanga74363c2016-07-28 18:06:15 -0700126 void PruneAllPorts();
Honghai Zhang049fbb12016-03-07 11:13:07 -0800127 int receiving_timeout() const { return config_.receiving_timeout; }
128 int check_receiving_interval() const { return check_receiving_interval_; }
Peter Thatcher54360512015-07-08 11:08:35 -0700129
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000130 // Helper method used only in unittest.
131 rtc::DiffServCodePoint DefaultDscpValue() const;
132
Peter Thatcher7351f462015-04-02 16:39:16 -0700133 // Public for unit tests.
134 Connection* FindNextPingableConnection();
guoweis36f01372016-03-02 18:02:40 -0800135 void MarkConnectionPinged(Connection* conn);
Peter Thatcher7351f462015-04-02 16:39:16 -0700136
honghaiz77d0d6e2015-10-27 11:34:45 -0700137 // Public for unit tests.
138 const std::vector<Connection*>& connections() const { return connections_; }
139
honghaiz9b669572015-11-04 12:07:44 -0800140 // Public for unit tests.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000141 PortAllocatorSession* allocator_session() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700142 return allocator_sessions_.back().get();
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000143 }
144
honghaiz112fe432015-12-30 13:32:47 -0800145 // Public for unit tests.
146 const std::vector<RemoteCandidate>& remote_candidates() const {
147 return remote_candidates_;
148 }
149
zhihuangd06adf62017-01-12 15:58:31 -0800150 std::string ToString() const {
151 const char RECEIVING_ABBREV[2] = {'_', 'R'};
152 const char WRITABLE_ABBREV[2] = {'_', 'W'};
153 std::stringstream ss;
154 ss << "Channel[" << transport_name_ << "|" << component_ << "|"
155 << RECEIVING_ABBREV[receiving_] << WRITABLE_ABBREV[writable_] << "]";
156 return ss.str();
157 }
158
honghaiz9b669572015-11-04 12:07:44 -0800159 private:
johan0fd22ef2016-09-29 01:19:20 -0700160 rtc::Thread* thread() const { return network_thread_; }
honghaiz9b669572015-11-04 12:07:44 -0800161 bool IsGettingPorts() { return allocator_session()->IsGettingPorts(); }
162
honghaiza58ea782015-09-24 08:13:36 -0700163 // A transport channel is weak if the current best connection is either
164 // not receiving or not writable, or if there is no best connection at all.
Honghai Zhang2b342bf2015-09-30 09:51:58 -0700165 bool weak() const;
skvlad51072462017-02-02 11:50:14 -0800166
167 int weak_ping_interval() const {
168 if (config_.ice_check_min_interval &&
169 weak_ping_interval_ < *config_.ice_check_min_interval) {
170 return *config_.ice_check_min_interval;
171 }
172 return weak_ping_interval_;
173 }
174
175 int strong_ping_interval() const {
176 if (config_.ice_check_min_interval &&
177 STRONG_PING_INTERVAL < *config_.ice_check_min_interval) {
178 return *config_.ice_check_min_interval;
179 }
180 return STRONG_PING_INTERVAL;
181 }
182
Honghai Zhange05bcc22016-08-16 18:19:14 -0700183 // Returns true if it's possible to send packets on |connection|.
184 bool ReadyToSend(Connection* connection) const;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000185 void UpdateConnectionStates();
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700186 void RequestSortAndStateUpdate();
187 // Start pinging if we haven't already started, and we now have a connection
188 // that's pingable.
189 void MaybeStartPinging();
deadbeef14f97f52016-06-22 17:14:15 -0700190
honghaiz9ad0db52016-07-14 19:30:28 -0700191 // The methods below return a positive value if |a| is preferable to |b|,
192 // a negative value if |b| is preferable, and 0 if they're equally preferable.
193 // If |receiving_unchanged_threshold| is set, then when |b| is receiving and
194 // |a| is not, returns a negative value only if |b| has been in receiving
195 // state and |a| has been in not receiving state since
196 // |receiving_unchanged_threshold| and sets
197 // |missed_receiving_unchanged_threshold| to true otherwise.
198 int CompareConnectionStates(
199 const cricket::Connection* a,
200 const cricket::Connection* b,
201 rtc::Optional<int64_t> receiving_unchanged_threshold,
202 bool* missed_receiving_unchanged_threshold) const;
deadbeef14f97f52016-06-22 17:14:15 -0700203 int CompareConnectionCandidates(const cricket::Connection* a,
204 const cricket::Connection* b) const;
Honghai Zhang572b0942016-06-23 12:26:57 -0700205 // Compares two connections based on the connection states
206 // (writable/receiving/connected), nomination states, last data received time,
207 // and static preferences. Does not include latency. Used by both sorting
208 // and ShouldSwitchSelectedConnection().
209 // Returns a positive value if |a| is better than |b|.
deadbeef14f97f52016-06-22 17:14:15 -0700210 int CompareConnections(const cricket::Connection* a,
honghaiz9ad0db52016-07-14 19:30:28 -0700211 const cricket::Connection* b,
212 rtc::Optional<int64_t> receiving_unchanged_threshold,
213 bool* missed_receiving_unchanged_threshold) const;
Honghai Zhang572b0942016-06-23 12:26:57 -0700214
deadbeef14f97f52016-06-22 17:14:15 -0700215 bool PresumedWritable(const cricket::Connection* conn) const;
216
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700217 void SortConnectionsAndUpdateState();
Honghai Zhang572b0942016-06-23 12:26:57 -0700218 void SwitchSelectedConnection(Connection* conn);
Honghai Zhang381b4212015-12-04 12:24:03 -0800219 void UpdateState();
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000220 void HandleAllTimedOut();
honghaiz9b669572015-11-04 12:07:44 -0800221 void MaybeStopPortAllocatorSessions();
zhihuangd06adf62017-01-12 15:58:31 -0800222 IceTransportState ComputeState() const;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000223
sprang716978d2016-10-11 06:43:28 -0700224 Connection* GetBestConnectionOnNetwork(rtc::Network* network) const;
Peter Thatcher04ac81f2015-09-21 11:48:28 -0700225 bool CreateConnections(const Candidate& remote_candidate,
226 PortInterface* origin_port);
227 bool CreateConnection(PortInterface* port,
228 const Candidate& remote_candidate,
229 PortInterface* origin_port);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000230 bool FindConnection(cricket::Connection* connection) const;
231
Peter Boström0c4e06b2015-10-07 12:23:21 +0200232 uint32_t GetRemoteCandidateGeneration(const Candidate& candidate);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000233 bool IsDuplicateRemoteCandidate(const Candidate& candidate);
234 void RememberRemoteCandidate(const Candidate& remote_candidate,
235 PortInterface* origin_port);
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700236 bool IsPingable(const Connection* conn, int64_t now) const;
honghaiz7252a002016-11-08 20:04:09 -0800237 // Whether a writable connection is past its ping interval and needs to be
238 // pinged again.
239 bool WritableConnectionPastPingInterval(const Connection* conn,
240 int64_t now) const;
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700241 int CalculateActiveWritablePingInterval(const Connection* conn,
242 int64_t now) const;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000243 void PingConnection(Connection* conn);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700244 void AddAllocatorSession(std::unique_ptr<PortAllocatorSession> session);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000245 void AddConnection(Connection* connection);
246
247 void OnPortReady(PortAllocatorSession *session, PortInterface* port);
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700248 void OnPortsPruned(PortAllocatorSession* session,
249 const std::vector<PortInterface*>& ports);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000250 void OnCandidatesReady(PortAllocatorSession *session,
251 const std::vector<Candidate>& candidates);
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700252 void OnCandidatesRemoved(PortAllocatorSession* session,
253 const std::vector<Candidate>& candidates);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000254 void OnCandidatesAllocationDone(PortAllocatorSession* session);
255 void OnUnknownAddress(PortInterface* port,
256 const rtc::SocketAddress& addr,
257 ProtocolType proto,
258 IceMessage* stun_msg,
259 const std::string& remote_username,
260 bool port_muxed);
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700261
262 // When a port is destroyed, remove it from both lists |ports_|
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700263 // and |pruned_ports_|.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000264 void OnPortDestroyed(PortInterface* port);
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700265 // When pruning a port, move it from |ports_| to |pruned_ports_|.
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700266 // Returns true if the port is found and removed from |ports_|.
Honghai Zhanga74363c2016-07-28 18:06:15 -0700267 bool PrunePort(PortInterface* port);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000268 void OnRoleConflict(PortInterface* port);
269
270 void OnConnectionStateChange(Connection* connection);
271 void OnReadPacket(Connection *connection, const char *data, size_t len,
272 const rtc::PacketTime& packet_time);
Stefan Holmer55674ff2016-01-14 15:49:16 +0100273 void OnSentPacket(const rtc::SentPacket& sent_packet);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000274 void OnReadyToSend(Connection* connection);
275 void OnConnectionDestroyed(Connection *connection);
276
honghaiz5a3acd82015-08-20 15:53:17 -0700277 void OnNominated(Connection* conn);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000278
deadbeefcbecd352015-09-23 11:50:27 -0700279 void OnMessage(rtc::Message* pmsg) override;
honghaiza58ea782015-09-24 08:13:36 -0700280 void OnCheckAndPing();
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700281 void OnRegatherOnFailedNetworks();
Steve Anton300bf8e2017-07-14 10:13:10 -0700282 void OnRegatherOnAllNetworks();
Peter Thatcher54360512015-07-08 11:08:35 -0700283
Honghai Zhang8cd8f812016-08-03 19:50:41 -0700284 uint32_t GetNominationAttr(Connection* conn) const;
285 bool GetUseCandidateAttr(Connection* conn, NominationMode mode) const;
286
honghaiz9ad0db52016-07-14 19:30:28 -0700287 // Returns true if we should switch to the new connection.
288 // sets |missed_receiving_unchanged_threshold| to true if either
289 // the selected connection or the new connection missed its
290 // receiving-unchanged-threshold.
291 bool ShouldSwitchSelectedConnection(
292 Connection* new_connection,
293 bool* missed_receiving_unchanged_threshold) const;
294 // Returns true if the new_connection is selected for transmission.
295 bool MaybeSwitchSelectedConnection(Connection* new_connection,
296 const std::string& reason);
honghaiz7252a002016-11-08 20:04:09 -0800297 // Gets the best connection for each network.
298 std::map<rtc::Network*, Connection*> GetBestConnectionByNetwork() const;
299 std::vector<Connection*> GetBestWritableConnectionPerNetwork() const;
honghaiz5a3acd82015-08-20 15:53:17 -0700300 void PruneConnections();
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700301 bool IsBackupConnection(const Connection* conn) const;
honghaiz5a3acd82015-08-20 15:53:17 -0700302
honghaiz34b11eb2016-03-16 08:55:44 -0700303 Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now);
guoweis36f01372016-03-02 18:02:40 -0800304 // Between |conn1| and |conn2|, this function returns the one which should
305 // be pinged first.
honghaiz7252a002016-11-08 20:04:09 -0800306 Connection* MorePingable(Connection* conn1, Connection* conn2);
guoweis36f01372016-03-02 18:02:40 -0800307 // Select the connection which is Relay/Relay. If both of them are,
308 // UDP relay protocol takes precedence.
309 Connection* MostLikelyToWork(Connection* conn1, Connection* conn2);
310 // Compare the last_ping_sent time and return the one least recently pinged.
311 Connection* LeastRecentlyPinged(Connection* conn1, Connection* conn2);
312
honghaiza54a0802015-12-16 18:37:23 -0800313 // Returns the latest remote ICE parameters or nullptr if there are no remote
314 // ICE parameters yet.
315 IceParameters* remote_ice() {
316 return remote_ice_parameters_.empty() ? nullptr
317 : &remote_ice_parameters_.back();
318 }
honghaiz112fe432015-12-30 13:32:47 -0800319 // Returns the remote IceParameters and generation that match |ufrag|
320 // if found, and returns nullptr otherwise.
321 const IceParameters* FindRemoteIceFromUfrag(const std::string& ufrag,
322 uint32_t* generation);
honghaiza54a0802015-12-16 18:37:23 -0800323 // Returns the index of the latest remote ICE parameters, or 0 if no remote
324 // ICE parameters have been received.
325 uint32_t remote_ice_generation() {
326 return remote_ice_parameters_.empty()
327 ? 0
328 : static_cast<uint32_t>(remote_ice_parameters_.size() - 1);
329 }
330
Steve Anton300bf8e2017-07-14 10:13:10 -0700331 // Samples a delay from the uniform distribution defined by the
332 // regather_on_all_networks_interval ICE configuration pair.
333 int SampleRegatherAllNetworksInterval();
334
335 // Indicates if the given local port has been pruned.
336 bool IsPortPruned(const Port* port) const;
337
338 // Indicates if the given remote candidate has been pruned.
339 bool IsRemoteCandidatePruned(const Candidate& cand) const;
340
zhihuangd06adf62017-01-12 15:58:31 -0800341 // Sets the writable state, signaling if necessary.
342 void set_writable(bool writable);
343 // Sets the receiving state, signaling if necessary.
344 void set_receiving(bool receiving);
345
346 std::string transport_name_;
347 int component_;
deadbeefcbecd352015-09-23 11:50:27 -0700348 PortAllocator* allocator_;
johan0fd22ef2016-09-29 01:19:20 -0700349 rtc::Thread* network_thread_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000350 bool incoming_only_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000351 int error_;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700352 std::vector<std::unique_ptr<PortAllocatorSession>> allocator_sessions_;
deadbeefdfc42442016-06-21 14:19:48 -0700353 // |ports_| contains ports that are used to form new connections when
354 // new remote candidates are added.
355 std::vector<PortInterface*> ports_;
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700356 // |pruned_ports_| contains ports that have been removed from |ports_| and
deadbeefdfc42442016-06-21 14:19:48 -0700357 // are not being used to form new connections, but that aren't yet destroyed.
358 // They may have existing connections, and they still fire signals such as
359 // SignalUnknownAddress.
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700360 std::vector<PortInterface*> pruned_ports_;
guoweis36f01372016-03-02 18:02:40 -0800361
362 // |connections_| is a sorted list with the first one always be the
Honghai Zhang572b0942016-06-23 12:26:57 -0700363 // |selected_connection_| when it's not nullptr. The combination of
guoweis36f01372016-03-02 18:02:40 -0800364 // |pinged_connections_| and |unpinged_connections_| has the same
365 // connections as |connections_|. These 2 sets maintain whether a
366 // connection should be pinged next or not.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000367 std::vector<Connection *> connections_;
guoweis36f01372016-03-02 18:02:40 -0800368 std::set<Connection*> pinged_connections_;
369 std::set<Connection*> unpinged_connections_;
370
Honghai Zhang572b0942016-06-23 12:26:57 -0700371 Connection* selected_connection_ = nullptr;
guoweis36f01372016-03-02 18:02:40 -0800372
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000373 std::vector<RemoteCandidate> remote_candidates_;
374 bool sort_dirty_; // indicates whether another sort is needed right now
deadbeefcbecd352015-09-23 11:50:27 -0700375 bool had_connection_ = false; // if connections_ has ever been nonempty
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000376 typedef std::map<rtc::Socket::Option, int> OptionMap;
377 OptionMap options_;
Honghai Zhang4cedf2b2016-08-31 08:18:11 -0700378 IceParameters ice_parameters_;
honghaiza54a0802015-12-16 18:37:23 -0800379 std::vector<IceParameters> remote_ice_parameters_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000380 IceMode remote_ice_mode_;
381 IceRole ice_role_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200382 uint64_t tiebreaker_;
deadbeefcbecd352015-09-23 11:50:27 -0700383 IceGatheringState gathering_state_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000384
Steve Anton300bf8e2017-07-14 10:13:10 -0700385 // Used to generate random intervals for regather_all_networks_interval_range.
386 webrtc::Random rand_;
387
Honghai Zhang049fbb12016-03-07 11:13:07 -0800388 int check_receiving_interval_;
honghaiz34b11eb2016-03-16 08:55:44 -0700389 int64_t last_ping_sent_ms_ = 0;
Honghai Zhang049fbb12016-03-07 11:13:07 -0800390 int weak_ping_interval_ = WEAK_PING_INTERVAL;
zhihuangd06adf62017-01-12 15:58:31 -0800391 IceTransportState state_ = IceTransportState::STATE_INIT;
guoweis36f01372016-03-02 18:02:40 -0800392 IceConfig config_;
Honghai Zhang52dce732016-03-31 12:37:31 -0700393 int last_sent_packet_id_ = -1; // -1 indicates no packet was sent before.
Taylor Brandstetterb825aee2016-06-29 13:07:16 -0700394 bool started_pinging_ = false;
Honghai Zhang8cd8f812016-08-03 19:50:41 -0700395 // The value put in the "nomination" attribute for the next nominated
396 // connection. A zero-value indicates the connection will not be nominated.
397 uint32_t nomination_ = 0;
zhihuangd06adf62017-01-12 15:58:31 -0800398 bool receiving_ = false;
399 bool writable_ = false;
Peter Thatcher54360512015-07-08 11:08:35 -0700400
Honghai Zhangd93f50c2016-10-05 11:47:22 -0700401 webrtc::MetricsObserverInterface* metrics_observer_ = nullptr;
402
henrikg3c089d72015-09-16 05:37:44 -0700403 RTC_DISALLOW_COPY_AND_ASSIGN(P2PTransportChannel);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000404};
405
406} // namespace cricket
407
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200408#endif // P2P_BASE_P2PTRANSPORTCHANNEL_H_