This is a reland of commit 6326c9c201c7331d68c9beb0a93f6f6e21063cd2 Original change's description: > Add an active ICE controller that wraps a legacy controller (#7/n) > > The wrapping ICE controller will allow existing ICE controller implementations to migrate to the active interface, and eventually deprecate the legacy interface. > > Follow-up CL has unit tests for P2PTransportChannel using the new wrapping controller. > > Bug: webrtc:14367, webrtc:14131 > Change-Id: I6c517449ff1e503e8268a7ef91afda793723fdeb > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/275302 > Reviewed-by: Per Kjellander <perkj@webrtc.org> > Reviewed-by: Jonas Oreland <jonaso@webrtc.org> > Commit-Queue: Sameer Vijaykar <samvi@google.com> > Cr-Commit-Position: refs/heads/main@{#38130} Bug: webrtc:14367, webrtc:14131 Change-Id: I5662595db1df8c06b3acac9b39749f236906fa7e Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/276044 Auto-Submit: Sameer Vijaykar <samvi@google.com> Reviewed-by: Jonas Oreland <jonaso@webrtc.org> Reviewed-by: Per Kjellander <perkj@webrtc.org> Commit-Queue: Per Kjellander <perkj@webrtc.org> Cr-Commit-Position: refs/heads/main@{#38149}
98 lines
4.0 KiB
C++
98 lines
4.0 KiB
C++
/*
|
|
* Copyright 2022 The WebRTC Project Authors. All rights reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#ifndef P2P_BASE_WRAPPING_ACTIVE_ICE_CONTROLLER_H_
|
|
#define P2P_BASE_WRAPPING_ACTIVE_ICE_CONTROLLER_H_
|
|
|
|
#include <memory>
|
|
|
|
#include "absl/types/optional.h"
|
|
#include "api/task_queue/pending_task_safety_flag.h"
|
|
#include "p2p/base/active_ice_controller_interface.h"
|
|
#include "p2p/base/connection.h"
|
|
#include "p2p/base/ice_agent_interface.h"
|
|
#include "p2p/base/ice_controller_factory_interface.h"
|
|
#include "p2p/base/ice_controller_interface.h"
|
|
#include "p2p/base/ice_switch_reason.h"
|
|
#include "p2p/base/ice_transport_internal.h"
|
|
#include "p2p/base/transport_description.h"
|
|
#include "rtc_base/thread.h"
|
|
#include "rtc_base/thread_annotations.h"
|
|
|
|
namespace cricket {
|
|
|
|
// WrappingActiveIceController provides the functionality of a legacy passive
|
|
// ICE controller but packaged as an active ICE Controller.
|
|
class WrappingActiveIceController : public ActiveIceControllerInterface {
|
|
public:
|
|
// Constructs an active ICE controller wrapping an already constructed legacy
|
|
// ICE controller. Does not take ownership of the ICE agent, which must
|
|
// already exist and outlive the ICE controller.
|
|
WrappingActiveIceController(IceAgentInterface* ice_agent,
|
|
std::unique_ptr<IceControllerInterface> wrapped);
|
|
// Constructs an active ICE controller that wraps over a legacy ICE
|
|
// controller. The legacy ICE controller is constructed through a factory, if
|
|
// one is supplied. If not, a default BasicIceController is wrapped instead.
|
|
// Does not take ownership of the ICE agent, which must already exist and
|
|
// outlive the ICE controller.
|
|
WrappingActiveIceController(
|
|
IceAgentInterface* ice_agent,
|
|
IceControllerFactoryInterface* wrapped_factory,
|
|
const IceControllerFactoryArgs& wrapped_factory_args);
|
|
virtual ~WrappingActiveIceController();
|
|
|
|
void SetIceConfig(const IceConfig& config) override;
|
|
bool GetUseCandidateAttribute(const Connection* connection,
|
|
NominationMode mode,
|
|
IceMode remote_ice_mode) const override;
|
|
|
|
void OnConnectionAdded(const Connection* connection) override;
|
|
void OnConnectionPinged(const Connection* connection) override;
|
|
void OnConnectionUpdated(const Connection* connection) override;
|
|
void OnConnectionSwitched(const Connection* connection) override;
|
|
void OnConnectionDestroyed(const Connection* connection) override;
|
|
|
|
void OnSortAndSwitchRequest(IceSwitchReason reason) override;
|
|
void OnImmediateSortAndSwitchRequest(IceSwitchReason reason) override;
|
|
bool OnImmediateSwitchRequest(IceSwitchReason reason,
|
|
const Connection* selected) override;
|
|
|
|
// Only for unit tests
|
|
const Connection* FindNextPingableConnection() override;
|
|
|
|
private:
|
|
void MaybeStartPinging();
|
|
void SelectAndPingConnection();
|
|
void HandlePingResult(IceControllerInterface::PingResult result);
|
|
|
|
void SortAndSwitchToBestConnection(IceSwitchReason reason);
|
|
void HandleSwitchResult(IceSwitchReason reason_for_switch,
|
|
IceControllerInterface::SwitchResult result);
|
|
void UpdateStateOnConnectionsResorted();
|
|
|
|
void PruneConnections();
|
|
|
|
rtc::Thread* const network_thread_;
|
|
webrtc::ScopedTaskSafety task_safety_;
|
|
|
|
bool started_pinging_ RTC_GUARDED_BY(network_thread_) = false;
|
|
bool sort_pending_ RTC_GUARDED_BY(network_thread_) = false;
|
|
const Connection* selected_connection_ RTC_GUARDED_BY(network_thread_) =
|
|
nullptr;
|
|
|
|
std::unique_ptr<IceControllerInterface> wrapped_
|
|
RTC_GUARDED_BY(network_thread_);
|
|
IceAgentInterface& agent_ RTC_GUARDED_BY(network_thread_);
|
|
};
|
|
|
|
} // namespace cricket
|
|
|
|
#endif // P2P_BASE_WRAPPING_ACTIVE_ICE_CONTROLLER_H_
|