diff --git a/bffhd/actors/mod.rs b/bffhd/actors/mod.rs index 8a64c7f..36424f2 100644 --- a/bffhd/actors/mod.rs +++ b/bffhd/actors/mod.rs @@ -6,6 +6,9 @@ use futures_signals::signal::{MutableSignalRef, ReadOnlyMutable, Signal}; use futures_util::future::BoxFuture; use crate::resources::state::State; +mod shelly; + + pub trait Actor { fn apply(&mut self, state: State) -> BoxFuture<'static, ()>; } diff --git a/bffhd/authentication/mod.rs b/bffhd/authentication/mod.rs index fedf66a..9594c5e 100644 --- a/bffhd/authentication/mod.rs +++ b/bffhd/authentication/mod.rs @@ -1,11 +1,31 @@ - +use std::sync::Arc; +use rsasl::error::SASLError; +use rsasl::mechname::Mechname; +use rsasl::SASL; +use rsasl::session::Session; pub mod db; -pub struct AuthenticationHandler { +struct Inner { + rsasl: SASL, +} +impl Inner { + pub fn new(rsasl: SASL) -> Self { + Self { rsasl } + } +} +#[derive(Clone)] +pub struct AuthenticationHandler { + inner: Arc, } impl AuthenticationHandler { + pub fn new(rsasl: SASL) -> Self { + Self { inner: Arc::new(Inner::new(rsasl)) } + } + pub fn start(&self, mechanism: &Mechname) -> Result { + self.inner.rsasl.server_start(mechanism) + } } \ No newline at end of file diff --git a/bffhd/capnp/authenticationsystem.rs b/bffhd/capnp/authenticationsystem.rs index 65ab985..7903cab 100644 --- a/bffhd/capnp/authenticationsystem.rs +++ b/bffhd/capnp/authenticationsystem.rs @@ -27,7 +27,7 @@ impl AuthenticationSystem for Authentication { } fn abort(&mut self, _: AbortParams, _: AbortResults) -> Promise<(), Error> { - std::mem::replace(&mut self.state, State::Aborted); + self.state = State::Aborted; Promise::ok(()) } } \ No newline at end of file diff --git a/bffhd/resources/mod.rs b/bffhd/resources/mod.rs index 49780de..3dbd15c 100644 --- a/bffhd/resources/mod.rs +++ b/bffhd/resources/mod.rs @@ -96,14 +96,14 @@ impl ResourceDriver { match self.res.on_update(&state).await { Ok(outstate) => { // FIXME: Send any error here to some global error collector. A failed write to - // the DB is not necessarily fatal, but it means that BFFH is now in an - // inconsistent state until a future update succeeds with writing to the DB. - // Not applying the new state isn't correct either since we don't know what the - // internal logic of the resources has done to make this happen. - // Another half right solution is to unwrap and recreate everything. - // "Best" solution would be to tell the resources to rollback their interal - // changes on a fatal failure and then notify the Claimant, while simply trying - // again for temporary failures. + // the DB is not necessarily fatal, but it means that BFFH is now in an + // inconsistent state until a future update succeeds with writing to the DB. + // Not applying the new state isn't correct either since we don't know what the + // internal logic of the resources has done to make this happen. + // Another half right solution is to unwrap and recreate everything. + // "Best" solution would be to tell the resources to rollback their interal + // changes on a fatal failure and then notify the Claimant, while simply trying + // again for temporary failures. let _ = self.db.set(&state, &outstate); self.signal.set(outstate); },