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

Convert certain methods from Option type to Result type #14

Closed
wants to merge 7 commits into from

Conversation

artech-git
Copy link
Contributor

For improved error handling certain methods of codebase required Result type for appropriate error handling, instead of Option type

These changes for supporting error handling are still very experimental, and therefore require multiple inputs and guidance for refinement and improvements 😊, feel free to let me know.

@jim-signal
Copy link
Contributor

Hi @artech-git, thanks for the changes! I think these are looking good so far and address some of our TODO's.

Could you update the PR with these tweaks?

  • Rebase on the latest main branch
  • Run cargo clippy and fix any warnings posted
  • For all functions that you have converted to Result, you can remove any related TODO comment
  • You can remove comments such as "Add more error variants for other scenarios as needed"

Once that done we will take another look, but it looks good so far.

Also, can you explain why the ahash dependency is needed?

@artech-git
Copy link
Contributor Author

Hi @artech-git, thanks for the changes! I think these are looking good so far and address some of our TODO's.

Could you update the PR with these tweaks?

  • Rebase on the latest main branch
  • Run cargo clippy and fix any warnings posted
  • For all functions that you have converted to Result, you can remove any related TODO comment
  • You can remove comments such as "Add more error variants for other scenarios as needed"

Once that done we will take another look, but it looks good so far.

Also, can you explain why the ahash dependency is needed?

I was actually trying to experiment with ahash crate regarding speeding up of SFU unit for clients, Iam still experimenting on that just to find out which hashing algorithm worked better between ahash and SipHash hashing algorithm so that we can speed up the computations, this may be out of context but in my understanding sequence practically won't go over 3 to 8 users and atmost around 200 users. Hence merely affects the performance.

Comment on lines +1738 to +1740
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the dependency updates in Cargo.lock necessary? We like to keep dependency updates separate from other changes and only add if needed.

Copy link
Contributor Author

@artech-git artech-git Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright noted I believed since I applied some dependencies updates on my local Envoirment, we can remove that .

backend/src/sfu.rs Outdated Show resolved Hide resolved
// pub for tests
pub fn decrypt_in_place(&mut self, key: &Key, salt: &Salt) -> Option<()> {
pub fn decrypt_in_place(&mut self, key: &Key, salt: &Salt) -> Result<(), PacketError> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am seeing a warning when running tests. For clippy, did you run this? It should catch them all:
cargo clippy --all-features --all-targets -- -D warnings

backend/src/rtp.rs Outdated Show resolved Hide resolved
backend/src/rtp.rs Outdated Show resolved Hide resolved
backend/src/rtp.rs Outdated Show resolved Hide resolved
backend/src/rtp.rs Outdated Show resolved Hide resolved
backend/src/rtp.rs Outdated Show resolved Hide resolved
backend/src/rtp.rs Outdated Show resolved Hide resolved
backend/src/rtp.rs Outdated Show resolved Hide resolved
backend/src/rtp.rs Outdated Show resolved Hide resolved
backend/src/rtp.rs Outdated Show resolved Hide resolved
Comment on lines 1797 to +1802
let incoming = ControlPacket::parse_and_decrypt_in_place(
encrypted,
&self.decrypt.rtcp.key,
&self.decrypt.rtcp.salt,
)?;
)
.ok_or(EndpointError::RtcpSenderSsrcNotSet)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think parse_and_decrypt_in_place should return EndpointError? They are all in the same file and hence should be able to share Error definitions. You could add all the different kinds of RTCP errors that the function might return. That might increase the scope of the PR a lot. Hmm, is it worth it?

Maybe just make the error more generic, like RtcpError. Because errors are more than just "Sender SSRC was not set", right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think making the error type generic is a nice idea I initially thought about it though, but didn't proceeded with that due to the over complexity it might present in maintaining it in the long run hence I opted for writing errors enum for each struct possible and keeping minimum only.

Also maybe we can add a another module for specifically for handling scenarios only( all errors seperated in that module only).

Again we need some more brainstorming on what can work out best and avoiding the burden, but speaking of generic errors I can happily work on this if you can present with some rough idea of what errors and the possible variants it should have for the scenarios !

just to explain what I understood is written below:

#[derive(...)]
pub enum RTXErrors {...
}
#[derive(...)]
pub enum SsrcErrors{...
}
#[derive(...)]
pub enum PacketErrors {...
}
#[derive(...)]
pub enum EndpointError<T> {...

to visually explain it, here is a small diagram I have prepared
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure that many error types is necessary. For example, I only see one RTXError, so I think it can just stay as an EndpointError. For SsrcError, that looks okay.

backend/src/rtp.rs Outdated Show resolved Hide resolved
backend/src/rtp.rs Outdated Show resolved Hide resolved
backend/src/rtp.rs Outdated Show resolved Hide resolved
backend/src/sfu.rs Outdated Show resolved Hide resolved
backend/src/connection.rs Outdated Show resolved Hide resolved
backend/src/connection.rs Outdated Show resolved Hide resolved
@artech-git artech-git changed the title Convert certain methods from option type to Result type Convert certain methods from Option type to Result type Nov 2, 2023
@jim-signal
Copy link
Contributor

The PR seems to be looking better. Here would be a checklist to complete this PR:

  • Rebase on the latest version from the main branch
  • Squash your commits
  • Make sure you are always running cargo fmt and cargo clippy before committing
  • Make sure there are no Cargo.lock file changes (since they don't seem to be needed for this PR)
  • Make sure there are no unused Error enumerations

Then we can do a final review and hopefully close this soon. Thanks!

@artech-git
Copy link
Contributor Author

The PR seems to be looking better. Here would be a checklist to complete this PR:

  • Rebase on the latest version from the main branch
  • Squash your commits
  • Make sure you are always running cargo fmt and cargo clippy before committing
  • Make sure there are no Cargo.lock file changes (since they don't seem to be needed for this PR)
  • Make sure there are no unused Error enumerations

Then we can do a final review and hopefully close this soon. Thanks!

Got it, thanks for the inputs. I will work on it asap.

Copy link

stale bot commented Feb 7, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 7, 2024
Copy link

stale bot commented Feb 14, 2024

This issue has been closed due to inactivity.

@stale stale bot closed this Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants