aboutsummaryrefslogtreecommitdiffstats
path: root/src/server.rs
diff options
context:
space:
mode:
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);
}
}