aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-10-14 11:58:09 +0200
committerAlex Auvolat <alex@adnab.me>2021-10-14 11:58:09 +0200
commit7e49d0dac847cc2a502038eb512255377ac6238a (patch)
tree84684b549067b7ad6390e4d1a311d25a0b39d629 /examples
parentd62b1610405d5f02b8725862fd4a4f1368bd684b (diff)
downloadnetapp-7e49d0dac847cc2a502038eb512255377ac6238a.tar.gz
netapp-7e49d0dac847cc2a502038eb512255377ac6238a.zip
Make a public function to parse peer addresses
Diffstat (limited to 'examples')
-rw-r--r--examples/basalt.rs9
-rw-r--r--examples/fullmesh.rs10
2 files changed, 4 insertions, 15 deletions
diff --git a/examples/basalt.rs b/examples/basalt.rs
index 85fbb58..752583d 100644
--- a/examples/basalt.rs
+++ b/examples/basalt.rs
@@ -1,5 +1,4 @@
use std::io::Write;
-use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;
@@ -17,6 +16,7 @@ use tokio::sync::watch;
use netapp::endpoint::*;
use netapp::peering::basalt::*;
use netapp::proto::*;
+use netapp::util::parse_peer_addr;
use netapp::{NetApp, NodeID};
#[derive(StructOpt, Debug)]
@@ -98,12 +98,7 @@ async fn main() {
let mut bootstrap_peers = vec![];
for peer in opt.bootstrap_peers.iter() {
- if let Some(delim) = peer.find('@') {
- let (key, ip) = peer.split_at(delim);
- let pubkey = ed25519::PublicKey::from_slice(&hex::decode(&key).unwrap()).unwrap();
- let ip = ip[1..].parse::<SocketAddr>().unwrap();
- bootstrap_peers.push((pubkey, ip));
- }
+ bootstrap_peers.push(parse_peer_addr(peer).expect("Invalid peer address"));
}
let basalt_params = BasaltParams {
diff --git a/examples/fullmesh.rs b/examples/fullmesh.rs
index 67861a7..f5b307b 100644
--- a/examples/fullmesh.rs
+++ b/examples/fullmesh.rs
@@ -1,5 +1,4 @@
use std::io::Write;
-use std::net::SocketAddr;
use log::info;
@@ -9,8 +8,8 @@ use sodiumoxide::crypto::auth;
use sodiumoxide::crypto::sign::ed25519;
use netapp::peering::fullmesh::*;
+use netapp::util::*;
use netapp::NetApp;
-use netapp::NodeID;
#[derive(StructOpt, Debug)]
#[structopt(name = "netapp")]
@@ -70,12 +69,7 @@ async fn main() {
let mut bootstrap_peers = vec![];
for peer in opt.bootstrap_peers.iter() {
- if let Some(delim) = peer.find('@') {
- let (key, ip) = peer.split_at(delim);
- let pubkey = NodeID::from_slice(&hex::decode(&key).unwrap()).unwrap();
- let ip = ip[1..].parse::<SocketAddr>().unwrap();
- bootstrap_peers.push((pubkey, ip));
- }
+ bootstrap_peers.push(parse_peer_addr(peer).expect("Invalid peer address"));
}
let peering = FullMeshPeeringStrategy::new(netapp.clone(), bootstrap_peers);