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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 enum class State { INIT, READY, PRUNED }; | |
pthatcher1
2016/07/28 19:35:05
This could use a description of states. Such as:
honghaiz3
2016/07/28 22:51:44
Done.
| |
125 Port(rtc::Thread* thread, | 126 Port(rtc::Thread* thread, |
126 const std::string& type, | 127 const std::string& type, |
127 rtc::PacketSocketFactory* factory, | 128 rtc::PacketSocketFactory* factory, |
128 rtc::Network* network, | 129 rtc::Network* network, |
129 const rtc::IPAddress& ip, | 130 const rtc::IPAddress& ip, |
130 const std::string& username_fragment, | 131 const std::string& username_fragment, |
131 const std::string& password); | 132 const std::string& password); |
132 Port(rtc::Thread* thread, | 133 Port(rtc::Thread* thread, |
133 const std::string& type, | 134 const std::string& type, |
134 rtc::PacketSocketFactory* factory, | 135 rtc::PacketSocketFactory* factory, |
(...skipping 11 matching lines...) Expand all Loading... | |
146 // Methods to set/get ICE role and tiebreaker values. | 147 // Methods to set/get ICE role and tiebreaker values. |
147 IceRole GetIceRole() const { return ice_role_; } | 148 IceRole GetIceRole() const { return ice_role_; } |
148 void SetIceRole(IceRole role) { ice_role_ = role; } | 149 void SetIceRole(IceRole role) { ice_role_ = role; } |
149 | 150 |
150 void SetIceTiebreaker(uint64_t tiebreaker) { tiebreaker_ = tiebreaker; } | 151 void SetIceTiebreaker(uint64_t tiebreaker) { tiebreaker_ = tiebreaker; } |
151 uint64_t IceTiebreaker() const { return tiebreaker_; } | 152 uint64_t IceTiebreaker() const { return tiebreaker_; } |
152 | 153 |
153 virtual bool SharedSocket() const { return shared_socket_; } | 154 virtual bool SharedSocket() const { return shared_socket_; } |
154 void ResetSharedSocket() { shared_socket_ = false; } | 155 void ResetSharedSocket() { shared_socket_ = false; } |
155 | 156 |
157 // Called when a port is ready to use. | |
158 void BecomeReady(); | |
pthatcher1
2016/07/28 19:35:05
I think a better name would be "KeepAliveUntilPrun
honghaiz3
2016/07/28 22:51:44
Done.
| |
159 // Called when a port is pruned. | |
pthatcher1
2016/07/28 19:35:05
A better comment would be "Allows the port to be d
honghaiz3
2016/07/28 22:52:28
Done.
| |
160 void Prune(); | |
161 | |
156 // The thread on which this port performs its I/O. | 162 // The thread on which this port performs its I/O. |
157 rtc::Thread* thread() { return thread_; } | 163 rtc::Thread* thread() { return thread_; } |
158 | 164 |
159 // The factory used to create the sockets of this port. | 165 // The factory used to create the sockets of this port. |
160 rtc::PacketSocketFactory* socket_factory() const { return factory_; } | 166 rtc::PacketSocketFactory* socket_factory() const { return factory_; } |
161 void set_socket_factory(rtc::PacketSocketFactory* factory) { | 167 void set_socket_factory(rtc::PacketSocketFactory* factory) { |
162 factory_ = factory; | 168 factory_ = factory; |
163 } | 169 } |
164 | 170 |
165 // For debugging purposes. | 171 // For debugging purposes. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 // Called when the socket is currently able to send. | 296 // Called when the socket is currently able to send. |
291 void OnReadyToSend(); | 297 void OnReadyToSend(); |
292 | 298 |
293 // Called when the Connection discovers a local peer reflexive candidate. | 299 // Called when the Connection discovers a local peer reflexive candidate. |
294 // Returns the index of the new local candidate. | 300 // Returns the index of the new local candidate. |
295 size_t AddPrflxCandidate(const Candidate& local); | 301 size_t AddPrflxCandidate(const Candidate& local); |
296 | 302 |
297 int16_t network_cost() const { return network_cost_; } | 303 int16_t network_cost() const { return network_cost_; } |
298 | 304 |
299 protected: | 305 protected: |
300 enum { | 306 enum { MSG_CHECK_DEAD = 0, MSG_FIRST_AVAILABLE }; |
pthatcher1
2016/07/28 19:35:05
MSG_MAYBE_DESTORY might be a better name than MSG_
honghaiz3
2016/07/28 22:51:44
Using MSG_DESTROY_IF_DEAD.
| |
301 MSG_DEAD = 0, | |
302 MSG_FIRST_AVAILABLE | |
303 }; | |
304 | 307 |
305 virtual void UpdateNetworkCost(); | 308 virtual void UpdateNetworkCost(); |
306 | 309 |
307 void set_type(const std::string& type) { type_ = type; } | 310 void set_type(const std::string& type) { type_ = type; } |
308 | 311 |
309 void AddAddress(const rtc::SocketAddress& address, | 312 void AddAddress(const rtc::SocketAddress& address, |
310 const rtc::SocketAddress& base_address, | 313 const rtc::SocketAddress& base_address, |
311 const rtc::SocketAddress& related_address, | 314 const rtc::SocketAddress& related_address, |
312 const std::string& protocol, | 315 const std::string& protocol, |
313 const std::string& relay_protocol, | 316 const std::string& relay_protocol, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 } | 353 } |
351 | 354 |
352 // Extra work to be done in subclasses when a connection is destroyed. | 355 // Extra work to be done in subclasses when a connection is destroyed. |
353 virtual void HandleConnectionDestroyed(Connection* conn) {} | 356 virtual void HandleConnectionDestroyed(Connection* conn) {} |
354 | 357 |
355 private: | 358 private: |
356 void Construct(); | 359 void Construct(); |
357 // Called when one of our connections deletes itself. | 360 // Called when one of our connections deletes itself. |
358 void OnConnectionDestroyed(Connection* conn); | 361 void OnConnectionDestroyed(Connection* conn); |
359 | 362 |
360 // Whether this port is dead, and hence, should be destroyed on the controlled | 363 // Whether this port is dead, and hence, should be destroyed. |
361 // side. | 364 bool dead() const; |
362 bool dead() const { | |
363 return ice_role_ == ICEROLE_CONTROLLED && connections_.empty(); | |
364 } | |
365 | 365 |
366 void OnNetworkTypeChanged(const rtc::Network* network); | 366 void OnNetworkTypeChanged(const rtc::Network* network); |
367 | 367 |
368 rtc::Thread* thread_; | 368 rtc::Thread* thread_; |
369 rtc::PacketSocketFactory* factory_; | 369 rtc::PacketSocketFactory* factory_; |
370 std::string type_; | 370 std::string type_; |
371 bool send_retransmit_count_attribute_; | 371 bool send_retransmit_count_attribute_; |
372 rtc::Network* network_; | 372 rtc::Network* network_; |
373 rtc::IPAddress ip_; | 373 rtc::IPAddress ip_; |
374 uint16_t min_port_; | 374 uint16_t min_port_; |
(...skipping 19 matching lines...) Expand all Loading... | |
394 uint64_t tiebreaker_; | 394 uint64_t tiebreaker_; |
395 bool shared_socket_; | 395 bool shared_socket_; |
396 // Information to use when going through a proxy. | 396 // Information to use when going through a proxy. |
397 std::string user_agent_; | 397 std::string user_agent_; |
398 rtc::ProxyInfo proxy_; | 398 rtc::ProxyInfo proxy_; |
399 | 399 |
400 // A virtual cost perceived by the user, usually based on the network type | 400 // A virtual cost perceived by the user, usually based on the network type |
401 // (WiFi. vs. Cellular). It takes precedence over the priority when | 401 // (WiFi. vs. Cellular). It takes precedence over the priority when |
402 // comparing two connections. | 402 // comparing two connections. |
403 uint16_t network_cost_; | 403 uint16_t network_cost_; |
404 State state_ = State::INIT; | |
404 | 405 |
405 friend class Connection; | 406 friend class Connection; |
406 }; | 407 }; |
407 | 408 |
408 // Represents a communication link between a port on the local client and a | 409 // Represents a communication link between a port on the local client and a |
409 // port on the remote client. | 410 // port on the remote client. |
410 class Connection : public CandidatePairInterface, | 411 class Connection : public CandidatePairInterface, |
411 public rtc::MessageHandler, | 412 public rtc::MessageHandler, |
412 public sigslot::has_slots<> { | 413 public sigslot::has_slots<> { |
413 public: | 414 public: |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
685 const rtc::PacketOptions& options) override; | 686 const rtc::PacketOptions& options) override; |
686 int GetError() override { return error_; } | 687 int GetError() override { return error_; } |
687 | 688 |
688 private: | 689 private: |
689 int error_ = 0; | 690 int error_ = 0; |
690 }; | 691 }; |
691 | 692 |
692 } // namespace cricket | 693 } // namespace cricket |
693 | 694 |
694 #endif // WEBRTC_P2P_BASE_PORT_H_ | 695 #endif // WEBRTC_P2P_BASE_PORT_H_ |
OLD | NEW |