Skip to main content

rightkit_send/
policy.rs

1//! Limits and folder names the host may tune. `Policy::default()` is Pulse's
2//! current behaviour, so a host that changes nothing keeps its existing rules.
3
4use std::time::Duration;
5
6#[derive(Clone, Debug, PartialEq, Eq)]
7pub struct Policy {
8    /// Folder under the save folder for files from a sender that could not prove
9    /// its key. Kept apart from the owner's own files.
10    pub unverified_folder: String,
11    /// Most files one request may name when the sender could not prove its key.
12    pub unproven_max_files: usize,
13    /// Most bytes one request may name when the sender could not prove its key.
14    pub unproven_max_bytes: u64,
15    /// Largest single file any request may name, proven or not.
16    pub max_file_bytes: u64,
17    /// Longest text message kept, in characters (not bytes). Longer text is cut.
18    pub max_message_chars: usize,
19    /// How long a request waits for the owner's answer before it is declined.
20    pub answer_wait: Duration,
21}
22
23impl Default for Policy {
24    fn default() -> Policy {
25        Policy {
26            unverified_folder: "Received (unverified)".to_string(),
27            unproven_max_files: 200,
28            unproven_max_bytes: 2 * 1024 * 1024 * 1024,
29            max_file_bytes: 64 * 1024 * 1024 * 1024,
30            max_message_chars: 64 * 1024,
31            answer_wait: Duration::from_secs(60),
32        }
33    }
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn defaults_are_pulse_current_values() {
42        let policy = Policy::default();
43        assert_eq!(policy.unverified_folder, "Received (unverified)");
44        assert_eq!(policy.unproven_max_files, 200);
45        assert_eq!(policy.unproven_max_bytes, 2 * 1024 * 1024 * 1024);
46        assert_eq!(policy.max_file_bytes, 64 * 1024 * 1024 * 1024);
47        assert_eq!(policy.max_message_chars, 64 * 1024);
48        assert_eq!(policy.answer_wait, Duration::from_secs(60));
49    }
50}