Refactoring, mainly formatting

This commit is contained in:
Philip (a-0) 2024-01-05 20:48:23 +01:00
parent 3825263fa3
commit d8f1733eb3
25 changed files with 667 additions and 348 deletions

View file

@ -5,8 +5,11 @@ use api::{Api, ApiBuilder};
use comm::{CommHandle, Peer};
use config::Config;
use i2p::net::I2pSocketAddr;
use serde::{Serialize, Deserialize};
use state::{State, types::{MessageId, PeerId}, CommState, ApiState};
use serde::{Deserialize, Serialize};
use state::{
types::{MessageId, PeerId},
ApiState, CommState, State,
};
pub mod api;
pub mod comm;
@ -18,7 +21,6 @@ pub struct MessageRelations {
pub parents: Vec<MessageId>,
}
pub struct Ubisync {
comm_handle: Arc<CommHandle>,
state_handle: Arc<State>,
@ -31,13 +33,17 @@ impl Ubisync {
let comm_handle = Arc::new(CommHandle::new(CommState::new(state.clone()), config)?);
state.set_comm_handle(comm_handle.clone());
let api = Arc::new(ApiBuilder::from(config.api_config.clone()).build(ApiState::new(state.clone(), &config.jwt_secret)).await);
let api = Arc::new(
ApiBuilder::from(config.api_config.clone())
.build(ApiState::new(state.clone(), &config.jwt_secret))
.await,
);
comm_handle.run().await;
Ok(Ubisync {
comm_handle: comm_handle,
state_handle: state,
api: api
api: api,
})
}
@ -45,7 +51,7 @@ impl Ubisync {
self.api.clone()
}
pub fn add_peer(&self, p: impl TryInto<Peer, Error=anyhow::Error>) -> anyhow::Result<()> {
pub fn add_peer(&self, p: impl TryInto<Peer, Error = anyhow::Error>) -> anyhow::Result<()> {
match p.try_into() {
Ok(peer) => self.state_handle.set_peer(&peer),
Err(e) => bail!(e),
@ -66,7 +72,6 @@ impl Ubisync {
}
}
#[cfg(test)]
mod tests {
#[test]