diff options
author | bnewbold <bnewbold@robocracy.org> | 2016-05-29 15:33:04 -0400 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2016-05-29 15:33:04 -0400 |
commit | 223da5cfea8608f7b11f32720203a2704dd02601 (patch) | |
tree | a03b59582f29488fb52fcba7485b8da276339da9 | |
parent | a7b4e46f76ec70f71a189a1f3fbbd30370d82b4f (diff) | |
download | ucp-223da5cfea8608f7b11f32720203a2704dd02601.tar.gz ucp-223da5cfea8608f7b11f32720203a2704dd02601.zip |
fix module hierarchy; actually call common functions
-rw-r--r-- | src/client.rs | 15 | ||||
-rw-r--r-- | src/common.rs | 13 | ||||
-rw-r--r-- | src/main.rs | 4 | ||||
-rw-r--r-- | src/server.rs | 24 |
4 files changed, 32 insertions, 24 deletions
diff --git a/src/client.rs b/src/client.rs index 9687488..a2ebf27 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,6 +1,8 @@ extern crate utp; +use super::common; + use std::string::String; use std::env; use std::process; @@ -46,12 +48,11 @@ pub fn run_client(host: &str, local_file: &str, remote_file: &str, remote_is_dir println!("\thost: {}", remote_host); println!("\tsecret: {}", remote_secret); - let mut buf = [0; 2000]; let mut socket = UtpSocket::connect((remote_host, remote_port)).unwrap();; - socket.send_to("PING".as_bytes()); - socket.flush(); - let (amt, _src) = socket.recv_from(&mut buf).ok().unwrap(); - let reply = String::from_utf8_lossy(&buf[..amt]); - println!("Got uTP reply: {}", reply); - socket.close(); + if is_recv { + common::receive_files(&mut socket, local_file, remote_is_dir); + } else { + common::send_files(&mut socket, local_file, remote_is_dir); + } + socket.close().unwrap(); } diff --git a/src/common.rs b/src/common.rs index 063b166..8183bbf 100644 --- a/src/common.rs +++ b/src/common.rs @@ -3,14 +3,21 @@ extern crate utp; use std::str; use std::env; +use std::fs::File; +use std::io::Read; use std::process::exit; use utp::{UtpSocket}; -fn send_files(socket: UtpSocket, file_path: &str, recursive: bool) { +pub fn send_files(socket: &mut UtpSocket, file_path: &str, recursive: bool) { + assert!(!recursive); + let f = File::open(file_path).unwrap(); unimplemented!(); } -fn receive_files(socket: UtpSocket, file_path: &str) { - unimplemented!(); +pub fn receive_files(socket: &mut UtpSocket, file_path: &str, recursive: bool) { + assert!(!recursive); + let f = File::create(file_path).unwrap(); + + //f.set_len(); } diff --git a/src/main.rs b/src/main.rs index 8a78e67..bf2ceba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,13 @@ +// XXX: re-enable these warnings +#![allow(unused_imports, unused_variables)] + extern crate getopts; extern crate utp; mod client; mod server; +mod common; use std::str; use std::env; diff --git a/src/server.rs b/src/server.rs index e1b414e..e60c054 100644 --- a/src/server.rs +++ b/src/server.rs @@ -3,6 +3,8 @@ extern crate getopts; extern crate utp; extern crate daemonize; +use super::common; + use std::str; use std::env; use std::env::home_dir; @@ -10,7 +12,7 @@ use std::process::exit; use getopts::Options; use utp::{UtpSocket, UtpListener}; -fn run_server(path: &str, is_receive: bool) { +fn run_server(path: &str, is_recv: bool, recursive: bool) { // TODO: try to detect the address the SSH connection came in on via the SSH_CONNECTION env // variable. @@ -46,18 +48,12 @@ fn run_server(path: &str, is_receive: bool) { let (mut socket, _src) = listener.accept().unwrap(); println!("Got connection from {}", socket.peer_addr().unwrap()); - loop { - - let mut buf = [0; 1000]; - let (amt, _src) = socket.recv_from(&mut buf).ok().unwrap(); - if amt <= 0 { - break; - } - let buf = &buf[..amt]; - let s = str::from_utf8(buf).unwrap(); - println!("\tgot: {}", s); - socket.send_to(buf); + if is_recv { + common::receive_files(&mut socket, path, recursive); + } else { + common::send_files(&mut socket, path, recursive); } + socket.close().unwrap(); } fn usage_server(opts: Options) { @@ -101,9 +97,9 @@ pub fn main_server() { } if matches.opt_present("f") { - run_server(&matches.opt_str("f").unwrap(), false); + run_server(&matches.opt_str("f").unwrap(), false, dir_mode); } if matches.opt_present("t") { - run_server(&matches.opt_str("t").unwrap(), true); + run_server(&matches.opt_str("t").unwrap(), true, dir_mode); } } |