-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new torrent repo implementation using parking_lot Mutex
- Loading branch information
1 parent
0fa396c
commit 0058e72
Showing
10 changed files
with
240 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/torrent-repository/src/entry/rw_lock_parking_lot.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::net::SocketAddr; | ||
use std::sync::Arc; | ||
|
||
use torrust_tracker_configuration::TrackerPolicy; | ||
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata; | ||
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch}; | ||
|
||
use super::{Entry, EntrySync}; | ||
use crate::{EntryRwLockParkingLot, EntrySingle}; | ||
|
||
impl EntrySync for EntryRwLockParkingLot { | ||
fn get_swarm_metadata(&self) -> SwarmMetadata { | ||
self.read().get_swarm_metadata() | ||
} | ||
|
||
fn is_good(&self, policy: &TrackerPolicy) -> bool { | ||
self.read().is_good(policy) | ||
} | ||
|
||
fn peers_is_empty(&self) -> bool { | ||
self.read().peers_is_empty() | ||
} | ||
|
||
fn get_peers_len(&self) -> usize { | ||
self.read().get_peers_len() | ||
} | ||
|
||
fn get_peers(&self, limit: Option<usize>) -> Vec<Arc<peer::Peer>> { | ||
self.read().get_peers(limit) | ||
} | ||
|
||
fn get_peers_for_client(&self, client: &SocketAddr, limit: Option<usize>) -> Vec<Arc<peer::Peer>> { | ||
self.read().get_peers_for_client(client, limit) | ||
} | ||
|
||
fn upsert_peer(&self, peer: &peer::Peer) -> bool { | ||
self.write().upsert_peer(peer) | ||
} | ||
|
||
fn remove_inactive_peers(&self, current_cutoff: DurationSinceUnixEpoch) { | ||
self.write().remove_inactive_peers(current_cutoff); | ||
} | ||
} | ||
|
||
impl From<EntrySingle> for EntryRwLockParkingLot { | ||
fn from(entry: EntrySingle) -> Self { | ||
Arc::new(parking_lot::RwLock::new(entry)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.