Commit 8627e9e8 authored by Erik Jensen's avatar Erik Jensen Committed by Commit Bot

remoting: Obtain max message size dynamically.

Previously, clipboard messages were capped at the default safe size of
64KiB. This patchset raises the limit when the session descriptor
indicates that a larger size is supported.

Bug: 988865
Change-Id: I651c4e0a5aa96b84950eb4fa8f798af7579eff85
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1726277
Commit-Queue: Erik Jensen <rkjnsn@chromium.org>
Reviewed-by: default avatarJoe Downing <joedow@chromium.org>
Auto-Submit: Erik Jensen <rkjnsn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682400}
parent 9a182334
......@@ -18,12 +18,6 @@
namespace remoting {
namespace protocol {
namespace {
// It seems Chrome currently only properly supports receiving messages up to
// 64KiB.
constexpr int kMaxSafeMessageSizeInBytes = 64 * 1024;
} // namespace
HostControlDispatcher::HostControlDispatcher()
: ChannelDispatcherBase(kControlChannelName) {}
HostControlDispatcher::~HostControlDispatcher() = default;
......@@ -58,9 +52,12 @@ void HostControlDispatcher::SetVideoLayout(const VideoLayout& layout) {
void HostControlDispatcher::InjectClipboardEvent(const ClipboardEvent& event) {
ControlMessage message;
message.mutable_clipboard_event()->CopyFrom(event);
if (message.ByteSizeLong() > kMaxSafeMessageSizeInBytes) {
std::size_t message_size = message.ByteSizeLong();
if (message_size > max_message_size_) {
// Better to drop the event than drop the connection, which can happen if
// the browser receives a message larger than it can handle.
LOG(WARNING) << "Clipboard message dropped because message size "
<< message_size << " is larger than " << max_message_size_;
return;
}
message_pipe()->Send(&message, base::Closure());
......
......@@ -5,6 +5,8 @@
#ifndef REMOTING_PROTOCOL_HOST_CONTROL_DISPATCHER_H_
#define REMOTING_PROTOCOL_HOST_CONTROL_DISPATCHER_H_
#include <cstddef>
#include "base/macros.h"
#include "remoting/protocol/channel_dispatcher_base.h"
#include "remoting/protocol/client_stub.h"
......@@ -48,11 +50,23 @@ class HostControlDispatcher : public ChannelDispatcherBase,
// message. |host_stub| must outlive this object.
void set_host_stub(HostStub* host_stub) { host_stub_ = host_stub; }
// Sets the maximum size of outgoing messages, which defaults to 64KiB. This
// is used to ensure we don't try to send any clipboard messages that the
// client can't receive. Clipboard updates that are larger than the maximum
// message size will be dropped.
void set_max_message_size(std::size_t max_message_size) {
LOG(INFO) << "Setting maximum message size to " << max_message_size;
max_message_size_ = max_message_size;
}
private:
void OnIncomingMessage(std::unique_ptr<CompoundBuffer> buffer) override;
ClipboardStub* clipboard_stub_ = nullptr;
HostStub* host_stub_ = nullptr;
// 64 KiB is the default message size expected to be supported in absence of
// a higher value negotiated via SDP.
std::size_t max_message_size_ = 64 * 1024;
DISALLOW_COPY_AND_ASSIGN(HostControlDispatcher);
};
......
......@@ -26,6 +26,7 @@
#include "remoting/protocol/webrtc_video_stream.h"
#include "third_party/webrtc/api/media_stream_interface.h"
#include "third_party/webrtc/api/peer_connection_interface.h"
#include "third_party/webrtc/api/sctp_transport_interface.h"
namespace remoting {
namespace protocol {
......@@ -179,6 +180,14 @@ void WebrtcConnectionToClient::OnWebrtcTransportConnecting() {
void WebrtcConnectionToClient::OnWebrtcTransportConnected() {
DCHECK(thread_checker_.CalledOnValidThread());
auto sctp_transport = transport_->peer_connection()->GetSctpTransport();
if (sctp_transport) {
absl::optional<double> max_message_size =
sctp_transport->Information().MaxMessageSize();
if (max_message_size && *max_message_size > 0) {
control_dispatcher_->set_max_message_size(*max_message_size);
}
}
}
void WebrtcConnectionToClient::OnWebrtcTransportError(ErrorCode error) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment