1 /*
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 #ifndef WEBRTC_P2P_BASE_PORT_H_
12 #define WEBRTC_P2P_BASE_PORT_H_
13 
14 #include <map>
15 #include <set>
16 #include <string>
17 #include <vector>
18 
19 #include "webrtc/p2p/base/candidate.h"
20 #include "webrtc/p2p/base/packetsocketfactory.h"
21 #include "webrtc/p2p/base/portinterface.h"
22 #include "webrtc/p2p/base/stun.h"
23 #include "webrtc/p2p/base/stunrequest.h"
24 #include "webrtc/p2p/base/transport.h"
25 #include "webrtc/base/asyncpacketsocket.h"
26 #include "webrtc/base/network.h"
27 #include "webrtc/base/proxyinfo.h"
28 #include "webrtc/base/ratetracker.h"
29 #include "webrtc/base/sigslot.h"
30 #include "webrtc/base/socketaddress.h"
31 #include "webrtc/base/thread.h"
32 
33 namespace cricket {
34 
35 class Connection;
36 class ConnectionRequest;
37 
38 extern const char LOCAL_PORT_TYPE[];
39 extern const char STUN_PORT_TYPE[];
40 extern const char PRFLX_PORT_TYPE[];
41 extern const char RELAY_PORT_TYPE[];
42 
43 extern const char UDP_PROTOCOL_NAME[];
44 extern const char TCP_PROTOCOL_NAME[];
45 extern const char SSLTCP_PROTOCOL_NAME[];
46 
47 // RFC 6544, TCP candidate encoding rules.
48 extern const int DISCARD_PORT;
49 extern const char TCPTYPE_ACTIVE_STR[];
50 extern const char TCPTYPE_PASSIVE_STR[];
51 extern const char TCPTYPE_SIMOPEN_STR[];
52 
53 // The length of time we wait before timing out readability on a connection.
54 const uint32 CONNECTION_READ_TIMEOUT = 30 * 1000;   // 30 seconds
55 
56 // The length of time we wait before timing out writability on a connection.
57 const uint32 CONNECTION_WRITE_TIMEOUT = 15 * 1000;  // 15 seconds
58 
59 // The length of time we wait before we become unwritable.
60 const uint32 CONNECTION_WRITE_CONNECT_TIMEOUT = 5 * 1000;  // 5 seconds
61 
62 // The number of pings that must fail to respond before we become unwritable.
63 const uint32 CONNECTION_WRITE_CONNECT_FAILURES = 5;
64 
65 // This is the length of time that we wait for a ping response to come back.
66 const int CONNECTION_RESPONSE_TIMEOUT = 5 * 1000;   // 5 seconds
67 
68 enum RelayType {
69   RELAY_GTURN,   // Legacy google relay service.
70   RELAY_TURN     // Standard (TURN) relay service.
71 };
72 
73 enum IcePriorityValue {
74   // The reason we are choosing Relay preference 2 is because, we can run
75   // Relay from client to server on UDP/TCP/TLS. To distinguish the transport
76   // protocol, we prefer UDP over TCP over TLS.
77   // For UDP ICE_TYPE_PREFERENCE_RELAY will be 2.
78   // For TCP ICE_TYPE_PREFERENCE_RELAY will be 1.
79   // For TLS ICE_TYPE_PREFERENCE_RELAY will be 0.
80   // Check turnport.cc for setting these values.
81   ICE_TYPE_PREFERENCE_RELAY = 2,
82   ICE_TYPE_PREFERENCE_HOST_TCP = 90,
83   ICE_TYPE_PREFERENCE_SRFLX = 100,
84   ICE_TYPE_PREFERENCE_PRFLX = 110,
85   ICE_TYPE_PREFERENCE_HOST = 126
86 };
87 
88 const char* ProtoToString(ProtocolType proto);
89 bool StringToProto(const char* value, ProtocolType* proto);
90 
91 struct ProtocolAddress {
92   rtc::SocketAddress address;
93   ProtocolType proto;
94   bool secure;
95 
ProtocolAddressProtocolAddress96   ProtocolAddress(const rtc::SocketAddress& a, ProtocolType p)
97       : address(a), proto(p), secure(false) { }
ProtocolAddressProtocolAddress98   ProtocolAddress(const rtc::SocketAddress& a, ProtocolType p, bool sec)
99       : address(a), proto(p), secure(sec) { }
100 };
101 
102 typedef std::set<rtc::SocketAddress> ServerAddresses;
103 
104 // Represents a local communication mechanism that can be used to create
105 // connections to similar mechanisms of the other client.  Subclasses of this
106 // one add support for specific mechanisms like local UDP ports.
107 class Port : public PortInterface, public rtc::MessageHandler,
108              public sigslot::has_slots<> {
109  public:
110   Port(rtc::Thread* thread,
111        rtc::PacketSocketFactory* factory,
112        rtc::Network* network,
113        const rtc::IPAddress& ip,
114        const std::string& username_fragment,
115        const std::string& password);
116   Port(rtc::Thread* thread,
117        const std::string& type,
118        rtc::PacketSocketFactory* factory,
119        rtc::Network* network,
120        const rtc::IPAddress& ip,
121        uint16 min_port,
122        uint16 max_port,
123        const std::string& username_fragment,
124        const std::string& password);
125   virtual ~Port();
126 
Type()127   virtual const std::string& Type() const { return type_; }
Network()128   virtual rtc::Network* Network() const { return network_; }
129 
130   // This method will set the flag which enables standard ICE/STUN procedures
131   // in STUN connectivity checks. Currently this method does
132   // 1. Add / Verify MI attribute in STUN binding requests.
133   // 2. Username attribute in STUN binding request will be RFRAF:LFRAG,
134   // as opposed to RFRAGLFRAG.
SetIceProtocolType(IceProtocolType protocol)135   virtual void SetIceProtocolType(IceProtocolType protocol) {
136     ice_protocol_ = protocol;
137   }
IceProtocol()138   virtual IceProtocolType IceProtocol() const { return ice_protocol_; }
139 
140   // Methods to set/get ICE role and tiebreaker values.
GetIceRole()141   IceRole GetIceRole() const { return ice_role_; }
SetIceRole(IceRole role)142   void SetIceRole(IceRole role) { ice_role_ = role; }
143 
SetIceTiebreaker(uint64 tiebreaker)144   void SetIceTiebreaker(uint64 tiebreaker) { tiebreaker_ = tiebreaker; }
IceTiebreaker()145   uint64 IceTiebreaker() const { return tiebreaker_; }
146 
SharedSocket()147   virtual bool SharedSocket() const { return shared_socket_; }
ResetSharedSocket()148   void ResetSharedSocket() { shared_socket_ = false; }
149 
150   // The thread on which this port performs its I/O.
thread()151   rtc::Thread* thread() { return thread_; }
152 
153   // The factory used to create the sockets of this port.
socket_factory()154   rtc::PacketSocketFactory* socket_factory() const { return factory_; }
set_socket_factory(rtc::PacketSocketFactory * factory)155   void set_socket_factory(rtc::PacketSocketFactory* factory) {
156     factory_ = factory;
157   }
158 
159   // For debugging purposes.
content_name()160   const std::string& content_name() const { return content_name_; }
set_content_name(const std::string & content_name)161   void set_content_name(const std::string& content_name) {
162     content_name_ = content_name;
163   }
164 
component()165   int component() const { return component_; }
set_component(int component)166   void set_component(int component) { component_ = component; }
167 
send_retransmit_count_attribute()168   bool send_retransmit_count_attribute() const {
169     return send_retransmit_count_attribute_;
170   }
set_send_retransmit_count_attribute(bool enable)171   void set_send_retransmit_count_attribute(bool enable) {
172     send_retransmit_count_attribute_ = enable;
173   }
174 
175   // Identifies the generation that this port was created in.
generation()176   uint32 generation() { return generation_; }
set_generation(uint32 generation)177   void set_generation(uint32 generation) { generation_ = generation; }
178 
179   // ICE requires a single username/password per content/media line. So the
180   // |ice_username_fragment_| of the ports that belongs to the same content will
181   // be the same. However this causes a small complication with our relay
182   // server, which expects different username for RTP and RTCP.
183   //
184   // To resolve this problem, we implemented the username_fragment(),
185   // which returns a different username (calculated from
186   // |ice_username_fragment_|) for RTCP in the case of ICEPROTO_GOOGLE. And the
187   // username_fragment() simply returns |ice_username_fragment_| when running
188   // in ICEPROTO_RFC5245.
189   //
190   // As a result the ICEPROTO_GOOGLE will use different usernames for RTP and
191   // RTCP. And the ICEPROTO_RFC5245 will use same username for both RTP and
192   // RTCP.
193   const std::string username_fragment() const;
password()194   const std::string& password() const { return password_; }
195 
196   // Fired when candidates are discovered by the port. When all candidates
197   // are discovered that belong to port SignalAddressReady is fired.
198   sigslot::signal2<Port*, const Candidate&> SignalCandidateReady;
199 
200   // Provides all of the above information in one handy object.
Candidates()201   virtual const std::vector<Candidate>& Candidates() const {
202     return candidates_;
203   }
204 
205   // SignalPortComplete is sent when port completes the task of candidates
206   // allocation.
207   sigslot::signal1<Port*> SignalPortComplete;
208   // This signal sent when port fails to allocate candidates and this port
209   // can't be used in establishing the connections. When port is in shared mode
210   // and port fails to allocate one of the candidates, port shouldn't send
211   // this signal as other candidates might be usefull in establishing the
212   // connection.
213   sigslot::signal1<Port*> SignalPortError;
214 
215   // Returns a map containing all of the connections of this port, keyed by the
216   // remote address.
217   typedef std::map<rtc::SocketAddress, Connection*> AddressMap;
connections()218   const AddressMap& connections() { return connections_; }
219 
220   // Returns the connection to the given address or NULL if none exists.
221   virtual Connection* GetConnection(
222       const rtc::SocketAddress& remote_addr);
223 
224   // Called each time a connection is created.
225   sigslot::signal2<Port*, Connection*> SignalConnectionCreated;
226 
227   // In a shared socket mode each port which shares the socket will decide
228   // to accept the packet based on the |remote_addr|. Currently only UDP
229   // port implemented this method.
230   // TODO(mallinath) - Make it pure virtual.
HandleIncomingPacket(rtc::AsyncPacketSocket * socket,const char * data,size_t size,const rtc::SocketAddress & remote_addr,const rtc::PacketTime & packet_time)231   virtual bool HandleIncomingPacket(
232       rtc::AsyncPacketSocket* socket, const char* data, size_t size,
233       const rtc::SocketAddress& remote_addr,
234       const rtc::PacketTime& packet_time) {
235     ASSERT(false);
236     return false;
237   }
238 
239   // Sends a response message (normal or error) to the given request.  One of
240   // these methods should be called as a response to SignalUnknownAddress.
241   // NOTE: You MUST call CreateConnection BEFORE SendBindingResponse.
242   virtual void SendBindingResponse(StunMessage* request,
243                                    const rtc::SocketAddress& addr);
244   virtual void SendBindingErrorResponse(
245       StunMessage* request, const rtc::SocketAddress& addr,
246       int error_code, const std::string& reason);
247 
set_proxy(const std::string & user_agent,const rtc::ProxyInfo & proxy)248   void set_proxy(const std::string& user_agent,
249                  const rtc::ProxyInfo& proxy) {
250     user_agent_ = user_agent;
251     proxy_ = proxy;
252   }
user_agent()253   const std::string& user_agent() { return user_agent_; }
proxy()254   const rtc::ProxyInfo& proxy() { return proxy_; }
255 
256   virtual void EnablePortPackets();
257 
258   // Called if the port has no connections and is no longer useful.
259   void Destroy();
260 
261   virtual void OnMessage(rtc::Message *pmsg);
262 
263   // Debugging description of this port
264   virtual std::string ToString() const;
ip()265   const rtc::IPAddress& ip() const { return ip_; }
min_port()266   uint16 min_port() { return min_port_; }
max_port()267   uint16 max_port() { return max_port_; }
268 
269   // Timeout shortening function to speed up unit tests.
set_timeout_delay(int delay)270   void set_timeout_delay(int delay) { timeout_delay_ = delay; }
271 
272   // This method will return local and remote username fragements from the
273   // stun username attribute if present.
274   bool ParseStunUsername(const StunMessage* stun_msg,
275                          std::string* local_username,
276                          std::string* remote_username,
277                          IceProtocolType* remote_protocol_type) const;
278   void CreateStunUsername(const std::string& remote_username,
279                           std::string* stun_username_attr_str) const;
280 
281   bool MaybeIceRoleConflict(const rtc::SocketAddress& addr,
282                             IceMessage* stun_msg,
283                             const std::string& remote_ufrag);
284 
285   // Called when the socket is currently able to send.
286   void OnReadyToSend();
287 
288   // Called when the Connection discovers a local peer reflexive candidate.
289   // Returns the index of the new local candidate.
290   size_t AddPrflxCandidate(const Candidate& local);
291 
292   // Returns if RFC 5245 ICE protocol is used.
293   bool IsStandardIce() const;
294 
295   // Returns if Google ICE protocol is used.
296   bool IsGoogleIce() const;
297 
298   // Returns if Hybrid ICE protocol is used.
299   bool IsHybridIce() const;
300 
set_candidate_filter(uint32 candidate_filter)301   void set_candidate_filter(uint32 candidate_filter) {
302     candidate_filter_ = candidate_filter;
303   }
304 
305  protected:
306   enum {
307     MSG_CHECKTIMEOUT = 0,
308     MSG_FIRST_AVAILABLE
309   };
310 
set_type(const std::string & type)311   void set_type(const std::string& type) { type_ = type; }
312 
313   void AddAddress(const rtc::SocketAddress& address,
314                   const rtc::SocketAddress& base_address,
315                   const rtc::SocketAddress& related_address,
316                   const std::string& protocol, const std::string& tcptype,
317                   const std::string& type, uint32 type_preference,
318                   uint32 relay_preference, bool final);
319 
320   // Adds the given connection to the list.  (Deleting removes them.)
321   void AddConnection(Connection* conn);
322 
323   // Called when a packet is received from an unknown address that is not
324   // currently a connection.  If this is an authenticated STUN binding request,
325   // then we will signal the client.
326   void OnReadPacket(const char* data, size_t size,
327                     const rtc::SocketAddress& addr,
328                     ProtocolType proto);
329 
330   // If the given data comprises a complete and correct STUN message then the
331   // return value is true, otherwise false. If the message username corresponds
332   // with this port's username fragment, msg will contain the parsed STUN
333   // message.  Otherwise, the function may send a STUN response internally.
334   // remote_username contains the remote fragment of the STUN username.
335   bool GetStunMessage(const char* data, size_t size,
336                       const rtc::SocketAddress& addr,
337                       IceMessage** out_msg, std::string* out_username);
338 
339   // Checks if the address in addr is compatible with the port's ip.
340   bool IsCompatibleAddress(const rtc::SocketAddress& addr);
341 
342   // Returns default DSCP value.
DefaultDscpValue()343   rtc::DiffServCodePoint DefaultDscpValue() const {
344     // No change from what MediaChannel set.
345     return rtc::DSCP_NO_CHANGE;
346   }
347 
candidate_filter()348   uint32 candidate_filter() { return candidate_filter_; }
349 
350  private:
351   void Construct();
352   // Called when one of our connections deletes itself.
353   void OnConnectionDestroyed(Connection* conn);
354 
355   // Checks if this port is useless, and hence, should be destroyed.
356   void CheckTimeout();
357 
358   rtc::Thread* thread_;
359   rtc::PacketSocketFactory* factory_;
360   std::string type_;
361   bool send_retransmit_count_attribute_;
362   rtc::Network* network_;
363   rtc::IPAddress ip_;
364   uint16 min_port_;
365   uint16 max_port_;
366   std::string content_name_;
367   int component_;
368   uint32 generation_;
369   // In order to establish a connection to this Port (so that real data can be
370   // sent through), the other side must send us a STUN binding request that is
371   // authenticated with this username_fragment and password.
372   // PortAllocatorSession will provide these username_fragment and password.
373   //
374   // Note: we should always use username_fragment() instead of using
375   // |ice_username_fragment_| directly. For the details see the comment on
376   // username_fragment().
377   std::string ice_username_fragment_;
378   std::string password_;
379   std::vector<Candidate> candidates_;
380   AddressMap connections_;
381   int timeout_delay_;
382   bool enable_port_packets_;
383   IceProtocolType ice_protocol_;
384   IceRole ice_role_;
385   uint64 tiebreaker_;
386   bool shared_socket_;
387   // Information to use when going through a proxy.
388   std::string user_agent_;
389   rtc::ProxyInfo proxy_;
390 
391   // Candidate filter is pushed down to Port such that each Port could
392   // make its own decision on how to create candidates. For example,
393   // when IceTransportsType is set to relay, both RelayPort and
394   // TurnPort will hide raddr to avoid local address leakage.
395   uint32 candidate_filter_;
396 
397   friend class Connection;
398 };
399 
400 // Represents a communication link between a port on the local client and a
401 // port on the remote client.
402 class Connection : public rtc::MessageHandler,
403     public sigslot::has_slots<> {
404  public:
405   // States are from RFC 5245. http://tools.ietf.org/html/rfc5245#section-5.7.4
406   enum State {
407     STATE_WAITING = 0,  // Check has not been performed, Waiting pair on CL.
408     STATE_INPROGRESS,   // Check has been sent, transaction is in progress.
409     STATE_SUCCEEDED,    // Check already done, produced a successful result.
410     STATE_FAILED        // Check for this connection failed.
411   };
412 
413   virtual ~Connection();
414 
415   // The local port where this connection sends and receives packets.
port()416   Port* port() { return port_; }
port()417   const Port* port() const { return port_; }
418 
419   // Returns the description of the local port
420   virtual const Candidate& local_candidate() const;
421 
422   // Returns the description of the remote port to which we communicate.
remote_candidate()423   const Candidate& remote_candidate() const { return remote_candidate_; }
424 
425   // Returns the pair priority.
426   uint64 priority() const;
427 
428   enum ReadState {
429     STATE_READ_INIT    = 0,  // we have yet to receive a ping
430     STATE_READABLE     = 1,  // we have received pings recently
431     STATE_READ_TIMEOUT = 2,  // we haven't received pings in a while
432   };
433 
read_state()434   ReadState read_state() const { return read_state_; }
readable()435   bool readable() const { return read_state_ == STATE_READABLE; }
436 
437   enum WriteState {
438     STATE_WRITABLE          = 0,  // we have received ping responses recently
439     STATE_WRITE_UNRELIABLE  = 1,  // we have had a few ping failures
440     STATE_WRITE_INIT        = 2,  // we have yet to receive a ping response
441     STATE_WRITE_TIMEOUT     = 3,  // we have had a large number of ping failures
442   };
443 
write_state()444   WriteState write_state() const { return write_state_; }
writable()445   bool writable() const { return write_state_ == STATE_WRITABLE; }
446 
447   // Determines whether the connection has finished connecting.  This can only
448   // be false for TCP connections.
connected()449   bool connected() const { return connected_; }
450 
451   // Estimate of the round-trip time over this connection.
rtt()452   uint32 rtt() const { return rtt_; }
453 
454   size_t sent_total_bytes();
455   size_t sent_bytes_second();
456   // Used to track how many packets are discarded in the application socket due
457   // to errors.
458   size_t sent_discarded_packets();
459   size_t sent_total_packets();
460   size_t recv_total_bytes();
461   size_t recv_bytes_second();
462   sigslot::signal1<Connection*> SignalStateChange;
463 
464   // Sent when the connection has decided that it is no longer of value.  It
465   // will delete itself immediately after this call.
466   sigslot::signal1<Connection*> SignalDestroyed;
467 
468   // The connection can send and receive packets asynchronously.  This matches
469   // the interface of AsyncPacketSocket, which may use UDP or TCP under the
470   // covers.
471   virtual int Send(const void* data, size_t size,
472                    const rtc::PacketOptions& options) = 0;
473 
474   // Error if Send() returns < 0
475   virtual int GetError() = 0;
476 
477   sigslot::signal4<Connection*, const char*, size_t,
478                    const rtc::PacketTime&> SignalReadPacket;
479 
480   sigslot::signal1<Connection*> SignalReadyToSend;
481 
482   // Called when a packet is received on this connection.
483   void OnReadPacket(const char* data, size_t size,
484                     const rtc::PacketTime& packet_time);
485 
486   // Called when the socket is currently able to send.
487   void OnReadyToSend();
488 
489   // Called when a connection is determined to be no longer useful to us.  We
490   // still keep it around in case the other side wants to use it.  But we can
491   // safely stop pinging on it and we can allow it to time out if the other
492   // side stops using it as well.
pruned()493   bool pruned() const { return pruned_; }
494   void Prune();
495 
use_candidate_attr()496   bool use_candidate_attr() const { return use_candidate_attr_; }
497   void set_use_candidate_attr(bool enable);
498 
set_remote_ice_mode(IceMode mode)499   void set_remote_ice_mode(IceMode mode) {
500     remote_ice_mode_ = mode;
501   }
502 
503   // Makes the connection go away.
504   void Destroy();
505 
506   // Checks that the state of this connection is up-to-date.  The argument is
507   // the current time, which is compared against various timeouts.
508   void UpdateState(uint32 now);
509 
510   // Called when this connection should try checking writability again.
last_ping_sent()511   uint32 last_ping_sent() const { return last_ping_sent_; }
512   void Ping(uint32 now);
513 
514   // Called whenever a valid ping is received on this connection.  This is
515   // public because the connection intercepts the first ping for us.
last_ping_received()516   uint32 last_ping_received() const { return last_ping_received_; }
517   void ReceivedPing();
518 
519   // Debugging description of this connection
520   std::string ToDebugId() const;
521   std::string ToString() const;
522   std::string ToSensitiveString() const;
523 
reported()524   bool reported() const { return reported_; }
set_reported(bool reported)525   void set_reported(bool reported) { reported_ = reported;}
526 
527   // This flag will be set if this connection is the chosen one for media
528   // transmission. This connection will send STUN ping with USE-CANDIDATE
529   // attribute.
530   sigslot::signal1<Connection*> SignalUseCandidate;
531   // Invoked when Connection receives STUN error response with 487 code.
532   void HandleRoleConflictFromPeer();
533 
state()534   State state() const { return state_; }
535 
remote_ice_mode()536   IceMode remote_ice_mode() const { return remote_ice_mode_; }
537 
538   // Update the ICE password of the remote candidate if |ice_ufrag| matches
539   // the candidate's ufrag, and the candidate's passwrod has not been set.
540   void MaybeSetRemoteIceCredentials(const std::string& ice_ufrag,
541                                     const std::string& ice_pwd);
542 
543   // If |remote_candidate_| is peer reflexive and is equivalent to
544   // |new_candidate| except the type, update |remote_candidate_| to
545   // |new_candidate|.
546   void MaybeUpdatePeerReflexiveCandidate(const Candidate& new_candidate);
547 
548  protected:
549   // Constructs a new connection to the given remote port.
550   Connection(Port* port, size_t index, const Candidate& candidate);
551 
552   // Called back when StunRequestManager has a stun packet to send
553   void OnSendStunPacket(const void* data, size_t size, StunRequest* req);
554 
555   // Callbacks from ConnectionRequest
556   void OnConnectionRequestResponse(ConnectionRequest* req,
557                                    StunMessage* response);
558   void OnConnectionRequestErrorResponse(ConnectionRequest* req,
559                                         StunMessage* response);
560   void OnConnectionRequestTimeout(ConnectionRequest* req);
561 
562   // Changes the state and signals if necessary.
563   void set_read_state(ReadState value);
564   void set_write_state(WriteState value);
565   void set_state(State state);
566   void set_connected(bool value);
567 
568   // Checks if this connection is useless, and hence, should be destroyed.
569   void CheckTimeout();
570 
571   void OnMessage(rtc::Message *pmsg);
572 
573   Port* port_;
574   size_t local_candidate_index_;
575   Candidate remote_candidate_;
576   ReadState read_state_;
577   WriteState write_state_;
578   bool connected_;
579   bool pruned_;
580   // By default |use_candidate_attr_| flag will be true,
581   // as we will be using agrressive nomination.
582   // But when peer is ice-lite, this flag "must" be initialized to false and
583   // turn on when connection becomes "best connection".
584   bool use_candidate_attr_;
585   IceMode remote_ice_mode_;
586   StunRequestManager requests_;
587   uint32 rtt_;
588   uint32 last_ping_sent_;      // last time we sent a ping to the other side
589   uint32 last_ping_received_;  // last time we received a ping from the other
590                                // side
591   uint32 last_data_received_;
592   uint32 last_ping_response_received_;
593   std::vector<uint32> pings_since_last_response_;
594 
595   rtc::RateTracker recv_rate_tracker_;
596   rtc::RateTracker send_rate_tracker_;
597   uint32 sent_packets_discarded_;
598   uint32 sent_packets_total_;
599 
600  private:
601   void MaybeAddPrflxCandidate(ConnectionRequest* request,
602                               StunMessage* response);
603 
604   bool reported_;
605   State state_;
606 
607   friend class Port;
608   friend class ConnectionRequest;
609 };
610 
611 // ProxyConnection defers all the interesting work to the port
612 class ProxyConnection : public Connection {
613  public:
614   ProxyConnection(Port* port, size_t index, const Candidate& candidate);
615 
616   virtual int Send(const void* data, size_t size,
617                    const rtc::PacketOptions& options);
GetError()618   virtual int GetError() { return error_; }
619 
620  private:
621   int error_;
622 };
623 
624 }  // namespace cricket
625 
626 #endif  // WEBRTC_P2P_BASE_PORT_H_
627