mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
Improve common AccessList code
This commit is contained in:
parent
2732e520f7
commit
119cd0fe46
1 changed files with 15 additions and 10 deletions
|
|
@ -51,6 +51,20 @@ impl AccessList {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn create_from_path(path: &PathBuf) -> anyhow::Result<Self> {
|
||||
let file = File::open(path)?;
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let mut new_list = Self::default();
|
||||
|
||||
for line in reader.lines() {
|
||||
new_list.insert_from_line(&line?)?;
|
||||
}
|
||||
|
||||
Ok(new_list)
|
||||
}
|
||||
|
||||
pub fn allows(&self, mode: AccessListMode, info_hash: &[u8; 20]) -> bool {
|
||||
match mode {
|
||||
AccessListMode::White => self.0.contains(info_hash),
|
||||
|
|
@ -69,16 +83,7 @@ pub type AccessListArcSwap = ArcSwap<AccessList>;
|
|||
|
||||
impl AccessListQuery for AccessListArcSwap {
|
||||
fn update_from_path(&self, path: &PathBuf) -> anyhow::Result<()> {
|
||||
let file = File::open(path)?;
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let mut new_list = HashSet::new();
|
||||
|
||||
for line in reader.lines() {
|
||||
new_list.insert(parse_info_hash(&line?)?);
|
||||
}
|
||||
|
||||
self.store(Arc::new(AccessList(new_list)));
|
||||
self.store(Arc::new(AccessList::create_from_path(path)?));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue