-
Notifications
You must be signed in to change notification settings - Fork 10
Decryption support #49
Comments
That's awesome! I'd be happy to add more functionality to this crate.
Looking at the docs for The error message involves recursive locks so I'm assuming we could accidentally deadlock if we naively used You may want to make an issue against the The standard library's |
Thanks for the feedback! The solution was quite simple. I just moved the acquiring of Once this was fixed I could replace the current mutex implementation with a reentrant mutex. This type only provided a RAII-based API. I put the lockguards in a That was the easy part. Testing this turned out to be much more challenging. I tried two approaches:
I created a branch for each of the above since the first is broken and the second is kind of flawed.
The reentrant mutex implementation is however pushed to https://github.com/furuholm/libsignal-protocol-rs/tree/decryption. Do you have any suggestion on how to proceed? Do you want me to create a PR without the tests or should we fix them first? |
You've got to be careful here because if the lock is poisoned then calling Moving You could remove the if let Ok(message) = std::str::from_utf8(buffer) {
// we can't log the errors that occur while logging errors, so just
// drop them on the floor...
if let Ok(log_func) = state.log_func.lock() {
let _ = std::panic::catch_unwind(|| {
let log_func = state.log_func.lock().unwrap();
log_func(level, message);
});
}
}
How do people normally test that locking is done correctly? I know one method is to verify using logical analysis or special tools like go's race detector, but that's not my area of expertise. Another question to ask is whether we even need to test it. We could argue that using locking correctly is Adding Another thing to keep in mind is if our
How did you initially determine we need a reentrant lock? If we can remove the requirement for reentrant locking these problems should all go away. |
I will play the Rust noob card here, but not spotting that I moved an unwrap out from a Using the lockless approach sounds like an excelent idea! One Went ahead and implemented this. I added a comment about the reasoning behind the noop locking strategy inside If we go this path I think the other dissucssion is kind of obsolete, but I still want to address a couple of your questions.
Note: The noop locking is now part of the decryption branch. Depending on your preferences this could potentially be a separate PR though. |
All good, it's always nice to have a second pair of eyes look over your code 😁
How about using
If you'd like to land it all in one big PR or break each set of changes up into their own smaller PRs I'm happy either way. I guess smaller PRs might make code review easier though. |
Implemented in #57. |
I have been working on adding support for decrypting messages and if it is ok I would like to submit a PR with this functionality once I am done.
I have an initial version that almost works at https://github.com/furuholm/libsignal-protocol-rs/tree/decryption. However, it turns out that the decryption code in the underlying C library requires the mutex implementation to be reentrant which
parking_lot::RawMutex
is not. When replacingRawMutex
withReentrantMutex
I get the following error messageJust like the message says it is caused by
RawReentrantMutex
containing acell::Cell
which is notRefUnwindSafe
.Any ideas on how to solve this?
The text was updated successfully, but these errors were encountered: