Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rust DataConsumer #1262

Merged
merged 9 commits into from Dec 12, 2023
Merged

Fix Rust DataConsumer #1262

merged 9 commits into from Dec 12, 2023

Conversation

ibc
Copy link
Member

@ibc ibc commented Dec 12, 2023

  • set_subchannels() method must exist not only in DirectDataConsumer but also in RegularDataConsumer.
  • Fix wrong usage of DataConsumer in tests.

### Details

* [x] Rust `set_subchannels()` method was only implemented in `DirectDataConsumer` which is wrong.
* [ ] Rust `DirectDataConsumer` lacks ALL methods of `DataConsumer` such as `pause()`, `closed()`, etc!!!
* [x] Bonus track: Use an ordered set in `DataConsumer` in worker so `subchannels` will be always shown in numerical order (no need to sort them later in Node/Rust layer).
@ibc ibc requested review from jmillan and nazar-pc December 12, 2023 15:13
@ibc
Copy link
Member Author

ibc commented Dec 12, 2023

Issue (NOTE: FIXED)

cargo fails with this:

cargo test
   Compiling mediasoup-sys v0.7.0 (/Users/ibc/src/v3-mediasoup/worker)
   Compiling mediasoup v0.13.0 (/Users/ibc/src/v3-mediasoup/rust)
error[E0599]: no method named `set_subchannels` found for reference `&DirectDataConsumer` in the current scope
   --> rust/tests/integration/direct_transport.rs:518:14
    |
517 | /         direct_data_consumer_2
518 | |             .set_subchannels(subchannels)
    | |             -^^^^^^^^^^^^^^^ method not found in `&DirectDataConsumer`
    | |_____________|
    |

For more information about this error, try `rustc --explain E0599`.
error: could not compile `mediasoup` (test "integration") due to previous error

Comments by @nazar-pc:

There is probably Deref implementation, that dereferences to underlying data structure that provides generic methods.

The same way as Vec<u8> dereferences to &[u8], so you can call slice methods on Vec<u8> directly.

https://doc.rust-lang.org/std/ops/trait.Deref.html
It is pretty neat actually, but I admit might be a bit confusing at first. It also goes exactly one level, so it is fairly straightforward to work with.

There are a few things. DirectDataConsumer impl is in a very different place than struct definition, I don't like that, they should be close to each other. Second, You have DataConsumer, it is an enum. You can match and get inner variant or you can turn inner variant back into enum with From implementation.

It is literally what it sounds like

pub enum DataConsumer {
/// Data consumer created on transport other than
/// [`DirectTransport`](crate::direct_transport::DirectTransport).
Regular(RegularDataConsumer),
/// Data consumer created on [`DirectTransport`](crate::direct_transport::DirectTransport).
Direct(DirectDataConsumer),
}
. Enum is just a fancy struct, it can have methods just like any other struct can in Rust.

@jmillan
Copy link
Member

jmillan commented Dec 12, 2023

data_consumer_2 there should be used as it is.

diff --git a/rust/tests/integration/direct_transport.rs b/rust/tests/integration/direct_transport.rs
index 380f3e1b3..6053de020 100644
--- a/rust/tests/integration/direct_transport.rs
+++ b/rust/tests/integration/direct_transport.rs
@@ -430,7 +430,7 @@ fn send_with_subchannels_succeeds() {
             }
         };

-        let direct_data_consumer_2 = match &data_consumer_2 {
+        let _ = match &data_consumer_2 {
             DataConsumer::Direct(direct_data_consumer) => direct_data_consumer,
             _ => {
                 panic!("Expected direct data consumer")
@@ -514,7 +514,7 @@ fn send_with_subchannels_succeeds() {
         let mut subchannels = data_consumer_2.subchannels();
         subchannels.push(1);

-        direct_data_consumer_2
+        data_consumer_2
             .set_subchannels(subchannels)
             .await
             .expect("Failed to set subchannels");

All methods are implemented for DataConsumer regardless it's a RegularDataConsumer or DirectDataConsumer. There is no need to duplicate those.

ibc added a commit that referenced this pull request Dec 12, 2023
**TODO:** Rust, but I won't do it until #1262 is done and merged.
@ibc
Copy link
Member Author

ibc commented Dec 12, 2023

cargo test
   Compiling mediasoup v0.13.0 (/Users/ibc/src/v3-mediasoup/rust)
warning: unused variable: `router`
   --> rust/tests/integration/data_consumer.rs:323:23
    |
323 |         let (_worker, router, transport1, data_producer) = init().await;
    |                       ^^^^^^ help: if this is intentional, prefix it with an underscore: `_router`
    |
    = note: `#[warn(unused_variables)]` on by default

error: literal out of range for `u16`
   --> rust/tests/integration/data_consumer.rs:338:47
    |
338 |             .set_subchannels([ 999, 999, 998, 65536 ].to_vec())
    |                                               ^^^^^
    |
    = note: the literal `65536` does not fit into the type `u16` whose range is `0..=65535`
    = note: `#[deny(overflowing_literals)]` on by default

@ibc
Copy link
Member Author

ibc commented Dec 12, 2023

cargo test
   Compiling mediasoup v0.13.0 (/Users/ibc/src/v3-mediasoup/rust)
warning: unused variable: `router`
   --> rust/tests/integration/data_consumer.rs:323:23
    |
323 |         let (_worker, router, transport1, data_producer) = init().await;
    |                       ^^^^^^ help: if this is intentional, prefix it with an underscore: `_router`
    |
    = note: `#[warn(unused_variables)]` on by default

error: literal out of range for `u16`
   --> rust/tests/integration/data_consumer.rs:338:47
    |
338 |             .set_subchannels([ 999, 999, 998, 65536 ].to_vec())
    |                                               ^^^^^
    |
    = note: the literal `65536` does not fit into the type `u16` whose range is `0..=65535`
    = note: `#[deny(overflowing_literals)]` on by default

I'm on it.

@ibc ibc changed the title Fix Rust DataConsumer Fix Rust DataConsumer usage in tests Dec 12, 2023
@ibc ibc marked this pull request as ready for review December 12, 2023 17:14
@ibc ibc changed the title Fix Rust DataConsumer usage in tests Fix Rust DataConsumer Dec 12, 2023
@ibc ibc merged commit eccc173 into v3 Dec 12, 2023
36 checks passed
@ibc ibc deleted the fix-rust-dataconsumer branch December 12, 2023 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants