xref: /aosp_15_r20/external/webrtc/p2p/base/ice_agent_interface.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2022 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_ICE_AGENT_INTERFACE_H_
12 #define P2P_BASE_ICE_AGENT_INTERFACE_H_
13 
14 #include "api/array_view.h"
15 #include "p2p/base/connection.h"
16 #include "p2p/base/ice_switch_reason.h"
17 
18 namespace cricket {
19 
20 // IceAgentInterface provides methods that allow an ICE controller to manipulate
21 // the connections available to a transport, and used by the transport to
22 // transfer data.
23 class IceAgentInterface {
24  public:
25   virtual ~IceAgentInterface() = default;
26 
27   // Get the time when the last ping was sent.
28   // This is only needed in some scenarios if the agent decides to ping on its
29   // own, eg. in some switchover scenarios. Otherwise the ICE controller could
30   // keep this state on its own.
31   // TODO(bugs.webrtc.org/14367): route extra pings through the ICE controller.
32   virtual int64_t GetLastPingSentMs() const = 0;
33 
34   // Get the ICE role of this ICE agent.
35   virtual IceRole GetIceRole() const = 0;
36 
37   // Called when a pingable connection first becomes available.
38   virtual void OnStartedPinging() = 0;
39 
40   // Update the state of all available connections.
41   virtual void UpdateConnectionStates() = 0;
42 
43   // Update the internal state of the ICE agent. An ICE controller should call
44   // this at the end of a sequence of actions to combine several mutations into
45   // a single state refresh.
46   // TODO(bugs.webrtc.org/14431): ICE agent state updates should be internal to
47   // the agent. If batching is necessary, use a more appropriate interface.
48   virtual void UpdateState() = 0;
49 
50   // Reset the given connections to a state of newly connected connections.
51   // - STATE_WRITE_INIT
52   // - receving = false
53   // - throw away all pending request
54   // - reset RttEstimate
55   //
56   // Keep the following unchanged:
57   // - connected
58   // - remote_candidate
59   // - statistics
60   //
61   // SignalStateChange will not be triggered.
62   virtual void ForgetLearnedStateForConnections(
63       rtc::ArrayView<const Connection* const> connections) = 0;
64 
65   // Send a STUN ping request for the given connection.
66   virtual void SendPingRequest(const Connection* connection) = 0;
67 
68   // Switch the transport to use the given connection.
69   virtual void SwitchSelectedConnection(const Connection* new_connection,
70                                         IceSwitchReason reason) = 0;
71 
72   // Prune away the given connections. Returns true if pruning is permitted and
73   // successfully performed.
74   virtual bool PruneConnections(
75       rtc::ArrayView<const Connection* const> connections) = 0;
76 };
77 
78 }  // namespace cricket
79 
80 #endif  // P2P_BASE_ICE_AGENT_INTERFACE_H_
81