Initial RustOpenMLS code #7

Open
dawn wants to merge 36 commits from RustOpenMLS into main
Owner

Should have all the required functions for a MVP to work.

The public interface is in the openmls_controls.rs file and the networking.rs file.

Should have all the required functions for a MVP to work. The public interface is in the `openmls_controls.rs` file and the `networking.rs` file.
dawn added 24 commits 2026-11-22 18:36:33 +11:00
dawn changed title from Very Baisc RustOpenMLS code to WIP: Very Baisc RustOpenMLS code 2026-11-22 18:36:43 +11:00
dawn force-pushed RustOpenMLS from b2823764d8 to 4ebc0530a7 2026-11-22 18:37:24 +11:00 Compare
dawn changed title from WIP: Very Baisc RustOpenMLS code to WIP: Basic RustOpenMLS code 2026-11-22 19:03:29 +11:00
Author
Owner

I realise now that this is now a very big PR. Should've been split up more and merged as I added things to make it more reviewable. :p

I realise now that this is now a very big PR. Should've been split up more and merged as I added things to make it more reviewable. :p
dawn changed title from WIP: Basic RustOpenMLS code to Initial RustOpenMLS code 2026-11-28 12:46:21 +11:00
Author
Owner

I've also realised that this doesn't provide a good way for the kotlin side to get location history unless it stores it itself, which I believe we decided against.

Storing in a new location history table can work but then your friends locations are stored unencrypted. I'll look into how to get openMLS message history.

I've also realised that this doesn't provide a good way for the kotlin side to get location history unless it stores it itself, which I believe we decided against. Storing in a new location history table can work but then your friends locations are stored unencrypted. I'll look into how to get openMLS message history.
maddie requested changes 2026-11-29 19:33:37 +11:00
Dismissed
maddie left a comment

Few minor things but looks awesome !!

Few minor things but looks awesome !!
@ -0,0 +27,4 @@
self_expected == other_expected && self_actual == other_actual
}
// close enough
Self::SerdeCborError(_) => true,
Collaborator

you're so funny <3

you're so funny <3
dawn marked this conversation as resolved
@ -0,0 +27,4 @@
user_id: String,
user_password: String,
) -> Result<Self, AppError> {
let db = AppStorage::from_path(&path)?;
Collaborator

If you're panicking in some places anyway, why are you returning standard results anywhere?

If you're panicking in some places anyway, why are you returning standard results anywhere?
Author
Owner

I decided the distinction was, "can the kotlin side actually do anything by having this error as a value". So with that , the kotlin side could like adjust the path it makes the file ig. ehh the reasoning isn't that great, i should probably just make locking the mutex also return an error as value cause it's easy to do and removes .expect() calls. I mean, at the point where the db mutex gets poisoned, there is nothing the kotlin side can do except restart itself because that means something has gone very wrong. I'll do it anywayy :p

I decided the distinction was, "can the kotlin side actually do anything by having this error as a value". So with that , the kotlin side could like adjust the path it makes the file ig. ehh the reasoning isn't that great, i should probably just make locking the mutex also return an error as value cause it's easy to do and removes `.expect()` calls. I mean, at the point where the db mutex gets poisoned, there is nothing the kotlin side can do except restart itself because that means something has gone very wrong. I'll do it anywayy :p
maddie marked this conversation as resolved
@ -0,0 +47,4 @@
})
}
/// blocks indefinitely
Collaborator

it shouldn't; everything should be called one n done from kotlin

it shouldn't; everything should be called one n done from kotlin
Author
Owner

should be resolved now!

