aboutsummaryrefslogtreecommitdiffstats
path: root/src/server.rs
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-05-30 16:32:21 -0400
committerbnewbold <bnewbold@robocracy.org>2016-05-30 16:32:21 -0400
commitccd871880d6a58a1b8decc3cd16951ee70ec2f57 (patch)
tree553d145663debde8816608ebfe2cb7bcd3f4e841 /src/server.rs
parent739816807c8b6a7c0e0be9c909f64d25dc0bf243 (diff)
downloaducp-ccd871880d6a58a1b8decc3cd16951ee70ec2f57.tar.gz
ucp-ccd871880d6a58a1b8decc3cd16951ee70ec2f57.zip
add --no-crypto in a crude way
Diffstat (limited to 'src/server.rs')
-rw-r--r--src/server.rs30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/server.rs b/src/server.rs
index 6f19fb0..596320d 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -12,7 +12,7 @@ use utp::{UtpSocket, UtpStream, UtpListener};
use crypto::{SecretStream, key2string, string2key, nonce2string, string2nonce};
use sodiumoxide::crypto::secretbox;
-fn run_server(path: &str, is_recv: bool, recursive: bool, daemonize: bool) {
+fn run_server(path: &str, is_recv: bool, recursive: bool, daemonize: bool, no_crypto: bool) {
// TODO: try to detect the address the SSH connection came in on via the SSH_CONNECTION env
// variable.
@@ -69,15 +69,23 @@ fn run_server(path: &str, is_recv: bool, recursive: bool, daemonize: bool) {
let (mut socket, _src) = listener.accept().unwrap();
println!("Got connection from {}", socket.peer_addr().unwrap());
let mut stream: UtpStream = socket.into();
- let mut stream = SecretStream::new(stream);
- stream.key = secret_key;
- stream.read_nonce = read_nonce;
- stream.write_nonce = write_nonce;
- if is_recv {
- common::sink_files(&mut stream, path, recursive);
+ if !no_crypto {
+ let mut stream = SecretStream::new(stream);
+ stream.key = secret_key;
+ stream.read_nonce = read_nonce;
+ stream.write_nonce = write_nonce;
+ if is_recv {
+ common::sink_files(&mut stream, path, recursive);
+ } else {
+ common::source_files(&mut stream, path, recursive);
+ }
} else {
- common::source_files(&mut stream, path, recursive);
+ if is_recv {
+ common::sink_files(&mut stream, path, recursive);
+ } else {
+ common::source_files(&mut stream, path, recursive);
+ }
}
// XXX: does Drop do this well enough?
//stream.close().unwrap();
@@ -101,6 +109,7 @@ pub fn main_server() {
opts.optflag("", "no-daemonize", "don't daemonize (for debuggign)");
opts.optopt("f", "from", "file or dir to read from (server side)", "FILE");
opts.optopt("t", "to", "file or dir to write to (server side)", "FILE");
+ opts.optflag("", "no-crypto", "sends data in the clear (no crypto or verification)");
assert!(args.len() >= 2 && args[1] == "server");
let matches = match opts.parse(&args[2..]) {
@@ -116,6 +125,7 @@ pub fn main_server() {
//let verbose: bool = matches.opt_present("v");
let dir_mode: bool = matches.opt_present("d");
let daemonize: bool = !matches.opt_present("no-daemonize");
+ let no_crypto: bool = matches.opt_present("no-crypto");
match (matches.opt_present("f"), matches.opt_present("t")) {
(true, true) | (false, false) => {
@@ -126,9 +136,9 @@ pub fn main_server() {
}
if matches.opt_present("f") {
- run_server(&matches.opt_str("f").unwrap(), false, dir_mode, daemonize);
+ run_server(&matches.opt_str("f").unwrap(), false, dir_mode, daemonize, no_crypto);
}
if matches.opt_present("t") {
- run_server(&matches.opt_str("t").unwrap(), true, dir_mode, daemonize);
+ run_server(&matches.opt_str("t").unwrap(), true, dir_mode, daemonize, no_crypto);
}
}