1 /*
2  *  Copyright 2019 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 P2P_BASE_CONNECTION_INFO_H_
12 #define P2P_BASE_CONNECTION_INFO_H_
13 
14 #include <vector>
15 
16 #include "absl/types/optional.h"
17 #include "api/candidate.h"
18 
19 namespace cricket {
20 
21 // States are from RFC 5245. http://tools.ietf.org/html/rfc5245#section-5.7.4
22 enum class IceCandidatePairState {
23   WAITING = 0,  // Check has not been performed, Waiting pair on CL.
24   IN_PROGRESS,  // Check has been sent, transaction is in progress.
25   SUCCEEDED,    // Check already done, produced a successful result.
26   FAILED,       // Check for this connection failed.
27   // According to spec there should also be a frozen state, but nothing is ever
28   // frozen because we have not implemented ICE freezing logic.
29 };
30 
31 // Stats that we can return about the connections for a transport channel.
32 // TODO(hta): Rename to ConnectionStats
33 struct ConnectionInfo {
34   ConnectionInfo();
35   ConnectionInfo(const ConnectionInfo&);
36   ~ConnectionInfo();
37 
38   bool best_connection;      // Is this the best connection we have?
39   bool writable;             // Has this connection received a STUN response?
40   bool receiving;            // Has this connection received anything?
41   bool timeout;              // Has this connection timed out?
42   bool new_connection;       // Is this a newly created connection?
43   size_t rtt;                // The STUN RTT for this connection.
44   size_t sent_total_bytes;   // Total bytes sent on this connection.
45   size_t sent_bytes_second;  // Bps over the last measurement interval.
46   size_t sent_discarded_packets;  // Number of outgoing packets discarded due to
47                                   // socket errors.
48   size_t sent_total_packets;  // Number of total outgoing packets attempted for
49                               // sending.
50   size_t sent_ping_requests_total;  // Number of STUN ping request sent.
51   size_t sent_ping_requests_before_first_response;  // Number of STUN ping
52   // sent before receiving the first response.
53   size_t sent_ping_responses;  // Number of STUN ping response sent.
54 
55   size_t recv_total_bytes;     // Total bytes received on this connection.
56   size_t recv_bytes_second;    // Bps over the last measurement interval.
57   size_t packets_received;     // Number of packets that were received.
58   size_t recv_ping_requests;   // Number of STUN ping request received.
59   size_t recv_ping_responses;  // Number of STUN ping response received.
60   Candidate local_candidate;   // The local candidate for this connection.
61   Candidate remote_candidate;  // The remote candidate for this connection.
62   void* key;                   // A static value that identifies this conn.
63   // https://w3c.github.io/webrtc-stats/#dom-rtcicecandidatepairstats-state
64   IceCandidatePairState state;
65   // https://w3c.github.io/webrtc-stats/#dom-rtcicecandidatepairstats-priority
66   uint64_t priority;
67   // https://w3c.github.io/webrtc-stats/#dom-rtcicecandidatepairstats-nominated
68   bool nominated;
69   // https://w3c.github.io/webrtc-stats/#dom-rtcicecandidatepairstats-totalroundtriptime
70   uint64_t total_round_trip_time_ms;
71   // https://w3c.github.io/webrtc-stats/#dom-rtcicecandidatepairstats-currentroundtriptime
72   absl::optional<uint32_t> current_round_trip_time_ms;
73 };
74 
75 // Information about all the candidate pairs of a channel.
76 typedef std::vector<ConnectionInfo> ConnectionInfos;
77 
78 }  // namespace cricket
79 
80 #endif  // P2P_BASE_CONNECTION_INFO_H_
81