mirror of
https://github.com/chatmail/core.git
synced 2026-05-04 05:46:29 +03:00
upgrade repl
This commit is contained in:
@@ -674,7 +674,7 @@ impl Contact {
|
||||
let mut ret = String::new();
|
||||
|
||||
if let Ok(contact) = Contact::load_from_db(context, contact_id).await {
|
||||
let peerstate = Peerstate::from_addr(context, &context.sql, &contact.addr).await;
|
||||
let peerstate = Peerstate::from_addr(context, &contact.addr).await;
|
||||
let loginparam = LoginParam::from_database(context, "configured_").await;
|
||||
|
||||
let mut self_key = Key::from_self_public(context, &loginparam.addr, &context.sql).await;
|
||||
@@ -940,7 +940,7 @@ impl Contact {
|
||||
}
|
||||
}
|
||||
|
||||
let peerstate = Peerstate::from_addr(context, &context.sql, &self.addr).await;
|
||||
let peerstate = Peerstate::from_addr(context, &self.addr).await;
|
||||
if let Some(ps) = peerstate {
|
||||
if ps.verified_key.is_some() {
|
||||
return VerifiedStatus::BidirectVerified;
|
||||
|
||||
@@ -136,10 +136,22 @@ impl Context {
|
||||
l.run(self.clone());
|
||||
}
|
||||
|
||||
pub async fn is_running(&self) -> bool {
|
||||
self.inner.scheduler.read().await.is_running()
|
||||
}
|
||||
|
||||
pub async fn stop(&self) {
|
||||
self.inner.stop().await;
|
||||
}
|
||||
|
||||
/// Returns a reference to the underlying SQL instance.
|
||||
///
|
||||
/// Warning: this is only here for testing, not part of the public API.
|
||||
#[cfg(feature = "internals")]
|
||||
pub fn sql(&self) -> &Sql {
|
||||
&self.inner.sql
|
||||
}
|
||||
|
||||
/// Returns database file path.
|
||||
pub fn get_dbfile(&self) -> &Path {
|
||||
self.dbfile.as_path()
|
||||
|
||||
@@ -1434,7 +1434,7 @@ async fn check_verified_properties(
|
||||
// this check is skipped for SELF as there is no proper SELF-peerstate
|
||||
// and results in group-splits otherwise.
|
||||
if from_id != DC_CONTACT_ID_SELF {
|
||||
let peerstate = Peerstate::from_addr(context, &context.sql, contact.get_addr()).await;
|
||||
let peerstate = Peerstate::from_addr(context, contact.get_addr()).await;
|
||||
|
||||
if peerstate.is_none()
|
||||
|| contact.is_verified_ex(context, peerstate.as_ref()).await
|
||||
@@ -1488,7 +1488,7 @@ async fn check_verified_properties(
|
||||
context.is_self_addr(&to_addr).await
|
||||
);
|
||||
let mut is_verified = _is_verified != 0;
|
||||
let peerstate = Peerstate::from_addr(context, &context.sql, &to_addr).await;
|
||||
let peerstate = Peerstate::from_addr(context, &to_addr).await;
|
||||
|
||||
// mark gossiped keys (if any) as verified
|
||||
if mimeparser.gossipped_addr.contains(&to_addr) {
|
||||
|
||||
@@ -137,7 +137,7 @@ pub async fn try_decrypt(
|
||||
let autocryptheader = Aheader::from_headers(context, &from, &mail.headers);
|
||||
|
||||
if message_time > 0 {
|
||||
peerstate = Peerstate::from_addr(context, &context.sql, &from).await;
|
||||
peerstate = Peerstate::from_addr(context, &from).await;
|
||||
|
||||
if let Some(ref mut peerstate) = peerstate {
|
||||
if let Some(ref header) = autocryptheader {
|
||||
@@ -167,7 +167,7 @@ pub async fn try_decrypt(
|
||||
.await
|
||||
{
|
||||
if peerstate.as_ref().map(|p| p.last_seen).unwrap_or_else(|| 0) == 0 {
|
||||
peerstate = Peerstate::from_addr(&context, &context.sql, &from).await;
|
||||
peerstate = Peerstate::from_addr(&context, &from).await;
|
||||
}
|
||||
if let Some(ref peerstate) = peerstate {
|
||||
if peerstate.degrade_event.is_some() {
|
||||
|
||||
17
src/lib.rs
17
src/lib.rs
@@ -20,20 +20,18 @@ pub trait ToSql: rusqlite::ToSql + Send + Sync {}
|
||||
|
||||
impl<T: rusqlite::ToSql + Send + Sync> ToSql for T {}
|
||||
|
||||
macro_rules! paramsv {
|
||||
() => {
|
||||
Vec::new()
|
||||
};
|
||||
($($param:expr),+ $(,)?) => {
|
||||
vec![$(&$param as &dyn $crate::ToSql),+]
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_use]
|
||||
pub mod log;
|
||||
#[macro_use]
|
||||
pub mod error;
|
||||
|
||||
#[cfg(feature = "internals")]
|
||||
#[macro_use]
|
||||
pub mod sql;
|
||||
#[cfg(not(feature = "internals"))]
|
||||
#[macro_use]
|
||||
mod sql;
|
||||
|
||||
pub mod headerdef;
|
||||
|
||||
pub(crate) mod events;
|
||||
@@ -71,7 +69,6 @@ pub mod qr;
|
||||
pub mod securejoin;
|
||||
mod simplify;
|
||||
mod smtp;
|
||||
mod sql;
|
||||
pub mod stock;
|
||||
mod token;
|
||||
#[macro_use]
|
||||
|
||||
@@ -7,9 +7,7 @@ macro_rules! info {
|
||||
};
|
||||
($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {{
|
||||
let formatted = format!($msg, $($args),*);
|
||||
let thread = ::std::thread::current();
|
||||
let full = format!("{thid:?} {file}:{line}: {msg}",
|
||||
thid = thread.id(),
|
||||
let full = format!("{file}:{line}: {msg}",
|
||||
file = file!(),
|
||||
line = line!(),
|
||||
msg = &formatted);
|
||||
@@ -24,9 +22,7 @@ macro_rules! warn {
|
||||
};
|
||||
($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {{
|
||||
let formatted = format!($msg, $($args),*);
|
||||
let thread = ::std::thread::current();
|
||||
let full = format!("{thid:?} {file}:{line}: {msg}",
|
||||
thid = thread.id(),
|
||||
let full = format!("{file}:{line}: {msg}",
|
||||
file = file!(),
|
||||
line = line!(),
|
||||
msg = &formatted);
|
||||
|
||||
@@ -240,7 +240,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
||||
.filter(|(_, addr)| addr != &self_addr)
|
||||
{
|
||||
res.push((
|
||||
Peerstate::from_addr(self.context, &self.context.sql, addr).await,
|
||||
Peerstate::from_addr(self.context, addr).await,
|
||||
addr.as_str(),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -886,7 +886,7 @@ async fn update_gossip_peerstates(
|
||||
.unwrap()
|
||||
.contains(&header.addr.to_lowercase())
|
||||
{
|
||||
let mut peerstate = Peerstate::from_addr(context, &context.sql, &header.addr).await;
|
||||
let mut peerstate = Peerstate::from_addr(context, &header.addr).await;
|
||||
if let Some(ref mut peerstate) = peerstate {
|
||||
peerstate.apply_gossip(header, message_time);
|
||||
peerstate.save_to_db(&context.sql, false).await?;
|
||||
|
||||
@@ -144,7 +144,7 @@ impl<'a> Peerstate<'a> {
|
||||
res
|
||||
}
|
||||
|
||||
pub async fn from_addr(context: &'a Context, _sql: &Sql, addr: &str) -> Option<Peerstate<'a>> {
|
||||
pub async fn from_addr(context: &'a Context, addr: &str) -> Option<Peerstate<'a>> {
|
||||
let query = "SELECT addr, last_seen, last_seen_autocrypt, prefer_encrypted, public_key, gossip_timestamp, gossip_key, public_key_fingerprint, gossip_key_fingerprint, verified_key, verified_key_fingerprint FROM acpeerstates WHERE addr=? COLLATE NOCASE;";
|
||||
Self::from_stmt(context, query, paramsv![addr]).await
|
||||
}
|
||||
@@ -510,7 +510,7 @@ mod tests {
|
||||
"failed to save to db"
|
||||
);
|
||||
|
||||
let peerstate_new = Peerstate::from_addr(&ctx.ctx, &ctx.ctx.sql, addr)
|
||||
let peerstate_new = Peerstate::from_addr(&ctx.ctx, addr)
|
||||
.await
|
||||
.expect("failed to load peerstate from db");
|
||||
|
||||
@@ -586,7 +586,7 @@ mod tests {
|
||||
"failed to save"
|
||||
);
|
||||
|
||||
let peerstate_new = Peerstate::from_addr(&ctx.ctx, &ctx.ctx.sql, addr)
|
||||
let peerstate_new = Peerstate::from_addr(&ctx.ctx, addr)
|
||||
.await
|
||||
.expect("failed to load peerstate from db");
|
||||
|
||||
|
||||
@@ -217,7 +217,6 @@ impl Scheduler {
|
||||
task::spawn(async move { smtp_loop(ctx1, smtp_handlers).await });
|
||||
|
||||
info!(ctx, "scheduler is running");
|
||||
println!("RUN DONE");
|
||||
}
|
||||
|
||||
fn set_probe_network(&mut self, val: bool) {
|
||||
|
||||
@@ -349,9 +349,7 @@ async fn fingerprint_equals_sender(
|
||||
|
||||
if contacts.len() == 1 {
|
||||
if let Ok(contact) = Contact::load_from_db(context, contacts[0]).await {
|
||||
if let Some(peerstate) =
|
||||
Peerstate::from_addr(context, &context.sql, contact.get_addr()).await
|
||||
{
|
||||
if let Some(peerstate) = Peerstate::from_addr(context, contact.get_addr()).await {
|
||||
let fingerprint_normalized = dc_normalize_fingerprint(fingerprint.as_ref());
|
||||
if peerstate.public_key_fingerprint.is_some()
|
||||
&& &fingerprint_normalized == peerstate.public_key_fingerprint.as_ref().unwrap()
|
||||
|
||||
12
src/sql.rs
12
src/sql.rs
@@ -17,6 +17,16 @@ use crate::dc_tools::*;
|
||||
use crate::param::*;
|
||||
use crate::peerstate::*;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! paramsv {
|
||||
() => {
|
||||
Vec::new()
|
||||
};
|
||||
($($param:expr),+ $(,)?) => {
|
||||
vec![$(&$param as &dyn $crate::ToSql),+]
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Debug, Fail)]
|
||||
pub enum Error {
|
||||
#[fail(display = "Sqlite Error: {:?}", _0)]
|
||||
@@ -1295,7 +1305,7 @@ async fn open(
|
||||
)
|
||||
.await?;
|
||||
for addr in &addrs {
|
||||
if let Some(ref mut peerstate) = Peerstate::from_addr(context, sql, addr).await {
|
||||
if let Some(ref mut peerstate) = Peerstate::from_addr(context, addr).await {
|
||||
peerstate.recalc_fingerprint();
|
||||
peerstate.save_to_db(sql, false).await?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user