should be resolved now!
maddie marked this conversation as resolved
@ -0,0 +34,4 @@
assert!(path.starts_with("https://"));
if !path.ends_with("/") {
path.push('/');
Collaborator

If you use the Reqwest URL type, you needn't verify the path's validity urself. Also we just get a tighter definition of what everything is, as lycanea loves to say

If you use [the Reqwest URL type](https://docs.rs/reqwest/latest/reqwest/struct.Url.html), you needn't verify the path's validity urself. Also we just get a tighter definition of what everything is, as lycanea loves to say
Author
Owner

ooa, i didn't know about that, ill use it.
omg it's just reexport of url crate okie dokie, i thought about using it but didnt want to add another dependency if it wasnt needed, but if it's already included I will.

ooa, i didn't know about that, ill use it. omg it's just reexport of url crate okie dokie, i thought about using it but didnt want to add another dependency if it wasnt needed, but if it's already included I will.
dawn marked this conversation as resolved
@ -0,0 +49,4 @@
/// blocks indefinitely
pub async fn run(&self) -> Result<(), AppError> {
let _ = self.create_account_if_does_not_exist().await?;
Collaborator

I feel like the client should know indefinitely that it has been registered; sending a request every time feels kinda unnecessary and en masse it's one extra request per client per period of time

I feel like the client should know indefinitely that it has been registered; sending a request every time feels kinda unnecessary and en masse it's one extra request per client per period of time
Collaborator

further on this: should the kotlin side pass the rust side info like location or should rust side collect it? either way, it needs to know all the people to send stuff to, and what level of info to give each person

further on this: should the kotlin side pass the rust side info like location or should rust side collect it? either way, it needs to know all the people to send stuff to, and what level of info to give each person
Author
Owner

First part should be resolved now, kotlin should pass location to rust side.

I'll work on setting up a permission system and things after this is merged in, in a separate MR.

First part should be resolved now, kotlin should pass location to rust side. I'll work on setting up a permission system and things after this is merged in, in a separate MR.
maddie marked this conversation as resolved
@ -0,0 +56,4 @@
let messages = db.pop_message_queue()?;
SendRequests(messages)
};
Collaborator

I like this, very stylish

I like this, very stylish
dawn marked this conversation as resolved
@ -0,0 +75,4 @@
let deserialzied: PollResponse = serde_cbor::from_slice(&bytes)?;
// hope this isn't expensive ...
let out = deserialzied
Collaborator

typo

typo
dawn marked this conversation as resolved
@ -0,0 +139,4 @@
"got unauthorised send message response. {:#?}",
response
))),
reqwest::StatusCode::INTERNAL_SERVER_ERROR => Err(Self::server_error(response).await),
Collaborator

should we consider retrying on an error 500? Not sure what the appropriate handling of this is, cus we can't really just post an error to the user on background tasks.

should we consider retrying on an error 500? Not sure what the appropriate handling of this is, cus we can't really just post an error to the user on background tasks.
Author
Owner

I tried doing request retrying with this function

    async fn retry_if_server_error<T, R>(&self, request: T) -> Result<R, AppError>
    where
        T: async Fn() -> Result<R, AppError>,
    {
        let mut attempts = 0;
        loop {
            let result = request().await;

            // give up
            if attempts > 3 {
                return result;
            }

            // if it is not an internal server error, dont bother retrying and ust return
            if !matches!(
                result,
                Err(AppError::InternalServerError {
                    endpoint: _,
                    response: _
                })
            ) {
                return result;
            } else {
                // otherwise increment the attempt counter and retry
                attempts += 1;
                continue;
            }
        }
    }

    async fn send_pending_messages(&self) -> Result<(), AppError> {
        self.retry_if_server_error(async || self.create_server_account_if_does_not_exist().await)
            .await?;

        self.retry_if_server_error(async || {
            let send_request = {
                let db = self.db.lock()?;
                let messages = db.pop_message_queue()?;

                SendRequests(messages)
            };
            self.send_messages(send_request).await
        })
        .await?;

        Ok(())
    }


but that resulted in this mysterious error.

~/code/BiggerSister/RustOpenMLS/shared RustOpenMLS* ⇡
❯ cargo b
   Compiling big_sister_rust v0.1.0 (/home/d/code/BiggerSister/RustOpenMLS/shared)
