diff --git a/ubisync/src/comm/mod.rs b/ubisync/src/comm/mod.rs index 75412f7..9dcc4b4 100644 --- a/ubisync/src/comm/mod.rs +++ b/ubisync/src/comm/mod.rs @@ -22,7 +22,7 @@ use crate::Config; pub struct CommHandle { state: Arc, i2p_server: Arc, - peer_id: RwLock, + peer_id: PeerId, // Maps peer addresses to existing connections to them clients: Arc>>>>, thread: RwLock>>, @@ -38,12 +38,13 @@ impl CommHandle { } let listener = listener_builder.build().unwrap(); - let own_peer_id: PeerId = (&listener).local_addr().map_err(|e| anyhow!(e))?.into(); + let mut own_peer_id: PeerId = (&listener).local_addr().map_err(|e| anyhow!(e))?.into(); + own_peer_id.b32_addr(); Ok(CommHandle { state: Arc::new(state), i2p_server: Arc::new(listener), - peer_id: RwLock::new(own_peer_id), + peer_id: own_peer_id, clients: Default::default(), thread: RwLock::new(None), }) @@ -104,6 +105,7 @@ impl CommHandle { } pub async fn send(&self, dest: &I2pSocketAddr, msg: Message) -> anyhow::Result<()> { + debug!("To '{dest:?}': '{msg:?}"); match serde_json::to_string(&msg) { Ok(msg_string) => { self.send_to_addr(dest, msg_string.as_bytes()).await?; @@ -116,6 +118,7 @@ impl CommHandle { pub async fn send_to_addr(&self, addr: &I2pSocketAddr, msg: &[u8]) -> anyhow::Result<()> { // Create client for this connection if necessary if !self.clients.read().await.contains_key(addr) { + debug!("No client exists for requested connection, creating one"); match I2pStream::connect(addr) { Ok(client) => { //client.inner.sam.conn.set_nodelay(true)?; @@ -153,15 +156,15 @@ impl CommHandle { } pub fn i2p_address(&self) -> I2pSocketAddr { - self.peer_id.blocking_read().addr() + self.peer_id.addr() } pub fn i2p_b32_address(&self) -> anyhow::Result { - self.peer_id.blocking_write().b32_addr() + self.peer_id.b32_addr_nocache() } pub fn own_peer_id(&self) -> anyhow::Result { - Ok(self.peer_id.blocking_read().to_owned()) + Ok(self.peer_id.to_owned()) } fn read_connection(