webrtc_m130/pc/data_channel_controller.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

442 lines
15 KiB
C++
Raw Normal View History

/*
* Copyright 2019 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.
*/
#include "pc/data_channel_controller.h"
#include <utility>
#include "absl/algorithm/container.h"
#include "api/peer_connection_interface.h"
#include "api/rtc_error.h"
#include "pc/peer_connection_internal.h"
#include "pc/sctp_utils.h"
#include "rtc_base/logging.h"
namespace webrtc {
DataChannelController::~DataChannelController() {
RTC_DCHECK(sctp_data_channels_n_.empty())
<< "Missing call to TeardownDataChannelTransport_n?";
RTC_DCHECK(!signaling_safety_.flag()->alive())
<< "Missing call to PrepareForShutdown?";
}
bool DataChannelController::HasDataChannelsForTest() const {
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
auto has_channels = [&] {
RTC_DCHECK_RUN_ON(network_thread());
return !sctp_data_channels_n_.empty();
};
if (network_thread()->IsCurrent())
return has_channels();
return network_thread()->BlockingCall(std::move(has_channels));
}
bool DataChannelController::HasUsedDataChannels() const {
RTC_DCHECK_RUN_ON(signaling_thread());
return has_used_data_channels_;
}
RTCError DataChannelController::SendData(
StreamId sid,
const SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload) {
RTC_DCHECK_RUN_ON(network_thread());
if (!data_channel_transport_) {
RTC_LOG(LS_ERROR) << "SendData called before transport is ready";
return RTCError(RTCErrorType::INVALID_STATE);
}
return data_channel_transport_->SendData(sid.stream_id_int(), params,
payload);
}
void DataChannelController::AddSctpDataStream(StreamId sid) {
RTC_DCHECK_RUN_ON(network_thread());
RTC_DCHECK(sid.HasValue());
if (data_channel_transport_) {
data_channel_transport_->OpenChannel(sid.stream_id_int());
}
}
void DataChannelController::RemoveSctpDataStream(StreamId sid) {
RTC_DCHECK_RUN_ON(network_thread());
if (data_channel_transport_) {
data_channel_transport_->CloseChannel(sid.stream_id_int());
}
}
void DataChannelController::OnChannelStateChanged(
SctpDataChannel* channel,
DataChannelInterface::DataState state) {
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
RTC_DCHECK_RUN_ON(network_thread());
if (state == DataChannelInterface::DataState::kClosed)
OnSctpDataChannelClosed(channel);
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
signaling_thread()->PostTask(
SafeTask(signaling_safety_.flag(),
[this, channel_id = channel->internal_id(), state = state] {
pc_->OnSctpDataChannelStateChanged(channel_id, state);
}));
}
void DataChannelController::OnDataReceived(
int channel_id,
DataMessageType type,
const rtc::CopyOnWriteBuffer& buffer) {
RTC_DCHECK_RUN_ON(network_thread());
if (HandleOpenMessage_n(channel_id, type, buffer))
return;
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
auto it = absl::c_find_if(sctp_data_channels_n_, [&](const auto& c) {
return c->sid_n().stream_id_int() == channel_id;
});
if (it != sctp_data_channels_n_.end())
(*it)->OnDataReceived(type, buffer);
}
void DataChannelController::OnChannelClosing(int channel_id) {
RTC_DCHECK_RUN_ON(network_thread());
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
auto it = absl::c_find_if(sctp_data_channels_n_, [&](const auto& c) {
return c->sid_n().stream_id_int() == channel_id;
});
if (it != sctp_data_channels_n_.end())
(*it)->OnClosingProcedureStartedRemotely();
}
void DataChannelController::OnChannelClosed(int channel_id) {
RTC_DCHECK_RUN_ON(network_thread());
StreamId sid(channel_id);
sid_allocator_.ReleaseSid(sid);
auto it = absl::c_find_if(sctp_data_channels_n_,
[&](const auto& c) { return c->sid_n() == sid; });
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
if (it != sctp_data_channels_n_.end()) {
rtc::scoped_refptr<SctpDataChannel> channel = std::move(*it);
sctp_data_channels_n_.erase(it);
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
channel->OnClosingProcedureComplete();
}
}
void DataChannelController::OnReadyToSend() {
RTC_DCHECK_RUN_ON(network_thread());
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
auto copy = sctp_data_channels_n_;
for (const auto& channel : copy) {
if (channel->sid_n().HasValue()) {
channel->OnTransportReady();
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
} else {
// This happens for role==SSL_SERVER channels when we get notified by
// the transport *before* the SDP code calls `AllocateSctpSids` to
// trigger assignment of sids. In this case OnTransportReady() will be
// called from within `AllocateSctpSids` below.
RTC_LOG(LS_INFO) << "OnReadyToSend: Still waiting for an id for channel.";
}
}
}
void DataChannelController::OnTransportClosed(RTCError error) {
RTC_DCHECK_RUN_ON(network_thread());
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
// This loop will close all data channels and trigger a callback to
// `OnSctpDataChannelClosed`. We'll empty `sctp_data_channels_n_`, first
// and `OnSctpDataChannelClosed` will become a noop but we'll release the
// StreamId here.
std::vector<rtc::scoped_refptr<SctpDataChannel>> temp_sctp_dcs;
temp_sctp_dcs.swap(sctp_data_channels_n_);
for (const auto& channel : temp_sctp_dcs) {
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
channel->OnTransportChannelClosed(error);
sid_allocator_.ReleaseSid(channel->sid_n());
}
}
void DataChannelController::SetupDataChannelTransport_n() {
RTC_DCHECK_RUN_ON(network_thread());
// There's a new data channel transport. This needs to be signaled to the
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
// `sctp_data_channels_n_` so that they can reopen and reconnect. This is
// necessary when bundling is applied.
NotifyDataChannelsOfTransportCreated();
}
void DataChannelController::PrepareForShutdown() {
RTC_DCHECK_RUN_ON(signaling_thread());
signaling_safety_.reset(PendingTaskSafetyFlag::CreateDetachedInactive());
}
void DataChannelController::TeardownDataChannelTransport_n(RTCError error) {
RTC_DCHECK_RUN_ON(network_thread());
OnTransportClosed(error);
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
if (data_channel_transport_) {
data_channel_transport_->SetDataSink(nullptr);
set_data_channel_transport(nullptr);
}
RTC_DCHECK(sctp_data_channels_n_.empty());
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
weak_factory_.InvalidateWeakPtrs();
}
void DataChannelController::OnTransportChanged(
DataChannelTransportInterface* new_data_channel_transport) {
RTC_DCHECK_RUN_ON(network_thread());
if (data_channel_transport_ &&
data_channel_transport_ != new_data_channel_transport) {
Reland "Use backticks not vertical bars to denote variables in comments for /pc" Original change's description: > Revert "Use backticks not vertical bars to denote variables in comments for /pc" > > This reverts commit 37ee0f5e594dd772ec6d620b5e5ea8a751b684f0. > > Reason for revert: Revert in order to be able to revert https://webrtc-review.googlesource.com/c/src/+/225642 > > Original change's description: > > Use backticks not vertical bars to denote variables in comments for /pc > > > > Bug: webrtc:12338 > > Change-Id: I88cf10afa5fc810b95d2a585ab2e895dcc163b63 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/226953 > > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Artem Titov <titovartem@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#34575} > > TBR=hta@webrtc.org,titovartem@webrtc.org,webrtc-scoped@luci-project-accounts.iam.gserviceaccount.com > > Change-Id: I5eddd3a14e1f664bf831e5c294fbc4de5f6a88af > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:12338 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227082 > Reviewed-by: Björn Terelius <terelius@webrtc.org> > Commit-Queue: Björn Terelius <terelius@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#34577} Bug: webrtc:12338 Change-Id: I96bd229b73613c162d11d75fa4f5934e1b4295c7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227087 Commit-Queue: Artem Titov <titovartem@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34611}
2021-07-30 22:30:23 +02:00
// Changed which data channel transport is used for `sctp_mid_` (eg. now
// it's bundled).
data_channel_transport_->SetDataSink(nullptr);
set_data_channel_transport(new_data_channel_transport);
if (new_data_channel_transport) {
new_data_channel_transport->SetDataSink(this);
// There's a new data channel transport. This needs to be signaled to the
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
// `sctp_data_channels_n_` so that they can reopen and reconnect. This is
// necessary when bundling is applied.
NotifyDataChannelsOfTransportCreated();
}
}
}
std::vector<DataChannelStats> DataChannelController::GetDataChannelStats()
const {
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
RTC_DCHECK_RUN_ON(network_thread());
std::vector<DataChannelStats> stats;
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
stats.reserve(sctp_data_channels_n_.size());
for (const auto& channel : sctp_data_channels_n_)
stats.push_back(channel->GetStats());
return stats;
}
bool DataChannelController::HandleOpenMessage_n(
int channel_id,
DataMessageType type,
const rtc::CopyOnWriteBuffer& buffer) {
if (type != DataMessageType::kControl || !IsOpenMessage(buffer))
return false;
// Received OPEN message; parse and signal that a new data channel should
// be created.
std::string label;
InternalDataChannelInit config;
config.id = channel_id;
if (!ParseDataChannelOpenMessage(buffer, &label, &config)) {
RTC_LOG(LS_WARNING) << "Failed to parse the OPEN message for sid "
<< channel_id;
} else {
config.open_handshake_role = InternalDataChannelInit::kAcker;
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
auto channel_or_error = CreateDataChannel(label, config);
if (channel_or_error.ok()) {
signaling_thread()->PostTask(SafeTask(
signaling_safety_.flag(),
[this, channel = channel_or_error.MoveValue(),
ready_to_send = data_channel_transport_->IsReadyToSend()] {
RTC_DCHECK_RUN_ON(signaling_thread());
OnDataChannelOpenMessage(std::move(channel), ready_to_send);
}));
} else {
RTC_LOG(LS_ERROR) << "Failed to create DataChannel from the OPEN message."
<< ToString(channel_or_error.error().type());
}
}
return true;
}
void DataChannelController::OnDataChannelOpenMessage(
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
rtc::scoped_refptr<SctpDataChannel> channel,
bool ready_to_send) {
has_used_data_channels_ = true;
auto proxy = SctpDataChannel::CreateProxy(channel, signaling_safety_.flag());
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
pc_->Observer()->OnDataChannel(proxy);
pc_->NoteDataAddedEvent();
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
if (ready_to_send) {
network_thread()->PostTask([channel = std::move(channel)] {
if (channel->state() != DataChannelInterface::DataState::kClosed)
channel->OnTransportReady();
});
}
}
// RTC_RUN_ON(network_thread())
RTCError DataChannelController::ReserveOrAllocateSid(
StreamId& sid,
absl::optional<rtc::SSLRole> fallback_ssl_role) {
if (sid.HasValue()) {
return sid_allocator_.ReserveSid(sid)
? RTCError::OK()
: RTCError(RTCErrorType::INVALID_RANGE,
"StreamId out of range or reserved.");
}
// Attempt to allocate an ID based on the negotiated role.
absl::optional<rtc::SSLRole> role = pc_->GetSctpSslRole_n();
if (!role)
role = fallback_ssl_role;
if (role) {
sid = sid_allocator_.AllocateSid(*role);
if (!sid.HasValue())
return RTCError(RTCErrorType::RESOURCE_EXHAUSTED);
}
// When we get here, we may still not have an ID, but that's a supported case
// whereby an id will be assigned later.
RTC_DCHECK(sid.HasValue() || !role);
return RTCError::OK();
}
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
// RTC_RUN_ON(network_thread())
RTCErrorOr<rtc::scoped_refptr<SctpDataChannel>>
DataChannelController::CreateDataChannel(const std::string& label,
InternalDataChannelInit& config) {
StreamId sid(config.id);
RTCError err = ReserveOrAllocateSid(sid, config.fallback_ssl_role);
if (!err.ok())
return err;
// In case `sid` has changed. Update `config` accordingly.
config.id = sid.stream_id_int();
rtc::scoped_refptr<SctpDataChannel> channel = SctpDataChannel::Create(
weak_factory_.GetWeakPtr(), label, data_channel_transport_ != nullptr,
config, signaling_thread(), network_thread());
RTC_DCHECK(channel);
sctp_data_channels_n_.push_back(channel);
// If we have an id already, notify the transport.
if (sid.HasValue())
AddSctpDataStream(sid);
return channel;
}
RTCErrorOr<rtc::scoped_refptr<DataChannelInterface>>
DataChannelController::InternalCreateDataChannelWithProxy(
const std::string& label,
const InternalDataChannelInit& config) {
RTC_DCHECK_RUN_ON(signaling_thread());
RTC_DCHECK(!pc_->IsClosed());
if (!config.IsValid()) {
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
"Invalid DataChannelInit");
}
bool ready_to_send = false;
InternalDataChannelInit new_config = config;
StreamId sid(new_config.id);
auto ret = network_thread()->BlockingCall(
[&]() -> RTCErrorOr<rtc::scoped_refptr<SctpDataChannel>> {
RTC_DCHECK_RUN_ON(network_thread());
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
auto channel = CreateDataChannel(label, new_config);
if (!channel.ok())
return channel;
ready_to_send =
data_channel_transport_ && data_channel_transport_->IsReadyToSend();
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
if (ready_to_send) {
// If the transport is ready to send because the initial channel
// ready signal may have been sent before the DataChannel creation.
// This has to be done async because the upper layer objects (e.g.
// Chrome glue and WebKit) are not wired up properly until after
// `InternalCreateDataChannelWithProxy` returns.
network_thread()->PostTask([channel = channel.value()] {
if (channel->state() != DataChannelInterface::DataState::kClosed)
channel->OnTransportReady();
});
}
return channel;
});
if (!ret.ok())
return ret.MoveError();
has_used_data_channels_ = true;
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
return SctpDataChannel::CreateProxy(ret.MoveValue(),
signaling_safety_.flag());
}
void DataChannelController::AllocateSctpSids(rtc::SSLRole role) {
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
RTC_DCHECK_RUN_ON(network_thread());
const bool ready_to_send =
data_channel_transport_ && data_channel_transport_->IsReadyToSend();
std::vector<std::pair<SctpDataChannel*, StreamId>> channels_to_update;
std::vector<rtc::scoped_refptr<SctpDataChannel>> channels_to_close;
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
for (auto it = sctp_data_channels_n_.begin();
it != sctp_data_channels_n_.end();) {
if (!(*it)->sid_n().HasValue()) {
StreamId sid = sid_allocator_.AllocateSid(role);
if (sid.HasValue()) {
(*it)->SetSctpSid_n(sid);
AddSctpDataStream(sid);
if (ready_to_send) {
RTC_LOG(LS_INFO) << "AllocateSctpSids: Id assigned, ready to send.";
(*it)->OnTransportReady();
}
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
channels_to_update.push_back(std::make_pair((*it).get(), sid));
} else {
channels_to_close.push_back(std::move(*it));
it = sctp_data_channels_n_.erase(it);
continue;
}
}
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
++it;
}
// Since closing modifies the list of channels, we have to do the actual
// closing outside the loop.
for (const auto& channel : channels_to_close) {
channel->CloseAbruptlyWithDataChannelFailure("Failed to allocate SCTP SID");
}
}
void DataChannelController::OnSctpDataChannelClosed(SctpDataChannel* channel) {
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
RTC_DCHECK_RUN_ON(network_thread());
// After the closing procedure is done, it's safe to use this ID for
// another data channel.
if (channel->sid_n().HasValue()) {
sid_allocator_.ReleaseSid(channel->sid_n());
}
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
auto it = absl::c_find_if(sctp_data_channels_n_,
[&](const auto& c) { return c.get() == channel; });
if (it != sctp_data_channels_n_.end())
sctp_data_channels_n_.erase(it);
}
void DataChannelController::set_data_channel_transport(
DataChannelTransportInterface* transport) {
RTC_DCHECK_RUN_ON(network_thread());
data_channel_transport_ = transport;
}
void DataChannelController::NotifyDataChannelsOfTransportCreated() {
RTC_DCHECK_RUN_ON(network_thread());
RTC_DCHECK(data_channel_transport_);
for (const auto& channel : sctp_data_channels_n_) {
if (channel->sid_n().HasValue())
AddSctpDataStream(channel->sid_n());
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
channel->OnTransportChannelCreated();
}
}
rtc::Thread* DataChannelController::network_thread() const {
return pc_->network_thread();
}
Reland "[DataChannel] Send and receive packets on the network thread." This reverts commit 7f16fcda0fd5bb625584b71311dd37b54c096136. Reason for reland: Re-landing after addressing issues in downstream code and hardening the ObserverAdapter from situations where attempted usage of data channel proxies could occur after shutting down the peer connection and terminating the network thread. Original change's description: > Revert "[DataChannel] Send and receive packets on the network thread." > > This reverts commit fe53fec24e02d2d644220f913c3f9ae596bbb2d9. > > Reason for revert: Speculative revert, may be breaking downstream project > > Original change's description: > > [DataChannel] Send and receive packets on the network thread. > > > > This updates sctp channels, including work that happens between the > > data channel controller and the transport, to run on the network > > thread. Previously all network traffic related to data channels was > > routed through the signaling thread before going to either the network > > thread or the caller's thread (e.g. js thread in chrome). Now the > > calls can go straight from the network thread to the JS thread with > > enabling a special flag on the observer (see below) and similarly > > calls to send data, involve 2 threads instead of 3. > > > > * Custom data channel observer adapter implementation that > > maintains compatibility with existing observer implementations in > > that notifications are delivered on the signaling thread. > > The adapter can be explicitly disabled for implementations that > > want to optimize the callback path and promise to not block the > > network thread. > > * Remove the signaling thread copy of data channels in the controller. > > * Remove several PostTask operations that were needed to keep things > > in sync (but the need has gone away). > > * Update tests for the controller to consistently call > > TeardownDataChannelTransport_n to match with production. > > * Update stats collectors (current and legacy) to fetch the data > > channel stats on the network thread where they're maintained. > > * Remove the AsyncChannelCloseTeardown test since the async teardown > > step has gone away. > > * Remove `sid_s` in the channel code since we only need the network > > state now. > > * For the custom observer support (with and without data adapter) and > > maintain compatibility with existing implementations, added a new > > proxy macro that allows an implementation to selectively provide > > its own implementation without being proxied. This is used for > > registering/unregistering a data channel observer. > > * Update the data channel proxy to map most methods to the network > > thread, avoiding the interim jump to the signaling thread. > > * Update a plethora of thread checkers from signaling to network. > > > > Bug: webrtc:11547 > > Change-Id: Ib4cff1482e31c46008e187189a79e967389bc518 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299142 > > Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39760} > > Bug: webrtc:11547 > Change-Id: Id0d65594bf727ccea5c49093c942b09714d101ad > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300341 > Auto-Submit: Andrey Logvin <landrey@webrtc.org> > Owners-Override: Andrey Logvin <landrey@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39764} Bug: webrtc:11547 Change-Id: I47dfa7e7168be0cd2faab4f8f3ebf110c3728af5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300360 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39786}
2023-04-06 21:21:45 +02:00
rtc::Thread* DataChannelController::signaling_thread() const {
return pc_->signaling_thread();
}
} // namespace webrtc