webrtc icon indicating copy to clipboard operation
webrtc copied to clipboard

[SCTP] Stream::read: partial read OR returning the expected size of the buffer

Open melekes opened this issue 3 years ago • 6 comments

The problem I'm facing right now is where I'm passing a buffer to Stream::read, which is not big enough (Error::ErrShortBuffer). Note there's no indication of the expected size => you're forced to guess the number.

Also note it's different from TcpStream https://doc.rust-lang.org/std/io/trait.Read.html#tymethod.read, which partially reads the data and does not put any restrictions on the size of the buffer (i.e. you, the caller, is in control of how fast you're consuming data).

I can see that the code in Pion is identical to one here, but I nonetheless think we need to change something.

Either

  1. switch to "tcp stream" partial reading model
  2. indicate the expected buffer size by changing ErrShortBuffer to be ErrShortBuffer { min: usize }

(1) is more "rust" therefore preferred.

There's also talk about auto-tuning buffer size, which is slightly related https://github.com/pion/sctp/issues/218#issuecomment-1080008490


https://github.com/webrtc-rs/sctp/blob/ed21dae1aa7dc5f37bd40fb344fa19746b932570/src/queue/reassembly_queue.rs#L282

also, why are we subtracting n_bytes before we've actually successfully written them to client's buffer?


Migrated from https://github.com/webrtc-rs/sctp/issues/28

melekes avatar Aug 29 '22 07:08 melekes

From the last issue, the agreement seems to be that we should mimic the TCP implementation. My only concern is whether it would be tricky to use an API like this for the data channels

k0nserv avatar Aug 29 '22 09:08 k0nserv

If anyone is interested in looking at this the first step should be to verify that the change in SCTP would not make its use impossible in the upstream crates. If it turns out to be okay the next step is to implement this

k0nserv avatar Sep 01 '22 09:09 k0nserv

I'm looking at this right now.

melekes avatar Sep 30 '22 08:09 melekes

If anyone is interested in looking at this the first step should be to verify that the change in SCTP would not make its use impossible in the upstream crates. If it turns out to be okay the next step is to implement this

@k0nserv what is the best way to do it?

opened https://github.com/webrtc-rs/webrtc/pull/304

melekes avatar Sep 30 '22 13:09 melekes

Well, with the merged monorepo I should think that we are okay as long as the code still compiles and the tests all pass 🤔

k0nserv avatar Oct 03 '22 10:10 k0nserv

See https://github.com/webrtc-rs/webrtc/pull/304#issuecomment-1271652707. Requires more thinking and design.

melekes avatar Oct 10 '22 08:10 melekes