Skip to content

Commit

Permalink
Set WebSocket max message size to 256KB
Browse files Browse the repository at this point in the history
  • Loading branch information
paullouisageneau committed Jan 18, 2024
1 parent cbaffdc commit 7a25011
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Channel::~Channel() { impl()->resetCallbacks(); }

Channel::Channel(impl_ptr<impl::Channel> impl) : CheshireCat<impl::Channel>(std::move(impl)) {}

size_t Channel::maxMessageSize() const { return DEFAULT_MAX_MESSAGE_SIZE; }
size_t Channel::maxMessageSize() const { return 0; }

size_t Channel::bufferedAmount() const { return impl()->bufferedAmount; }

Expand Down
2 changes: 1 addition & 1 deletion src/impl/datachannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ bool DataChannel::isClosed(void) const { return mIsClosed; }

size_t DataChannel::maxMessageSize() const {
auto pc = mPeerConnection.lock();
return pc ? pc->remoteMaxMessageSize() : DEFAULT_MAX_MESSAGE_SIZE;
return pc ? pc->remoteMaxMessageSize() : DEFAULT_REMOTE_MAX_MESSAGE_SIZE;
}

void DataChannel::assignStream(uint16_t stream) {
Expand Down
4 changes: 3 additions & 1 deletion src/impl/internals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ const uint16_t MAX_SCTP_STREAMS_COUNT = 1024; // Max number of negotiated SCTP s
// of memory, Chromium historically limits to 1024.

const size_t DEFAULT_LOCAL_MAX_MESSAGE_SIZE = 256 * 1024; // Default local max message size
const size_t DEFAULT_MAX_MESSAGE_SIZE = 65536; // Remote max message size if not specified in SDP
const size_t DEFAULT_REMOTE_MAX_MESSAGE_SIZE = 65536; // Remote max message size if not in SDP

const size_t DEFAULT_WS_MAX_MESSAGE_SIZE = 256 * 1024; // Default max message size for WebSockets

const size_t RECV_QUEUE_LIMIT = 1024 * 1024; // Max per-channel queue size

Expand Down
2 changes: 1 addition & 1 deletion src/impl/peerconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ optional<Description> PeerConnection::remoteDescription() const {
size_t PeerConnection::remoteMaxMessageSize() const {
const size_t localMax = config.maxMessageSize.value_or(DEFAULT_LOCAL_MAX_MESSAGE_SIZE);

size_t remoteMax = DEFAULT_MAX_MESSAGE_SIZE;
size_t remoteMax = DEFAULT_REMOTE_MAX_MESSAGE_SIZE;
std::lock_guard lock(mRemoteDescriptionMutex);
if (mRemoteDescription)
if (auto *application = mRemoteDescription->application())
Expand Down
2 changes: 1 addition & 1 deletion src/impl/websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ bool WebSocket::isOpen() const { return state == State::Open; }

bool WebSocket::isClosed() const { return state == State::Closed; }

size_t WebSocket::maxMessageSize() const { return config.maxMessageSize.value_or(DEFAULT_MAX_MESSAGE_SIZE); }
size_t WebSocket::maxMessageSize() const { return config.maxMessageSize.value_or(DEFAULT_WS_MAX_MESSAGE_SIZE); }

optional<message_variant> WebSocket::receive() {
auto next = mRecvQueue.pop();
Expand Down
2 changes: 1 addition & 1 deletion src/impl/wstransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ WsTransport::WsTransport(LowerTransport lower, shared_ptr<WsHandshake> handshake
std::visit(rtc::overloaded{[](auto l) { return l->isActive(); },
[](shared_ptr<TlsTransport> l) { return l->isClient(); }},
lower)),
mMaxMessageSize(config.maxMessageSize.value_or(DEFAULT_MAX_MESSAGE_SIZE)),
mMaxMessageSize(config.maxMessageSize.value_or(DEFAULT_WS_MAX_MESSAGE_SIZE)),
mMaxOutstandingPings(config.maxOutstandingPings.value_or(0)) {

onRecv(std::move(recvCallback));
Expand Down

0 comments on commit 7a25011

Please sign in to comment.