state.rs (1709B)
1 use std::{collections::BTreeMap, net::SocketAddr, path::PathBuf, sync::Arc}; 2 3 use secrecy::SecretString; 4 use tokio::sync::Mutex; 5 6 use crate::{ 7 adapters::{ 8 chain_store::SqliteChainStore, config_store::UiConfig, p2p::GossipNetwork, 9 ui_data_store::SqliteUiDataStore, 10 }, 11 app::{SharedNode, SharedPeerBook, StratumStatus}, 12 }; 13 14 #[derive(Clone)] 15 pub(super) struct HttpState { 16 pub(super) node: SharedNode, 17 pub(super) peers: SharedPeerBook, 18 pub(super) gossip: GossipNetwork, 19 pub(super) ui_config: Arc<Mutex<UiConfig>>, 20 pub(super) config_path: PathBuf, 21 pub(super) chain_store: SqliteChainStore, 22 pub(super) ui_data_store: SqliteUiDataStore, 23 pub(super) wallet_path: PathBuf, 24 pub(super) stratum: StratumStatus, 25 pub(super) auth_sessions: Arc<Mutex<BTreeMap<String, AuthSession>>>, 26 pub(super) auth_backoff: Arc<Mutex<BTreeMap<String, AuthBackoff>>>, 27 pub(super) setup_capability: Arc<Mutex<Option<SecretString>>>, 28 pub(super) management_port: u16, 29 pub(super) wallet_endpoint_addr: Option<SocketAddr>, 30 } 31 32 #[derive(Clone)] 33 pub(super) struct AuthSession { 34 pub(super) expires_at: u64, 35 pub(super) wallet_password: Arc<SecretString>, 36 } 37 38 #[derive(Clone, Debug)] 39 pub(super) struct AuthClientKey(pub(super) String); 40 41 #[derive(Clone, Debug, Default)] 42 pub(super) struct AuthBackoff { 43 pub(super) failed_attempts: u32, 44 pub(super) locked_until_ms: Option<u64>, 45 } 46 47 pub struct ServeOptions { 48 pub config_path: PathBuf, 49 pub chain_store: SqliteChainStore, 50 pub ui_data_store: SqliteUiDataStore, 51 pub wallet_path: PathBuf, 52 pub stratum: StratumStatus, 53 pub wallet_endpoint_addr: Option<SocketAddr>, 54 pub addr: SocketAddr, 55 }