Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reduce MIN_CHUNK_SIZE and MIN_ENCRYPTABLE_BYTES down to 1/3 bytes. #377

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ use xor_name::XorName;
pub use bytes;
pub use xor_name;

/// The minimum size (before compression) of data to be self-encrypted, defined as 3kiB.
/// The minimum size (before compression) of data to be self-encrypted, defined as 3B.
pub const MIN_ENCRYPTABLE_BYTES: usize = 3 * MIN_CHUNK_SIZE;
/// The maximum size (before compression) of an individual chunk of a file, defined as 500kiB.
pub const MAX_CHUNK_SIZE: usize = 512 * 1024;
/// The minimum size (before compression) of an individual chunk of a file, defined as 1kiB.
pub const MIN_CHUNK_SIZE: usize = 1024;
/// The minimum size (before compression) of an individual chunk of a file, defined as 1B.
pub const MIN_CHUNK_SIZE: usize = 1;
/// Controls the compression-speed vs compression-density tradeoffs. The higher the quality, the
/// slower the compression. Range is 0 to 11.
pub const COMPRESSION_QUALITY: i32 = 6;
Expand Down
25 changes: 15 additions & 10 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ async fn cross_platform_check() -> Result<()> {
145, 206, 168, 75, 176, 141, 46, 197, 1, 83, 199, 165, 37, 28,
]),
dst_hash: XorName([
91, 220, 23, 234, 225, 117, 102, 56, 66, 156, 244, 221, 200, 200, 209, 201, 243,
186, 176, 29, 76, 93, 211, 59, 14, 196, 32, 112, 176, 1, 204, 125,
160, 57, 64, 193, 147, 235, 173, 54, 53, 206, 248, 12, 40, 147, 119, 107, 154, 21,
50, 57, 151, 18, 151, 0, 95, 157, 103, 220, 160, 79, 248, 85,
]),
index: 0,
src_size: 0,
Expand Down Expand Up @@ -295,31 +295,36 @@ async fn cross_platform_check() -> Result<()> {
},
ChunkInfo {
src_hash: XorName([
234, 107, 8, 130, 125, 216, 160, 160, 13, 230, 7, 11, 37, 118, 105, 223, 105, 87,
90, 209, 211, 79, 27, 158, 16, 167, 235, 67, 91, 131, 251, 172,
227, 224, 98, 89, 131, 120, 169, 214, 165, 171, 189, 187, 15, 7, 80, 133, 16, 63,
74, 197, 17, 127, 22, 137, 171, 117, 34, 195, 186, 185, 51, 2,
]),
dst_hash: XorName([
115, 244, 10, 81, 146, 92, 255, 68, 159, 239, 113, 254, 174, 79, 20, 28, 89, 48,
192, 18, 78, 92, 61, 129, 26, 243, 119, 250, 119, 18, 168, 130,
166, 232, 206, 232, 6, 23, 232, 20, 105, 230, 249, 86, 35, 117, 181, 65, 192, 245,
65, 130, 238, 50, 188, 82, 193, 115, 172, 113, 237, 33, 248, 102,
]),
index: 0,
src_size: 0,
},
ChunkInfo {
src_hash: XorName([
173, 132, 16, 44, 184, 235, 162, 98, 194, 197, 157, 156, 131, 245, 181, 91, 83, 51,
15, 204, 124, 193, 209, 249, 155, 19, 89, 201, 64, 247, 95, 73,
199, 77, 9, 166, 29, 63, 254, 6, 165, 71, 110, 151, 121, 199, 60, 144, 197, 6, 92,
182, 237, 202, 223, 171, 20, 80, 193, 237, 148, 96, 190, 70,
]),
dst_hash: XorName([
64, 23, 138, 48, 198, 43, 63, 70, 55, 164, 9, 209, 103, 37, 27, 45, 49, 204, 180,
86, 179, 79, 240, 178, 148, 160, 184, 252, 32, 102, 123, 216,
221, 131, 122, 148, 84, 180, 72, 155, 240, 84, 4, 189, 156, 65, 164, 204, 215, 198,
118, 227, 41, 95, 185, 117, 152, 128, 119, 205, 173, 180, 155, 86,
]),
index: 0,
src_size: 0,
},
];

for (i, c) in data_map.infos().into_iter().enumerate() {
println!("expected[i].src_hash {:?}", ref_data_map[i].src_hash.0);
println!("got .src_hash {:?}", c.src_hash.0);
println!("expected[i].dst_hash {:?}", ref_data_map[i].dst_hash.0);
println!("got .dst_hash {:?}", c.dst_hash.0);

assert_eq!(c.src_hash, ref_data_map[i].src_hash);
assert_eq!(c.dst_hash, ref_data_map[i].dst_hash);
}
Expand Down
Loading