error: higher-ranked lifetime error
  --> src/commonMain/rust/networking.rs:19:1
   |
19 | #[uniffi::export(async_runtime = "tokio")]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the attribute macro `uniffi::export` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `big_sister_rust` (lib) due to 1 previous error

(enabling macro backtrace is no more useful)

so idk i could do it some other way or whatever, but idk i think telling the user, via like a notification or smth, "hey we tried to talk to the ds and it returned a 500. Contact the server administrator" is fine

I tried doing request retrying with this function ```rust async fn retry_if_server_error<T, R>(&self, request: T) -> Result<R, AppError> where T: async Fn() -> Result<R, AppError>, { let mut attempts = 0; loop { let result = request().await; // give up if attempts > 3 { return result; } // if it is not an internal server error, dont bother retrying and ust return if !matches!( result, Err(AppError::InternalServerError { endpoint: _, response: _ }) ) { return result; } else { // otherwise increment the attempt counter and retry attempts += 1; continue; } } } async fn send_pending_messages(&self) -> Result<(), AppError> { self.retry_if_server_error(async || self.create_server_account_if_does_not_exist().await) .await?; self.retry_if_server_error(async || { let send_request = { let db = self.db.lock()?; let messages = db.pop_message_queue()?; SendRequests(messages) }; self.send_messages(send_request).await }) .await?; Ok(()) } ``` but that resulted in this mysterious error. ``` ~/code/BiggerSister/RustOpenMLS/shared RustOpenMLS* ⇡ ❯ cargo b Compiling big_sister_rust v0.1.0 (/home/d/code/BiggerSister/RustOpenMLS/shared) error: higher-ranked lifetime error --> src/commonMain/rust/networking.rs:19:1 | 19 | #[uniffi::export(async_runtime = "tokio")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the attribute macro `uniffi::export` (in Nightly builds, run with -Z macro-backtrace for more info) error: could not compile `big_sister_rust` (lib) due to 1 previous error ``` (enabling macro backtrace is no more useful) so idk i could do it some other way or whatever, but idk i think telling the user, via like a notification or smth, "hey we tried to talk to the ds and it returned a 500. Contact the server administrator" is fine
Collaborator

yaya oki this works

yaya oki this works
maddie marked this conversation as resolved
there's still a little unwrapping cause i think it's fine :3
dawn force-pushed RustOpenMLS from 35deb1641f to 944eba0bfb 2026-11-29 21:08:56 +11:00 Compare
dawn force-pushed RustOpenMLS from 585b4f4b8c to 6dfccdbfc9 2026-11-29 21:53:40 +11:00 Compare
dawn requested review from maddie 2026-12-01 13:41:31 +11:00
@ -80,6 +80,15 @@ impl AppStorage {
)
}
pub fn get_all_known_uuids(&self) -> Result<Vec<String>, rusqlite::Error> {
Collaborator

Instead of just returning UUIDs, there should be a way to get all users as user structs

Instead of just returning UUIDs, there should be a way to get all users as user structs
dawn marked this conversation as resolved
@ -12,3 +12,3 @@
* Docs for the specific kotlin plugin we use: https://docs.oxikt.dev/
*
* A few things to note.
* A few things to note.
Collaborator

This is a major change and I think we need to have a real and serious discussion before we proceed with adding something like this to a pr

This is a major change and I think we need to have a real and serious discussion before we proceed with adding something like this to a pr
maddie marked this conversation as resolved
maddie requested changes 2026-12-01 14:02:41 +11:00
Dismissed
maddie left a comment

just needs the get all user structs method n we're good :>

just needs the get all user structs method n we're good :>
maddie approved these changes 2026-12-01 14:15:49 +11:00
maddie left a comment

YAYYYY

YAYYYY
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'RustOpenMLS:RustOpenMLS'
git switch 'RustOpenMLS'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Depends on
Reference
dawn/BigSister!7
No description provided.