Code cleanup

This commit is contained in:
Philip (a-0) 2024-03-23 18:39:06 +01:00
parent 51682c04b1
commit 3758249a28
8 changed files with 13 additions and 18 deletions

View file

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use crate::types::{ElementContent, ElementId, Family, FamilyId, MessageId, PotId};
use crate::types::{ElementContent, ElementId, Family, MessageId, PotId};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Message {

View file

@ -1,7 +1,7 @@
use tracing::debug;
use ubisync_lib::peer::Peer;
use ubisync_lib::types::{ContentUpdateStrategy, Family, PeerId};
use ubisync_lib::types::{ContentUpdateStrategy, PeerId};
use ubisync_lib::messages::{Message, MessageContent};
@ -25,15 +25,9 @@ pub fn handle(state: &CommState, peer: &PeerId, message: Message) {
MessageContent::JoinFamily => state.request_family_join(peer.to_owned()),
MessageContent::AddedToFamily { family } => {
if state.has_family_join_request(peer.to_owned()) {
debug!("Own join request was accepted, setting family");
state
.set_own_family(family.to_owned())
.expect("State failed");
debug!("New own family: {:?}", state.get_family_of_peer(state.own_peer_id().unwrap()))
}
else {
debug!("Got AddedToFamily message, but no family join request was found")
}
}
MessageContent::LeaveFamily => state.remove_peer_from_family(peer.to_owned()),

View file

@ -1,7 +1,6 @@
mod conflict_resolution;
pub mod message_processor;
use i2p::sam::StreamForward;
use tracing::{debug, error, warn};
use ubisync_lib::messages::Message;
use ubisync_lib::types::PeerId;
@ -39,7 +38,7 @@ impl CommHandle {
}
let listener = listener_builder.build().unwrap();
let mut own_peer_id: PeerId = (&listener).local_addr().map_err(|e| anyhow!(e))?.into();
let own_peer_id: PeerId = (&listener).local_addr().map_err(|e| anyhow!(e))?.into();
Ok(CommHandle {
state: Arc::new(state),

View file

@ -1,4 +1,4 @@
use std::{future::Future, sync::Arc};
use std::sync::Arc;
use anyhow::bail;
use api::{v0::app::App, Api, ApiBuilder};

View file

@ -6,7 +6,8 @@ use ubisync_lib::{
api::events::AppEvent,
peer::Peer,
types::{
ContentUpdateStrategy, Element, ElementContent, ElementId, Family, FamilyId, MessageId, PeerId, PotId
ContentUpdateStrategy, Element, ElementContent, ElementId, Family, FamilyId, MessageId,
PeerId, PotId,
},
};
@ -101,12 +102,13 @@ impl CommState {
}
pub fn request_family_join(&self, peer: PeerId) {
self.state
let _ = self
.state
.emit_node_event(UbisyncNodeEvent::FamilyJoinRequest { joiner: peer });
}
pub fn remove_peer_from_family(&self, peer: PeerId) {
self.db().remove_peer_from_family(peer);
let _ = self.db().remove_peer_from_family(peer);
}
pub fn has_family_join_request(&self, peer: PeerId) -> bool {

View file

@ -32,7 +32,7 @@ impl StateDB {
}
pub fn add_family_join_request(&self, peer: PeerId) {
self.db.set_key(peer.to_string(), &"").execute();
let _ = self.db.set_key(peer.to_string(), &"").execute();
debug!(
"Added join request: {:?}",
self.db.get_key(peer.to_string()).query()

View file

@ -13,7 +13,7 @@ use ubisync_lib::{
types::{AppId, Element, ElementContent, ElementId, Family, FamilyId, PeerId, PotId, Tag},
};
use anyhow::{anyhow, Error};
use anyhow::Error;
use tracing::{debug, warn};
mod api_state;

View file

@ -41,7 +41,7 @@ async fn two_nodes_element_creation() {
let app_id2 = api_client2.app_id();
ubi2.set_node_event_callback(
move |ev, node| {
if let UbisyncNodeEvent::NewPot { id, app_type } = ev {
if let UbisyncNodeEvent::NewPot { id, app_type: _ } = ev {
debug!("callback called");
node.add_pot_member(id, app_id2.clone()).unwrap();
}
@ -105,7 +105,7 @@ async fn two_nodes_api_event() {
ubi1.set_node_event_callback(
move |ev, node| {
debug!("callback called");
if let UbisyncNodeEvent::NewPot { id, app_type } = ev {
if let UbisyncNodeEvent::NewPot { id, app_type: _ } = ev {
node.add_pot_member(id, app_id1.clone()).unwrap();
}
},