Refactoring, mainly formatting
This commit is contained in:
parent
3825263fa3
commit
d8f1733eb3
25 changed files with 667 additions and 348 deletions
19
src/lib.rs
19
src/lib.rs
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue