Skip to content

Commit

Permalink
fix: increase WebRTC max datachannel message size (#2627)
Browse files Browse the repository at this point in the history
We automatically chunk stream messages larger than [16KB](https://github.com/libp2p/js-libp2p/blob/main/packages/transport-webrtc/src/stream.ts#L50) when sending over a datachannel.

This limit is based on [browser limitations](https://lgrahl.de/articles/demystifying-webrtc-dc-size-limit.html) that have since been resolved.

We should be ok to increase the limit to [256KB at least](https://issues.webrtc.org/issues/40644524), maybe more.

Ref: https://blog.mozilla.org/webrtc/large-data-channel-messages/

Fixes #2612
  • Loading branch information
achingbrain authored Jul 22, 2024
1 parent 4a994c5 commit 9e92b0c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/transport-webrtc/src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export const MAX_BUFFERED_AMOUNT = 2 * 1024 * 1024
export const BUFFERED_AMOUNT_LOW_TIMEOUT = 30 * 1000

/**
* protobuf field definition overhead
* protobuf field definition overhead + length encoding prefix length
*/
export const PROTOBUF_OVERHEAD = 5
export const PROTOBUF_OVERHEAD = 7

/**
* Length of varint, in bytes
Expand All @@ -46,8 +46,11 @@ export const VARINT_LENGTH = 2

/**
* Max message size that can be sent to the DataChannel
*
* @see https://blog.mozilla.org/webrtc/large-data-channel-messages/
* @see https://issues.webrtc.org/issues/40644524
*/
export const MAX_MESSAGE_SIZE = 16 * 1024
export const MAX_MESSAGE_SIZE = 256 * 1024

/**
* When closing streams we send a FIN then wait for the remote to
Expand Down

0 comments on commit 9e92b0c

Please sign in to comment.