aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-06-03 01:16:08 -0400
committerbnewbold <bnewbold@robocracy.org>2016-06-03 01:16:08 -0400
commitf68ff03d06a489114989b501e7e82cba1525f99e (patch)
tree473a994b9d15c3c32a8006e476755f2ffa38721b /src
parenta4d30ec5255a188ad9c359c52fd74d8091721e62 (diff)
downloaducp-f68ff03d06a489114989b501e7e82cba1525f99e.tar.gz
ucp-f68ff03d06a489114989b501e7e82cba1525f99e.zip
optimize by increasing CHUNK_SIZE to 16KB (from 4KB)
Diffstat (limited to 'src')
-rw-r--r--src/common.rs6
-rw-r--r--src/crypto.rs5
2 files changed, 7 insertions, 4 deletions
diff --git a/src/common.rs b/src/common.rs
index facd527..1900385 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -13,6 +13,8 @@ fn fake_io_error(msg: &str) -> io::Result<()> {
Err(io::Error::new(io::ErrorKind::Other, msg))
}
+const CHUNK_SIZE: usize = 1024*16;
+
pub fn source_files<S: Read + Write>(stream: &mut S, file_path: &str, recursive: bool) -> io::Result<()> {
println!("SOURCE FILE: {}", file_path);
if recursive { unimplemented!(); }
@@ -38,7 +40,7 @@ pub fn source_files<S: Read + Write>(stream: &mut S, file_path: &str, recursive:
_ => { return fake_io_error("Unexpected status char!"); },
};
- let mut buf = [0; 4096];
+ let mut buf = [0; CHUNK_SIZE];
let mut sent: usize = 0;
while sent < flen {
let rlen = try!(f.read(&mut buf));
@@ -83,7 +85,7 @@ pub fn sink_files<S: Read + Write>(stream: &mut S, file_path: &str, recursive: b
let mut f = try!(File::create(file_path));
let mut byte_buf = [0; 1];
- let mut buf = [0; 4096];
+ let mut buf = [0; CHUNK_SIZE];
try!(stream.read_exact(&mut byte_buf));
let msg_type = byte_buf[0];
match msg_type as char {
diff --git a/src/crypto.rs b/src/crypto.rs
index d6b65be..da0a770 100644
--- a/src/crypto.rs
+++ b/src/crypto.rs
@@ -9,13 +9,14 @@ use rustc_serialize::base64::{ToBase64, FromBase64, STANDARD};
use std::mem::transmute;
// TODO: handle case of splitting up writes > 2^32 bytes into multiple small writes
+const CHUNK_SIZE: usize = 1024*64;
pub struct SecretStream<S: Read+Write> {
pub read_nonce: Nonce,
pub write_nonce: Nonce,
pub key: Key,
inner: S,
- read_buf: [u8; 4096+1024],
+ read_buf: [u8; CHUNK_SIZE+512],
read_buf_offset: usize,
read_buf_len: usize,
}
@@ -27,7 +28,7 @@ impl<S: Read+Write> SecretStream<S> {
read_nonce: secretbox::gen_nonce(),
write_nonce: secretbox::gen_nonce(),
key: secretbox::gen_key(),
- read_buf: [0; 4096+1024],
+ read_buf: [0; CHUNK_SIZE+512],
read_buf_offset: 0,
read_buf_len: 0,
}