diff --git a/src/globals.rs b/src/globals.rs index 4449b690..dd2e8e77 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -5,6 +5,7 @@ use crate::event_related::EventRelated; use nostr_proto::{Event, EventKind, Id, Metadata, PublicKey, PublicKeyHex, Tag, Unixtime}; use rusqlite::Connection; use std::collections::HashMap; +use std::sync::atomic::AtomicBool; use tokio::sync::{broadcast, mpsc, Mutex}; use tracing::info; @@ -34,6 +35,10 @@ pub struct Globals { /// All nostr people records currently loaded into memory, keyed by pubkey pub people: Mutex>, + + /// Whether or not we have a saved private key and need the password to unlock it + #[allow(dead_code)] + pub need_password: AtomicBool, } lazy_static! { @@ -53,6 +58,7 @@ lazy_static! { events: Mutex::new(HashMap::new()), event_relateds: Mutex::new(HashMap::new()), people: Mutex::new(HashMap::new()), + need_password: AtomicBool::new(false), } }; } diff --git a/src/overlord/mod.rs b/src/overlord/mod.rs index 699840c5..f052a9a0 100644 --- a/src/overlord/mod.rs +++ b/src/overlord/mod.rs @@ -2,12 +2,12 @@ mod minion; mod relay_picker; use crate::comms::BusMessage; -use crate::db::{DbEvent, DbPerson, DbPersonRelay, DbRelay}; +use crate::db::{DbEvent, DbPerson, DbPersonRelay, DbRelay, DbSetting}; use crate::error::Error; use crate::globals::GLOBALS; use crate::settings::Settings; use minion::Minion; -use nostr_proto::{Event, PublicKey, PublicKeyHex, Unixtime, Url}; +use nostr_proto::{Event, PrivateKey, PublicKey, PublicKeyHex, Unixtime, Url}; use relay_picker::{BestRelay, RelayPicker}; use std::collections::HashMap; use tokio::sync::broadcast::Sender; @@ -21,6 +21,8 @@ pub struct Overlord { from_minions: UnboundedReceiver, minions: task::JoinSet<()>, minions_task_url: HashMap, + #[allow(dead_code)] + private_key: Option, // note that PrivateKey already zeroizes on drop } impl Overlord { @@ -32,6 +34,7 @@ impl Overlord { from_minions, minions: task::JoinSet::new(), minions_task_url: HashMap::new(), + private_key: None, } } @@ -63,6 +66,19 @@ impl Overlord { // Load settings self.settings = Settings::load().await?; + // Check for a private key + if DbSetting::fetch_setting("user_private_key") + .await? + .is_some() + { + // We don't bother loading the value just yet because we don't have + // the password. + info!("Saved private key found. Will need a password to unlock."); + GLOBALS + .need_password + .store(true, std::sync::atomic::Ordering::Relaxed); + } + // FIXME - if this needs doing, it should be done dynamically as // new people are encountered, not batch-style on startup. // Create a person record for every person seen, possibly autofollow