webrtc_m130/pc/sctp_data_channel.h

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

307 lines
12 KiB
C
Raw Normal View History

/*
* Copyright 2020 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef PC_SCTP_DATA_CHANNEL_H_
#define PC_SCTP_DATA_CHANNEL_H_
#include <stdint.h>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include "api/data_channel_interface.h"
#include "api/priority.h"
#include "api/rtc_error.h"
#include "api/scoped_refptr.h"
#include "api/sequence_checker.h"
#include "api/task_queue/pending_task_safety_flag.h"
#include "api/transport/data_channel_transport_interface.h"
#include "pc/data_channel_utils.h"
#include "pc/sctp_utils.h"
#include "rtc_base/containers/flat_set.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/ssl_stream_adapter.h" // For SSLRole
#include "rtc_base/system/no_unique_address.h"
#include "rtc_base/thread.h"
#include "rtc_base/thread_annotations.h"
#include "rtc_base/weak_ptr.h"
namespace webrtc {
class SctpDataChannel;
// Interface that acts as a bridge from the data channel to the transport.
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
// All methods in this interface need to be invoked on the network thread.
class SctpDataChannelControllerInterface {
public:
// Sends the data to the transport.
virtual RTCError SendData(StreamId sid,
const SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload) = 0;
// Adds the data channel SID to the transport for SCTP.
virtual void AddSctpDataStream(StreamId sid, PriorityValue priority) = 0;
// Begins the closing procedure by sending an outgoing stream reset. Still
// need to wait for callbacks to tell when this completes.
virtual void RemoveSctpDataStream(StreamId sid) = 0;
// Notifies the controller of state changes.
virtual void OnChannelStateChanged(SctpDataChannel* data_channel,
DataChannelInterface::DataState state) = 0;
virtual size_t buffered_amount(StreamId sid) const = 0;
virtual size_t buffered_amount_low_threshold(StreamId sid) const = 0;
virtual void SetBufferedAmountLowThreshold(StreamId sid, size_t bytes) = 0;
protected:
virtual ~SctpDataChannelControllerInterface() {}
};
struct InternalDataChannelInit : public DataChannelInit {
enum OpenHandshakeRole { kOpener, kAcker, kNone };
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
// The default role is kOpener because the default `negotiated` is false.
InternalDataChannelInit() : open_handshake_role(kOpener) {}
explicit InternalDataChannelInit(const DataChannelInit& base);
// Does basic validation to determine if a data channel instance can be
// constructed using the configuration.
bool IsValid() const;
OpenHandshakeRole open_handshake_role;
// Optional fallback or backup flag from PC that's used for non-prenegotiated
// stream ids in situations where we cannot determine the SSL role from the
// transport for purposes of generating a stream ID.
// See: https://www.rfc-editor.org/rfc/rfc8832.html#name-protocol-overview
std::optional<rtc::SSLRole> fallback_ssl_role;
};
// Helper class to allocate unique IDs for SCTP DataChannels.
class SctpSidAllocator {
public:
SctpSidAllocator() = default;
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
// Gets the first unused odd/even id based on the DTLS role. If `role` is
// SSL_CLIENT, the allocated id starts from 0 and takes even numbers;
// otherwise, the id starts from 1 and takes odd numbers.
// If a `StreamId` cannot be allocated, `std::nullopt` is returned.
std::optional<StreamId> AllocateSid(rtc::SSLRole role);
// Attempts to reserve a specific sid. Returns false if it's unavailable.
bool ReserveSid(StreamId sid);
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
// Indicates that `sid` isn't in use any more, and is thus available again.
void ReleaseSid(StreamId sid);
private:
flat_set<StreamId> used_sids_ RTC_GUARDED_BY(&sequence_checker_);
RTC_NO_UNIQUE_ADDRESS SequenceChecker sequence_checker_{
SequenceChecker::kDetached};
};
// SctpDataChannel is an implementation of the DataChannelInterface based on
// SctpTransport. It provides an implementation of unreliable or
// reliable data channels.
// DataChannel states:
// kConnecting: The channel has been created the transport might not yet be
// ready.
// kOpen: The open handshake has been performed (if relevant) and the data
// channel is able to send messages.
// kClosing: DataChannelInterface::Close has been called, or the remote side
// initiated the closing procedure, but the closing procedure has not
// yet finished.
// kClosed: The closing handshake is finished (possibly initiated from this,
// side, possibly from the peer).
//
// How the closing procedure works for SCTP:
// 1. Alice calls Close(), state changes to kClosing.
// 2. Alice finishes sending any queued data.
// 3. Alice calls RemoveSctpDataStream, sends outgoing stream reset.
// 4. Bob receives incoming stream reset; OnClosingProcedureStartedRemotely
// called.
// 5. Bob sends outgoing stream reset.
// 6. Alice receives incoming reset, Bob receives acknowledgement. Both receive
// OnClosingProcedureComplete callback and transition to kClosed.
class SctpDataChannel : public DataChannelInterface {
public:
static rtc::scoped_refptr<SctpDataChannel> Create(
rtc::WeakPtr<SctpDataChannelControllerInterface> controller,
const std::string& label,
bool connected_to_transport,
const InternalDataChannelInit& config,
rtc::Thread* signaling_thread,
rtc::Thread* network_thread);
// Instantiates an API proxy for a SctpDataChannel instance that will be
// handed out to external callers.
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
// The `signaling_safety` flag is used for the ObserverAdapter callback proxy
// which delivers callbacks on the signaling thread but must not deliver such
// callbacks after the peerconnection has been closed. The data controller
// will update the flag when closed, which will cancel any pending event
// notifications.
static rtc::scoped_refptr<DataChannelInterface> CreateProxy(
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,
rtc::scoped_refptr<PendingTaskSafetyFlag> signaling_safety);
void RegisterObserver(DataChannelObserver* observer) override;
void UnregisterObserver() override;
std::string label() const override;
bool reliable() const override;
bool ordered() const override;
// Backwards compatible accessors
uint16_t maxRetransmitTime() const override;
uint16_t maxRetransmits() const override;
std::optional<int> maxPacketLifeTime() const override;
std::optional<int> maxRetransmitsOpt() const override;
std::string protocol() const override;
bool negotiated() const override;
int id() const override;
PriorityValue priority() const override;
uint64_t buffered_amount() const override;
void Close() override;
DataState state() const override;
RTCError error() const override;
uint32_t messages_sent() const override;
uint64_t bytes_sent() const override;
uint32_t messages_received() const override;
uint64_t bytes_received() const override;
bool Send(const DataBuffer& buffer) override;
void SendAsync(DataBuffer buffer,
absl::AnyInvocable<void(RTCError) &&> on_complete) override;
// Close immediately, ignoring any queued data or closing procedure.
// This is called when the underlying SctpTransport is being destroyed.
// It is also called by the PeerConnection if SCTP ID assignment fails.
void CloseAbruptlyWithError(RTCError error);
// Specializations of CloseAbruptlyWithError
void CloseAbruptlyWithDataChannelFailure(const std::string& message);
// Called when the SctpTransport's ready to use. That can happen when we've
// finished negotiation, or if the channel was created after negotiation has
// already finished.
void OnTransportReady();
void OnDataReceived(DataMessageType type,
const rtc::CopyOnWriteBuffer& payload);
// Sets the SCTP sid and adds to transport layer if not set yet. Should only
// be called once.
void SetSctpSid_n(StreamId sid);
// The remote side started the closing procedure by resetting its outgoing
// stream (our incoming stream). Sets state to kClosing.
void OnClosingProcedureStartedRemotely();
// The closing procedure is complete; both incoming and outgoing stream
// resets are done and the channel can transition to kClosed. Called
// asynchronously after RemoveSctpDataStream.
void OnClosingProcedureComplete();
// Called when the transport channel is created.
void OnTransportChannelCreated();
// Called when the transport channel is unusable.
// This method makes sure the DataChannel is disconnected and changes state
// to kClosed.
void OnTransportChannelClosed(RTCError error);
// Called when the amount of data buffered to be sent falls to or below the
// threshold set when calling `SetBufferedAmountLowThreshold`.
void OnBufferedAmountLow();
DataChannelStats GetStats() const;
// Returns a unique identifier that's guaranteed to always be available,
// doesn't change throughout SctpDataChannel's lifetime and is used for
// stats purposes (see also `GetStats()`).
int internal_id() const { return internal_id_; }
std::optional<StreamId> sid_n() const {
RTC_DCHECK_RUN_ON(network_thread_);
return id_n_;
}
// Reset the allocator for internal ID values for testing, so that
// the internal IDs generated are predictable. Test only.
static void ResetInternalIdAllocatorForTesting(int new_value);
protected:
SctpDataChannel(const InternalDataChannelInit& config,
rtc::WeakPtr<SctpDataChannelControllerInterface> controller,
const std::string& label,
bool connected_to_transport,
rtc::Thread* signaling_thread,
rtc::Thread* network_thread);
~SctpDataChannel() override;
private:
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
class ObserverAdapter;
// The OPEN(_ACK) signaling state.
enum HandshakeState {
kHandshakeInit,
kHandshakeShouldSendOpen,
kHandshakeShouldSendAck,
kHandshakeWaitingForAck,
kHandshakeReady
};
RTCError SendImpl(DataBuffer buffer) RTC_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
void UpdateState() RTC_RUN_ON(network_thread_);
void SetState(DataState state) RTC_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
void DeliverQueuedReceivedData() RTC_RUN_ON(network_thread_);
RTCError SendDataMessage(const DataBuffer& buffer, bool queue_if_blocked)
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_);
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
bool SendControlMessage(const rtc::CopyOnWriteBuffer& buffer)
RTC_RUN_ON(network_thread_);
bool connected_to_transport() const RTC_RUN_ON(network_thread_) {
return network_safety_->alive();
}
pc: Remove additional buffering in SctpDataChannel This CL removes the send buffers (but not the receive buffer) from SctpDataChannel and increases the send buffer in DcSctpSocket instead. The reasons are: 1) Simplify the code. This additional buffering was strictly needed before we migrated away from usrsctp, as that send buffer was very limited in size (by design). But with the migration to dcSCTP, it's no longer needed, so it just adds complexity. 2) Make `RTCDataChannel::bufferedAmount` correct. Before this CL, it represented just the data buffered in SctpDataChannel, and not the data accepted by the SCTP socket, but not yet put on the wire. This makes it hard for clients to know when a message has ever been sent. 3) Better handle draining data on data channel close. While this is not implemented in dcSCTP, having a single buffer makes this easier to add. While most of this CL is straightforward, the handling of bufferedAmount in the signaling thread (in RTCDataChannel in Blink), is a bit special. The number returned by `RTCDataChannel::bufferedAmount` is not what the true value is inside the SCTP socket, but an eventual consistent view of that value. When a message is sent, the value is incremented and: - Before this change: When a message was put on the SCTP socket, the view's value was decremented. Which made the view reflect what was buffered outside the SCTP socket, and that buffering is now gone. - After this change: SctpDataChannel will track what RTCDataChannel will think it is, and provide updates to that number as we are notified that it's reduced - by setting a "low threshold" callback trigger. A bonus with the new behavior is that it will be eventually consistent and auto-heal also in error conditions - when messages are dropped due to errors (bad input, bad state, etc). Previously, the bufferedAmount value could drift away from the correct value on errors. Note that a big chunk of unit tests were removed with this CL, as those tested how the buffering behaved. Now, there is no buffering, so the removed test cases represent a simpler interface. This CL has been extensively tested with data channel benchmarks that use the bufferedAmount thresholds (in Javascript). Bug: chromium:40072842 Change-Id: I1a6a4af6b6e1116832f5028f989ce9f44683d229 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/343361 Commit-Queue: Victor Boivie <boivie@webrtc.org> Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Florent Castelli <orphis@webrtc.org> Cr-Commit-Position: refs/heads/main@{#41945}
2024-03-18 13:51:40 +01:00
void MaybeSendOnBufferedAmountChanged() RTC_RUN_ON(network_thread_);
rtc::Thread* const signaling_thread_;
rtc::Thread* const network_thread_;
std::optional<StreamId> id_n_ RTC_GUARDED_BY(network_thread_) = std::nullopt;
const int internal_id_;
const std::string label_;
const std::string protocol_;
const std::optional<int> max_retransmit_time_;
const std::optional<int> max_retransmits_;
const std::optional<PriorityValue> priority_;
const bool negotiated_;
const bool ordered_;
pc: Remove additional buffering in SctpDataChannel This CL removes the send buffers (but not the receive buffer) from SctpDataChannel and increases the send buffer in DcSctpSocket instead. The reasons are: 1) Simplify the code. This additional buffering was strictly needed before we migrated away from usrsctp, as that send buffer was very limited in size (by design). But with the migration to dcSCTP, it's no longer needed, so it just adds complexity. 2) Make `RTCDataChannel::bufferedAmount` correct. Before this CL, it represented just the data buffered in SctpDataChannel, and not the data accepted by the SCTP socket, but not yet put on the wire. This makes it hard for clients to know when a message has ever been sent. 3) Better handle draining data on data channel close. While this is not implemented in dcSCTP, having a single buffer makes this easier to add. While most of this CL is straightforward, the handling of bufferedAmount in the signaling thread (in RTCDataChannel in Blink), is a bit special. The number returned by `RTCDataChannel::bufferedAmount` is not what the true value is inside the SCTP socket, but an eventual consistent view of that value. When a message is sent, the value is incremented and: - Before this change: When a message was put on the SCTP socket, the view's value was decremented. Which made the view reflect what was buffered outside the SCTP socket, and that buffering is now gone. - After this change: SctpDataChannel will track what RTCDataChannel will think it is, and provide updates to that number as we are notified that it's reduced - by setting a "low threshold" callback trigger. A bonus with the new behavior is that it will be eventually consistent and auto-heal also in error conditions - when messages are dropped due to errors (bad input, bad state, etc). Previously, the bufferedAmount value could drift away from the correct value on errors. Note that a big chunk of unit tests were removed with this CL, as those tested how the buffering behaved. Now, there is no buffering, so the removed test cases represent a simpler interface. This CL has been extensively tested with data channel benchmarks that use the bufferedAmount thresholds (in Javascript). Bug: chromium:40072842 Change-Id: I1a6a4af6b6e1116832f5028f989ce9f44683d229 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/343361 Commit-Queue: Victor Boivie <boivie@webrtc.org> Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Florent Castelli <orphis@webrtc.org> Cr-Commit-Position: refs/heads/main@{#41945}
2024-03-18 13:51:40 +01:00
// See the body of `MaybeSendOnBufferedAmountChanged`.
size_t expected_buffer_amount_ = 0;
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
DataChannelObserver* observer_ RTC_GUARDED_BY(network_thread_) = nullptr;
std::unique_ptr<ObserverAdapter> observer_adapter_;
DataState state_ RTC_GUARDED_BY(network_thread_) = kConnecting;
RTCError error_ RTC_GUARDED_BY(network_thread_);
uint32_t messages_sent_ RTC_GUARDED_BY(network_thread_) = 0;
uint64_t bytes_sent_ RTC_GUARDED_BY(network_thread_) = 0;
uint32_t messages_received_ RTC_GUARDED_BY(network_thread_) = 0;
uint64_t bytes_received_ RTC_GUARDED_BY(network_thread_) = 0;
rtc::WeakPtr<SctpDataChannelControllerInterface> controller_
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_GUARDED_BY(network_thread_);
HandshakeState handshake_state_ RTC_GUARDED_BY(network_thread_) =
kHandshakeInit;
// Did we already start the graceful SCTP closing procedure?
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
bool started_closing_procedure_ RTC_GUARDED_BY(network_thread_) = false;
PacketQueue queued_received_data_ RTC_GUARDED_BY(network_thread_);
rtc::scoped_refptr<PendingTaskSafetyFlag> network_safety_ =
PendingTaskSafetyFlag::CreateDetachedInactive();
};
} // namespace webrtc
#endif // PC_SCTP_DATA_CHANNEL_H_