aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2017-11-26 19:12:38 -0800
committerBryan Newbold <bnewbold@robocracy.org>2017-11-26 19:12:38 -0800
commit1c56f3179c07be3b77353c3b3f6847a46a366e80 (patch)
tree057625188e2e4ec6db8ecfeb329a13cb664d531b /src/bin
parent0cbb542ccd3b62e7b099ae01e5d58418c254862c (diff)
downloadgeniza-1c56f3179c07be3b77353c3b3f6847a46a366e80.tar.gz
geniza-1c56f3179c07be3b77353c3b3f6847a46a366e80.zip
helper command for generating dns lookup names
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/geniza-net.rs48
1 files changed, 48 insertions, 0 deletions
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("<host_port> 'peer host:port to connect to'")
.arg_from_usage("<dat_key> '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> '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> '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());