Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: webrtc/p2p/base/port.h

Issue 2171183002: Remove ports that are not used by any channel after timeout (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel_unittest.cc ('k') | webrtc/p2p/base/port.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 }; 115 };
116 116
117 typedef std::set<rtc::SocketAddress> ServerAddresses; 117 typedef std::set<rtc::SocketAddress> ServerAddresses;
118 118
119 // Represents a local communication mechanism that can be used to create 119 // Represents a local communication mechanism that can be used to create
120 // connections to similar mechanisms of the other client. Subclasses of this 120 // connections to similar mechanisms of the other client. Subclasses of this
121 // one add support for specific mechanisms like local UDP ports. 121 // one add support for specific mechanisms like local UDP ports.
122 class Port : public PortInterface, public rtc::MessageHandler, 122 class Port : public PortInterface, public rtc::MessageHandler,
123 public sigslot::has_slots<> { 123 public sigslot::has_slots<> {
124 public: 124 public:
125 // INIT: The state when a port is just created.
126 // KEEP_ALIVE_UNTIL_PRUNED: A port should not be destroyed even if no
127 // connection is using it.
128 // PRUNED: It will be destroyed if no connection is using it for a period of
129 // 30 seconds.
130 enum class State { INIT, KEEP_ALIVE_UNTIL_PRUNED, PRUNED };
125 Port(rtc::Thread* thread, 131 Port(rtc::Thread* thread,
126 const std::string& type, 132 const std::string& type,
127 rtc::PacketSocketFactory* factory, 133 rtc::PacketSocketFactory* factory,
128 rtc::Network* network, 134 rtc::Network* network,
129 const rtc::IPAddress& ip, 135 const rtc::IPAddress& ip,
130 const std::string& username_fragment, 136 const std::string& username_fragment,
131 const std::string& password); 137 const std::string& password);
132 Port(rtc::Thread* thread, 138 Port(rtc::Thread* thread,
133 const std::string& type, 139 const std::string& type,
134 rtc::PacketSocketFactory* factory, 140 rtc::PacketSocketFactory* factory,
(...skipping 11 matching lines...) Expand all
146 // Methods to set/get ICE role and tiebreaker values. 152 // Methods to set/get ICE role and tiebreaker values.
147 IceRole GetIceRole() const { return ice_role_; } 153 IceRole GetIceRole() const { return ice_role_; }
148 void SetIceRole(IceRole role) { ice_role_ = role; } 154 void SetIceRole(IceRole role) { ice_role_ = role; }
149 155
150 void SetIceTiebreaker(uint64_t tiebreaker) { tiebreaker_ = tiebreaker; } 156 void SetIceTiebreaker(uint64_t tiebreaker) { tiebreaker_ = tiebreaker; }
151 uint64_t IceTiebreaker() const { return tiebreaker_; } 157 uint64_t IceTiebreaker() const { return tiebreaker_; }
152 158
153 virtual bool SharedSocket() const { return shared_socket_; } 159 virtual bool SharedSocket() const { return shared_socket_; }
154 void ResetSharedSocket() { shared_socket_ = false; } 160 void ResetSharedSocket() { shared_socket_ = false; }
155 161
162 // Should not destroy the port even if no connection is using it. Called when
163 // a port is ready to use.
164 void KeepAliveUntilPruned();
165 // Allows a port to be destroyed if no connection is using it.
166 void Prune();
167
156 // The thread on which this port performs its I/O. 168 // The thread on which this port performs its I/O.
157 rtc::Thread* thread() { return thread_; } 169 rtc::Thread* thread() { return thread_; }
158 170
159 // The factory used to create the sockets of this port. 171 // The factory used to create the sockets of this port.
160 rtc::PacketSocketFactory* socket_factory() const { return factory_; } 172 rtc::PacketSocketFactory* socket_factory() const { return factory_; }
161 void set_socket_factory(rtc::PacketSocketFactory* factory) { 173 void set_socket_factory(rtc::PacketSocketFactory* factory) {
162 factory_ = factory; 174 factory_ = factory;
163 } 175 }
164 176
165 // For debugging purposes. 177 // For debugging purposes.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // Called when the socket is currently able to send. 302 // Called when the socket is currently able to send.
291 void OnReadyToSend(); 303 void OnReadyToSend();
292 304
293 // Called when the Connection discovers a local peer reflexive candidate. 305 // Called when the Connection discovers a local peer reflexive candidate.
294 // Returns the index of the new local candidate. 306 // Returns the index of the new local candidate.
295 size_t AddPrflxCandidate(const Candidate& local); 307 size_t AddPrflxCandidate(const Candidate& local);
296 308
297 int16_t network_cost() const { return network_cost_; } 309 int16_t network_cost() const { return network_cost_; }
298 310
299 protected: 311 protected:
300 enum { MSG_CHECK_DEAD = 0, MSG_FIRST_AVAILABLE }; 312 enum { MSG_DESTROY_IF_DEAD = 0, MSG_FIRST_AVAILABLE };
301 313
302 virtual void UpdateNetworkCost(); 314 virtual void UpdateNetworkCost();
303 315
304 void set_type(const std::string& type) { type_ = type; } 316 void set_type(const std::string& type) { type_ = type; }
305 317
306 void AddAddress(const rtc::SocketAddress& address, 318 void AddAddress(const rtc::SocketAddress& address,
307 const rtc::SocketAddress& base_address, 319 const rtc::SocketAddress& base_address,
308 const rtc::SocketAddress& related_address, 320 const rtc::SocketAddress& related_address,
309 const std::string& protocol, 321 const std::string& protocol,
310 const std::string& relay_protocol, 322 const std::string& relay_protocol,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 } 359 }
348 360
349 // Extra work to be done in subclasses when a connection is destroyed. 361 // Extra work to be done in subclasses when a connection is destroyed.
350 virtual void HandleConnectionDestroyed(Connection* conn) {} 362 virtual void HandleConnectionDestroyed(Connection* conn) {}
351 363
352 private: 364 private:
353 void Construct(); 365 void Construct();
354 // Called when one of our connections deletes itself. 366 // Called when one of our connections deletes itself.
355 void OnConnectionDestroyed(Connection* conn); 367 void OnConnectionDestroyed(Connection* conn);
356 368
357 // Whether this port is dead, and hence, should be destroyed on the controlled
358 // side.
359 bool dead() const;
360
361 void OnNetworkTypeChanged(const rtc::Network* network); 369 void OnNetworkTypeChanged(const rtc::Network* network);
362 370
363 rtc::Thread* thread_; 371 rtc::Thread* thread_;
364 rtc::PacketSocketFactory* factory_; 372 rtc::PacketSocketFactory* factory_;
365 std::string type_; 373 std::string type_;
366 bool send_retransmit_count_attribute_; 374 bool send_retransmit_count_attribute_;
367 rtc::Network* network_; 375 rtc::Network* network_;
368 rtc::IPAddress ip_; 376 rtc::IPAddress ip_;
369 uint16_t min_port_; 377 uint16_t min_port_;
370 uint16_t max_port_; 378 uint16_t max_port_;
(...skipping 18 matching lines...) Expand all
389 uint64_t tiebreaker_; 397 uint64_t tiebreaker_;
390 bool shared_socket_; 398 bool shared_socket_;
391 // Information to use when going through a proxy. 399 // Information to use when going through a proxy.
392 std::string user_agent_; 400 std::string user_agent_;
393 rtc::ProxyInfo proxy_; 401 rtc::ProxyInfo proxy_;
394 402
395 // A virtual cost perceived by the user, usually based on the network type 403 // A virtual cost perceived by the user, usually based on the network type
396 // (WiFi. vs. Cellular). It takes precedence over the priority when 404 // (WiFi. vs. Cellular). It takes precedence over the priority when
397 // comparing two connections. 405 // comparing two connections.
398 uint16_t network_cost_; 406 uint16_t network_cost_;
407 State state_ = State::INIT;
399 int64_t last_time_all_connections_removed_ = 0; 408 int64_t last_time_all_connections_removed_ = 0;
400 409
401 friend class Connection; 410 friend class Connection;
402 }; 411 };
403 412
404 // Represents a communication link between a port on the local client and a 413 // Represents a communication link between a port on the local client and a
405 // port on the remote client. 414 // port on the remote client.
406 class Connection : public CandidatePairInterface, 415 class Connection : public CandidatePairInterface,
407 public rtc::MessageHandler, 416 public rtc::MessageHandler,
408 public sigslot::has_slots<> { 417 public sigslot::has_slots<> {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 const rtc::PacketOptions& options) override; 690 const rtc::PacketOptions& options) override;
682 int GetError() override { return error_; } 691 int GetError() override { return error_; }
683 692
684 private: 693 private:
685 int error_ = 0; 694 int error_ = 0;
686 }; 695 };
687 696
688 } // namespace cricket 697 } // namespace cricket
689 698
690 #endif // WEBRTC_P2P_BASE_PORT_H_ 699 #endif // WEBRTC_P2P_BASE_PORT_H_
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel_unittest.cc ('k') | webrtc/p2p/base/port.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698