Skip to content

Commit 7789bfe

Browse files
committed
Securejoin: store bobstate in database instead of context
The state bob needs to maintain during a secure-join process when exchanging messages used to be stored on the context. This means if the process was killed this state was lost and the securejoin process would fail. Moving this state into the database should help this. This still only allows a single securejoin process at a time, this may be relaxed in the future. For now any previous securejoin process that was running is killed if a new one is started (this was already the case). This can remove some of the complexity around BobState handling: since the state is in the database we can already make state interactions transactional and correct. We no longer need the mutex around the state handling. This means the BobStateHandle construct that was handling the interactions between always having a valid state and handling the mutex is no longer needed, resulting in some nice simplifications. Part of #2777.
1 parent fb95573 commit 7789bfe

10 files changed

+485
-375
lines changed

src/chat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl ChatId {
175175
/// Returns the unblocked 1:1 chat with `contact_id`.
176176
///
177177
/// This should be used when **a user action** creates a chat 1:1, it ensures the chat
178-
/// exists and is unblocked and scales the [`Contact`]'s origin.
178+
/// exists, is unblocked and scales the [`Contact`]'s origin.
179179
pub async fn create_for_contact(context: &Context, contact_id: u32) -> Result<Self> {
180180
ChatId::create_for_contact_with_blocked(context, contact_id, Blocked::Not).await
181181
}

src/context.rs

-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use crate::login_param::LoginParam;
2424
use crate::message::{self, MessageState, MsgId};
2525
use crate::quota::QuotaInfo;
2626
use crate::scheduler::Scheduler;
27-
use crate::securejoin::Bob;
2827
use crate::sql::Sql;
2928

3029
#[derive(Clone, Debug)]
@@ -45,7 +44,6 @@ pub struct InnerContext {
4544
/// Blob directory path
4645
pub(crate) blobdir: PathBuf,
4746
pub(crate) sql: Sql,
48-
pub(crate) bob: Bob,
4947
pub(crate) last_smeared_timestamp: RwLock<i64>,
5048
pub(crate) running_state: RwLock<RunningState>,
5149
/// Mutex to avoid generating the key for the user more than once.
@@ -171,7 +169,6 @@ impl Context {
171169
blobdir,
172170
running_state: RwLock::new(Default::default()),
173171
sql: Sql::new(dbfile),
174-
bob: Default::default(),
175172
last_smeared_timestamp: RwLock::new(0),
176173
generating_key_mutex: Mutex::new(()),
177174
oauth2_mutex: Mutex::new(()),

src/events.rs

+23
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,26 @@ pub enum EventType {
334334
status_update_id: StatusUpdateId,
335335
},
336336
}
337+
338+
/// Progress indicator with mili-units precision.
339+
///
340+
/// This indicates a linear progress, generally from 0 to 1000, however the extreme values
341+
/// have their own enum variants for clarity.
342+
#[derive(Debug, Copy, Clone)]
343+
pub enum Progress {
344+
/// The progress reported has encountered an error.
345+
Error,
346+
/// A progress indication between 1-999.
347+
Progress(usize),
348+
/// The progress reported has completed.
349+
Complete,
350+
}
351+
352+
/// Trait to report progress.
353+
///
354+
/// Normal usage is to convert custom enums to a standard progress report which can be shown
355+
/// as a progress bar.
356+
pub trait ProgressReport {
357+
/// Current progress.
358+
fn progress(&self) -> Progress;
359+
}

src/key.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ pub async fn store_self_keypair(
318318
}
319319

320320
/// A key fingerprint
321-
#[derive(Clone, Eq, PartialEq, Hash)]
321+
#[derive(Clone, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
322322
pub struct Fingerprint(Vec<u8>);
323323

324324
impl Fingerprint {

0 commit comments

Comments
 (0)