aboutsummaryrefslogtreecommitdiff
path: root/src/conn.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-12-12 21:14:15 +0100
committerAlex Auvolat <alex@adnab.me>2020-12-12 21:14:15 +0100
commit6742638c81f8bda2ba3e3ab72ec520ab22b314e2 (patch)
tree0e85579ed8523a4fc8448d931a302350cbf9e952 /src/conn.rs
parent50401989724ed70f031055463e21caad76589742 (diff)
downloadnetapp-6742638c81f8bda2ba3e3ab72ec520ab22b314e2.tar.gz
netapp-6742638c81f8bda2ba3e3ab72ec520ab22b314e2.zip
Replace pk,pubkey,PublicKey by id,NodeID,etc
Diffstat (limited to 'src/conn.rs')
-rw-r--r--src/conn.rs33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/conn.rs b/src/conn.rs
index e965fc9..a4c4f4e 100644
--- a/src/conn.rs
+++ b/src/conn.rs
@@ -6,7 +6,6 @@ use std::sync::{Arc, Mutex};
use bytes::Bytes;
use log::{debug, error, trace};
-use sodiumoxide::crypto::sign::ed25519;
use tokio::io::split;
use tokio::net::TcpStream;
use tokio::sync::{mpsc, oneshot, watch};
@@ -26,7 +25,7 @@ use crate::util::*;
pub(crate) struct ServerConn {
pub(crate) remote_addr: SocketAddr,
- pub(crate) peer_pk: ed25519::PublicKey,
+ pub(crate) peer_id: NodeID,
netapp: Arc<NetApp>,
@@ -40,18 +39,18 @@ impl ServerConn {
let handshake = handshake_server(
&mut asyncstd_socket,
netapp.netid.clone(),
- netapp.pubkey.clone(),
+ netapp.id.clone(),
netapp.privkey.clone(),
)
.await?;
- let peer_pk = handshake.peer_pk.clone();
+ let peer_id = handshake.peer_pk.clone();
let tokio_socket = asyncstd_socket.into_inner();
let remote_addr = tokio_socket.peer_addr().unwrap();
debug!(
"Handshake complete (server) with {}@{}",
- hex::encode(&peer_pk),
+ hex::encode(&peer_id),
remote_addr
);
@@ -70,12 +69,12 @@ impl ServerConn {
let conn = Arc::new(ServerConn {
netapp: netapp.clone(),
remote_addr,
- peer_pk: peer_pk.clone(),
+ peer_id: peer_id.clone(),
resp_send,
close_send,
});
- netapp.connected_as_server(peer_pk.clone(), conn.clone());
+ netapp.connected_as_server(peer_id.clone(), conn.clone());
let conn2 = conn.clone();
let conn3 = conn.clone();
@@ -97,7 +96,7 @@ impl ServerConn {
.map(|_| ())
.log_err("ServerConn recv_loop/send_loop");
- netapp.disconnected_as_server(&peer_pk, conn);
+ netapp.disconnected_as_server(&peer_id, conn);
Ok(())
}
@@ -124,7 +123,7 @@ impl RecvLoop for ServerConn {
if let Some(handler) = self.netapp.msg_handlers.load().get(&kind) {
let net_handler = &handler.net_handler;
- let resp = net_handler(self.peer_pk.clone(), bytes.slice(5..)).await;
+ let resp = net_handler(self.peer_id.clone(), bytes.slice(5..)).await;
self.resp_send
.send(Some((id, prio, resp)))
.log_err("ServerConn recv_handler send resp");
@@ -133,7 +132,7 @@ impl RecvLoop for ServerConn {
}
pub(crate) struct ClientConn {
pub(crate) remote_addr: SocketAddr,
- pub(crate) peer_pk: ed25519::PublicKey,
+ pub(crate) peer_id: NodeID,
query_send: mpsc::UnboundedSender<Option<(RequestID, RequestPriority, Vec<u8>)>>,
@@ -147,16 +146,16 @@ impl ClientConn {
pub(crate) async fn init(
netapp: Arc<NetApp>,
socket: TcpStream,
- remote_pk: ed25519::PublicKey,
+ peer_id: NodeID,
) -> Result<(), Error> {
let mut asyncstd_socket = TokioCompatExt::wrap(socket);
let handshake = handshake_client(
&mut asyncstd_socket,
netapp.netid.clone(),
- netapp.pubkey.clone(),
+ netapp.id.clone(),
netapp.privkey.clone(),
- remote_pk.clone(),
+ peer_id.clone(),
)
.await?;
@@ -165,7 +164,7 @@ impl ClientConn {
debug!(
"Handshake complete (client) with {}@{}",
- hex::encode(&remote_pk),
+ hex::encode(&peer_id),
remote_addr
);
@@ -183,7 +182,7 @@ impl ClientConn {
let conn = Arc::new(ClientConn {
remote_addr,
- peer_pk: remote_pk.clone(),
+ peer_id: peer_id.clone(),
next_query_number: AtomicU16::from(0u16),
query_send,
inflight: Mutex::new(HashMap::new()),
@@ -191,7 +190,7 @@ impl ClientConn {
stop_recv_loop,
});
- netapp.connected_as_client(remote_pk.clone(), conn.clone());
+ netapp.connected_as_client(peer_id.clone(), conn.clone());
tokio::spawn(async move {
let conn2 = conn.clone();
@@ -205,7 +204,7 @@ impl ClientConn {
.map(|_| ())
.log_err("ClientConn send_loop/recv_loop/dispatch_loop");
- netapp.disconnected_as_client(&remote_pk, conn);
+ netapp.disconnected_as_client(&peer_id, conn);
});
Ok(())