diff options
author | Alex Auvolat <alex@adnab.me> | 2020-12-12 21:14:15 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-12-12 21:14:15 +0100 |
commit | 6742638c81f8bda2ba3e3ab72ec520ab22b314e2 (patch) | |
tree | 0e85579ed8523a4fc8448d931a302350cbf9e952 /src/peering/basalt.rs | |
parent | 50401989724ed70f031055463e21caad76589742 (diff) | |
download | netapp-6742638c81f8bda2ba3e3ab72ec520ab22b314e2.tar.gz netapp-6742638c81f8bda2ba3e3ab72ec520ab22b314e2.zip |
Replace pk,pubkey,PublicKey by id,NodeID,etc
Diffstat (limited to 'src/peering/basalt.rs')
-rw-r--r-- | src/peering/basalt.rs | 60 |
1 files changed, 27 insertions, 33 deletions
diff --git a/src/peering/basalt.rs b/src/peering/basalt.rs index 4d56319..3c1fc9e 100644 --- a/src/peering/basalt.rs +++ b/src/peering/basalt.rs @@ -9,11 +9,11 @@ use rand::{thread_rng, Rng}; use serde::{Deserialize, Serialize}; use sodiumoxide::crypto::hash; -use sodiumoxide::crypto::sign::ed25519; use crate::message::*; use crate::netapp::*; use crate::proto::*; +use crate::NodeID; // -- Protocol messages -- @@ -41,7 +41,7 @@ type Seed = [u8; 32]; #[derive(Hash, Clone, Copy, Debug, PartialOrd, PartialEq, Eq, Serialize, Deserialize)] struct Peer { - id: ed25519::PublicKey, + id: NodeID, addr: SocketAddr, } @@ -168,7 +168,7 @@ impl BasaltView { } } - fn disconnected(&mut self, id: ed25519::PublicKey) { + fn disconnected(&mut self, id: NodeID) { let mut cleared_slots = vec![]; for i in 0..self.slots.len() { if let Some(p) = self.slots[i].peer { @@ -248,7 +248,7 @@ pub struct Basalt { impl Basalt { pub fn new( netapp: Arc<NetApp>, - bootstrap_list: Vec<(ed25519::PublicKey, SocketAddr)>, + bootstrap_list: Vec<(NodeID, SocketAddr)>, param: BasaltParams, ) -> Arc<Self> { let bootstrap_peers = bootstrap_list @@ -272,37 +272,31 @@ impl Basalt { }); let basalt2 = basalt.clone(); - netapp.on_connected( - move |pk: ed25519::PublicKey, addr: SocketAddr, is_incoming: bool| { - basalt2.on_connected(pk, addr, is_incoming); - }, - ); + netapp.on_connected(move |id: NodeID, addr: SocketAddr, is_incoming: bool| { + basalt2.on_connected(id, addr, is_incoming); + }); let basalt2 = basalt.clone(); - netapp.on_disconnected(move |pk: ed25519::PublicKey, is_incoming: bool| { - basalt2.on_disconnected(pk, is_incoming); + netapp.on_disconnected(move |id: NodeID, is_incoming: bool| { + basalt2.on_disconnected(id, is_incoming); }); let basalt2 = basalt.clone(); - netapp.add_msg_handler::<PullMessage, _, _>( - move |_from: ed25519::PublicKey, _pullmsg: PullMessage| { - let push_msg = basalt2.make_push_message(); - async move { push_msg } - }, - ); + netapp.add_msg_handler::<PullMessage, _, _>(move |_from: NodeID, _pullmsg: PullMessage| { + let push_msg = basalt2.make_push_message(); + async move { push_msg } + }); let basalt2 = basalt.clone(); - netapp.add_msg_handler::<PushMessage, _, _>( - move |_from: ed25519::PublicKey, push_msg: PushMessage| { - basalt2.handle_peer_list(&push_msg.peers[..]); - async move { () } - }, - ); + netapp.add_msg_handler::<PushMessage, _, _>(move |_from: NodeID, push_msg: PushMessage| { + basalt2.handle_peer_list(&push_msg.peers[..]); + async move { () } + }); basalt } - pub fn sample(&self, count: usize) -> Vec<ed25519::PublicKey> { + pub fn sample(&self, count: usize) -> Vec<NodeID> { self.view .read() .unwrap() @@ -337,7 +331,7 @@ impl Basalt { } } - async fn do_pull(self: Arc<Self>, peer: ed25519::PublicKey) { + async fn do_pull(self: Arc<Self>, peer: NodeID) { match self .netapp .request(&peer, PullMessage {}, PRIO_NORMAL) @@ -353,7 +347,7 @@ impl Basalt { }; } - async fn do_push(self: Arc<Self>, peer: ed25519::PublicKey) { + async fn do_push(self: Arc<Self>, peer: NodeID) { let push_msg = self.make_push_message(); match self.netapp.request(&peer, push_msg, PRIO_NORMAL).await { Ok(_) => { @@ -434,12 +428,12 @@ impl Basalt { } } - fn on_connected(self: &Arc<Self>, pk: ed25519::PublicKey, addr: SocketAddr, is_incoming: bool) { + fn on_connected(self: &Arc<Self>, id: NodeID, addr: SocketAddr, is_incoming: bool) { if is_incoming { - self.handle_peer_list(&[Peer { id: pk, addr }][..]); + self.handle_peer_list(&[Peer { id, addr }][..]); } else { - info!("KYEV C {} {}", hex::encode(pk), addr); - let peer = Peer { id: pk, addr }; + info!("KYEV C {} {}", hex::encode(id), addr); + let peer = Peer { id, addr }; let mut backlog = self.backlog.write().unwrap(); if backlog.get(&peer).is_none() { @@ -459,10 +453,10 @@ impl Basalt { } } - fn on_disconnected(&self, pk: ed25519::PublicKey, is_incoming: bool) { + fn on_disconnected(&self, id: NodeID, is_incoming: bool) { if !is_incoming { - info!("KYEV D {}", hex::encode(pk)); - self.view.write().unwrap().disconnected(pk); + info!("KYEV D {}", hex::encode(id)); + self.view.write().unwrap().disconnected(id); } } |