| 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 |
| 11 #ifndef WEBRTC_P2P_BASE_STUNPORT_H_ | 11 #ifndef WEBRTC_P2P_BASE_STUNPORT_H_ |
| 12 #define WEBRTC_P2P_BASE_STUNPORT_H_ | 12 #define WEBRTC_P2P_BASE_STUNPORT_H_ |
| 13 | 13 |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <string> | 15 #include <string> |
| 16 | 16 |
| 17 #include "webrtc/p2p/base/port.h" | 17 #include "webrtc/p2p/base/port.h" |
| 18 #include "webrtc/p2p/base/stunrequest.h" | 18 #include "webrtc/p2p/base/stunrequest.h" |
| 19 #include "webrtc/base/asyncpacketsocket.h" | 19 #include "webrtc/base/asyncpacketsocket.h" |
| 20 | 20 |
| 21 // TODO(mallinath) - Rename stunport.cc|h to udpport.cc|h. | 21 // TODO(mallinath) - Rename stunport.cc|h to udpport.cc|h. |
| 22 namespace rtc { | 22 namespace rtc { |
| 23 class AsyncResolver; | 23 class AsyncResolver; |
| 24 class SignalThread; | 24 class SignalThread; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace cricket { | 27 namespace cricket { |
| 28 | 28 |
| 29 // Lifetime chosen for STUN ports on low-cost networks. |
| 30 static const int INFINITE_LIFETIME = -1; |
| 31 // Lifetime for STUN ports on high-cost networks: 2 minutes |
| 32 static const int HIGH_COST_PORT_KEEPALIVE_LIFETIME = 2 * 60 * 1000; |
| 33 |
| 29 // Communicates using the address on the outside of a NAT. | 34 // Communicates using the address on the outside of a NAT. |
| 30 class UDPPort : public Port { | 35 class UDPPort : public Port { |
| 31 public: | 36 public: |
| 32 static UDPPort* Create(rtc::Thread* thread, | 37 static UDPPort* Create(rtc::Thread* thread, |
| 33 rtc::PacketSocketFactory* factory, | 38 rtc::PacketSocketFactory* factory, |
| 34 rtc::Network* network, | 39 rtc::Network* network, |
| 35 rtc::AsyncPacketSocket* socket, | 40 rtc::AsyncPacketSocket* socket, |
| 36 const std::string& username, | 41 const std::string& username, |
| 37 const std::string& password, | 42 const std::string& password, |
| 38 const std::string& origin, | 43 const std::string& origin, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 const std::string& origin, | 143 const std::string& origin, |
| 139 bool emit_local_for_anyaddress); | 144 bool emit_local_for_anyaddress); |
| 140 | 145 |
| 141 bool Init(); | 146 bool Init(); |
| 142 | 147 |
| 143 virtual int SendTo(const void* data, size_t size, | 148 virtual int SendTo(const void* data, size_t size, |
| 144 const rtc::SocketAddress& addr, | 149 const rtc::SocketAddress& addr, |
| 145 const rtc::PacketOptions& options, | 150 const rtc::PacketOptions& options, |
| 146 bool payload); | 151 bool payload); |
| 147 | 152 |
| 153 virtual void UpdateNetworkCost(); |
| 154 |
| 148 void OnLocalAddressReady(rtc::AsyncPacketSocket* socket, | 155 void OnLocalAddressReady(rtc::AsyncPacketSocket* socket, |
| 149 const rtc::SocketAddress& address); | 156 const rtc::SocketAddress& address); |
| 150 void OnReadPacket(rtc::AsyncPacketSocket* socket, | 157 void OnReadPacket(rtc::AsyncPacketSocket* socket, |
| 151 const char* data, size_t size, | 158 const char* data, size_t size, |
| 152 const rtc::SocketAddress& remote_addr, | 159 const rtc::SocketAddress& remote_addr, |
| 153 const rtc::PacketTime& packet_time); | 160 const rtc::PacketTime& packet_time); |
| 154 | 161 |
| 155 void OnSentPacket(rtc::AsyncPacketSocket* socket, | 162 void OnSentPacket(rtc::AsyncPacketSocket* socket, |
| 156 const rtc::SentPacket& sent_packet); | 163 const rtc::SentPacket& sent_packet); |
| 157 | 164 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 219 |
| 213 // Sends STUN requests to the server. | 220 // Sends STUN requests to the server. |
| 214 void OnSendPacket(const void* data, size_t size, StunRequest* req); | 221 void OnSendPacket(const void* data, size_t size, StunRequest* req); |
| 215 | 222 |
| 216 // TODO(mallinaht) - Move this up to cricket::Port when SignalAddressReady is | 223 // TODO(mallinaht) - Move this up to cricket::Port when SignalAddressReady is |
| 217 // changed to SignalPortReady. | 224 // changed to SignalPortReady. |
| 218 void MaybeSetPortCompleteOrError(); | 225 void MaybeSetPortCompleteOrError(); |
| 219 | 226 |
| 220 bool HasCandidateWithAddress(const rtc::SocketAddress& addr) const; | 227 bool HasCandidateWithAddress(const rtc::SocketAddress& addr) const; |
| 221 | 228 |
| 229 // If this is a low-cost network, it will keep on sending STUN binding |
| 230 // requests indefinitely to keep the NAT binding alive. Otherwise, stop |
| 231 // sending STUN binding requests after HIGH_COST_PORT_KEEPALIVE_LIFETIME. |
| 232 int GetStunKeepaliveLifetime() { |
| 233 return (network_cost() >= rtc::kNetworkCostHigh) |
| 234 ? HIGH_COST_PORT_KEEPALIVE_LIFETIME |
| 235 : INFINITE_LIFETIME; |
| 236 } |
| 237 |
| 222 ServerAddresses server_addresses_; | 238 ServerAddresses server_addresses_; |
| 223 ServerAddresses bind_request_succeeded_servers_; | 239 ServerAddresses bind_request_succeeded_servers_; |
| 224 ServerAddresses bind_request_failed_servers_; | 240 ServerAddresses bind_request_failed_servers_; |
| 225 StunRequestManager requests_; | 241 StunRequestManager requests_; |
| 226 rtc::AsyncPacketSocket* socket_; | 242 rtc::AsyncPacketSocket* socket_; |
| 227 int error_; | 243 int error_; |
| 228 std::unique_ptr<AddressResolver> resolver_; | 244 std::unique_ptr<AddressResolver> resolver_; |
| 229 bool ready_; | 245 bool ready_; |
| 230 int stun_keepalive_delay_; | 246 int stun_keepalive_delay_; |
| 231 int stun_keepalive_lifetime_; | 247 int stun_keepalive_lifetime_ = INFINITE_LIFETIME; |
| 232 | 248 |
| 233 // This is true by default and false when | 249 // This is true by default and false when |
| 234 // PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE is specified. | 250 // PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE is specified. |
| 235 bool emit_local_for_anyaddress_; | 251 bool emit_local_for_anyaddress_; |
| 236 | 252 |
| 237 friend class StunBindingRequest; | 253 friend class StunBindingRequest; |
| 238 }; | 254 }; |
| 239 | 255 |
| 240 class StunPort : public UDPPort { | 256 class StunPort : public UDPPort { |
| 241 public: | 257 public: |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 false) { | 305 false) { |
| 290 // UDPPort will set these to local udp, updating these to STUN. | 306 // UDPPort will set these to local udp, updating these to STUN. |
| 291 set_type(STUN_PORT_TYPE); | 307 set_type(STUN_PORT_TYPE); |
| 292 set_server_addresses(servers); | 308 set_server_addresses(servers); |
| 293 } | 309 } |
| 294 }; | 310 }; |
| 295 | 311 |
| 296 } // namespace cricket | 312 } // namespace cricket |
| 297 | 313 |
| 298 #endif // WEBRTC_P2P_BASE_STUNPORT_H_ | 314 #endif // WEBRTC_P2P_BASE_STUNPORT_H_ |
| OLD | NEW |