From 1c56f3179c07be3b77353c3b3f6847a46a366e80 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sun, 26 Nov 2017 19:12:38 -0800 Subject: helper command for generating dns lookup names --- src/bin/geniza-net.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src') diff --git a/src/bin/geniza-net.rs b/src/bin/geniza-net.rs index a3abc61..853b497 100644 --- a/src/bin/geniza-net.rs +++ b/src/bin/geniza-net.rs @@ -28,6 +28,16 @@ fn run() -> Result<()> { .arg_from_usage(" 'peer host:port to connect to'") .arg_from_usage(" 'dat key (public key) to register with'"), ) + .subcommand( + SubCommand::with_name("discovery-key") + .about("Prints (in hex) the discovery key for a dat archive") + .arg_from_usage(" 'dat key (public key) to convert (in hex)'"), + ) + .subcommand( + SubCommand::with_name("discovery-dns-name") + .about("Prints the DNS name to query (mDNS or centrally) for peers") + .arg_from_usage(" 'dat key (public key) to convert (in hex)'"), + ) .get_matches(); @@ -69,6 +79,44 @@ fn run() -> Result<()> { dc.receive_all(true, 10)?; println!("Done!"); } + ("discovery-key", Some(subm)) => { + 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), + }; + } + let disc_key = make_discovery_key(&key_bytes); + for b in disc_key { + print!("{:02x}", b); + } + println!(""); + } + ("discovery-dns-name", Some(subm)) => { + 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), + }; + } + let disc_key = make_discovery_key(&key_bytes); + for b in 0..20 { + print!("{:02x}", disc_key[b]); + } + println!(".dat.local"); + } _ => { println!("Missing or unimplemented command!"); println!("{}", matches.usage()); -- cgit v1.2.3