forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmutex_std.rs
More file actions
51 lines (40 loc) · 1.63 KB
/
mutex_std.rs
File metadata and controls
51 lines (40 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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::{EntryMutexStd, EntrySingle};
impl EntrySync for EntryMutexStd {
fn get_swarm_metadata(&self) -> SwarmMetadata {
self.lock().expect("it should get a lock").get_swarm_metadata()
}
fn meets_retaining_policy(&self, policy: &TrackerPolicy) -> bool {
self.lock().expect("it should get a lock").meets_retaining_policy(policy)
}
fn peers_is_empty(&self) -> bool {
self.lock().expect("it should get a lock").peers_is_empty()
}
fn get_peers_len(&self) -> usize {
self.lock().expect("it should get a lock").get_peers_len()
}
fn get_peers(&self, limit: Option<usize>) -> Vec<Arc<peer::Peer>> {
self.lock().expect("it should get lock").get_peers(limit)
}
fn get_peers_for_client(&self, client: &SocketAddr, limit: Option<usize>) -> Vec<Arc<peer::Peer>> {
self.lock().expect("it should get lock").get_peers_for_client(client, limit)
}
fn upsert_peer(&self, peer: &peer::Peer) -> bool {
self.lock().expect("it should lock the entry").upsert_peer(peer)
}
fn remove_inactive_peers(&self, current_cutoff: DurationSinceUnixEpoch) {
self.lock()
.expect("it should lock the entry")
.remove_inactive_peers(current_cutoff);
}
}
impl From<EntrySingle> for EntryMutexStd {
fn from(entry: EntrySingle) -> Self {
Arc::new(std::sync::Mutex::new(entry))
}
}