@@ -27,14 +27,17 @@ mod error;
2727pub use error:: SctpError ;
2828
2929/// Bytes that can be buffered inside str0m across all streams.
30- const MAX_BUFFERED_ACROSS_STREAMS : usize = 128 * 1024 ;
30+ const DEFAULT_MAX_BUFFERED_ACROSS_STREAMS : usize = 128 * 1024 ;
3131
3232/// Maximum message size we advertise in SDP (what we can receive)
3333pub const LOCAL_MAX_MESSAGE_SIZE : u32 = 256 * 1024 ;
3434
3535/// Default max message size if remote doesn't advertise
3636pub const DEFAULT_REMOTE_MAX_MESSAGE_SIZE : u32 = 64 * 1024 ;
3737
38+ /// Headroom for max_buffered_across_streams vs remote_max_message_size
39+ pub const BUFFER_MULTIPLIER : u32 = 2 ;
40+
3841pub ( crate ) struct RtcSctp {
3942 state : RtcSctpState ,
4043 endpoint : Endpoint ,
@@ -46,6 +49,7 @@ pub(crate) struct RtcSctp {
4649 last_now : Instant ,
4750 client : bool ,
4851 remote_max_message_size : u32 ,
52+ max_buffered_across_streams : usize ,
4953 snap_enabled : bool ,
5054 snap_init : Option < SctpInitData > ,
5155 #[ cfg( test) ]
@@ -279,6 +283,7 @@ impl RtcSctp {
279283 last_now : Instant :: now ( ) , // placeholder until init()
280284 client : false ,
281285 remote_max_message_size : DEFAULT_REMOTE_MAX_MESSAGE_SIZE ,
286+ max_buffered_across_streams : DEFAULT_MAX_BUFFERED_ACROSS_STREAMS ,
282287 snap_enabled : false ,
283288 snap_init : None ,
284289 #[ cfg( test) ]
@@ -315,6 +320,12 @@ impl RtcSctp {
315320 self . remote_max_message_size = max_msg_size;
316321 }
317322
323+ let bufsize: usize =
324+ BUFFER_MULTIPLIER . saturating_mul ( self . remote_max_message_size ) as usize ;
325+ if self . max_buffered_across_streams < bufsize {
326+ self . max_buffered_across_streams = bufsize;
327+ }
328+
318329 if let Some ( snap_data) = sctp_init_data {
319330 // SNAP path: both local and remote INIT chunks must be present.
320331 if snap_data. local_init . is_none ( ) || snap_data. remote_init . is_none ( ) {
@@ -333,6 +344,7 @@ impl RtcSctp {
333344 . connect ( config, self . fake_addr )
334345 . map_err ( |e| SctpError :: Proto ( ProtoError :: Other ( e. to_string ( ) ) ) ) ?;
335346 assoc. set_max_send_message_size ( self . remote_max_message_size ) ;
347+
336348 self . handle = handle;
337349 self . assoc = Some ( assoc) ;
338350
@@ -549,7 +561,7 @@ impl RtcSctp {
549561 } )
550562 . sum ( ) ;
551563
552- MAX_BUFFERED_ACROSS_STREAMS - total
564+ self . max_buffered_across_streams - total
553565 }
554566
555567 pub fn write ( & mut self , id : u16 , binary : bool , buf : & [ u8 ] ) -> Result < usize , SctpError > {
0 commit comments