blob: 30b6ade6e606b1f6b04492d735be113def5ccab7 [file] [log] [blame]
Sameer Vijaykarb88c3b52022-09-12 10:20:54 +02001/*
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
Sameer Vijaykarf0e65ba2022-10-11 10:02:06 +020014#include "api/array_view.h"
Sameer Vijaykarb88c3b52022-09-12 10:20:54 +020015#include "p2p/base/connection.h"
16#include "p2p/base/ice_switch_reason.h"
17
18namespace 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.
23class 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(
Sameer Vijaykarf0e65ba2022-10-11 10:02:06 +020063 rtc::ArrayView<const Connection* const> connections) = 0;
Sameer Vijaykarb88c3b52022-09-12 10:20:54 +020064
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.
Sameer Vijaykarf0e65ba2022-10-11 10:02:06 +020074 virtual bool PruneConnections(
75 rtc::ArrayView<const Connection* const> connections) = 0;
Sameer Vijaykarb88c3b52022-09-12 10:20:54 +020076};
77
78} // namespace cricket
79
80#endif // P2P_BASE_ICE_AGENT_INTERFACE_H_