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