stats.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. package ice
  4. import (
  5. "time"
  6. )
  7. // CandidatePairStats contains ICE candidate pair statistics
  8. type CandidatePairStats struct {
  9. // Timestamp is the timestamp associated with this object.
  10. Timestamp time.Time
  11. // LocalCandidateID is the ID of the local candidate
  12. LocalCandidateID string
  13. // RemoteCandidateID is the ID of the remote candidate
  14. RemoteCandidateID string
  15. // State represents the state of the checklist for the local and remote
  16. // candidates in a pair.
  17. State CandidatePairState
  18. // Nominated is true when this valid pair that should be used for media
  19. // if it is the highest-priority one amongst those whose nominated flag is set
  20. Nominated bool
  21. // PacketsSent represents the total number of packets sent on this candidate pair.
  22. PacketsSent uint32
  23. // PacketsReceived represents the total number of packets received on this candidate pair.
  24. PacketsReceived uint32
  25. // BytesSent represents the total number of payload bytes sent on this candidate pair
  26. // not including headers or padding.
  27. BytesSent uint64
  28. // BytesReceived represents the total number of payload bytes received on this candidate pair
  29. // not including headers or padding.
  30. BytesReceived uint64
  31. // LastPacketSentTimestamp represents the timestamp at which the last packet was
  32. // sent on this particular candidate pair, excluding STUN packets.
  33. LastPacketSentTimestamp time.Time
  34. // LastPacketReceivedTimestamp represents the timestamp at which the last packet
  35. // was received on this particular candidate pair, excluding STUN packets.
  36. LastPacketReceivedTimestamp time.Time
  37. // FirstRequestTimestamp represents the timestamp at which the first STUN request
  38. // was sent on this particular candidate pair.
  39. FirstRequestTimestamp time.Time
  40. // LastRequestTimestamp represents the timestamp at which the last STUN request
  41. // was sent on this particular candidate pair. The average interval between two
  42. // consecutive connectivity checks sent can be calculated with
  43. // (LastRequestTimestamp - FirstRequestTimestamp) / RequestsSent.
  44. LastRequestTimestamp time.Time
  45. // LastResponseTimestamp represents the timestamp at which the last STUN response
  46. // was received on this particular candidate pair.
  47. LastResponseTimestamp time.Time
  48. // TotalRoundTripTime represents the sum of all round trip time measurements
  49. // in seconds since the beginning of the session, based on STUN connectivity
  50. // check responses (ResponsesReceived), including those that reply to requests
  51. // that are sent in order to verify consent. The average round trip time can
  52. // be computed from TotalRoundTripTime by dividing it by ResponsesReceived.
  53. TotalRoundTripTime float64
  54. // CurrentRoundTripTime represents the latest round trip time measured in seconds,
  55. // computed from both STUN connectivity checks, including those that are sent
  56. // for consent verification.
  57. CurrentRoundTripTime float64
  58. // AvailableOutgoingBitrate is calculated by the underlying congestion control
  59. // by combining the available bitrate for all the outgoing RTP streams using
  60. // this candidate pair. The bitrate measurement does not count the size of the
  61. // IP or other transport layers like TCP or UDP. It is similar to the TIAS defined
  62. // in RFC 3890, i.e., it is measured in bits per second and the bitrate is calculated
  63. // over a 1 second window.
  64. AvailableOutgoingBitrate float64
  65. // AvailableIncomingBitrate is calculated by the underlying congestion control
  66. // by combining the available bitrate for all the incoming RTP streams using
  67. // this candidate pair. The bitrate measurement does not count the size of the
  68. // IP or other transport layers like TCP or UDP. It is similar to the TIAS defined
  69. // in RFC 3890, i.e., it is measured in bits per second and the bitrate is
  70. // calculated over a 1 second window.
  71. AvailableIncomingBitrate float64
  72. // CircuitBreakerTriggerCount represents the number of times the circuit breaker
  73. // is triggered for this particular 5-tuple, ceasing transmission.
  74. CircuitBreakerTriggerCount uint32
  75. // RequestsReceived represents the total number of connectivity check requests
  76. // received (including retransmissions). It is impossible for the receiver to
  77. // tell whether the request was sent in order to check connectivity or check
  78. // consent, so all connectivity checks requests are counted here.
  79. RequestsReceived uint64
  80. // RequestsSent represents the total number of connectivity check requests
  81. // sent (not including retransmissions).
  82. RequestsSent uint64
  83. // ResponsesReceived represents the total number of connectivity check responses received.
  84. ResponsesReceived uint64
  85. // ResponsesSent represents the total number of connectivity check responses sent.
  86. // Since we cannot distinguish connectivity check requests and consent requests,
  87. // all responses are counted.
  88. ResponsesSent uint64
  89. // RetransmissionsReceived represents the total number of connectivity check
  90. // request retransmissions received.
  91. RetransmissionsReceived uint64
  92. // RetransmissionsSent represents the total number of connectivity check
  93. // request retransmissions sent.
  94. RetransmissionsSent uint64
  95. // ConsentRequestsSent represents the total number of consent requests sent.
  96. ConsentRequestsSent uint64
  97. // ConsentExpiredTimestamp represents the timestamp at which the latest valid
  98. // STUN binding response expired.
  99. ConsentExpiredTimestamp time.Time
  100. }
  101. // CandidateStats contains ICE candidate statistics related to the ICETransport objects.
  102. type CandidateStats struct {
  103. // Timestamp is the timestamp associated with this object.
  104. Timestamp time.Time
  105. // ID is the candidate ID
  106. ID string
  107. // NetworkType represents the type of network interface used by the base of a
  108. // local candidate (the address the ICE agent sends from). Only present for
  109. // local candidates; it's not possible to know what type of network interface
  110. // a remote candidate is using.
  111. //
  112. // Note:
  113. // This stat only tells you about the network interface used by the first "hop";
  114. // it's possible that a connection will be bottlenecked by another type of network.
  115. // For example, when using Wi-Fi tethering, the networkType of the relevant candidate
  116. // would be "wifi", even when the next hop is over a cellular connection.
  117. NetworkType NetworkType
  118. // IP is the IP address of the candidate, allowing for IPv4 addresses and
  119. // IPv6 addresses, but fully qualified domain names (FQDNs) are not allowed.
  120. IP string
  121. // Port is the port number of the candidate.
  122. Port int
  123. // CandidateType is the "Type" field of the ICECandidate.
  124. CandidateType CandidateType
  125. // Priority is the "Priority" field of the ICECandidate.
  126. Priority uint32
  127. // URL is the URL of the TURN or STUN server indicated in the that translated
  128. // this IP address. It is the URL address surfaced in an PeerConnectionICEEvent.
  129. URL string
  130. // RelayProtocol is the protocol used by the endpoint to communicate with the
  131. // TURN server. This is only present for local candidates. Valid values for
  132. // the TURN URL protocol is one of UDP, TCP, or TLS.
  133. RelayProtocol string
  134. // Deleted is true if the candidate has been deleted/freed. For host candidates,
  135. // this means that any network resources (typically a socket) associated with the
  136. // candidate have been released. For TURN candidates, this means the TURN allocation
  137. // is no longer active.
  138. //
  139. // Only defined for local candidates. For remote candidates, this property is not applicable.
  140. Deleted bool
  141. }