use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct SessionEntry {
pub gid: u64,
pub uris: Vec<String>,
pub options: HashMap<String, String>,
pub paused: bool,
pub total_length: u64,
pub completed_length: u64,
pub upload_length: u64,
pub download_speed: u64,
pub status: String,
pub error_code: Option<i32>,
pub bitfield: Option<Vec<u8>>,
pub num_pieces: Option<u32>,
pub piece_length: Option<u32>,
pub info_hash_hex: Option<String>,
pub resume_offset: Option<u64>,
}
impl SessionEntry {
pub fn new(gid: u64, uris: Vec<String>) -> Self {
SessionEntry {
gid,
uris,
options: HashMap::new(),
paused: false,
total_length: 0,
completed_length: 0,
upload_length: 0,
download_speed: 0,
status: "active".to_string(),
error_code: None,
bitfield: None,
num_pieces: None,
piece_length: None,
info_hash_hex: None,
resume_offset: None,
}
}
pub fn with_options(mut self, options: HashMap<String, String>) -> Self {
self.options = options;
self
}
pub fn paused(mut self) -> Self {
self.paused = true;
self
}
#[allow(dead_code)] fn get_opt(&self, key: &str) -> Option<&str> {
self.options.get(key).map(|s| s.as_str())
}
}