summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Stock <stuart@int08h.com>2019-10-12 16:58:30 -0500
committerGitHub <noreply@github.com>2019-10-12 16:58:30 -0500
commitf1f834e8c65d518f66b4732a6c9655f04555b9cd (patch)
tree2c16527476e15308e470ab2d3b75518195437ab7
parent50a505e66f44f0efcfc0fa1390fcc889ab8dcd01 (diff)
parent5bb92b7b2120b95105e15c70a90188487320cda3 (diff)
downloadroughenough-f1f834e8c65d518f66b4732a6c9655f04555b9cd.zip
Merge pull request #21 from katharostech/extra-client-options
Improved Client Output
-rw-r--r--README.md14
-rw-r--r--src/bin/roughenough-client.rs33
2 files changed, 40 insertions, 7 deletions
diff --git a/README.md b/README.md
index 8f35e83..7a9bbed 100644
--- a/README.md
+++ b/README.md
@@ -45,9 +45,18 @@ $ cp target/release/roughenough-client /usr/local/bin
### Using the Client to Query a Roughtime Server
```bash
-$ target/release/roughenough-client roughtime.int08h.com 2002
+$ target/release/roughenough-client -v roughtime.int08h.com 2002
Requesting time from: "roughtime.int08h.com":2002
Received time from server: midpoint="Oct 26 2018 23:20:44", radius=1000000, verified=No (merkle_index=0)
+Oct 26 2018 23:20:44
+```
+
+### Setting The System Time on Linux
+
+You can use the `date` utility on Linux machines to set the system time to the time determined by the Roughenough client:
+
+```bash
+sudo date --utc --set "$(roughenough-client roughtime.int08h.com 2002)"
```
### Validating Server Responses
@@ -60,9 +69,10 @@ $ host -t TXT roughtime.int08h.com
roughtime.int08h.com descriptive text "016e6e0284d24c37c6e4d7d8d5b4e1d3c1949ceaa545bf875616c9dce0c9bec1"
# Validate the server response using its public key
-$ target/release/roughenough-client roughtime.int08h.com 2002 -p 016e6e0284d24c37c6e4d7d8d5b4e1d3c1949ceaa545bf875616c9dce0c9bec1
+$ target/release/roughenough-client -v roughtime.int08h.com 2002 -p 016e6e0284d24c37c6e4d7d8d5b4e1d3c1949ceaa545bf875616c9dce0c9bec1
Requesting time from: "roughtime.int08h.com":2002
Received time from server: midpoint="Oct 26 2018 23:22:20", radius=1000000, verified=Yes (merkle_index=0)
+Oct 26 2018 23:22:20
```
The **`verified=Yes`** in the output confirms that the server's response had a valid signature.
diff --git a/src/bin/roughenough-client.rs b/src/bin/roughenough-client.rs
index a8cc28f..dd780f5 100644
--- a/src/bin/roughenough-client.rs
+++ b/src/bin/roughenough-client.rs
@@ -222,6 +222,14 @@ fn main() {
.required(true)
.help("The Roughtime server port to connect to")
.takes_value(true))
+ .arg(Arg::with_name("verbose")
+ .short("v")
+ .long("verbose")
+ .help("Print more output"))
+ .arg(Arg::with_name("json")
+ .short("j")
+ .long("json")
+ .help("Print output in JSON"))
.arg(Arg::with_name("public-key")
.short("p")
.long("public-key")
@@ -256,6 +264,8 @@ fn main() {
let host = matches.value_of("host").unwrap();
let port = value_t_or_exit!(matches.value_of("port"), u16);
+ let verbose = matches.is_present("verbose");
+ let json = matches.is_present("json");
let num_requests = value_t_or_exit!(matches.value_of("num-requests"), u16) as usize;
let time_format = matches.value_of("time-format").unwrap();
let stress = matches.is_present("stress");
@@ -264,7 +274,9 @@ fn main() {
.map(|pkey| hex::decode(pkey).expect("Error parsing public key!"));
let out = matches.value_of("output");
- println!("Requesting time from: {:?}:{:?}", host, port);
+ if verbose {
+ eprintln!("Requesting time from: {:?}:{:?}", host, port);
+ }
let addr = (host, port).to_socket_addrs().unwrap().next().unwrap();
@@ -312,10 +324,21 @@ fn main() {
let out = spec.format(time_format).to_string();
let verify_str = if verified { "Yes" } else { "No" };
- println!(
- "Received time from server: midpoint={:?}, radius={:?}, verified={} (merkle_index={})",
- out, radius, verify_str, index
- );
+ if verbose {
+ eprintln!(
+ "Received time from server: midpoint={:?}, radius={:?}, verified={} (merkle_index={})",
+ out, radius, verify_str, index
+ );
+ }
+
+ if json {
+ println!(
+ r#"{{ "midpoint": {:?}, "radius": {:?}, "verified": {}, "merkle_index": {} }}"#,
+ out, radius, verified, index
+ );
+ } else {
+ println!("{}", out);
+ }
}
}