Remove adapter indirection for ICE controller interactions.
This removes (now unused) the legacy ICE controller code paths from P2PTransportChannel. Bug: webrtc:14367 Change-Id: I53dc7ee46ec844d20331e2622fa99dbe8b740ad6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/294291 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Sameer Vijaykar <samvi@google.com> Cr-Commit-Position: refs/heads/main@{#39398}
This commit is contained in:
parent
e80416334d
commit
72b11a407a
@ -94,15 +94,6 @@ rtc::RouteEndpoint CreateRouteEndpointFromCandidate(
|
|||||||
uses_turn);
|
uses_turn);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UseActiveIceControllerFieldTrialEnabled(
|
|
||||||
const webrtc::FieldTrialsView* field_trials) {
|
|
||||||
// Feature to refactor ICE controller and enable active ICE controllers.
|
|
||||||
// Default enable for full launch.
|
|
||||||
// TODO(bugs.webrtc.org/14367): Code branching will be cleaned up in a
|
|
||||||
// follow-up CL.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
using ::webrtc::RTCError;
|
using ::webrtc::RTCError;
|
||||||
using ::webrtc::RTCErrorType;
|
using ::webrtc::RTCErrorType;
|
||||||
using ::webrtc::SafeTask;
|
using ::webrtc::SafeTask;
|
||||||
@ -182,7 +173,6 @@ P2PTransportChannel::P2PTransportChannel(
|
|||||||
network_thread_(rtc::Thread::Current()),
|
network_thread_(rtc::Thread::Current()),
|
||||||
incoming_only_(false),
|
incoming_only_(false),
|
||||||
error_(0),
|
error_(0),
|
||||||
sort_dirty_(false),
|
|
||||||
remote_ice_mode_(ICEMODE_FULL),
|
remote_ice_mode_(ICEMODE_FULL),
|
||||||
ice_role_(ICEROLE_UNKNOWN),
|
ice_role_(ICEROLE_UNKNOWN),
|
||||||
tiebreaker_(0),
|
tiebreaker_(0),
|
||||||
@ -224,9 +214,15 @@ P2PTransportChannel::P2PTransportChannel(
|
|||||||
&ice_field_trials_,
|
&ice_field_trials_,
|
||||||
field_trials ? field_trials->Lookup("WebRTC-IceControllerFieldTrials")
|
field_trials ? field_trials->Lookup("WebRTC-IceControllerFieldTrials")
|
||||||
: ""};
|
: ""};
|
||||||
ice_adapter_ = std::make_unique<IceControllerAdapter>(
|
|
||||||
args, ice_controller_factory, active_ice_controller_factory, field_trials,
|
if (active_ice_controller_factory) {
|
||||||
/* transport= */ this);
|
ActiveIceControllerFactoryArgs active_args{args,
|
||||||
|
/* ice_agent= */ this};
|
||||||
|
ice_controller_ = active_ice_controller_factory->Create(active_args);
|
||||||
|
} else {
|
||||||
|
ice_controller_ = std::make_unique<WrappingActiveIceController>(
|
||||||
|
/* ice_agent= */ this, ice_controller_factory, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
P2PTransportChannel::~P2PTransportChannel() {
|
P2PTransportChannel::~P2PTransportChannel() {
|
||||||
@ -294,49 +290,7 @@ void P2PTransportChannel::AddConnection(Connection* connection) {
|
|||||||
webrtc::IceCandidatePairConfigType::kAdded);
|
webrtc::IceCandidatePairConfigType::kAdded);
|
||||||
|
|
||||||
connections_.push_back(connection);
|
connections_.push_back(connection);
|
||||||
ice_adapter_->OnConnectionAdded(connection);
|
ice_controller_->OnConnectionAdded(connection);
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
bool P2PTransportChannel::MaybeSwitchSelectedConnection(
|
|
||||||
const Connection* new_connection,
|
|
||||||
IceSwitchReason reason) {
|
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
|
||||||
|
|
||||||
return MaybeSwitchSelectedConnection(
|
|
||||||
reason,
|
|
||||||
ice_adapter_->LegacyShouldSwitchConnection(reason, new_connection));
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
bool P2PTransportChannel::MaybeSwitchSelectedConnection(
|
|
||||||
IceSwitchReason reason,
|
|
||||||
IceControllerInterface::SwitchResult result) {
|
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
|
||||||
if (result.connection.has_value()) {
|
|
||||||
RTC_LOG(LS_INFO) << "Switching selected connection due to: "
|
|
||||||
<< IceSwitchReasonToString(reason);
|
|
||||||
SwitchSelectedConnection(FromIceController(*result.connection), reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.recheck_event.has_value()) {
|
|
||||||
// If we do not switch to the connection because it missed the receiving
|
|
||||||
// threshold, the new connection is in a better receiving state than the
|
|
||||||
// currently selected connection. So we need to re-check whether it needs
|
|
||||||
// to be switched at a later time.
|
|
||||||
network_thread_->PostDelayedTask(
|
|
||||||
SafeTask(task_safety_.flag(),
|
|
||||||
[this, reason = result.recheck_event->reason]() {
|
|
||||||
SortConnectionsAndUpdateState(reason);
|
|
||||||
}),
|
|
||||||
TimeDelta::Millis(result.recheck_event->recheck_delay_ms));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto* con : result.connections_to_forget_state_on) {
|
|
||||||
FromIceController(con)->ForgetLearnedState();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.connection.has_value();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void P2PTransportChannel::ForgetLearnedStateForConnections(
|
void P2PTransportChannel::ForgetLearnedStateForConnections(
|
||||||
@ -545,7 +499,7 @@ void P2PTransportChannel::SetRemoteIceParameters(
|
|||||||
ice_params, static_cast<int>(remote_ice_parameters_.size() - 1));
|
ice_params, static_cast<int>(remote_ice_parameters_.size() - 1));
|
||||||
}
|
}
|
||||||
// Updating the remote ICE candidate generation could change the sort order.
|
// Updating the remote ICE candidate generation could change the sort order.
|
||||||
ice_adapter_->OnSortAndSwitchRequest(
|
ice_controller_->OnSortAndSwitchRequest(
|
||||||
IceSwitchReason::REMOTE_CANDIDATE_GENERATION_CHANGE);
|
IceSwitchReason::REMOTE_CANDIDATE_GENERATION_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -700,7 +654,7 @@ void P2PTransportChannel::SetIceConfig(const IceConfig& config) {
|
|||||||
|
|
||||||
if (config_.network_preference != config.network_preference) {
|
if (config_.network_preference != config.network_preference) {
|
||||||
config_.network_preference = config.network_preference;
|
config_.network_preference = config.network_preference;
|
||||||
ice_adapter_->OnSortAndSwitchRequest(
|
ice_controller_->OnSortAndSwitchRequest(
|
||||||
IceSwitchReason::NETWORK_PREFERENCE_CHANGE);
|
IceSwitchReason::NETWORK_PREFERENCE_CHANGE);
|
||||||
RTC_LOG(LS_INFO) << "Set network preference to "
|
RTC_LOG(LS_INFO) << "Set network preference to "
|
||||||
<< (config_.network_preference.has_value()
|
<< (config_.network_preference.has_value()
|
||||||
@ -727,7 +681,7 @@ void P2PTransportChannel::SetIceConfig(const IceConfig& config) {
|
|||||||
config_.vpn_preference = config.vpn_preference;
|
config_.vpn_preference = config.vpn_preference;
|
||||||
allocator_->SetVpnPreference(config_.vpn_preference);
|
allocator_->SetVpnPreference(config_.vpn_preference);
|
||||||
|
|
||||||
ice_adapter_->SetIceConfig(config_);
|
ice_controller_->SetIceConfig(config_);
|
||||||
|
|
||||||
RTC_DCHECK(ValidateIceConfig(config_).ok());
|
RTC_DCHECK(ValidateIceConfig(config_).ok());
|
||||||
}
|
}
|
||||||
@ -1004,7 +958,7 @@ void P2PTransportChannel::OnPortReady(PortAllocatorSession* session,
|
|||||||
CreateConnection(port, *iter, iter->origin_port());
|
CreateConnection(port, *iter, iter->origin_port());
|
||||||
}
|
}
|
||||||
|
|
||||||
ice_adapter_->OnImmediateSortAndSwitchRequest(
|
ice_controller_->OnImmediateSortAndSwitchRequest(
|
||||||
IceSwitchReason::NEW_CONNECTION_FROM_LOCAL_CANDIDATE);
|
IceSwitchReason::NEW_CONNECTION_FROM_LOCAL_CANDIDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1184,7 +1138,7 @@ void P2PTransportChannel::OnUnknownAddress(PortInterface* port,
|
|||||||
// Update the list of connections since we just added another. We do this
|
// Update the list of connections since we just added another. We do this
|
||||||
// after sending the response since it could (in principle) delete the
|
// after sending the response since it could (in principle) delete the
|
||||||
// connection in question.
|
// connection in question.
|
||||||
ice_adapter_->OnImmediateSortAndSwitchRequest(
|
ice_controller_->OnImmediateSortAndSwitchRequest(
|
||||||
IceSwitchReason::NEW_CONNECTION_FROM_UNKNOWN_REMOTE_ADDRESS);
|
IceSwitchReason::NEW_CONNECTION_FROM_UNKNOWN_REMOTE_ADDRESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1235,11 +1189,11 @@ void P2PTransportChannel::OnNominated(Connection* conn) {
|
|||||||
|
|
||||||
// TODO(qingsi): RequestSortAndStateUpdate will eventually call
|
// TODO(qingsi): RequestSortAndStateUpdate will eventually call
|
||||||
// MaybeSwitchSelectedConnection again. Rewrite this logic.
|
// MaybeSwitchSelectedConnection again. Rewrite this logic.
|
||||||
if (ice_adapter_->OnImmediateSwitchRequest(
|
if (ice_controller_->OnImmediateSwitchRequest(
|
||||||
IceSwitchReason::NOMINATION_ON_CONTROLLED_SIDE, conn)) {
|
IceSwitchReason::NOMINATION_ON_CONTROLLED_SIDE, conn)) {
|
||||||
// Now that we have selected a connection, it is time to prune other
|
// Now that we have selected a connection, it is time to prune other
|
||||||
// connections and update the read/write state of the channel.
|
// connections and update the read/write state of the channel.
|
||||||
ice_adapter_->OnSortAndSwitchRequest(
|
ice_controller_->OnSortAndSwitchRequest(
|
||||||
IceSwitchReason::NOMINATION_ON_CONTROLLED_SIDE);
|
IceSwitchReason::NOMINATION_ON_CONTROLLED_SIDE);
|
||||||
} else {
|
} else {
|
||||||
RTC_LOG(LS_INFO)
|
RTC_LOG(LS_INFO)
|
||||||
@ -1388,7 +1342,7 @@ void P2PTransportChannel::FinishAddingRemoteCandidate(
|
|||||||
CreateConnections(new_remote_candidate, NULL);
|
CreateConnections(new_remote_candidate, NULL);
|
||||||
|
|
||||||
// Resort the connections list, which may have new elements.
|
// Resort the connections list, which may have new elements.
|
||||||
ice_adapter_->OnImmediateSortAndSwitchRequest(
|
ice_controller_->OnImmediateSortAndSwitchRequest(
|
||||||
IceSwitchReason::NEW_CONNECTION_FROM_REMOTE_CANDIDATE);
|
IceSwitchReason::NEW_CONNECTION_FROM_REMOTE_CANDIDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1708,7 +1662,8 @@ rtc::DiffServCodePoint P2PTransportChannel::DefaultDscpValue() const {
|
|||||||
|
|
||||||
rtc::ArrayView<Connection*> P2PTransportChannel::connections() const {
|
rtc::ArrayView<Connection*> P2PTransportChannel::connections() const {
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
RTC_DCHECK_RUN_ON(network_thread_);
|
||||||
return ice_adapter_->LegacyConnections();
|
return rtc::ArrayView<Connection*>(
|
||||||
|
const_cast<Connection**>(connections_.data()), connections_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void P2PTransportChannel::RemoveConnectionForTest(Connection* connection) {
|
void P2PTransportChannel::RemoveConnectionForTest(Connection* connection) {
|
||||||
@ -1738,38 +1693,6 @@ void P2PTransportChannel::UpdateConnectionStates() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare for best candidate sorting.
|
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
void P2PTransportChannel::RequestSortAndStateUpdate(
|
|
||||||
IceSwitchReason reason_to_sort) {
|
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
|
||||||
if (!sort_dirty_) {
|
|
||||||
network_thread_->PostTask(
|
|
||||||
SafeTask(task_safety_.flag(), [this, reason_to_sort]() {
|
|
||||||
SortConnectionsAndUpdateState(reason_to_sort);
|
|
||||||
}));
|
|
||||||
sort_dirty_ = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
void P2PTransportChannel::MaybeStartPinging() {
|
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
|
||||||
if (started_pinging_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ice_adapter_->LegacyHasPingableConnection()) {
|
|
||||||
RTC_LOG(LS_INFO) << ToString()
|
|
||||||
<< ": Have a pingable connection for the first time; "
|
|
||||||
"starting to ping.";
|
|
||||||
network_thread_->PostTask(
|
|
||||||
SafeTask(task_safety_.flag(), [this]() { CheckAndPing(); }));
|
|
||||||
regathering_controller_->Start();
|
|
||||||
started_pinging_ = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void P2PTransportChannel::OnStartedPinging() {
|
void P2PTransportChannel::OnStartedPinging() {
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
RTC_DCHECK_RUN_ON(network_thread_);
|
||||||
RTC_LOG(LS_INFO) << ToString()
|
RTC_LOG(LS_INFO) << ToString()
|
||||||
@ -1797,63 +1720,6 @@ bool P2PTransportChannel::PresumedWritable(const Connection* conn) const {
|
|||||||
conn->remote_candidate().type() == PRFLX_PORT_TYPE));
|
conn->remote_candidate().type() == PRFLX_PORT_TYPE));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort the available connections to find the best one. We also monitor
|
|
||||||
// the number of available connections and the current state.
|
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
void P2PTransportChannel::SortConnectionsAndUpdateState(
|
|
||||||
IceSwitchReason reason_to_sort) {
|
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
|
||||||
|
|
||||||
// Make sure the connection states are up-to-date since this affects how they
|
|
||||||
// will be sorted.
|
|
||||||
UpdateConnectionStates();
|
|
||||||
|
|
||||||
// Any changes after this point will require a re-sort.
|
|
||||||
sort_dirty_ = false;
|
|
||||||
|
|
||||||
// If necessary, switch to the new choice. Note that `top_connection` doesn't
|
|
||||||
// have to be writable to become the selected connection although it will
|
|
||||||
// have higher priority if it is writable.
|
|
||||||
MaybeSwitchSelectedConnection(
|
|
||||||
reason_to_sort,
|
|
||||||
ice_adapter_->LegacySortAndSwitchConnection(reason_to_sort));
|
|
||||||
|
|
||||||
// The controlled side can prune only if the selected connection has been
|
|
||||||
// nominated because otherwise it may prune the connection that will be
|
|
||||||
// selected by the controlling side.
|
|
||||||
// TODO(honghaiz): This is not enough to prevent a connection from being
|
|
||||||
// pruned too early because with aggressive nomination, the controlling side
|
|
||||||
// will nominate every connection until it becomes writable.
|
|
||||||
if (AllowedToPruneConnections()) {
|
|
||||||
PruneConnections();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if all connections are timedout.
|
|
||||||
bool all_connections_timedout = true;
|
|
||||||
for (const Connection* conn : connections()) {
|
|
||||||
if (conn->write_state() != Connection::STATE_WRITE_TIMEOUT) {
|
|
||||||
all_connections_timedout = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now update the writable state of the channel with the information we have
|
|
||||||
// so far.
|
|
||||||
if (all_connections_timedout) {
|
|
||||||
HandleAllTimedOut();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the state of this channel.
|
|
||||||
UpdateTransportState();
|
|
||||||
|
|
||||||
// Also possibly start pinging.
|
|
||||||
// We could start pinging if:
|
|
||||||
// * The first connection was created.
|
|
||||||
// * ICE credentials were provided.
|
|
||||||
// * A TCP connection became connected.
|
|
||||||
MaybeStartPinging();
|
|
||||||
}
|
|
||||||
|
|
||||||
void P2PTransportChannel::UpdateState() {
|
void P2PTransportChannel::UpdateState() {
|
||||||
// Check if all connections are timedout.
|
// Check if all connections are timedout.
|
||||||
bool all_connections_timedout = true;
|
bool all_connections_timedout = true;
|
||||||
@ -1880,14 +1746,6 @@ bool P2PTransportChannel::AllowedToPruneConnections() const {
|
|||||||
(selected_connection_ && selected_connection_->nominated());
|
(selected_connection_ && selected_connection_->nominated());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
void P2PTransportChannel::PruneConnections() {
|
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
|
||||||
std::vector<const Connection*> connections_to_prune =
|
|
||||||
ice_adapter_->LegacyPruneConnections();
|
|
||||||
PruneConnections(connections_to_prune);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool P2PTransportChannel::PruneConnections(
|
bool P2PTransportChannel::PruneConnections(
|
||||||
rtc::ArrayView<const Connection* const> connections) {
|
rtc::ArrayView<const Connection* const> connections) {
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
RTC_DCHECK_RUN_ON(network_thread_);
|
||||||
@ -1995,7 +1853,7 @@ void P2PTransportChannel::SwitchSelectedConnectionInternal(
|
|||||||
|
|
||||||
++selected_candidate_pair_changes_;
|
++selected_candidate_pair_changes_;
|
||||||
|
|
||||||
ice_adapter_->OnConnectionSwitched(selected_connection_);
|
ice_controller_->OnConnectionSwitched(selected_connection_);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t P2PTransportChannel::ComputeEstimatedDisconnectedTimeMs(
|
int64_t P2PTransportChannel::ComputeEstimatedDisconnectedTimeMs(
|
||||||
@ -2110,7 +1968,7 @@ void P2PTransportChannel::OnSelectedConnectionDestroyed() {
|
|||||||
RTC_LOG(LS_INFO) << "Selected connection destroyed. Will choose a new one.";
|
RTC_LOG(LS_INFO) << "Selected connection destroyed. Will choose a new one.";
|
||||||
IceSwitchReason reason = IceSwitchReason::SELECTED_CONNECTION_DESTROYED;
|
IceSwitchReason reason = IceSwitchReason::SELECTED_CONNECTION_DESTROYED;
|
||||||
SwitchSelectedConnectionInternal(nullptr, reason);
|
SwitchSelectedConnectionInternal(nullptr, reason);
|
||||||
ice_adapter_->OnSortAndSwitchRequest(reason);
|
ice_controller_->OnSortAndSwitchRequest(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If all connections timed out, delete them all.
|
// If all connections timed out, delete them all.
|
||||||
@ -2143,29 +2001,10 @@ bool P2PTransportChannel::ReadyToSend(const Connection* connection) const {
|
|||||||
PresumedWritable(connection));
|
PresumedWritable(connection));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle queued up check-and-ping request
|
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
void P2PTransportChannel::CheckAndPing() {
|
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
|
||||||
// Make sure the states of the connections are up-to-date (since this
|
|
||||||
// affects which ones are pingable).
|
|
||||||
UpdateConnectionStates();
|
|
||||||
|
|
||||||
auto result = ice_adapter_->LegacySelectConnectionToPing(last_ping_sent_ms_);
|
|
||||||
TimeDelta delay = TimeDelta::Millis(result.recheck_delay_ms);
|
|
||||||
|
|
||||||
if (result.connection.value_or(nullptr)) {
|
|
||||||
SendPingRequest(result.connection.value());
|
|
||||||
}
|
|
||||||
|
|
||||||
network_thread_->PostDelayedTask(
|
|
||||||
SafeTask(task_safety_.flag(), [this]() { CheckAndPing(); }), delay);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This method is only for unit testing.
|
// This method is only for unit testing.
|
||||||
Connection* P2PTransportChannel::FindNextPingableConnection() {
|
Connection* P2PTransportChannel::FindNextPingableConnection() {
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
RTC_DCHECK_RUN_ON(network_thread_);
|
||||||
const Connection* conn = ice_adapter_->FindNextPingableConnection();
|
const Connection* conn = ice_controller_->FindNextPingableConnection();
|
||||||
if (conn) {
|
if (conn) {
|
||||||
return FromIceController(conn);
|
return FromIceController(conn);
|
||||||
} else {
|
} else {
|
||||||
@ -2194,7 +2033,7 @@ void P2PTransportChannel::SendPingRequestInternal(Connection* connection) {
|
|||||||
// active.
|
// active.
|
||||||
void P2PTransportChannel::MarkConnectionPinged(Connection* conn) {
|
void P2PTransportChannel::MarkConnectionPinged(Connection* conn) {
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
RTC_DCHECK_RUN_ON(network_thread_);
|
||||||
ice_adapter_->OnConnectionPinged(conn);
|
ice_controller_->OnConnectionPinged(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apart from sending ping from `conn` this method also updates
|
// Apart from sending ping from `conn` this method also updates
|
||||||
@ -2228,7 +2067,7 @@ uint32_t P2PTransportChannel::GetNominationAttr(Connection* conn) const {
|
|||||||
// Nominate a connection based on the NominationMode.
|
// Nominate a connection based on the NominationMode.
|
||||||
bool P2PTransportChannel::GetUseCandidateAttr(Connection* conn) const {
|
bool P2PTransportChannel::GetUseCandidateAttr(Connection* conn) const {
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
RTC_DCHECK_RUN_ON(network_thread_);
|
||||||
return ice_adapter_->GetUseCandidateAttribute(
|
return ice_controller_->GetUseCandidateAttribute(
|
||||||
conn, config_.default_nomination_mode, remote_ice_mode_);
|
conn, config_.default_nomination_mode, remote_ice_mode_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2253,7 +2092,7 @@ void P2PTransportChannel::OnConnectionStateChange(Connection* connection) {
|
|||||||
}
|
}
|
||||||
// We have to unroll the stack before doing this because we may be changing
|
// We have to unroll the stack before doing this because we may be changing
|
||||||
// the state of connections while sorting.
|
// the state of connections while sorting.
|
||||||
ice_adapter_->OnSortAndSwitchRequest(
|
ice_controller_->OnSortAndSwitchRequest(
|
||||||
IceSwitchReason::CONNECT_STATE_CHANGE); // "candidate pair state
|
IceSwitchReason::CONNECT_STATE_CHANGE); // "candidate pair state
|
||||||
// changed");
|
// changed");
|
||||||
}
|
}
|
||||||
@ -2293,7 +2132,7 @@ void P2PTransportChannel::RemoveConnection(const Connection* connection) {
|
|||||||
auto it = absl::c_find(connections_, connection);
|
auto it = absl::c_find(connections_, connection);
|
||||||
RTC_DCHECK(it != connections_.end());
|
RTC_DCHECK(it != connections_.end());
|
||||||
connections_.erase(it);
|
connections_.erase(it);
|
||||||
ice_adapter_->OnConnectionDestroyed(connection);
|
ice_controller_->OnConnectionDestroyed(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
// When a port is destroyed, remove it from our list of ports to use for
|
// When a port is destroyed, remove it from our list of ports to use for
|
||||||
@ -2394,7 +2233,7 @@ void P2PTransportChannel::OnReadPacket(Connection* connection,
|
|||||||
// May need to switch the sending connection based on the receiving media
|
// May need to switch the sending connection based on the receiving media
|
||||||
// path if this is the controlled side.
|
// path if this is the controlled side.
|
||||||
if (ice_role_ == ICEROLE_CONTROLLED) {
|
if (ice_role_ == ICEROLE_CONTROLLED) {
|
||||||
ice_adapter_->OnImmediateSwitchRequest(IceSwitchReason::DATA_RECEIVED,
|
ice_controller_->OnImmediateSwitchRequest(IceSwitchReason::DATA_RECEIVED,
|
||||||
connection);
|
connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2466,172 +2305,4 @@ void P2PTransportChannel::LogCandidatePairConfig(
|
|||||||
conn->ToLogDescription());
|
conn->ToLogDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
P2PTransportChannel::IceControllerAdapter::IceControllerAdapter(
|
|
||||||
const IceControllerFactoryArgs& args,
|
|
||||||
IceControllerFactoryInterface* ice_controller_factory,
|
|
||||||
ActiveIceControllerFactoryInterface* active_ice_controller_factory,
|
|
||||||
const webrtc::FieldTrialsView* field_trials,
|
|
||||||
P2PTransportChannel* transport)
|
|
||||||
: transport_(transport) {
|
|
||||||
if (UseActiveIceControllerFieldTrialEnabled(field_trials)) {
|
|
||||||
if (active_ice_controller_factory) {
|
|
||||||
ActiveIceControllerFactoryArgs active_args{args,
|
|
||||||
/* ice_agent= */ transport};
|
|
||||||
active_ice_controller_ =
|
|
||||||
active_ice_controller_factory->Create(active_args);
|
|
||||||
} else {
|
|
||||||
active_ice_controller_ = std::make_unique<WrappingActiveIceController>(
|
|
||||||
/* ice_agent= */ transport, ice_controller_factory, args);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (ice_controller_factory != nullptr) {
|
|
||||||
legacy_ice_controller_ = ice_controller_factory->Create(args);
|
|
||||||
} else {
|
|
||||||
legacy_ice_controller_ = std::make_unique<BasicIceController>(args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
P2PTransportChannel::IceControllerAdapter::~IceControllerAdapter() = default;
|
|
||||||
|
|
||||||
void P2PTransportChannel::IceControllerAdapter::SetIceConfig(
|
|
||||||
const IceConfig& config) {
|
|
||||||
active_ice_controller_ ? active_ice_controller_->SetIceConfig(config)
|
|
||||||
: legacy_ice_controller_->SetIceConfig(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
void P2PTransportChannel::IceControllerAdapter::OnConnectionAdded(
|
|
||||||
const Connection* connection) {
|
|
||||||
active_ice_controller_ ? active_ice_controller_->OnConnectionAdded(connection)
|
|
||||||
: legacy_ice_controller_->AddConnection(connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
void P2PTransportChannel::IceControllerAdapter::OnConnectionSwitched(
|
|
||||||
const Connection* connection) {
|
|
||||||
active_ice_controller_
|
|
||||||
? active_ice_controller_->OnConnectionSwitched(connection)
|
|
||||||
: legacy_ice_controller_->SetSelectedConnection(connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
void P2PTransportChannel::IceControllerAdapter::OnConnectionPinged(
|
|
||||||
const Connection* connection) {
|
|
||||||
active_ice_controller_
|
|
||||||
? active_ice_controller_->OnConnectionPinged(connection)
|
|
||||||
: legacy_ice_controller_->MarkConnectionPinged(connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
void P2PTransportChannel::IceControllerAdapter::OnConnectionDestroyed(
|
|
||||||
const Connection* connection) {
|
|
||||||
active_ice_controller_
|
|
||||||
? active_ice_controller_->OnConnectionDestroyed(connection)
|
|
||||||
: legacy_ice_controller_->OnConnectionDestroyed(connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
void P2PTransportChannel::IceControllerAdapter::OnConnectionUpdated(
|
|
||||||
const Connection* connection) {
|
|
||||||
if (active_ice_controller_) {
|
|
||||||
active_ice_controller_->OnConnectionUpdated(connection);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
RTC_DCHECK_NOTREACHED();
|
|
||||||
}
|
|
||||||
|
|
||||||
void P2PTransportChannel::IceControllerAdapter::OnSortAndSwitchRequest(
|
|
||||||
IceSwitchReason reason) {
|
|
||||||
active_ice_controller_
|
|
||||||
? active_ice_controller_->OnSortAndSwitchRequest(reason)
|
|
||||||
: transport_->RequestSortAndStateUpdate(reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
void P2PTransportChannel::IceControllerAdapter::OnImmediateSortAndSwitchRequest(
|
|
||||||
IceSwitchReason reason) {
|
|
||||||
active_ice_controller_
|
|
||||||
? active_ice_controller_->OnImmediateSortAndSwitchRequest(reason)
|
|
||||||
: transport_->SortConnectionsAndUpdateState(reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool P2PTransportChannel::IceControllerAdapter::OnImmediateSwitchRequest(
|
|
||||||
IceSwitchReason reason,
|
|
||||||
const Connection* connection) {
|
|
||||||
return active_ice_controller_
|
|
||||||
? active_ice_controller_->OnImmediateSwitchRequest(reason,
|
|
||||||
connection)
|
|
||||||
: transport_->MaybeSwitchSelectedConnection(connection, reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool P2PTransportChannel::IceControllerAdapter::GetUseCandidateAttribute(
|
|
||||||
const cricket::Connection* connection,
|
|
||||||
cricket::NominationMode mode,
|
|
||||||
cricket::IceMode remote_ice_mode) const {
|
|
||||||
return active_ice_controller_
|
|
||||||
? active_ice_controller_->GetUseCandidateAttribute(
|
|
||||||
connection, mode, remote_ice_mode)
|
|
||||||
: legacy_ice_controller_->GetUseCandidateAttr(connection, mode,
|
|
||||||
remote_ice_mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
const Connection*
|
|
||||||
P2PTransportChannel::IceControllerAdapter::FindNextPingableConnection() {
|
|
||||||
return active_ice_controller_
|
|
||||||
? active_ice_controller_->FindNextPingableConnection()
|
|
||||||
: legacy_ice_controller_->FindNextPingableConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
rtc::ArrayView<Connection*>
|
|
||||||
P2PTransportChannel::IceControllerAdapter::LegacyConnections() const {
|
|
||||||
RTC_DCHECK_RUN_ON(transport_->network_thread_);
|
|
||||||
if (active_ice_controller_) {
|
|
||||||
return rtc::ArrayView<Connection*>(transport_->connections_.data(),
|
|
||||||
transport_->connections_.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
rtc::ArrayView<const Connection*> res = legacy_ice_controller_->connections();
|
|
||||||
return rtc::ArrayView<Connection*>(const_cast<Connection**>(res.data()),
|
|
||||||
res.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool P2PTransportChannel::IceControllerAdapter::LegacyHasPingableConnection()
|
|
||||||
const {
|
|
||||||
if (active_ice_controller_) {
|
|
||||||
RTC_DCHECK_NOTREACHED();
|
|
||||||
}
|
|
||||||
return legacy_ice_controller_->HasPingableConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
IceControllerInterface::PingResult
|
|
||||||
P2PTransportChannel::IceControllerAdapter::LegacySelectConnectionToPing(
|
|
||||||
int64_t last_ping_sent_ms) {
|
|
||||||
if (active_ice_controller_) {
|
|
||||||
RTC_DCHECK_NOTREACHED();
|
|
||||||
}
|
|
||||||
return legacy_ice_controller_->SelectConnectionToPing(last_ping_sent_ms);
|
|
||||||
}
|
|
||||||
|
|
||||||
IceControllerInterface::SwitchResult
|
|
||||||
P2PTransportChannel::IceControllerAdapter::LegacyShouldSwitchConnection(
|
|
||||||
IceSwitchReason reason,
|
|
||||||
const Connection* connection) {
|
|
||||||
if (active_ice_controller_) {
|
|
||||||
RTC_DCHECK_NOTREACHED();
|
|
||||||
}
|
|
||||||
return legacy_ice_controller_->ShouldSwitchConnection(reason, connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
IceControllerInterface::SwitchResult
|
|
||||||
P2PTransportChannel::IceControllerAdapter::LegacySortAndSwitchConnection(
|
|
||||||
IceSwitchReason reason) {
|
|
||||||
if (active_ice_controller_) {
|
|
||||||
RTC_DCHECK_NOTREACHED();
|
|
||||||
}
|
|
||||||
return legacy_ice_controller_->SortAndSwitchConnection(reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<const Connection*>
|
|
||||||
P2PTransportChannel::IceControllerAdapter::LegacyPruneConnections() {
|
|
||||||
if (active_ice_controller_) {
|
|
||||||
RTC_DCHECK_NOTREACHED();
|
|
||||||
}
|
|
||||||
return legacy_ice_controller_->PruneConnections();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace cricket
|
} // namespace cricket
|
||||||
|
|||||||
@ -278,16 +278,8 @@ class RTC_EXPORT P2PTransportChannel : public IceTransportInternal,
|
|||||||
// Returns true if it's possible to send packets on `connection`.
|
// Returns true if it's possible to send packets on `connection`.
|
||||||
bool ReadyToSend(const Connection* connection) const;
|
bool ReadyToSend(const Connection* connection) const;
|
||||||
bool PresumedWritable(const Connection* conn) const;
|
bool PresumedWritable(const Connection* conn) const;
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
void RequestSortAndStateUpdate(IceSwitchReason reason_to_sort);
|
|
||||||
// Start pinging if we haven't already started, and we now have a connection
|
|
||||||
// that's pingable.
|
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
void MaybeStartPinging();
|
|
||||||
void SendPingRequestInternal(Connection* connection);
|
void SendPingRequestInternal(Connection* connection);
|
||||||
|
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
void SortConnectionsAndUpdateState(IceSwitchReason reason_to_sort);
|
|
||||||
rtc::NetworkRoute ConfigureNetworkRoute(const Connection* conn);
|
rtc::NetworkRoute ConfigureNetworkRoute(const Connection* conn);
|
||||||
void SwitchSelectedConnectionInternal(Connection* conn,
|
void SwitchSelectedConnectionInternal(Connection* conn,
|
||||||
IceSwitchReason reason);
|
IceSwitchReason reason);
|
||||||
@ -355,26 +347,13 @@ class RTC_EXPORT P2PTransportChannel : public IceTransportInternal,
|
|||||||
|
|
||||||
void OnNominated(Connection* conn);
|
void OnNominated(Connection* conn);
|
||||||
|
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
void CheckAndPing();
|
|
||||||
|
|
||||||
void LogCandidatePairConfig(Connection* conn,
|
void LogCandidatePairConfig(Connection* conn,
|
||||||
webrtc::IceCandidatePairConfigType type);
|
webrtc::IceCandidatePairConfigType type);
|
||||||
|
|
||||||
uint32_t GetNominationAttr(Connection* conn) const;
|
uint32_t GetNominationAttr(Connection* conn) const;
|
||||||
bool GetUseCandidateAttr(Connection* conn) const;
|
bool GetUseCandidateAttr(Connection* conn) const;
|
||||||
|
|
||||||
// Returns true if the new_connection is selected for transmission.
|
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
bool MaybeSwitchSelectedConnection(const Connection* new_connection,
|
|
||||||
IceSwitchReason reason);
|
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
bool MaybeSwitchSelectedConnection(
|
|
||||||
IceSwitchReason reason,
|
|
||||||
IceControllerInterface::SwitchResult result);
|
|
||||||
bool AllowedToPruneConnections() const;
|
bool AllowedToPruneConnections() const;
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
void PruneConnections();
|
|
||||||
|
|
||||||
// Returns the latest remote ICE parameters or nullptr if there are no remote
|
// Returns the latest remote ICE parameters or nullptr if there are no remote
|
||||||
// ICE parameters yet.
|
// ICE parameters yet.
|
||||||
@ -431,8 +410,6 @@ class RTC_EXPORT P2PTransportChannel : public IceTransportInternal,
|
|||||||
|
|
||||||
void ParseFieldTrials(const webrtc::FieldTrialsView* field_trials);
|
void ParseFieldTrials(const webrtc::FieldTrialsView* field_trials);
|
||||||
|
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
webrtc::ScopedTaskSafety task_safety_;
|
|
||||||
std::string transport_name_ RTC_GUARDED_BY(network_thread_);
|
std::string transport_name_ RTC_GUARDED_BY(network_thread_);
|
||||||
int component_ RTC_GUARDED_BY(network_thread_);
|
int component_ RTC_GUARDED_BY(network_thread_);
|
||||||
PortAllocator* allocator_ RTC_GUARDED_BY(network_thread_);
|
PortAllocator* allocator_ RTC_GUARDED_BY(network_thread_);
|
||||||
@ -459,9 +436,6 @@ class RTC_EXPORT P2PTransportChannel : public IceTransportInternal,
|
|||||||
|
|
||||||
std::vector<RemoteCandidate> remote_candidates_
|
std::vector<RemoteCandidate> remote_candidates_
|
||||||
RTC_GUARDED_BY(network_thread_);
|
RTC_GUARDED_BY(network_thread_);
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
bool sort_dirty_ RTC_GUARDED_BY(
|
|
||||||
network_thread_); // indicates whether another sort is needed right now
|
|
||||||
bool had_connection_ RTC_GUARDED_BY(network_thread_) =
|
bool had_connection_ RTC_GUARDED_BY(network_thread_) =
|
||||||
false; // if connections_ has ever been nonempty
|
false; // if connections_ has ever been nonempty
|
||||||
typedef std::map<rtc::Socket::Option, int> OptionMap;
|
typedef std::map<rtc::Socket::Option, int> OptionMap;
|
||||||
@ -486,8 +460,6 @@ class RTC_EXPORT P2PTransportChannel : public IceTransportInternal,
|
|||||||
IceConfig config_ RTC_GUARDED_BY(network_thread_);
|
IceConfig config_ RTC_GUARDED_BY(network_thread_);
|
||||||
int last_sent_packet_id_ RTC_GUARDED_BY(network_thread_) =
|
int last_sent_packet_id_ RTC_GUARDED_BY(network_thread_) =
|
||||||
-1; // -1 indicates no packet was sent before.
|
-1; // -1 indicates no packet was sent before.
|
||||||
// TODO(bugs.webrtc.org/14367) remove once refactor lands.
|
|
||||||
bool started_pinging_ RTC_GUARDED_BY(network_thread_) = false;
|
|
||||||
// The value put in the "nomination" attribute for the next nominated
|
// The value put in the "nomination" attribute for the next nominated
|
||||||
// connection. A zero-value indicates the connection will not be nominated.
|
// connection. A zero-value indicates the connection will not be nominated.
|
||||||
uint32_t nomination_ RTC_GUARDED_BY(network_thread_) = 0;
|
uint32_t nomination_ RTC_GUARDED_BY(network_thread_) = 0;
|
||||||
@ -500,53 +472,7 @@ class RTC_EXPORT P2PTransportChannel : public IceTransportInternal,
|
|||||||
RTC_GUARDED_BY(network_thread_);
|
RTC_GUARDED_BY(network_thread_);
|
||||||
webrtc::IceEventLog ice_event_log_ RTC_GUARDED_BY(network_thread_);
|
webrtc::IceEventLog ice_event_log_ RTC_GUARDED_BY(network_thread_);
|
||||||
|
|
||||||
// The adapter transparently delegates ICE controller interactions to either
|
std::unique_ptr<ActiveIceControllerInterface> ice_controller_
|
||||||
// the legacy or the active ICE controller depending on field trials.
|
|
||||||
// TODO(bugs.webrtc.org/14367) replace with active ICE controller eventually.
|
|
||||||
class IceControllerAdapter : public ActiveIceControllerInterface {
|
|
||||||
public:
|
|
||||||
IceControllerAdapter(
|
|
||||||
const IceControllerFactoryArgs& args,
|
|
||||||
IceControllerFactoryInterface* ice_controller_factory,
|
|
||||||
ActiveIceControllerFactoryInterface* active_ice_controller_factory,
|
|
||||||
const webrtc::FieldTrialsView* field_trials,
|
|
||||||
P2PTransportChannel* transport);
|
|
||||||
~IceControllerAdapter() override;
|
|
||||||
|
|
||||||
// ActiveIceControllerInterface overrides
|
|
||||||
void SetIceConfig(const IceConfig& config) override;
|
|
||||||
void OnConnectionAdded(const Connection* connection) override;
|
|
||||||
void OnConnectionSwitched(const Connection* connection) override;
|
|
||||||
void OnConnectionPinged(const Connection* connection) override;
|
|
||||||
void OnConnectionDestroyed(const Connection* connection) override;
|
|
||||||
void OnConnectionUpdated(const Connection* connection) override;
|
|
||||||
void OnSortAndSwitchRequest(IceSwitchReason reason) override;
|
|
||||||
void OnImmediateSortAndSwitchRequest(IceSwitchReason reason) override;
|
|
||||||
bool OnImmediateSwitchRequest(IceSwitchReason reason,
|
|
||||||
const Connection* connection) override;
|
|
||||||
bool GetUseCandidateAttribute(const Connection* connection,
|
|
||||||
NominationMode mode,
|
|
||||||
IceMode remote_ice_mode) const override;
|
|
||||||
const Connection* FindNextPingableConnection() override;
|
|
||||||
|
|
||||||
// Methods only available with legacy ICE controller.
|
|
||||||
rtc::ArrayView<Connection*> LegacyConnections() const;
|
|
||||||
bool LegacyHasPingableConnection() const;
|
|
||||||
IceControllerInterface::PingResult LegacySelectConnectionToPing(
|
|
||||||
int64_t last_ping_sent_ms);
|
|
||||||
IceControllerInterface::SwitchResult LegacyShouldSwitchConnection(
|
|
||||||
IceSwitchReason reason,
|
|
||||||
const Connection* connection);
|
|
||||||
IceControllerInterface::SwitchResult LegacySortAndSwitchConnection(
|
|
||||||
IceSwitchReason reason);
|
|
||||||
std::vector<const Connection*> LegacyPruneConnections();
|
|
||||||
|
|
||||||
private:
|
|
||||||
P2PTransportChannel* transport_;
|
|
||||||
std::unique_ptr<IceControllerInterface> legacy_ice_controller_;
|
|
||||||
std::unique_ptr<ActiveIceControllerInterface> active_ice_controller_;
|
|
||||||
};
|
|
||||||
std::unique_ptr<IceControllerAdapter> ice_adapter_
|
|
||||||
RTC_GUARDED_BY(network_thread_);
|
RTC_GUARDED_BY(network_thread_);
|
||||||
|
|
||||||
struct CandidateAndResolver final {
|
struct CandidateAndResolver final {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user