| 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_H_ |
| 12 | #define P2P_BASE_CONNECTION_H_ |
| 13 |
| 14 | #include <stddef.h> |
| 15 |
| 16 | #include <cstdint> |
| 17 | #include <functional> |
| 18 | #include <memory> |
| 19 | #include <string> |
| 20 | #include <type_traits> |
| 21 | #include <utility> |
| 22 | #include <vector> |
| 23 |
| 24 | #include "absl/functional/any_invocable.h" |
| 25 | #include "absl/strings/string_view.h" |
| 26 | #include "absl/types/optional.h" |
| 27 | #include "api/candidate.h" |
| 28 | #include "api/rtc_error.h" |
| 29 | #include "api/sequence_checker.h" |
| 30 | #include "api/task_queue/task_queue_base.h" |
| 31 | #include "api/transport/stun.h" |
| 32 | #include "logging/rtc_event_log/events/rtc_event_ice_candidate_pair.h" |
| 33 | #include "logging/rtc_event_log/events/rtc_event_ice_candidate_pair_config.h" |
| 34 | #include "logging/rtc_event_log/ice_logger.h" |
| 35 | #include "p2p/base/candidate_pair_interface.h" |
| 36 | #include "p2p/base/connection_info.h" |
| 37 | #include "p2p/base/p2p_transport_channel_ice_field_trials.h" |
| 38 | #include "p2p/base/port_interface.h" |
| 39 | #include "p2p/base/stun_request.h" |
| 40 | #include "p2p/base/transport_description.h" |
| 41 | #include "rtc_base/async_packet_socket.h" |
| 42 | #include "rtc_base/network.h" |
| 43 | #include "rtc_base/network/received_packet.h" |
| 44 | #include "rtc_base/numerics/event_based_exponential_moving_average.h" |
| 45 | #include "rtc_base/rate_tracker.h" |
| 46 | #include "rtc_base/system/rtc_export.h" |
| 47 | #include "rtc_base/third_party/sigslot/sigslot.h" |
| 48 | #include "rtc_base/thread_annotations.h" |
| 49 | #include "rtc_base/weak_ptr.h" |
| 50 |
| 51 | namespace cricket { |
| 52 |
| 53 | // Version number for GOOG_PING, this is added to have the option of |
| 54 | // adding other flavors in the future. |
| 55 | constexpr int kGoogPingVersion = 1; |
| 56 |
| 57 | // Forward declaration so that a ConnectionRequest can contain a Connection. |
| 58 | class Connection; |
| 59 |
| 60 | // Represents a communication link between a port on the local client and a |
| 61 | // port on the remote client. |
| 62 | class RTC_EXPORT Connection : public CandidatePairInterface { |
| 63 | public: |
| 64 | struct SentPing { |
| 65 | SentPing(absl::string_view id, int64_t sent_time, uint32_t nomination) |
| 66 | : id(id), sent_time(sent_time), nomination(nomination) {} |
| 67 |
| 68 | std::string id; |
| 69 | int64_t sent_time; |
| 70 | uint32_t nomination; |
| 71 | }; |
| 72 |
| 73 | ~Connection() override; |
| 74 |
| 75 | // A unique ID assigned when the connection is created. |
| 76 | uint32_t id() const { return id_; } |
| 77 |
| 78 | webrtc::TaskQueueBase* network_thread() const; |
| 79 |
| 80 | // Implementation of virtual methods in CandidatePairInterface. |
| 81 | // Returns the description of the local port |
| 82 | const Candidate& local_candidate() const override; |
| 83 | // Returns the description of the remote port to which we communicate. |
| 84 | const Candidate& remote_candidate() const override; |
| 85 |
| 86 | // Return local network for this connection. |
| 87 | virtual const rtc::Network* network() const; |
| 88 | // Return generation for this connection. |
| 89 | virtual int generation() const; |
| 90 |
| 91 | // Returns the pair priority. |
| 92 | virtual uint64_t priority() const; |
| 93 |
| 94 | enum WriteState { |
| 95 | STATE_WRITABLE = 0, // we have received ping responses recently |
| 96 | STATE_WRITE_UNRELIABLE = 1, // we have had a few ping failures |
| 97 | STATE_WRITE_INIT = 2, // we have yet to receive a ping response |
| 98 | STATE_WRITE_TIMEOUT = 3, // we have had a large number of ping failures |
| 99 | }; |
| 100 |
| 101 | WriteState write_state() const; |
| 102 | bool writable() const; |
| 103 | bool receiving() const; |
| 104 |
| 105 | const PortInterface* port() const { |
| 106 | RTC_DCHECK_RUN_ON(network_thread_); |
| 107 | return port_.get(); |
| 108 | } |
| 109 |
| 110 | // Determines whether the connection has finished connecting. This can only |
| 111 | // be false for TCP connections. |
| 112 | bool connected() const; |
| 113 | bool weak() const; |
| 114 | bool active() const; |
| 115 | bool pending_delete() const { return !port_; } |
| 116 |
| 117 | // A connection is dead if it can be safely deleted. |
| 118 | bool dead(int64_t now) const; |
| 119 |
| 120 | // Estimate of the round-trip time over this connection. |
| 121 | int rtt() const; |
| 122 |
| 123 | int unwritable_timeout() const; |
| 124 | void set_unwritable_timeout(const absl::optional<int>& value_ms); |
| 125 | int unwritable_min_checks() const; |
| 126 | void set_unwritable_min_checks(const absl::optional<int>& value); |
| 127 | int inactive_timeout() const; |
| 128 | void set_inactive_timeout(const absl::optional<int>& value); |
| 129 |
| 130 | // Gets the `ConnectionInfo` stats, where `best_connection` has not been |
| 131 | // populated (default value false). |
| 132 | ConnectionInfo stats(); |
| 133 |
| 134 | sigslot::signal1<Connection*> SignalStateChange; |
| 135 |
| 136 | // Sent when the connection has decided that it is no longer of value. It |
| 137 | // will delete itself immediately after this call. |
| 138 | sigslot::signal1<Connection*> SignalDestroyed; |
| 139 |
| 140 | // The connection can send and receive packets asynchronously. This matches |
| 141 | // the interface of AsyncPacketSocket, which may use UDP or TCP under the |
| 142 | // covers. |
| 143 | virtual int Send(const void* data, |
| 144 | size_t size, |
| 145 | const rtc::PacketOptions& options) = 0; |
| 146 |
| 147 | // Error if Send() returns < 0 |
| 148 | virtual int GetError() = 0; |
| 149 |
| 150 | // Register as a recipient of received packets. There can only be one. |
| 151 | void RegisterReceivedPacketCallback( |
| 152 | absl::AnyInvocable<void(Connection*, const rtc::ReceivedPacket&)> |
| 153 | received_packet_callback); |
| 154 | void DeregisterReceivedPacketCallback(); |
| 155 |
| 156 | sigslot::signal1<Connection*> SignalReadyToSend; |
| 157 |
| 158 | // Called when a packet is received on this connection. |
| 159 | void OnReadPacket(const rtc::ReceivedPacket& packet); |
| 160 | [[deprecated("Pass a rtc::ReceivedPacket")]] void |
| 161 | OnReadPacket(const char* data, size_t size, int64_t packet_time_us); |
| 162 |
| 163 | // Called when the socket is currently able to send. |
| 164 | void OnReadyToSend(); |
| 165 |
| 166 | // Called when a connection is determined to be no longer useful to us. We |
| 167 | // still keep it around in case the other side wants to use it. But we can |
| 168 | // safely stop pinging on it and we can allow it to time out if the other |
| 169 | // side stops using it as well. |
| 170 | bool pruned() const; |
| 171 | void Prune(); |
| 172 |
| 173 | bool use_candidate_attr() const; |
| 174 | void set_use_candidate_attr(bool enable); |
| 175 |
| 176 | void set_nomination(uint32_t value); |
| 177 |
| 178 | uint32_t remote_nomination() const; |
| 179 | // One or several pairs may be nominated based on if Regular or Aggressive |
| 180 | // Nomination is used. https://tools.ietf.org/html/rfc5245#section-8 |
| 181 | // `nominated` is defined both for the controlling or controlled agent based |
| 182 | // on if a nomination has been pinged or acknowledged. The controlled agent |
| 183 | // gets its `remote_nomination_` set when pinged by the controlling agent with |
| 184 | // a nomination value. The controlling agent gets its `acked_nomination_` set |
| 185 | // when receiving a response to a nominating ping. |
| 186 | bool nominated() const; |
| 187 |
| 188 | int receiving_timeout() const; |
| 189 | void set_receiving_timeout(absl::optional<int> receiving_timeout_ms); |
| 190 |
| 191 | // Deletes a `Connection` instance is by calling the `DestroyConnection` |
| 192 | // method in `Port`. |
| 193 | // Note: When the function returns, the object has been deleted. |
| 194 | void Destroy(); |
| 195 |
| 196 | // Signals object destruction, releases outstanding references and performs |
| 197 | // final logging. |
| 198 | // The function will return `true` when shutdown was performed, signals |
| 199 | // emitted and outstanding references released. If the function returns |
| 200 | // `false`, `Shutdown()` has previously been called. |
| 201 | bool Shutdown(); |
| 202 |
| 203 | // Prunes the connection and sets its state to STATE_FAILED, |
| 204 | // It will not be used or send pings although it can still receive packets. |
| 205 | void FailAndPrune(); |
| 206 |
| 207 | // Checks that the state of this connection is up-to-date. The argument is |
| 208 | // the current time, which is compared against various timeouts. |
| 209 | void UpdateState(int64_t now); |
| 210 |
| 211 | void UpdateLocalIceParameters(int component, |
| 212 | absl::string_view username_fragment, |
| 213 | absl::string_view password); |
| 214 |
| 215 | // Called when this connection should try checking writability again. |
| 216 | int64_t last_ping_sent() const; |
| 217 | void Ping(int64_t now, |
| 218 | std::unique_ptr<StunByteStringAttribute> delta = nullptr); |
| 219 | void ReceivedPingResponse( |
| 220 | int rtt, |
| 221 | absl::string_view request_id, |
| 222 | const absl::optional<uint32_t>& nomination = absl::nullopt); |
| 223 | std::unique_ptr<IceMessage> BuildPingRequest( |
| 224 | std::unique_ptr<StunByteStringAttribute> delta) |
| 225 | RTC_RUN_ON(network_thread_); |
| 226 |
| 227 | int64_t last_ping_response_received() const; |
| 228 | const absl::optional<std::string>& last_ping_id_received() const; |
| 229 |
| 230 | // Used to check if any STUN ping response has been received. |
| 231 | int rtt_samples() const; |
| 232 |
| 233 | // Called whenever a valid ping is received on this connection. This is |
| 234 | // public because the connection intercepts the first ping for us. |
| 235 | int64_t last_ping_received() const; |
| 236 |
| 237 | void ReceivedPing( |
| 238 | const absl::optional<std::string>& request_id = absl::nullopt); |
| 239 | // Handles the binding request; sends a response if this is a valid request. |
| 240 | void HandleStunBindingOrGoogPingRequest(IceMessage* msg); |
| 241 | // Handles the piggyback acknowledgement of the lastest connectivity check |
| 242 | // that the remote peer has received, if it is indicated in the incoming |
| 243 | // connectivity check from the peer. |
| 244 | void HandlePiggybackCheckAcknowledgementIfAny(StunMessage* msg); |
| 245 | // Timestamp when data was last sent (or attempted to be sent). |
| 246 | int64_t last_send_data() const; |
| 247 | int64_t last_data_received() const; |
| 248 |
| 249 | // Debugging description of this connection |
| 250 | std::string ToDebugId() const; |
| 251 | std::string ToString() const; |
| 252 | std::string ToSensitiveString() const; |
| 253 | // Structured description of this candidate pair. |
| 254 | const webrtc::IceCandidatePairDescription& ToLogDescription(); |
| 255 | void set_ice_event_log(webrtc::IceEventLog* ice_event_log); |
| 256 |
| 257 | // Prints pings_since_last_response_ into a string. |
| 258 | void PrintPingsSinceLastResponse(std::string* pings, size_t max); |
| 259 |
| 260 | // `set_selected` is only used for logging in ToString above. The flag is |
| 261 | // set true by P2PTransportChannel for its selected candidate pair. |
| 262 | // TODO(tommi): Remove `selected()` once not referenced downstream. |
| 263 | bool selected() const; |
| 264 | void set_selected(bool selected); |
| 265 |
| 266 | // This signal will be fired if this connection is nominated by the |
| 267 | // controlling side. |
| 268 | sigslot::signal1<Connection*> SignalNominated; |
| 269 |
| 270 | IceCandidatePairState state() const; |
| 271 |
| 272 | int num_pings_sent() const; |
| 273 |
| 274 | uint32_t ComputeNetworkCost() const; |
| 275 |
| 276 | // Update the ICE password and/or generation of the remote candidate if the |
| 277 | // ufrag in `params` matches the candidate's ufrag, and the |
| 278 | // candidate's password and/or ufrag has not been set. |
| 279 | void MaybeSetRemoteIceParametersAndGeneration(const IceParameters& params, |
| 280 | int generation); |
| 281 |
| 282 | // If `remote_candidate_` is peer reflexive and is equivalent to |
| 283 | // `new_candidate` except the type, update `remote_candidate_` to |
| 284 | // `new_candidate`. |
| 285 | void MaybeUpdatePeerReflexiveCandidate(const Candidate& new_candidate); |
| 286 |
| 287 | // Returns the last received time of any data, stun request, or stun |
| 288 | // response in milliseconds |
| 289 | int64_t last_received() const; |
| 290 | // Returns the last time when the connection changed its receiving state. |
| 291 | int64_t receiving_unchanged_since() const; |
| 292 |
| 293 | // Constructs the prflx priority as described in |
| 294 | // https://datatracker.ietf.org/doc/html/rfc5245#section-4.1.2.1 |
| 295 | uint32_t prflx_priority() const; |
| 296 |
| 297 | bool stable(int64_t now) const; |
| 298 |
| 299 | // Check if we sent `val` pings without receving a response. |
| 300 | bool TooManyOutstandingPings(const absl::optional<int>& val) const; |
| 301 |
| 302 | // Called by Port when the network cost changes. |
| 303 | void SetLocalCandidateNetworkCost(uint16_t cost); |
| 304 |
| 305 | void SetIceFieldTrials(const IceFieldTrials* field_trials); |
| 306 | const rtc::EventBasedExponentialMovingAverage& GetRttEstimate() const { |
| 307 | return rtt_estimate_; |
| 308 | } |
| 309 |
| 310 | // Reset the connection to a state of a newly connected. |
| 311 | // - STATE_WRITE_INIT |
| 312 | // - receving = false |
| 313 | // - throw away all pending request |
| 314 | // - reset RttEstimate |
| 315 | // |
| 316 | // Keep the following unchanged: |
| 317 | // - connected |
| 318 | // - remote_candidate |
| 319 | // - statistics |
| 320 | // |
| 321 | // Does not trigger SignalStateChange |
| 322 | void ForgetLearnedState(); |
| 323 |
| 324 | void SendStunBindingResponse(const StunMessage* message); |
| 325 | void SendGoogPingResponse(const StunMessage* message); |
| 326 | void SendResponseMessage(const StunMessage& response); |
| 327 |
| 328 | // An accessor for unit tests. |
| 329 | PortInterface* PortForTest() { return port_.get(); } |
| 330 | const PortInterface* PortForTest() const { return port_.get(); } |
| 331 |
| 332 | std::unique_ptr<IceMessage> BuildPingRequestForTest() { |
| 333 | RTC_DCHECK_RUN_ON(network_thread_); |
| 334 | return BuildPingRequest(nullptr); |
| 335 | } |
| 336 |
| 337 | // Public for unit tests. |
| 338 | uint32_t acked_nomination() const; |
| 339 | void set_remote_nomination(uint32_t remote_nomination); |
| 340 |
| 341 | const std::string& remote_password_for_test() const { |
| 342 | return remote_candidate().password(); |
| 343 | } |
| 344 | void set_remote_password_for_test(absl::string_view pwd) { |
| 345 | remote_candidate_.set_password(pwd); |
| 346 | } |
| 347 |
| 348 | void SetStunDictConsumer( |
| 349 | std::function<std::unique_ptr<StunAttribute>( |
| 350 | const StunByteStringAttribute*)> goog_delta_consumer, |
| 351 | std::function<void(webrtc::RTCErrorOr<const StunUInt64Attribute*>)> |
| 352 | goog_delta_ack_consumer) { |
| 353 | goog_delta_consumer_ = std::move(goog_delta_consumer); |
| 354 | goog_delta_ack_consumer_ = std::move(goog_delta_ack_consumer); |
| 355 | } |
| 356 |
| 357 | void ClearStunDictConsumer() { |
| 358 | goog_delta_consumer_ = absl::nullopt; |
| 359 | goog_delta_ack_consumer_ = absl::nullopt; |
| 360 | } |
| 361 |
| 362 | protected: |
| 363 | // A ConnectionRequest is a simple STUN ping used to determine writability. |
| 364 | class ConnectionRequest; |
| 365 |
| 366 | // Constructs a new connection to the given remote port. |
| 367 | Connection(rtc::WeakPtr<PortInterface> port, |
| 368 | size_t index, |
| 369 | const Candidate& candidate); |
| 370 |
| 371 | // Called back when StunRequestManager has a stun packet to send |
| 372 | void OnSendStunPacket(const void* data, size_t size, StunRequest* req); |
| 373 |
| 374 | // Callbacks from ConnectionRequest |
| 375 | virtual void OnConnectionRequestResponse(StunRequest* req, |
| 376 | StunMessage* response); |
| 377 | void OnConnectionRequestErrorResponse(ConnectionRequest* req, |
| 378 | StunMessage* response) |
| 379 | RTC_RUN_ON(network_thread_); |
| 380 | void OnConnectionRequestTimeout(ConnectionRequest* req) |
| 381 | RTC_RUN_ON(network_thread_); |
| 382 | void OnConnectionRequestSent(ConnectionRequest* req) |
| 383 | RTC_RUN_ON(network_thread_); |
| 384 |
| 385 | bool rtt_converged() const; |
| 386 |
| 387 | // If the response is not received within 2 * RTT, the response is assumed to |
| 388 | // be missing. |
| 389 | bool missing_responses(int64_t now) const; |
| 390 |
| 391 | // Changes the state and signals if necessary. |
| 392 | void set_write_state(WriteState value); |
| 393 | void UpdateReceiving(int64_t now); |
| 394 | void set_state(IceCandidatePairState state); |
| 395 | void set_connected(bool value); |
| 396 |
| 397 | // The local port where this connection sends and receives packets. |
| 398 | PortInterface* port() { return port_.get(); } |
| 399 |
| 400 | // NOTE: A pointer to the network thread is held by `port_` so in theory we |
| 401 | // shouldn't need to hold on to this pointer here, but rather defer to |
| 402 | // port_->thread(). However, some tests delete the classes in the wrong order |
| 403 | // so `port_` may be deleted before an instance of this class is deleted. |
| 404 | // TODO(tommi): This ^^^ should be fixed. |
| 405 | webrtc::TaskQueueBase* const network_thread_; |
| 406 | const uint32_t id_; |
| 407 | rtc::WeakPtr<PortInterface> port_; |
| 408 | Candidate local_candidate_ RTC_GUARDED_BY(network_thread_); |
| 409 | Candidate remote_candidate_; |
| 410 |
| 411 | ConnectionInfo stats_; |
| 412 | rtc::RateTracker recv_rate_tracker_; |
| 413 | rtc::RateTracker send_rate_tracker_; |
| 414 | int64_t last_send_data_ = 0; |
| 415 |
| 416 | private: |
| 417 | // Update the local candidate based on the mapped address attribute. |
| 418 | // If the local candidate changed, fires SignalStateChange. |
| 419 | void MaybeUpdateLocalCandidate(StunRequest* request, StunMessage* response) |
| 420 | RTC_RUN_ON(network_thread_); |
| 421 |
| 422 | void LogCandidatePairConfig(webrtc::IceCandidatePairConfigType type) |
| 423 | RTC_RUN_ON(network_thread_); |
| 424 | void LogCandidatePairEvent(webrtc::IceCandidatePairEventType type, |
| 425 | uint32_t transaction_id) |
| 426 | RTC_RUN_ON(network_thread_); |
| 427 |
| 428 | // Check if this IceMessage is identical |
| 429 | // to last message ack:ed STUN_BINDING_REQUEST. |
| 430 | bool ShouldSendGoogPing(const StunMessage* message) |
| 431 | RTC_RUN_ON(network_thread_); |
| 432 |
| 433 | WriteState write_state_ RTC_GUARDED_BY(network_thread_); |
| 434 | bool receiving_ RTC_GUARDED_BY(network_thread_); |
| 435 | bool connected_ RTC_GUARDED_BY(network_thread_); |
| 436 | bool pruned_ RTC_GUARDED_BY(network_thread_); |
| 437 | bool selected_ RTC_GUARDED_BY(network_thread_) = false; |
| 438 | // By default `use_candidate_attr_` flag will be true, |
| 439 | // as we will be using aggressive nomination. |
| 440 | // But when peer is ice-lite, this flag "must" be initialized to false and |
| 441 | // turn on when connection becomes "best connection". |
| 442 | bool use_candidate_attr_ RTC_GUARDED_BY(network_thread_); |
| 443 | // Used by the controlling side to indicate that this connection will be |
| 444 | // selected for transmission if the peer supports ICE-renomination when this |
| 445 | // value is positive. A larger-value indicates that a connection is nominated |
| 446 | // later and should be selected by the controlled side with higher precedence. |
| 447 | // A zero-value indicates not nominating this connection. |
| 448 | uint32_t nomination_ RTC_GUARDED_BY(network_thread_) = 0; |
| 449 | // The last nomination that has been acknowledged. |
| 450 | uint32_t acked_nomination_ RTC_GUARDED_BY(network_thread_) = 0; |
| 451 | // Used by the controlled side to remember the nomination value received from |
| 452 | // the controlling side. When the peer does not support ICE re-nomination, its |
| 453 | // value will be 1 if the connection has been nominated. |
| 454 | uint32_t remote_nomination_ RTC_GUARDED_BY(network_thread_) = 0; |
| 455 |
| 456 | StunRequestManager requests_ RTC_GUARDED_BY(network_thread_); |
| 457 | int rtt_ RTC_GUARDED_BY(network_thread_); |
| 458 | int rtt_samples_ RTC_GUARDED_BY(network_thread_) = 0; |
| 459 | // https://w3c.github.io/webrtc-stats/#dom-rtcicecandidatepairstats-totalroundtriptime |
| 460 | uint64_t total_round_trip_time_ms_ RTC_GUARDED_BY(network_thread_) = 0; |
| 461 | // https://w3c.github.io/webrtc-stats/#dom-rtcicecandidatepairstats-currentroundtriptime |
| 462 | absl::optional<uint32_t> current_round_trip_time_ms_ |
| 463 | RTC_GUARDED_BY(network_thread_); |
| 464 | int64_t last_ping_sent_ RTC_GUARDED_BY( |
| 465 | network_thread_); // last time we sent a ping to the other side |
| 466 | int64_t last_ping_received_ |
| 467 | RTC_GUARDED_BY(network_thread_); // last time we received a ping from the |
| 468 | // other side |
| 469 | int64_t last_data_received_ RTC_GUARDED_BY(network_thread_); |
| 470 | int64_t last_ping_response_received_ RTC_GUARDED_BY(network_thread_); |
| 471 | int64_t receiving_unchanged_since_ RTC_GUARDED_BY(network_thread_) = 0; |
| 472 | std::vector<SentPing> pings_since_last_response_ |
| 473 | RTC_GUARDED_BY(network_thread_); |
| 474 | // Transaction ID of the last connectivity check received. Null if having not |
| 475 | // received a ping yet. |
| 476 | absl::optional<std::string> last_ping_id_received_ |
| 477 | RTC_GUARDED_BY(network_thread_); |
| 478 |
| 479 | absl::optional<int> unwritable_timeout_ RTC_GUARDED_BY(network_thread_); |
| 480 | absl::optional<int> unwritable_min_checks_ RTC_GUARDED_BY(network_thread_); |
| 481 | absl::optional<int> inactive_timeout_ RTC_GUARDED_BY(network_thread_); |
| 482 |
| 483 | IceCandidatePairState state_ RTC_GUARDED_BY(network_thread_); |
| 484 | // Time duration to switch from receiving to not receiving. |
| 485 | absl::optional<int> receiving_timeout_ RTC_GUARDED_BY(network_thread_); |
| 486 | const int64_t time_created_ms_ RTC_GUARDED_BY(network_thread_); |
| 487 | const int64_t delta_internal_unix_epoch_ms_ RTC_GUARDED_BY(network_thread_); |
| 488 | int num_pings_sent_ RTC_GUARDED_BY(network_thread_) = 0; |
| 489 |
| 490 | absl::optional<webrtc::IceCandidatePairDescription> log_description_ |
| 491 | RTC_GUARDED_BY(network_thread_); |
| 492 | webrtc::IceEventLog* ice_event_log_ RTC_GUARDED_BY(network_thread_) = nullptr; |
| 493 |
| 494 | // GOOG_PING_REQUEST is sent in place of STUN_BINDING_REQUEST |
| 495 | // if configured via field trial, the remote peer supports it (signaled |
| 496 | // in STUN_BINDING) and if the last STUN BINDING is identical to the one |
| 497 | // that is about to be sent. |
| 498 | absl::optional<bool> remote_support_goog_ping_ |
| 499 | RTC_GUARDED_BY(network_thread_); |
| 500 | std::unique_ptr<StunMessage> cached_stun_binding_ |
| 501 | RTC_GUARDED_BY(network_thread_); |
| 502 |
| 503 | const IceFieldTrials* field_trials_; |
| 504 | rtc::EventBasedExponentialMovingAverage rtt_estimate_ |
| 505 | RTC_GUARDED_BY(network_thread_); |
| 506 |
| 507 | absl::optional<std::function<std::unique_ptr<StunAttribute>( |
| 508 | const StunByteStringAttribute*)>> |
| 509 | goog_delta_consumer_; |
| 510 | absl::optional< |
| 511 | std::function<void(webrtc::RTCErrorOr<const StunUInt64Attribute*>)>> |
| 512 | goog_delta_ack_consumer_; |
| 513 | absl::AnyInvocable<void(Connection*, const rtc::ReceivedPacket&)> |
| 514 | received_packet_callback_; |
| 515 | }; |
| 516 |
| 517 | // ProxyConnection defers all the interesting work to the port. |
| 518 | class ProxyConnection : public Connection { |
| 519 | public: |
| 520 | ProxyConnection(rtc::WeakPtr<PortInterface> port, |
| 521 | size_t index, |
| 522 | const Candidate& remote_candidate); |
| 523 |
| 524 | int Send(const void* data, |
| 525 | size_t size, |
| 526 | const rtc::PacketOptions& options) override; |
| 527 | int GetError() override; |
| 528 |
| 529 | private: |
| 530 | int error_ = 0; |
| 531 | }; |
| 532 |
| 533 | } // namespace cricket |
| 534 |
| 535 | #endif // P2P_BASE_CONNECTION_H_ |
| 536 |