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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 extern const char SSLTCP_PROTOCOL_NAME[]; | 45 extern const char SSLTCP_PROTOCOL_NAME[]; |
46 | 46 |
47 // RFC 6544, TCP candidate encoding rules. | 47 // RFC 6544, TCP candidate encoding rules. |
48 extern const int DISCARD_PORT; | 48 extern const int DISCARD_PORT; |
49 extern const char TCPTYPE_ACTIVE_STR[]; | 49 extern const char TCPTYPE_ACTIVE_STR[]; |
50 extern const char TCPTYPE_PASSIVE_STR[]; | 50 extern const char TCPTYPE_PASSIVE_STR[]; |
51 extern const char TCPTYPE_SIMOPEN_STR[]; | 51 extern const char TCPTYPE_SIMOPEN_STR[]; |
52 | 52 |
53 // If a connection does not receive anything for this long, it is considered | 53 // If a connection does not receive anything for this long, it is considered |
54 // dead. | 54 // dead. |
55 const uint32 DEAD_CONNECTION_RECEIVE_TIMEOUT = 30 * 1000; // 30 seconds. | 55 const uint32_t DEAD_CONNECTION_RECEIVE_TIMEOUT = 30 * 1000; // 30 seconds. |
56 | 56 |
57 // The timeout duration when a connection does not receive anything. | 57 // The timeout duration when a connection does not receive anything. |
58 const uint32 WEAK_CONNECTION_RECEIVE_TIMEOUT = 2500; // 2.5 seconds | 58 const uint32_t WEAK_CONNECTION_RECEIVE_TIMEOUT = 2500; // 2.5 seconds |
59 | 59 |
60 // The length of time we wait before timing out writability on a connection. | 60 // The length of time we wait before timing out writability on a connection. |
61 const uint32 CONNECTION_WRITE_TIMEOUT = 15 * 1000; // 15 seconds | 61 const uint32_t CONNECTION_WRITE_TIMEOUT = 15 * 1000; // 15 seconds |
62 | 62 |
63 // The length of time we wait before we become unwritable. | 63 // The length of time we wait before we become unwritable. |
64 const uint32 CONNECTION_WRITE_CONNECT_TIMEOUT = 5 * 1000; // 5 seconds | 64 const uint32_t CONNECTION_WRITE_CONNECT_TIMEOUT = 5 * 1000; // 5 seconds |
65 | 65 |
66 // The number of pings that must fail to respond before we become unwritable. | 66 // The number of pings that must fail to respond before we become unwritable. |
67 const uint32 CONNECTION_WRITE_CONNECT_FAILURES = 5; | 67 const uint32_t CONNECTION_WRITE_CONNECT_FAILURES = 5; |
68 | 68 |
69 // This is the length of time that we wait for a ping response to come back. | 69 // This is the length of time that we wait for a ping response to come back. |
70 const int CONNECTION_RESPONSE_TIMEOUT = 5 * 1000; // 5 seconds | 70 const int CONNECTION_RESPONSE_TIMEOUT = 5 * 1000; // 5 seconds |
71 | 71 |
72 enum RelayType { | 72 enum RelayType { |
73 RELAY_GTURN, // Legacy google relay service. | 73 RELAY_GTURN, // Legacy google relay service. |
74 RELAY_TURN // Standard (TURN) relay service. | 74 RELAY_TURN // Standard (TURN) relay service. |
75 }; | 75 }; |
76 | 76 |
77 enum IcePriorityValue { | 77 enum IcePriorityValue { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 rtc::PacketSocketFactory* factory, | 115 rtc::PacketSocketFactory* factory, |
116 rtc::Network* network, | 116 rtc::Network* network, |
117 const rtc::IPAddress& ip, | 117 const rtc::IPAddress& ip, |
118 const std::string& username_fragment, | 118 const std::string& username_fragment, |
119 const std::string& password); | 119 const std::string& password); |
120 Port(rtc::Thread* thread, | 120 Port(rtc::Thread* thread, |
121 const std::string& type, | 121 const std::string& type, |
122 rtc::PacketSocketFactory* factory, | 122 rtc::PacketSocketFactory* factory, |
123 rtc::Network* network, | 123 rtc::Network* network, |
124 const rtc::IPAddress& ip, | 124 const rtc::IPAddress& ip, |
125 uint16 min_port, | 125 uint16_t min_port, |
126 uint16 max_port, | 126 uint16_t max_port, |
127 const std::string& username_fragment, | 127 const std::string& username_fragment, |
128 const std::string& password); | 128 const std::string& password); |
129 virtual ~Port(); | 129 virtual ~Port(); |
130 | 130 |
131 virtual const std::string& Type() const { return type_; } | 131 virtual const std::string& Type() const { return type_; } |
132 virtual rtc::Network* Network() const { return network_; } | 132 virtual rtc::Network* Network() const { return network_; } |
133 | 133 |
134 // Methods to set/get ICE role and tiebreaker values. | 134 // Methods to set/get ICE role and tiebreaker values. |
135 IceRole GetIceRole() const { return ice_role_; } | 135 IceRole GetIceRole() const { return ice_role_; } |
136 void SetIceRole(IceRole role) { ice_role_ = role; } | 136 void SetIceRole(IceRole role) { ice_role_ = role; } |
137 | 137 |
138 void SetIceTiebreaker(uint64 tiebreaker) { tiebreaker_ = tiebreaker; } | 138 void SetIceTiebreaker(uint64_t tiebreaker) { tiebreaker_ = tiebreaker; } |
139 uint64 IceTiebreaker() const { return tiebreaker_; } | 139 uint64_t IceTiebreaker() const { return tiebreaker_; } |
140 | 140 |
141 virtual bool SharedSocket() const { return shared_socket_; } | 141 virtual bool SharedSocket() const { return shared_socket_; } |
142 void ResetSharedSocket() { shared_socket_ = false; } | 142 void ResetSharedSocket() { shared_socket_ = false; } |
143 | 143 |
144 // The thread on which this port performs its I/O. | 144 // The thread on which this port performs its I/O. |
145 rtc::Thread* thread() { return thread_; } | 145 rtc::Thread* thread() { return thread_; } |
146 | 146 |
147 // The factory used to create the sockets of this port. | 147 // The factory used to create the sockets of this port. |
148 rtc::PacketSocketFactory* socket_factory() const { return factory_; } | 148 rtc::PacketSocketFactory* socket_factory() const { return factory_; } |
149 void set_socket_factory(rtc::PacketSocketFactory* factory) { | 149 void set_socket_factory(rtc::PacketSocketFactory* factory) { |
(...skipping 10 matching lines...) Expand all Loading... |
160 void set_component(int component) { component_ = component; } | 160 void set_component(int component) { component_ = component; } |
161 | 161 |
162 bool send_retransmit_count_attribute() const { | 162 bool send_retransmit_count_attribute() const { |
163 return send_retransmit_count_attribute_; | 163 return send_retransmit_count_attribute_; |
164 } | 164 } |
165 void set_send_retransmit_count_attribute(bool enable) { | 165 void set_send_retransmit_count_attribute(bool enable) { |
166 send_retransmit_count_attribute_ = enable; | 166 send_retransmit_count_attribute_ = enable; |
167 } | 167 } |
168 | 168 |
169 // Identifies the generation that this port was created in. | 169 // Identifies the generation that this port was created in. |
170 uint32 generation() { return generation_; } | 170 uint32_t generation() { return generation_; } |
171 void set_generation(uint32 generation) { generation_ = generation; } | 171 void set_generation(uint32_t generation) { generation_ = generation; } |
172 | 172 |
173 // ICE requires a single username/password per content/media line. So the | 173 // ICE requires a single username/password per content/media line. So the |
174 // |ice_username_fragment_| of the ports that belongs to the same content will | 174 // |ice_username_fragment_| of the ports that belongs to the same content will |
175 // be the same. However this causes a small complication with our relay | 175 // be the same. However this causes a small complication with our relay |
176 // server, which expects different username for RTP and RTCP. | 176 // server, which expects different username for RTP and RTCP. |
177 // | 177 // |
178 // To resolve this problem, we implemented the username_fragment(), | 178 // To resolve this problem, we implemented the username_fragment(), |
179 // which returns a different username (calculated from | 179 // which returns a different username (calculated from |
180 // |ice_username_fragment_|) for RTCP in the case of ICEPROTO_GOOGLE. And the | 180 // |ice_username_fragment_|) for RTCP in the case of ICEPROTO_GOOGLE. And the |
181 // username_fragment() simply returns |ice_username_fragment_| when running | 181 // username_fragment() simply returns |ice_username_fragment_| when running |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 virtual void EnablePortPackets(); | 250 virtual void EnablePortPackets(); |
251 | 251 |
252 // Called if the port has no connections and is no longer useful. | 252 // Called if the port has no connections and is no longer useful. |
253 void Destroy(); | 253 void Destroy(); |
254 | 254 |
255 virtual void OnMessage(rtc::Message *pmsg); | 255 virtual void OnMessage(rtc::Message *pmsg); |
256 | 256 |
257 // Debugging description of this port | 257 // Debugging description of this port |
258 virtual std::string ToString() const; | 258 virtual std::string ToString() const; |
259 const rtc::IPAddress& ip() const { return ip_; } | 259 const rtc::IPAddress& ip() const { return ip_; } |
260 uint16 min_port() { return min_port_; } | 260 uint16_t min_port() { return min_port_; } |
261 uint16 max_port() { return max_port_; } | 261 uint16_t max_port() { return max_port_; } |
262 | 262 |
263 // Timeout shortening function to speed up unit tests. | 263 // Timeout shortening function to speed up unit tests. |
264 void set_timeout_delay(int delay) { timeout_delay_ = delay; } | 264 void set_timeout_delay(int delay) { timeout_delay_ = delay; } |
265 | 265 |
266 // This method will return local and remote username fragements from the | 266 // This method will return local and remote username fragements from the |
267 // stun username attribute if present. | 267 // stun username attribute if present. |
268 bool ParseStunUsername(const StunMessage* stun_msg, | 268 bool ParseStunUsername(const StunMessage* stun_msg, |
269 std::string* local_username, | 269 std::string* local_username, |
270 std::string* remote_username) const; | 270 std::string* remote_username) const; |
271 void CreateStunUsername(const std::string& remote_username, | 271 void CreateStunUsername(const std::string& remote_username, |
272 std::string* stun_username_attr_str) const; | 272 std::string* stun_username_attr_str) const; |
273 | 273 |
274 bool MaybeIceRoleConflict(const rtc::SocketAddress& addr, | 274 bool MaybeIceRoleConflict(const rtc::SocketAddress& addr, |
275 IceMessage* stun_msg, | 275 IceMessage* stun_msg, |
276 const std::string& remote_ufrag); | 276 const std::string& remote_ufrag); |
277 | 277 |
278 // Called when the socket is currently able to send. | 278 // Called when the socket is currently able to send. |
279 void OnReadyToSend(); | 279 void OnReadyToSend(); |
280 | 280 |
281 // Called when the Connection discovers a local peer reflexive candidate. | 281 // Called when the Connection discovers a local peer reflexive candidate. |
282 // Returns the index of the new local candidate. | 282 // Returns the index of the new local candidate. |
283 size_t AddPrflxCandidate(const Candidate& local); | 283 size_t AddPrflxCandidate(const Candidate& local); |
284 | 284 |
285 void set_candidate_filter(uint32 candidate_filter) { | 285 void set_candidate_filter(uint32_t candidate_filter) { |
286 candidate_filter_ = candidate_filter; | 286 candidate_filter_ = candidate_filter; |
287 } | 287 } |
288 | 288 |
289 protected: | 289 protected: |
290 enum { | 290 enum { |
291 MSG_CHECKTIMEOUT = 0, | 291 MSG_CHECKTIMEOUT = 0, |
292 MSG_FIRST_AVAILABLE | 292 MSG_FIRST_AVAILABLE |
293 }; | 293 }; |
294 | 294 |
295 void set_type(const std::string& type) { type_ = type; } | 295 void set_type(const std::string& type) { type_ = type; } |
296 | 296 |
297 void AddAddress(const rtc::SocketAddress& address, | 297 void AddAddress(const rtc::SocketAddress& address, |
298 const rtc::SocketAddress& base_address, | 298 const rtc::SocketAddress& base_address, |
299 const rtc::SocketAddress& related_address, | 299 const rtc::SocketAddress& related_address, |
300 const std::string& protocol, | 300 const std::string& protocol, |
301 const std::string& relay_protocol, | 301 const std::string& relay_protocol, |
302 const std::string& tcptype, | 302 const std::string& tcptype, |
303 const std::string& type, | 303 const std::string& type, |
304 uint32 type_preference, | 304 uint32_t type_preference, |
305 uint32 relay_preference, | 305 uint32_t relay_preference, |
306 bool final); | 306 bool final); |
307 | 307 |
308 // Adds the given connection to the list. (Deleting removes them.) | 308 // Adds the given connection to the list. (Deleting removes them.) |
309 void AddConnection(Connection* conn); | 309 void AddConnection(Connection* conn); |
310 | 310 |
311 // Called when a packet is received from an unknown address that is not | 311 // Called when a packet is received from an unknown address that is not |
312 // currently a connection. If this is an authenticated STUN binding request, | 312 // currently a connection. If this is an authenticated STUN binding request, |
313 // then we will signal the client. | 313 // then we will signal the client. |
314 void OnReadPacket(const char* data, size_t size, | 314 void OnReadPacket(const char* data, size_t size, |
315 const rtc::SocketAddress& addr, | 315 const rtc::SocketAddress& addr, |
(...skipping 10 matching lines...) Expand all Loading... |
326 | 326 |
327 // Checks if the address in addr is compatible with the port's ip. | 327 // Checks if the address in addr is compatible with the port's ip. |
328 bool IsCompatibleAddress(const rtc::SocketAddress& addr); | 328 bool IsCompatibleAddress(const rtc::SocketAddress& addr); |
329 | 329 |
330 // Returns default DSCP value. | 330 // Returns default DSCP value. |
331 rtc::DiffServCodePoint DefaultDscpValue() const { | 331 rtc::DiffServCodePoint DefaultDscpValue() const { |
332 // No change from what MediaChannel set. | 332 // No change from what MediaChannel set. |
333 return rtc::DSCP_NO_CHANGE; | 333 return rtc::DSCP_NO_CHANGE; |
334 } | 334 } |
335 | 335 |
336 uint32 candidate_filter() { return candidate_filter_; } | 336 uint32_t candidate_filter() { return candidate_filter_; } |
337 | 337 |
338 private: | 338 private: |
339 void Construct(); | 339 void Construct(); |
340 // Called when one of our connections deletes itself. | 340 // Called when one of our connections deletes itself. |
341 void OnConnectionDestroyed(Connection* conn); | 341 void OnConnectionDestroyed(Connection* conn); |
342 | 342 |
343 // Checks if this port is useless, and hence, should be destroyed. | 343 // Checks if this port is useless, and hence, should be destroyed. |
344 void CheckTimeout(); | 344 void CheckTimeout(); |
345 | 345 |
346 rtc::Thread* thread_; | 346 rtc::Thread* thread_; |
347 rtc::PacketSocketFactory* factory_; | 347 rtc::PacketSocketFactory* factory_; |
348 std::string type_; | 348 std::string type_; |
349 bool send_retransmit_count_attribute_; | 349 bool send_retransmit_count_attribute_; |
350 rtc::Network* network_; | 350 rtc::Network* network_; |
351 rtc::IPAddress ip_; | 351 rtc::IPAddress ip_; |
352 uint16 min_port_; | 352 uint16_t min_port_; |
353 uint16 max_port_; | 353 uint16_t max_port_; |
354 std::string content_name_; | 354 std::string content_name_; |
355 int component_; | 355 int component_; |
356 uint32 generation_; | 356 uint32_t generation_; |
357 // In order to establish a connection to this Port (so that real data can be | 357 // In order to establish a connection to this Port (so that real data can be |
358 // sent through), the other side must send us a STUN binding request that is | 358 // sent through), the other side must send us a STUN binding request that is |
359 // authenticated with this username_fragment and password. | 359 // authenticated with this username_fragment and password. |
360 // PortAllocatorSession will provide these username_fragment and password. | 360 // PortAllocatorSession will provide these username_fragment and password. |
361 // | 361 // |
362 // Note: we should always use username_fragment() instead of using | 362 // Note: we should always use username_fragment() instead of using |
363 // |ice_username_fragment_| directly. For the details see the comment on | 363 // |ice_username_fragment_| directly. For the details see the comment on |
364 // username_fragment(). | 364 // username_fragment(). |
365 std::string ice_username_fragment_; | 365 std::string ice_username_fragment_; |
366 std::string password_; | 366 std::string password_; |
367 std::vector<Candidate> candidates_; | 367 std::vector<Candidate> candidates_; |
368 AddressMap connections_; | 368 AddressMap connections_; |
369 int timeout_delay_; | 369 int timeout_delay_; |
370 bool enable_port_packets_; | 370 bool enable_port_packets_; |
371 IceRole ice_role_; | 371 IceRole ice_role_; |
372 uint64 tiebreaker_; | 372 uint64_t tiebreaker_; |
373 bool shared_socket_; | 373 bool shared_socket_; |
374 // Information to use when going through a proxy. | 374 // Information to use when going through a proxy. |
375 std::string user_agent_; | 375 std::string user_agent_; |
376 rtc::ProxyInfo proxy_; | 376 rtc::ProxyInfo proxy_; |
377 | 377 |
378 // Candidate filter is pushed down to Port such that each Port could | 378 // Candidate filter is pushed down to Port such that each Port could |
379 // make its own decision on how to create candidates. For example, | 379 // make its own decision on how to create candidates. For example, |
380 // when IceTransportsType is set to relay, both RelayPort and | 380 // when IceTransportsType is set to relay, both RelayPort and |
381 // TurnPort will hide raddr to avoid local address leakage. | 381 // TurnPort will hide raddr to avoid local address leakage. |
382 uint32 candidate_filter_; | 382 uint32_t candidate_filter_; |
383 | 383 |
384 friend class Connection; | 384 friend class Connection; |
385 }; | 385 }; |
386 | 386 |
387 // Represents a communication link between a port on the local client and a | 387 // Represents a communication link between a port on the local client and a |
388 // port on the remote client. | 388 // port on the remote client. |
389 class Connection : public rtc::MessageHandler, | 389 class Connection : public rtc::MessageHandler, |
390 public sigslot::has_slots<> { | 390 public sigslot::has_slots<> { |
391 public: | 391 public: |
392 struct SentPing { | 392 struct SentPing { |
393 SentPing(const std::string id, uint32 sent_time) | 393 SentPing(const std::string id, uint32_t sent_time) |
394 : id(id), | 394 : id(id), sent_time(sent_time) {} |
395 sent_time(sent_time) {} | |
396 | 395 |
397 std::string id; | 396 std::string id; |
398 uint32 sent_time; | 397 uint32_t sent_time; |
399 }; | 398 }; |
400 | 399 |
401 // States are from RFC 5245. http://tools.ietf.org/html/rfc5245#section-5.7.4 | 400 // States are from RFC 5245. http://tools.ietf.org/html/rfc5245#section-5.7.4 |
402 enum State { | 401 enum State { |
403 STATE_WAITING = 0, // Check has not been performed, Waiting pair on CL. | 402 STATE_WAITING = 0, // Check has not been performed, Waiting pair on CL. |
404 STATE_INPROGRESS, // Check has been sent, transaction is in progress. | 403 STATE_INPROGRESS, // Check has been sent, transaction is in progress. |
405 STATE_SUCCEEDED, // Check already done, produced a successful result. | 404 STATE_SUCCEEDED, // Check already done, produced a successful result. |
406 STATE_FAILED // Check for this connection failed. | 405 STATE_FAILED // Check for this connection failed. |
407 }; | 406 }; |
408 | 407 |
409 virtual ~Connection(); | 408 virtual ~Connection(); |
410 | 409 |
411 // The local port where this connection sends and receives packets. | 410 // The local port where this connection sends and receives packets. |
412 Port* port() { return port_; } | 411 Port* port() { return port_; } |
413 const Port* port() const { return port_; } | 412 const Port* port() const { return port_; } |
414 | 413 |
415 // Returns the description of the local port | 414 // Returns the description of the local port |
416 virtual const Candidate& local_candidate() const; | 415 virtual const Candidate& local_candidate() const; |
417 | 416 |
418 // Returns the description of the remote port to which we communicate. | 417 // Returns the description of the remote port to which we communicate. |
419 const Candidate& remote_candidate() const { return remote_candidate_; } | 418 const Candidate& remote_candidate() const { return remote_candidate_; } |
420 | 419 |
421 // Returns the pair priority. | 420 // Returns the pair priority. |
422 uint64 priority() const; | 421 uint64_t priority() const; |
423 | 422 |
424 enum WriteState { | 423 enum WriteState { |
425 STATE_WRITABLE = 0, // we have received ping responses recently | 424 STATE_WRITABLE = 0, // we have received ping responses recently |
426 STATE_WRITE_UNRELIABLE = 1, // we have had a few ping failures | 425 STATE_WRITE_UNRELIABLE = 1, // we have had a few ping failures |
427 STATE_WRITE_INIT = 2, // we have yet to receive a ping response | 426 STATE_WRITE_INIT = 2, // we have yet to receive a ping response |
428 STATE_WRITE_TIMEOUT = 3, // we have had a large number of ping failures | 427 STATE_WRITE_TIMEOUT = 3, // we have had a large number of ping failures |
429 }; | 428 }; |
430 | 429 |
431 WriteState write_state() const { return write_state_; } | 430 WriteState write_state() const { return write_state_; } |
432 bool writable() const { return write_state_ == STATE_WRITABLE; } | 431 bool writable() const { return write_state_ == STATE_WRITABLE; } |
433 bool receiving() const { return receiving_; } | 432 bool receiving() const { return receiving_; } |
434 | 433 |
435 // Determines whether the connection has finished connecting. This can only | 434 // Determines whether the connection has finished connecting. This can only |
436 // be false for TCP connections. | 435 // be false for TCP connections. |
437 bool connected() const { return connected_; } | 436 bool connected() const { return connected_; } |
438 | 437 |
439 // Estimate of the round-trip time over this connection. | 438 // Estimate of the round-trip time over this connection. |
440 uint32 rtt() const { return rtt_; } | 439 uint32_t rtt() const { return rtt_; } |
441 | 440 |
442 size_t sent_total_bytes(); | 441 size_t sent_total_bytes(); |
443 size_t sent_bytes_second(); | 442 size_t sent_bytes_second(); |
444 // Used to track how many packets are discarded in the application socket due | 443 // Used to track how many packets are discarded in the application socket due |
445 // to errors. | 444 // to errors. |
446 size_t sent_discarded_packets(); | 445 size_t sent_discarded_packets(); |
447 size_t sent_total_packets(); | 446 size_t sent_total_packets(); |
448 size_t recv_total_bytes(); | 447 size_t recv_total_bytes(); |
449 size_t recv_bytes_second(); | 448 size_t recv_bytes_second(); |
450 sigslot::signal1<Connection*> SignalStateChange; | 449 sigslot::signal1<Connection*> SignalStateChange; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 bool use_candidate_attr() const { return use_candidate_attr_; } | 483 bool use_candidate_attr() const { return use_candidate_attr_; } |
485 void set_use_candidate_attr(bool enable); | 484 void set_use_candidate_attr(bool enable); |
486 | 485 |
487 bool nominated() const { return nominated_; } | 486 bool nominated() const { return nominated_; } |
488 void set_nominated(bool nominated) { nominated_ = nominated; } | 487 void set_nominated(bool nominated) { nominated_ = nominated; } |
489 | 488 |
490 void set_remote_ice_mode(IceMode mode) { | 489 void set_remote_ice_mode(IceMode mode) { |
491 remote_ice_mode_ = mode; | 490 remote_ice_mode_ = mode; |
492 } | 491 } |
493 | 492 |
494 void set_receiving_timeout(uint32 receiving_timeout_ms) { | 493 void set_receiving_timeout(uint32_t receiving_timeout_ms) { |
495 receiving_timeout_ = receiving_timeout_ms; | 494 receiving_timeout_ = receiving_timeout_ms; |
496 } | 495 } |
497 | 496 |
498 // Makes the connection go away. | 497 // Makes the connection go away. |
499 void Destroy(); | 498 void Destroy(); |
500 | 499 |
501 // Checks that the state of this connection is up-to-date. The argument is | 500 // Checks that the state of this connection is up-to-date. The argument is |
502 // the current time, which is compared against various timeouts. | 501 // the current time, which is compared against various timeouts. |
503 void UpdateState(uint32 now); | 502 void UpdateState(uint32_t now); |
504 | 503 |
505 // Called when this connection should try checking writability again. | 504 // Called when this connection should try checking writability again. |
506 uint32 last_ping_sent() const { return last_ping_sent_; } | 505 uint32_t last_ping_sent() const { return last_ping_sent_; } |
507 void Ping(uint32 now); | 506 void Ping(uint32_t now); |
508 void ReceivedPingResponse(); | 507 void ReceivedPingResponse(); |
509 | 508 |
510 // Called whenever a valid ping is received on this connection. This is | 509 // Called whenever a valid ping is received on this connection. This is |
511 // public because the connection intercepts the first ping for us. | 510 // public because the connection intercepts the first ping for us. |
512 uint32 last_ping_received() const { return last_ping_received_; } | 511 uint32_t last_ping_received() const { return last_ping_received_; } |
513 void ReceivedPing(); | 512 void ReceivedPing(); |
514 | 513 |
515 // Debugging description of this connection | 514 // Debugging description of this connection |
516 std::string ToDebugId() const; | 515 std::string ToDebugId() const; |
517 std::string ToString() const; | 516 std::string ToString() const; |
518 std::string ToSensitiveString() const; | 517 std::string ToSensitiveString() const; |
519 // Prints pings_since_last_response_ into a string. | 518 // Prints pings_since_last_response_ into a string. |
520 void PrintPingsSinceLastResponse(std::string* pings, size_t max); | 519 void PrintPingsSinceLastResponse(std::string* pings, size_t max); |
521 | 520 |
522 bool reported() const { return reported_; } | 521 bool reported() const { return reported_; } |
(...skipping 15 matching lines...) Expand all Loading... |
538 void MaybeSetRemoteIceCredentials(const std::string& ice_ufrag, | 537 void MaybeSetRemoteIceCredentials(const std::string& ice_ufrag, |
539 const std::string& ice_pwd); | 538 const std::string& ice_pwd); |
540 | 539 |
541 // If |remote_candidate_| is peer reflexive and is equivalent to | 540 // If |remote_candidate_| is peer reflexive and is equivalent to |
542 // |new_candidate| except the type, update |remote_candidate_| to | 541 // |new_candidate| except the type, update |remote_candidate_| to |
543 // |new_candidate|. | 542 // |new_candidate|. |
544 void MaybeUpdatePeerReflexiveCandidate(const Candidate& new_candidate); | 543 void MaybeUpdatePeerReflexiveCandidate(const Candidate& new_candidate); |
545 | 544 |
546 // Returns the last received time of any data, stun request, or stun | 545 // Returns the last received time of any data, stun request, or stun |
547 // response in milliseconds | 546 // response in milliseconds |
548 uint32 last_received(); | 547 uint32_t last_received(); |
549 | 548 |
550 protected: | 549 protected: |
551 enum { MSG_DELETE = 0, MSG_FIRST_AVAILABLE }; | 550 enum { MSG_DELETE = 0, MSG_FIRST_AVAILABLE }; |
552 | 551 |
553 // Constructs a new connection to the given remote port. | 552 // Constructs a new connection to the given remote port. |
554 Connection(Port* port, size_t index, const Candidate& candidate); | 553 Connection(Port* port, size_t index, const Candidate& candidate); |
555 | 554 |
556 // Called back when StunRequestManager has a stun packet to send | 555 // Called back when StunRequestManager has a stun packet to send |
557 void OnSendStunPacket(const void* data, size_t size, StunRequest* req); | 556 void OnSendStunPacket(const void* data, size_t size, StunRequest* req); |
558 | 557 |
(...skipping 26 matching lines...) Expand all Loading... |
585 // By default |use_candidate_attr_| flag will be true, | 584 // By default |use_candidate_attr_| flag will be true, |
586 // as we will be using aggressive nomination. | 585 // as we will be using aggressive nomination. |
587 // But when peer is ice-lite, this flag "must" be initialized to false and | 586 // But when peer is ice-lite, this flag "must" be initialized to false and |
588 // turn on when connection becomes "best connection". | 587 // turn on when connection becomes "best connection". |
589 bool use_candidate_attr_; | 588 bool use_candidate_attr_; |
590 // Whether this connection has been nominated by the controlling side via | 589 // Whether this connection has been nominated by the controlling side via |
591 // the use_candidate attribute. | 590 // the use_candidate attribute. |
592 bool nominated_; | 591 bool nominated_; |
593 IceMode remote_ice_mode_; | 592 IceMode remote_ice_mode_; |
594 StunRequestManager requests_; | 593 StunRequestManager requests_; |
595 uint32 rtt_; | 594 uint32_t rtt_; |
596 uint32 last_ping_sent_; // last time we sent a ping to the other side | 595 uint32_t last_ping_sent_; // last time we sent a ping to the other side |
597 uint32 last_ping_received_; // last time we received a ping from the other | 596 uint32_t last_ping_received_; // last time we received a ping from the other |
598 // side | 597 // side |
599 uint32 last_data_received_; | 598 uint32_t last_data_received_; |
600 uint32 last_ping_response_received_; | 599 uint32_t last_ping_response_received_; |
601 std::vector<SentPing> pings_since_last_response_; | 600 std::vector<SentPing> pings_since_last_response_; |
602 | 601 |
603 rtc::RateTracker recv_rate_tracker_; | 602 rtc::RateTracker recv_rate_tracker_; |
604 rtc::RateTracker send_rate_tracker_; | 603 rtc::RateTracker send_rate_tracker_; |
605 uint32 sent_packets_discarded_; | 604 uint32_t sent_packets_discarded_; |
606 uint32 sent_packets_total_; | 605 uint32_t sent_packets_total_; |
607 | 606 |
608 private: | 607 private: |
609 void MaybeAddPrflxCandidate(ConnectionRequest* request, | 608 void MaybeAddPrflxCandidate(ConnectionRequest* request, |
610 StunMessage* response); | 609 StunMessage* response); |
611 | 610 |
612 bool reported_; | 611 bool reported_; |
613 State state_; | 612 State state_; |
614 // Time duration to switch from receiving to not receiving. | 613 // Time duration to switch from receiving to not receiving. |
615 uint32 receiving_timeout_; | 614 uint32_t receiving_timeout_; |
616 | 615 |
617 friend class Port; | 616 friend class Port; |
618 friend class ConnectionRequest; | 617 friend class ConnectionRequest; |
619 }; | 618 }; |
620 | 619 |
621 // ProxyConnection defers all the interesting work to the port | 620 // ProxyConnection defers all the interesting work to the port |
622 class ProxyConnection : public Connection { | 621 class ProxyConnection : public Connection { |
623 public: | 622 public: |
624 ProxyConnection(Port* port, size_t index, const Candidate& candidate); | 623 ProxyConnection(Port* port, size_t index, const Candidate& candidate); |
625 | 624 |
626 virtual int Send(const void* data, size_t size, | 625 virtual int Send(const void* data, size_t size, |
627 const rtc::PacketOptions& options); | 626 const rtc::PacketOptions& options); |
628 virtual int GetError() { return error_; } | 627 virtual int GetError() { return error_; } |
629 | 628 |
630 private: | 629 private: |
631 int error_; | 630 int error_; |
632 }; | 631 }; |
633 | 632 |
634 } // namespace cricket | 633 } // namespace cricket |
635 | 634 |
636 #endif // WEBRTC_P2P_BASE_PORT_H_ | 635 #endif // WEBRTC_P2P_BASE_PORT_H_ |
OLD | NEW |