aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2017-10-20 20:05:20 -0700
committerBryan Newbold <bnewbold@robocracy.org>2017-10-20 20:05:20 -0700
commit1940f7b082bfd958ae9e4155f62afbd8f0100fd8 (patch)
treecbff21956497120a1a655a515f9d098d7ec46ebd /src/bin
parent0cd766546ae13d4d543c3da7f5f02d2720a8e2f7 (diff)
downloadgeniza-1940f7b082bfd958ae9e4155f62afbd8f0100fd8.tar.gz
geniza-1940f7b082bfd958ae9e4155f62afbd8f0100fd8.zip
crude WIP net client
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/geniza-net.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/bin/geniza-net.rs b/src/bin/geniza-net.rs
new file mode 100644
index 0000000..0f413a8
--- /dev/null
+++ b/src/bin/geniza-net.rs
@@ -0,0 +1,51 @@
+
+#[macro_use]
+extern crate error_chain;
+extern crate clap;
+extern crate geniza;
+
+// TODO: more careful import
+use geniza::*;
+use clap::{App, SubCommand};
+
+fn run() -> Result<()> {
+
+ let matches = App::new("geniza-net")
+ .version(env!("CARGO_PKG_VERSION"))
+ .subcommand(SubCommand::with_name("connect")
+ .about("Connects to a peer and exchanges handshake")
+ .arg_from_usage("<host_port> 'peer host:port to connect to'")
+ .arg_from_usage("<dat_key> 'dat key (public key) to register with'"))
+ .get_matches();
+
+
+ match matches.subcommand() {
+ ("connect", Some(subm)) => {
+ let host_port = subm.value_of("host_port").unwrap();
+ let dat_key = subm.value_of("dat_key").unwrap();
+ if dat_key.len() != 32*2 {
+ bail!("dat key not correct length");
+ }
+ let mut key_bytes = vec![];
+ for i in 0..32 {
+ let r = u8::from_str_radix(&dat_key[2*i .. 2*i+2], 16);
+ match r {
+ Ok(b) => key_bytes.push(b),
+ Err(e) => bail!("Problem with hex: {}", e),
+ };
+ }
+ DatConnection::connect(
+ host_port,
+ &key_bytes)?;
+ println!("Done!");
+ },
+ _ => {
+ println!("Missing or unimplemented command!");
+ println!("{}", matches.usage());
+ ::std::process::exit(-1);
+ },
+ }
+ Ok(())
+}
+
+quick_main!(run);