socket clients: setting up with id and local parameters
This commit is contained in:
+3
-13
@@ -1,26 +1,16 @@
|
||||
use crate::banner;
|
||||
use crate::clients::NymClient;
|
||||
use crate::identity::mixnet;
|
||||
use crate::persistence::pathfinder::Pathfinder;
|
||||
use crate::persistence::pemstore::PemStore;
|
||||
use crate::persistence::pemstore;
|
||||
use clap::ArgMatches;
|
||||
|
||||
pub fn execute(matches: &ArgMatches) {
|
||||
println!("{}", banner());
|
||||
|
||||
let is_local = matches.is_present("local");
|
||||
|
||||
let id = matches.value_of("id").unwrap().to_string();
|
||||
println!("Starting client, local: {:?}", is_local);
|
||||
println!("Starting client...");
|
||||
|
||||
let keypair = read_keypair_from_disk(id);
|
||||
let keypair = pemstore::read_keypair_from_disk(id);
|
||||
let client = NymClient::new(keypair.public_bytes(), is_local);
|
||||
client.start().unwrap();
|
||||
}
|
||||
|
||||
fn read_keypair_from_disk(id: String) -> mixnet::KeyPair {
|
||||
let pathfinder = Pathfinder::new(id);
|
||||
let pem_store = PemStore::new(pathfinder);
|
||||
let keypair = pem_store.read();
|
||||
keypair
|
||||
}
|
||||
|
||||
@@ -1,10 +1,33 @@
|
||||
use crate::banner;
|
||||
use crate::clients::NymClient;
|
||||
use crate::persistence::pemstore;
|
||||
use crate::sockets::tcp;
|
||||
|
||||
use clap::ArgMatches;
|
||||
use std::net::ToSocketAddrs;
|
||||
|
||||
pub fn execute(matches: &ArgMatches) {
|
||||
let port = match matches.value_of("port").unwrap().parse::<u16>() {
|
||||
println!("{}", banner());
|
||||
|
||||
let is_local = matches.is_present("local");
|
||||
let id = matches.value_of("id").unwrap().to_string();
|
||||
let port = match matches.value_of("port").unwrap_or("9001").parse::<u16>() {
|
||||
Ok(n) => n,
|
||||
Err(err) => panic!("Invalid port value provided - {:?}", err),
|
||||
};
|
||||
|
||||
println!("On the following port: {:?}", port);
|
||||
println!("Starting TCP socket on port: {:?}", port);
|
||||
println!("Listening for messages...");
|
||||
|
||||
let socket_address = ("127.0.0.1", port)
|
||||
.to_socket_addrs()
|
||||
.expect("Failed to combine host and port")
|
||||
.next()
|
||||
.expect("Failed to extract the socket address from the iterator");
|
||||
|
||||
let keypair = pemstore::read_keypair_from_disk(id);
|
||||
let _client = NymClient::new(keypair.public_bytes(), is_local);
|
||||
// Question: should we be passing the client into the TCP socket somehow next?
|
||||
|
||||
tcp::start(socket_address);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
use crate::banner;
|
||||
use crate::clients::NymClient;
|
||||
use crate::persistence::pemstore;
|
||||
use crate::sockets::ws;
|
||||
|
||||
use clap::ArgMatches;
|
||||
use std::net::ToSocketAddrs;
|
||||
|
||||
pub fn execute(matches: &ArgMatches) {
|
||||
println!("{}", banner());
|
||||
|
||||
let port = match matches.value_of("port").unwrap().parse::<u16>() {
|
||||
let is_local = matches.is_present("local");
|
||||
let id = matches.value_of("id").unwrap().to_string();
|
||||
let port = match matches.value_of("port").unwrap_or("9001").parse::<u16>() {
|
||||
Ok(n) => n,
|
||||
Err(err) => panic!("Invalid port value provided - {:?}", err),
|
||||
};
|
||||
|
||||
println!("{}", banner());
|
||||
println!("Starting websocket on port: {:?}", port);
|
||||
println!("Listening for messages...");
|
||||
|
||||
@@ -21,5 +25,9 @@ pub fn execute(matches: &ArgMatches) {
|
||||
.next()
|
||||
.expect("Failed to extract the socket address from the iterator");
|
||||
|
||||
let keypair = pemstore::read_keypair_from_disk(id);
|
||||
let _client = NymClient::new(keypair.public_bytes(), is_local);
|
||||
// Question: should we be passing the client into the websocket somehow next?
|
||||
|
||||
ws::start(socket_address);
|
||||
}
|
||||
|
||||
+23
-2
@@ -50,9 +50,19 @@ fn main() {
|
||||
Arg::with_name("port")
|
||||
.short("p")
|
||||
.long("port")
|
||||
.help("Port to listen on")
|
||||
.help("Port for TCP socket to listen on")
|
||||
.takes_value(true)
|
||||
.required(true),
|
||||
).arg(Arg::with_name("local")
|
||||
.long("local")
|
||||
.help("Flag to indicate whether the client is expected to run on the local deployment.")
|
||||
.takes_value(false)
|
||||
)
|
||||
.arg(Arg::with_name("id")
|
||||
.long("id")
|
||||
.help("Id of the nym-mixnet-client we want to run.")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
@@ -62,10 +72,21 @@ fn main() {
|
||||
Arg::with_name("port")
|
||||
.short("p")
|
||||
.long("port")
|
||||
.help("Port to listen on")
|
||||
.help("Port for websocket to listen on")
|
||||
.takes_value(true)
|
||||
.required(true),
|
||||
)
|
||||
.arg(Arg::with_name("local")
|
||||
.long("local")
|
||||
.help("Flag to indicate whether the client is expected to run on the local deployment.")
|
||||
.takes_value(false)
|
||||
)
|
||||
.arg(Arg::with_name("id")
|
||||
.long("id")
|
||||
.help("Id of the nym-mixnet-client we want to run.")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
)
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
|
||||
@@ -5,6 +5,13 @@ use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn read_keypair_from_disk(id: String) -> KeyPair {
|
||||
let pathfinder = Pathfinder::new(id);
|
||||
let pem_store = PemStore::new(pathfinder);
|
||||
let keypair = pem_store.read();
|
||||
keypair
|
||||
}
|
||||
|
||||
pub struct PemStore {
|
||||
config_dir: PathBuf,
|
||||
private_mix_key: PathBuf,
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pub mod tcp;
|
||||
pub mod ws;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
pub fn start(_socket_address: SocketAddr) {
|
||||
println!("TCP server time!!!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user