aboutsummaryrefslogtreecommitdiff
path: root/src/netapp.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-12-07 18:07:55 +0100
committerAlex Auvolat <alex@adnab.me>2020-12-07 18:07:55 +0100
commit58ec2abe1a805d0fe6c86ab009f6947adbd9ca2b (patch)
tree1060640d08de00ddf59aa6f2d213061ff0db27aa /src/netapp.rs
parent32a0fbcbd919ec45bb6380352190115f701f2c91 (diff)
downloadnetapp-58ec2abe1a805d0fe6c86ab009f6947adbd9ca2b.tar.gz
netapp-58ec2abe1a805d0fe6c86ab009f6947adbd9ca2b.zip
Small changes
Diffstat (limited to 'src/netapp.rs')
-rw-r--r--src/netapp.rs24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/netapp.rs b/src/netapp.rs
index 967105e..6f6da5b 100644
--- a/src/netapp.rs
+++ b/src/netapp.rs
@@ -3,6 +3,7 @@ use std::collections::HashMap;
use std::net::SocketAddr;
use std::pin::Pin;
use std::sync::{Arc, RwLock};
+use std::time::Instant;
use std::future::Future;
@@ -75,10 +76,18 @@ where
M::KIND,
hex::encode(remote)
);
+ let begin_time = Instant::now();
let res = match rmp_serde::decode::from_read_ref::<_, M>(&bytes[..]) {
Ok(msg) => Ok(handler(remote, msg).await),
Err(e) => Err(e.to_string()),
};
+ let end_time = Instant::now();
+ debug!(
+ "Request {:08x} from {} handled in {}msec",
+ M::KIND,
+ hex::encode(remote),
+ (end_time - begin_time).as_millis()
+ );
rmp_to_vec_all_named(&res).unwrap_or(vec![])
}
@@ -291,8 +300,7 @@ impl NetApp {
pub(crate) fn connected_as_server(&self, id: ed25519::PublicKey, conn: Arc<ServerConn>) {
info!("Accepted connection from {}", hex::encode(id));
- let mut conn_list = self.server_conns.write().unwrap();
- conn_list.insert(id.clone(), conn);
+ self.server_conns.write().unwrap().insert(id, conn);
}
// Handle hello message from a client. This message is used for them to tell us
@@ -319,10 +327,11 @@ impl NetApp {
if let Some(c) = conn_list.get(id) {
if Arc::ptr_eq(c, &conn) {
conn_list.remove(id);
- }
+ drop(conn_list);
- if let Some(h) = self.on_disconnected_handler.load().as_ref() {
- h(conn.peer_pk, true);
+ if let Some(h) = self.on_disconnected_handler.load().as_ref() {
+ h(conn.peer_pk, true);
+ }
}
}
}
@@ -338,8 +347,8 @@ impl NetApp {
info!("Connection established to {}", hex::encode(id));
{
- let mut conn_list = self.client_conns.write().unwrap();
- if let Some(old_c) = conn_list.insert(id.clone(), conn.clone()) {
+ let old_c_opt = self.client_conns.write().unwrap().insert(id, conn.clone());
+ if let Some(old_c) = old_c_opt {
tokio::spawn(async move { old_c.close() });
}
}
@@ -365,6 +374,7 @@ impl NetApp {
if let Some(c) = conn_list.get(id) {
if Arc::ptr_eq(c, &conn) {
conn_list.remove(id);
+ drop(conn_list);
if let Some(h) = self.on_disconnected_handler.load().as_ref() {
h(conn.peer_pk, false);